Class: Vm::Instructions::ArithmeticInstruction
- Inherits:
-
Object
- Object
- Vm::Instructions::ArithmeticInstruction
- Defined in:
- lib/hackasm/vm/instructions/arithmetic_instruction.rb
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
Instance Method Summary collapse
- #comment ⇒ Object
-
#initialize(instruction) ⇒ ArithmeticInstruction
constructor
A new instance of ArithmeticInstruction.
- #to_asm ⇒ Object
Constructor Details
#initialize(instruction) ⇒ ArithmeticInstruction
Returns a new instance of ArithmeticInstruction.
10 11 12 |
# File 'lib/hackasm/vm/instructions/arithmetic_instruction.rb', line 10 def initialize(instruction) @operation = instruction[:operation].to_s end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
8 9 10 |
# File 'lib/hackasm/vm/instructions/arithmetic_instruction.rb', line 8 def operation @operation end |
Instance Method Details
#comment ⇒ Object
25 26 27 |
# File 'lib/hackasm/vm/instructions/arithmetic_instruction.rb', line 25 def comment "// #{operation}\n" end |
#to_asm ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hackasm/vm/instructions/arithmetic_instruction.rb', line 14 def to_asm comment + case operation when *ArithmeticOperations::Comparison.operations ArithmeticOperations::Comparison.new(operation).to_asm when *ArithmeticOperations::UnaryOperation.operations ArithmeticOperations::UnaryOperation.new(operation).to_asm when *ArithmeticOperations::BinaryOperation.operations ArithmeticOperations::BinaryOperation.new(operation).to_asm end.split("\n").map(&:strip).join("\n") end |