phase 2, add/sub instructions work with +- operator

This commit is contained in:
Torsten Ruger
2014-05-20 11:54:59 +03:00
parent c3c6928dc8
commit c7a2ce5af9
3 changed files with 23 additions and 8 deletions

View File

@ -43,13 +43,27 @@ module Vm
end
end
class LogicInstruction < Instruction
# result = left op right
#
# Logic instruction are your basic operator implementation. But unlike the (normal) code we write
# these Instructions must have "place" to write their results. Ie when you write 4 + 5 in ruby
# the result is sort of up in the air, but with Instructions the result must be assigned
def initialize result , left , right , options = {}
@result = result
@left = left
@right = right
super(options)
end
attr_accessor :result
# this is used to write code that looks like assignment
# So instructions can be created without the result (register) set, and this assigns where
# the reuslt after the fact, but usually in the same line
# Example (with block b, and variables int,a,b): b.int = a + b
# a + b actually creates an add instruction while the b.int= assigns the result to int
# b.add( int , a , b) is an alternative (assmbler style) way of writing the same.
def assign left
@result = left
self
end
end
class MathInstruction < Instruction
def initialize first , options = {}

View File

@ -88,7 +88,10 @@ module Vm
end
def + other
class_for(LogicInstruction).new(nil , self , other , :opcode => :add)
class_for(LogicInstruction).new(nil , self , other , opcode: :add)
end
def - other
class_for(LogicInstruction).new(nil , self , other , opcode: :sub , update_status: 1 )
end
def plus block , first , right
CMachine.instance.integer_plus block , self , first , right