Class: CodeContainsQInstruction
- Inherits:
-
Instruction
- Object
- Instruction
- CodeContainsQInstruction
- Defined in:
- lib/instructions/code/code_contains_q.rb
Overview
pops the top 2 item of the :code
stack; pushes a new ValuePoint onto the :bool
stack, with value true
if the second argument appears as a sub-block anywhere in the first argument
note: order matters, and the top stack item is the second argument, the second stack item is the first
needs: 2 :code
pushes: 1 :bool
Instance Attribute Summary
Attributes inherited from Instruction
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
30 31 32 |
# File 'lib/instructions/code/code_contains_q.rb', line 30 def cleanup pushes :bool, @result end |
#derive ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/instructions/code/code_contains_q.rb', line 20 def derive looking_for_this = NudgeProgram.new(@arg1) tree = NudgeProgram.new(@arg2) if tree.parses? && looking_for_this.parses? found = tree.linked_code.any? {|point| point.blueprint == looking_for_this.blueprint} else found = false end @result = ValuePoint.new("bool", found) end |
#preconditions? ⇒ Boolean
13 14 15 |
# File 'lib/instructions/code/code_contains_q.rb', line 13 def preconditions? needs :code, 2 end |
#setup ⇒ Object
16 17 18 19 |
# File 'lib/instructions/code/code_contains_q.rb', line 16 def setup @arg2 = @context.pop_value(:code) @arg1 = @context.pop_value(:code) end |