Module: DefineInstruction

Included in:
BoolDefineInstruction, ExecDefineInstruction, FloatDefineInstruction, IntDefineInstruction
Defined in:
lib/instructions/infrastructure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#target_stackObject (readonly)

Returns the value of attribute target_stack.



380
381
382
# File 'lib/instructions/infrastructure.rb', line 380

def target_stack
  @target_stack
end

Instance Method Details

#cleanupObject



406
407
408
# File 'lib/instructions/infrastructure.rb', line 406

def cleanup
  @context.bind_name(@bound_name, @new_value)
end

#deriveObject



401
402
403
404
# File 'lib/instructions/infrastructure.rb', line 401

def derive
  raise Instruction::InstructionMethodError, "#{self.class} cannot redefine a variable" if
    @context.variables[@bound_name] != nil
end

#initialize(context, target_stack) ⇒ Object



382
383
384
385
# File 'lib/instructions/infrastructure.rb', line 382

def initialize(context, target_stack)
  @target_stack = target_stack
  super(context)
end

#preconditions?Boolean

Returns:

  • (Boolean)


387
388
389
390
391
392
393
394
# File 'lib/instructions/infrastructure.rb', line 387

def preconditions?
  if @target_stack != :name
    needs @target_stack, 1
    needs :name, 1
  else
    needs :name, 2
  end
end

#setupObject



396
397
398
399
# File 'lib/instructions/infrastructure.rb', line 396

def setup
  @bound_name = @context.pop_value(:name)
  @new_value =  @context.pop(@target_stack)
end