Module: YankInstruction

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#target_stackObject (readonly)

Returns the value of attribute target_stack.



300
301
302
# File 'lib/instructions/infrastructure.rb', line 300

def target_stack
  @target_stack
end

Instance Method Details

#cleanupObject



332
333
334
335
# File 'lib/instructions/infrastructure.rb', line 332

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

#deriveObject



320
321
322
323
324
325
326
327
328
329
330
# File 'lib/instructions/infrastructure.rb', line 320

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



302
303
304
305
# File 'lib/instructions/infrastructure.rb', line 302

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

#preconditions?Boolean

Returns:

  • (Boolean)


307
308
309
310
311
312
313
314
# File 'lib/instructions/infrastructure.rb', line 307

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

#setupObject



316
317
318
# File 'lib/instructions/infrastructure.rb', line 316

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