Class: Whitespace::ISA::Binop
- Inherits:
-
Instruction
- Object
- Instruction
- Whitespace::ISA::Binop
- Defined in:
- lib/whitespace/instructions/arithmetic/binop.rb
Instance Attribute Summary
Attributes inherited from Instruction
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(vm, op) ⇒ Binop
constructor
A new instance of Binop.
Constructor Details
#initialize(vm, op) ⇒ Binop
Returns a new instance of Binop.
3 4 5 6 7 8 9 |
# File 'lib/whitespace/instructions/arithmetic/binop.rb', line 3 def initialize(vm, op) unless Whitespace::Util.is_binop?(op) raise ArgumentError, "must be a binary operator: #{op}" end super(vm) @op = op end |
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 |
# File 'lib/whitespace/instructions/arithmetic/binop.rb', line 11 def execute right = vm.vstack.pop left = vm.vstack.pop vm.vstack.push Whitespace::Util::BINOPS[@op].call(left, right) end |