Class: CodeNthInstruction
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
21
22
23
|
# File 'lib/instructions/code/code_nth.rb', line 21
def cleanup
pushes :code, @result
end
|
#derive ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/instructions/code/code_nth.rb', line 10
def derive
tree = NudgeProgram.new(@arg2)
if tree.linked_code.kind_of?(CodeblockPoint)
pts = tree[1].contents.length
raise InstructionMethodError, "#{self.class} can't work on empty blocks" if pts < 1
val = tree[1].contents[@arg1 % pts]
else
val = tree
end
@result = ValuePoint.new("code", val.blueprint)
end
|
#preconditions? ⇒ Boolean
2
3
4
5
|
# File 'lib/instructions/code/code_nth.rb', line 2
def preconditions?
needs :int, 1
needs :code, 1
end
|
#setup ⇒ Object
6
7
8
9
|
# File 'lib/instructions/code/code_nth.rb', line 6
def setup
@arg1 = @context.pop_value(:int)
@arg2 = @context.pop_value(:code)
end
|