Class: CodeDoCountInstruction
Overview
Again, the original description of this instruction appears to be confusing “CODE.DO*RANGE” with “EXEC.DO*RANGE”; I’ve made the adjustment to the code so that the behavior is as described, not the implementation.
Instance Attribute Summary
Attributes inherited from Instruction
#context
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
22
23
24
25
26
|
# File 'lib/instructions/code/code_do_count.rb', line 22
def cleanup
recursor = CodeblockPoint.new([ValuePoint.new("int",0), @one_less,
InstructionPoint.new("exec_do_range"),@codeblock])
pushes :exec, recursor
end
|
#derive ⇒ Object
17
18
19
20
|
# File 'lib/instructions/code/code_do_count.rb', line 17
def derive
@codeblock = NudgeProgram.new(@code).linked_code
@one_less = ValuePoint.new("int",@destination.value-1)
end
|
#preconditions? ⇒ Boolean
4
5
6
7
8
|
# File 'lib/instructions/code/code_do_count.rb', line 4
def preconditions?
needs ExecDoRangeInstruction
needs :code, 1
needs :int, 1
end
|
#setup ⇒ Object
10
11
12
13
14
15
|
# File 'lib/instructions/code/code_do_count.rb', line 10
def setup
@destination = @context.pop(:int)
@code = @context.pop_value(:code)
raise InstructionMethodError,
"#{self.class.to_nudgecode} needs a positive argument" if @destination.value < 1
end
|