Class: CodePositionInstruction
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
19
20
21
|
# File 'lib/instructions/code/code_position.rb', line 19
def cleanup
pushes :int, @result
end
|
#derive ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/instructions/code/code_position.rb', line 9
def derive
looking_for_this = NudgeProgram.new(@arg1).linked_code
inside_this = NudgeProgram.new(@arg2).linked_code
if inside_this && looking_for_this
index = inside_this.find_index {|point| point.blueprint == looking_for_this.blueprint} || -2
else
index = -2
end
@result = ValuePoint.new("int", index+1)
end
|
#preconditions? ⇒ Boolean
2
3
4
|
# File 'lib/instructions/code/code_position.rb', line 2
def preconditions?
needs :code, 2
end
|
#setup ⇒ Object
5
6
7
8
|
# File 'lib/instructions/code/code_position.rb', line 5
def setup
@arg2 = @context.pop_value(:code)
@arg1 = @context.pop_value(:code)
end
|