Module: YankdupInstruction

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#target_stackObject (readonly)

Returns the value of attribute target_stack.



340
341
342
# File 'lib/instructions/infrastructure.rb', line 340

def target_stack
  @target_stack
end

Instance Method Details

#cleanupObject



372
373
374
375
# File 'lib/instructions/infrastructure.rb', line 372

def cleanup
  moved_value = @context.stacks[@target_stack].entries[@which].clone
  @context.stacks[@target_stack].push(moved_value)
end

#deriveObject



360
361
362
363
364
365
366
367
368
369
370
# File 'lib/instructions/infrastructure.rb', line 360

def derive
  max = @context.stacks[@target_stack].depth-1
  case 
  when @from_where < 0
    @which = max
  when @from_where > max
    @which = 0
  else
    @which = max - @from_where 
  end
end

#initialize(context, target_stack) ⇒ Object



342
343
344
345
# File 'lib/instructions/infrastructure.rb', line 342

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

#preconditions?Boolean

Returns:

  • (Boolean)


347
348
349
350
351
352
353
354
# File 'lib/instructions/infrastructure.rb', line 347

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

#setupObject



356
357
358
# File 'lib/instructions/infrastructure.rb', line 356

def setup
  @from_where = @context.pop_value(:int)
end