Class: CodeNameLookupInstruction

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

Overview

pops the top :name item; pushes a new :code item that has a value equal to the current context binding

note: if there is no binding, the resulting :code value will be an empty string

needs: 1 :name

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



26
27
28
# File 'lib/instructions/code/code_name_lookup.rb', line 26

def cleanup
  pushes :code, @result
end

#deriveObject



18
19
20
21
22
23
24
25
# File 'lib/instructions/code/code_name_lookup.rb', line 18

def derive
  bound_value = @context.variables[@the_reference] || @context.names[@the_reference] || nil
  if bound_value != nil
    @result = ValuePoint.new("code", bound_value.blueprint)
  else
    @result = ValuePoint.new("code", "")
  end
end

#preconditions?Boolean

was Push3 CODE.DEFINITION

Returns:

  • (Boolean)


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

def preconditions?
  needs :name, 1
end

#setupObject



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

def setup
  @the_reference = @context.pop_value(:name)
end