Class: CodeNthPointInstruction
Overview
was CODE.EXTRACT in Push3
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
18
19
20
|
# File 'lib/instructions/code/code_nth_point.rb', line 18
def cleanup
pushes :code, @result
end
|
#derive ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/instructions/code/code_nth_point.rb', line 10
def derive
tree = NudgeProgram.new(@arg2)
tree_size = tree.points
raise InstructionMethodError, "#{self.class} divied by zero" if tree_size < 1
which = (@arg1-1) % tree_size + 1
pt = tree[which]
@result = ValuePoint.new("code", pt.blueprint)
end
|
#preconditions? ⇒ Boolean
2
3
4
5
|
# File 'lib/instructions/code/code_nth_point.rb', line 2
def preconditions?
needs :int, 1
needs :code, 1
end
|
#setup ⇒ Object
6
7
8
9
|
# File 'lib/instructions/code/code_nth_point.rb', line 6
def setup
@arg1 = @context.pop_value(:int)
@arg2 = @context.pop_value(:code)
end
|