Class: Whitespace::ISA::Njmp

Inherits:
Instruction show all
Defined in:
lib/whitespace/instructions/flow_control/njmp.rb

Instance Attribute Summary collapse

Attributes inherited from Instruction

#vm

Instance Method Summary collapse

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

#nameObject (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

#executeObject



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