Class: CodeConcatenateInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/code/code_concatenate.rb

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

#cleanupObject



28
29
30
# File 'lib/instructions/code/code_concatenate.rb', line 28

def cleanup
  pushes :code, @result
end

#deriveObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/instructions/code/code_concatenate.rb', line 9

def derive
  t1 = NudgeProgram.new(@arg1)
  t2 = NudgeProgram.new(@arg2)
  if t1.parses? && t2.parses?
    if t1.linked_code.kind_of?(CodeblockPoint)
      if t2.linked_code.kind_of?(CodeblockPoint)
        new_tree = t1[1].contents + t2[1].contents
      else
        new_tree = t1[1].contents << t2.linked_code
      end
    else
      new_tree = [t1.linked_code, t2.linked_code]
    end
    listed = CodeblockPoint.new(new_tree).blueprint
    @result = ValuePoint.new("code", listed)
  else
    @result = ValuePoint.new("code", "block {}")
  end
end

#preconditions?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/instructions/code/code_concatenate.rb', line 2

def preconditions?
  needs :code, 2
end

#setupObject



5
6
7
8
# File 'lib/instructions/code/code_concatenate.rb', line 5

def setup
  @arg2 = @context.pop_value(:code)
  @arg1 = @context.pop_value(:code)
end