Class: CodeDoRangeInstruction
Overview
That description must be flawed; “a recursive call to CODE.DO*RANGE” would not run the same code, but rather run the next piece of code from the :code stack. I’m interpreting it as a typo, and using exec_do_range instead, since that will have the desired outcome without running through all kinds of weird :code items.
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
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/instructions/code/code_do_range.rb', line 32
def cleanup
if @finished
pushes :int, @counter
pushes :exec, @codeblock
else
pushes :int, @counter
pushes :exec, @recursor
pushes :exec, @codeblock
end
end
|
#derive ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/instructions/code/code_do_range.rb', line 18
def derive
@codeblock = NudgeProgram.new(@code).linked_code
@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
@recursor = CodeblockPoint.new([@new_counter, @destination,
InstructionPoint.new("exec_do_range"),@codeblock])
end
|
#preconditions? ⇒ Boolean
6
7
8
9
10
|
# File 'lib/instructions/code/code_do_range.rb', line 6
def preconditions?
needs ExecDoRangeInstruction
needs :code, 1
needs :int, 2
end
|
#setup ⇒ Object
12
13
14
15
16
|
# File 'lib/instructions/code/code_do_range.rb', line 12
def setup
@destination = @context.pop(:int)
@counter = @context.pop(:int)
@code = @context.pop_value(:code)
end
|