add integer minus
rework plus to make that easy
This commit is contained in:
@ -184,7 +184,7 @@ module Risc
|
||||
end
|
||||
|
||||
obj = space.get_class_by_name(:Integer)
|
||||
[ :putint, :mod4, :div10, :+].each do |f| #mod4 is just a forward declaration
|
||||
[ :putint, :mod4, :div10, :+ , :-].each do |f| #mod4 is just a forward declaration
|
||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ module Risc
|
||||
two = compiler.use_reg :fixnum , 2
|
||||
compiler.add_load_data( source , 2 , two )
|
||||
compiler.add_code Risc.op( source , :>> , me , two)
|
||||
compiler.add_new_int(me , two)
|
||||
compiler.add_new_int(source,me , two)
|
||||
compiler.add_reg_to_slot( source , two , :message , :return_value)
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
return compiler.method
|
||||
@ -23,16 +23,20 @@ module Risc
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
return compiler.method
|
||||
end
|
||||
|
||||
def +( context )
|
||||
source = "plus"
|
||||
compiler = compiler_for(:Integer,:+ ,{other: :Integer})
|
||||
me , other = compiler.self_and_int_arg(source + "1")
|
||||
compiler.reduce_int( source + "2", me )
|
||||
compiler.reduce_int( source + "3", other )
|
||||
compiler.add_code Risc.op( source + "4", :+ , me , other)
|
||||
compiler.add_new_int(me , other)
|
||||
compiler.add_reg_to_slot( source + "5" , other , :message , :return_value)
|
||||
operator_method( "plus" , :+)
|
||||
end
|
||||
def -( context )
|
||||
operator_method( "minus" , :-)
|
||||
end
|
||||
def operator_method(op_name , op_sym )
|
||||
compiler = compiler_for(:Integer, op_sym ,{other: :Integer})
|
||||
me , other = compiler.self_and_int_arg(op_name + "load receiver and arg")
|
||||
compiler.reduce_int( op_name + " fix me", me )
|
||||
compiler.reduce_int( op_name + " fix arg", other )
|
||||
compiler.add_code Risc.op( op_name + " operator", op_sym , me , other)
|
||||
compiler.add_new_int(op_name + " new int", me , other)
|
||||
compiler.add_reg_to_slot( op_name + "save ret" , other , :message , :return_value)
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
return compiler.method
|
||||
end
|
||||
@ -92,7 +96,7 @@ module Risc
|
||||
# return q + tmp
|
||||
compiler.add_code Risc.op( s , :+ , q , tmp )
|
||||
|
||||
compiler.add_new_int(q , tmp)
|
||||
compiler.add_new_int(s,q , tmp)
|
||||
compiler.add_reg_to_slot( s , tmp , :message , :return_value)
|
||||
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
|
@ -134,8 +134,8 @@ module Risc
|
||||
|
||||
# move a machine int from register "from" to a Parfait::Integer in register "to"
|
||||
# have to grab an integer from space and stick it in the "to" register first.
|
||||
def add_new_int( from, to )
|
||||
source = "add_new_int "
|
||||
def add_new_int( source , from, to )
|
||||
source += "add_new_int "
|
||||
space = use_reg(:Space)
|
||||
int = use_reg(:Integer)
|
||||
space_i = Risc.resolve_to_index(:Space, :next_integer)
|
||||
|
Reference in New Issue
Block a user