Class: CodeIfInstruction

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

Overview

pops the top 2 items of the :code stack, and one :bool; returns the top :code item if the :bool is false, the second one if true

needs: 2 :code, 1 :bool

pushes: 1 :code

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



27
28
29
# File 'lib/instructions/code/code_if.rb', line 27

def cleanup
  pushes :exec, @result
end

#deriveObject



22
23
24
25
# File 'lib/instructions/code/code_if.rb', line 22

def derive
  which = @stay ? @ifTrue : @ifFalse
  @result = NudgeProgram.new(which).linked_code
end

#preconditions?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/instructions/code/code_if.rb', line 11

def preconditions?
  needs :code, 2
  needs :bool, 1
end

#setupObject



16
17
18
19
20
# File 'lib/instructions/code/code_if.rb', line 16

def setup
  @stay = @context.pop_value(:bool)
  @ifFalse = @context.pop_value(:code)
  @ifTrue = @context.pop_value(:code)
end