Class: ExecDoCountInstruction
- Inherits:
-
Instruction
- Object
- Instruction
- ExecDoCountInstruction
- Defined in:
- lib/instructions/exec/exec_do_count.rb
Overview
Pops one “count” item from the :int
stack, and one item from the :exec
stack. The net effect of the instruction (unless interfered with by another operation) is to evaluate the :exec
item “count” times.
If the count is negative, an :error
item will be pushed to the :error
stack. Otherwise, a ValuePoint containing the following “macro” is created and pushed onto the :exec
stack:
block {
value «int»
value «int»
do exec_do_range
popped item
}
«int» 0
«int» count - 1
where popped_item
is the code from the :exec
stack, and count - 1 is a decrement of the “count” value.
needs: ExecDoRangeInstruction must be active in the context for this to work; needs 1 :int
and 1 :exec
item
pushes: it’s complicated…
Instance Attribute Summary
Attributes inherited from Instruction
Instance Method Summary collapse
Methods inherited from Instruction
all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode
Constructor Details
This class inherits a constructor from Instruction
Instance Method Details
#cleanup ⇒ Object
40 41 42 43 44 |
# File 'lib/instructions/exec/exec_do_count.rb', line 40 def cleanup recursor = CodeblockPoint.new([ValuePoint.new("int",0), @one_less, InstructionPoint.new("exec_do_range"),@code]) pushes :exec, recursor end |
#derive ⇒ Object
35 36 37 38 |
# File 'lib/instructions/exec/exec_do_count.rb', line 35 def derive raise InstructionMethodError, "#{self.class} needs a positive argument" if @destination.value < 1 @one_less = ValuePoint.new("int",@destination.value-1) end |
#preconditions? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/instructions/exec/exec_do_count.rb', line 24 def preconditions? needs ExecDoRangeInstruction needs :exec, 1 needs :int, 1 end |
#setup ⇒ Object
30 31 32 33 |
# File 'lib/instructions/exec/exec_do_count.rb', line 30 def setup @destination = @context.pop(:int) @code = @context.pop(:exec) end |