Class: ExecDoTimesInstruction
Instance Attribute Summary
Attributes inherited from Instruction
#context
Instance Method Summary
collapse
Methods inherited from Instruction
all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode
Constructor Details
This class inherits a constructor from Instruction
Instance Method Details
#cleanup ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/instructions/exec/exec_do_times.rb', line 24
def cleanup
if @finished
pushes :exec, @code
else
recursor = CodeblockPoint.new([@new_counter, @destination,
InstructionPoint.new("exec_do_times"),@code])
pushes :exec, recursor
pushes :exec, @code
end
end
|
#derive ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/instructions/exec/exec_do_times.rb', line 13
def derive
@finished = false
if @counter.value == @destination.value
@finished = true
elsif @counter.value < @destination.value
@new_counter = ValuePoint.new("int", @counter.value + 1)
else
@new_counter = ValuePoint.new("int", @counter.value - 1)
end
end
|
#preconditions? ⇒ Boolean
2
3
4
5
|
# File 'lib/instructions/exec/exec_do_times.rb', line 2
def preconditions?
needs :exec, 1
needs :int, 2
end
|
#setup ⇒ Object
7
8
9
10
11
|
# File 'lib/instructions/exec/exec_do_times.rb', line 7
def setup
@destination = @context.pop(:int)
@counter = @context.pop(:int)
@code = @context.pop(:exec)
end
|