Class: Whitespace::ISA::Push

Inherits:
Instruction show all
Defined in:
lib/whitespace/instructions/stack_manipulation/push.rb

Instance Attribute Summary collapse

Attributes inherited from Instruction

#vm

Instance Method Summary collapse

Constructor Details

#initialize(vm, n) ⇒ Push

Returns a new instance of Push.



5
6
7
8
9
10
11
# File 'lib/whitespace/instructions/stack_manipulation/push.rb', line 5

def initialize(vm, n)
  unless Whitespace::Util.is_integer?(n)
    raise ArgumentError, "must be an integer: #{n}"
  end
  super(vm)
  @n = n
end

Instance Attribute Details

#nObject (readonly)

Returns the value of attribute n.



3
4
5
# File 'lib/whitespace/instructions/stack_manipulation/push.rb', line 3

def n
  @n
end

Instance Method Details

#executeObject



13
14
15
# File 'lib/whitespace/instructions/stack_manipulation/push.rb', line 13

def execute
  vm.vstack.push n
end