Module: YankdupInstruction
- Included in:
- BoolYankdupInstruction, CodeYankdupInstruction, ExecYankdupInstruction, FloatYankdupInstruction, IntYankdupInstruction, NameYankdupInstruction
- Defined in:
- lib/instructions/infrastructure.rb
Instance Attribute Summary collapse
-
#target_stack ⇒ Object
readonly
Returns the value of attribute target_stack.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #derive ⇒ Object
- #initialize(context, target_stack) ⇒ Object
- #preconditions? ⇒ Boolean
- #setup ⇒ Object
Instance Attribute Details
#target_stack ⇒ Object (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
#cleanup ⇒ Object
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 |
#derive ⇒ Object
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
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 |
#setup ⇒ Object
356 357 358 |
# File 'lib/instructions/infrastructure.rb', line 356 def setup @from_where = @context.pop_value(:int) end |