Class: Whitespace::ISA::Njmp
- Inherits:
-
Instruction
- Object
- Instruction
- Whitespace::ISA::Njmp
- Defined in:
- lib/whitespace/instructions/flow_control/njmp.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Instruction
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(vm, name) ⇒ Njmp
constructor
A new instance of Njmp.
Constructor Details
#initialize(vm, name) ⇒ Njmp
Returns a new instance of Njmp.
5 6 7 8 9 10 11 |
# File 'lib/whitespace/instructions/flow_control/njmp.rb', line 5 def initialize(vm, name) unless Whitespace::Util.is_label?(name) raise ArgumentError, "must be a label: #{name}" end super(vm) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/whitespace/instructions/flow_control/njmp.rb', line 3 def name @name end |
Instance Method Details
#execute ⇒ Object
13 14 15 16 17 18 |
# File 'lib/whitespace/instructions/flow_control/njmp.rb', line 13 def execute if vm.vstack.pop < 0 index = Whitespace::Util.find_label(vm.instructions, name) vm.pc.change_to index + 1 end end |