Class: CodeIfInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/code/code_if.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



19
20
21
# File 'lib/instructions/code/code_if.rb', line 19

def cleanup
  pushes :exec, @result
end

#deriveObject



14
15
16
17
# File 'lib/instructions/code/code_if.rb', line 14

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

#preconditions?Boolean

Returns:

  • (Boolean)


3
4
5
6
# File 'lib/instructions/code/code_if.rb', line 3

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

#setupObject



8
9
10
11
12
# File 'lib/instructions/code/code_if.rb', line 8

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