implement smaller than comparison
which is NOT an operator in the risc sense rather a minus and a check for sign (which _could be more efficient in arm, with conditional execution)
This commit is contained in:
parent
9e21719aeb
commit
be3d125b82
@ -184,7 +184,7 @@ module Risc
|
||||
Risc.operators.each do |op|
|
||||
obj.instance_type.add_method Builtin::Integer.operator_method(op)
|
||||
end
|
||||
[:putint, :div4, :div10].each do |f| #div4 is just a forward declaration
|
||||
[:putint, :div4, :div10 , :<].each do |f| #div4 is just a forward declaration
|
||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
end
|
||||
|
@ -114,7 +114,7 @@ module Risc
|
||||
add_slot_to_reg(source , int_arg , at + 1, int_arg ) #1 for type
|
||||
return int_arg
|
||||
end
|
||||
|
||||
|
||||
# assumed Integer in given register is replaced by the fixnum that it is holding
|
||||
def reduce_int( source , register )
|
||||
add_slot_to_reg( source + "int -> fix" , register , Parfait::Integer.integer_index , register)
|
||||
|
@ -19,6 +19,25 @@ module Risc
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
return compiler.method
|
||||
end
|
||||
def <( context )
|
||||
compiler = compiler_for(:Integer, :< ,{other: :Integer})
|
||||
builder = compiler.builder(true, compiler.method)
|
||||
me , other = builder.self_and_int_arg("< load receiver and arg")
|
||||
false_label = Risc.label(compiler.method , "false_label_#{builder.object_id}")
|
||||
merge_label = Risc.label(compiler.method , "merge_label_#{builder.object_id}")
|
||||
builder.reduce_int( "< fix me", me )
|
||||
builder.reduce_int( "< fix arg", other )
|
||||
builder.add_code Risc.op( "< operator", :- , me , other)
|
||||
builder.add_code Risc::IsPlus.new( "< if", false_label)
|
||||
builder.add_load_constant("< new int", Parfait.object_space.true_object , other)
|
||||
builder.add_code Risc::Branch.new("jump over false", merge_label)
|
||||
builder.add_code false_label
|
||||
builder.add_load_constant("< new int", Parfait.object_space.false_object , other)
|
||||
builder.add_code merge_label
|
||||
builder.add_reg_to_slot( "< save ret" , other , :message , :return_value)
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
return compiler.method
|
||||
end
|
||||
def putint(context)
|
||||
compiler = compiler_for(:Integer,:putint ,{})
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
|
@ -31,7 +31,7 @@ module Risc
|
||||
end
|
||||
def test_smaller
|
||||
run_all "4 < 5"
|
||||
assert_equal 16 , get_return.value
|
||||
assert_equal Parfait::TrueClass , get_return.class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user