Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // fibonacci algorithm
- {
- Script s;
- uint32_t label_for = s.createLabel();
- uint32_t label_end = s.createLabel();
- // a = 1
- s.pushi_e(1);
- s.pop_v(var_a, DataType::i32);
- // b = 1
- s.pushi_e(1);
- s.pop_v(var_b, DataType::i32);
- // for(i=0; i<10; i+=1) {
- s.pushi_e(0);
- s.pop_v(var_i, DataType::i32);
- s.setLabel(label_for);
- s.push_v(var_i);
- s.pushi_e(10);
- s.set(DataType::i32, DataType::variable, CompFunc::lt);
- s.bf(label_end);
- // t = b
- s.push_v(var_b);
- s.pop_v(var_t, DataType::variable);
- // b += a
- s.push_v(var_b);
- s.push_v(var_a);
- s.add(DataType::variable, DataType::variable);
- s.pop_v(var_b, DataType::variable);
- // a = t
- s.push_v(var_t);
- s.pop_v(var_a, DataType::variable);
- // i+=1
- s.push_v(var_i);
- s.pushi_e(1);
- s.add(DataType::i32, DataType::variable);
- s.pop_v(var_i, DataType::variable);
- s.b(label_for);
- s.setLabel(label_end);
- script_event = sim.addObjectEvent(
- object0_ind, EventType::create, std::move(s) );
- }
Advertisement
Add Comment
Please, Sign In to add comment