Class: CodeConsInstruction
Overview
This is a tricky one to translate from Push, which assumes a very Lisp-like list structure. Here we’ll simply build a new block with the consed item first, and the original code second.
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
22
23
24
|
# File 'lib/instructions/code/code_cons.rb', line 22
def cleanup
pushes :code, @result
end
|
#derive ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/instructions/code/code_cons.rb', line 11
def derive
t1 = NudgeProgram.new(@arg1)
t2 = NudgeProgram.new(@arg2)
if t1.parses? && t2.parses?
consed_tree = t2.insert_point_before(1,t1.linked_code)
else
raise InstructionMethodError,
"#{self.class.to_nudgecode} cannot parse the arguments"
end
@result = ValuePoint.new("code", consed_tree.blueprint)
end
|
#preconditions? ⇒ Boolean
4
5
6
|
# File 'lib/instructions/code/code_cons.rb', line 4
def preconditions?
needs :code, 2
end
|
#setup ⇒ Object
7
8
9
10
|
# File 'lib/instructions/code/code_cons.rb', line 7
def setup
@arg2 = @context.pop_value(:code)
@arg1 = @context.pop_value(:code)
end
|