Module: ShoveInstruction

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#target_stackObject (readonly)

Returns the value of attribute target_stack.



260
261
262
# File 'lib/instructions/infrastructure.rb', line 260

def target_stack
  @target_stack
end

Instance Method Details

#cleanupObject



293
294
295
# File 'lib/instructions/infrastructure.rb', line 293

def cleanup
  @context.stacks[@target_stack].entries.insert(@new_depth,@result)
end

#deriveObject



281
282
283
284
285
286
287
288
289
290
291
# File 'lib/instructions/infrastructure.rb', line 281

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

#initialize(context, target_stack) ⇒ Object



262
263
264
265
# File 'lib/instructions/infrastructure.rb', line 262

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

#preconditions?Boolean

Returns:

  • (Boolean)


267
268
269
270
271
272
273
274
# File 'lib/instructions/infrastructure.rb', line 267

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

#setupObject



276
277
278
279
# File 'lib/instructions/infrastructure.rb', line 276

def setup
  @how_far = @context.pop_value(:int)
  @result = @context.pop(@target_stack)
end