fix comparison operator
< implemented <=
This commit is contained in:
@ -20,12 +20,12 @@ module Risc
|
||||
return compiler.method
|
||||
end
|
||||
def >( context )
|
||||
comparison( :> , Risc::IsMinus)
|
||||
comparison( :> )
|
||||
end
|
||||
def <( context )
|
||||
comparison( :< , Risc::IsPlus)
|
||||
comparison( :< )
|
||||
end
|
||||
def comparison( operator , branch )
|
||||
def comparison( operator )
|
||||
compiler = compiler_for(:Integer, operator ,{other: :Integer})
|
||||
builder = compiler.builder(true, compiler.method)
|
||||
me , other = builder.self_and_int_arg("#{operator} load receiver and arg")
|
||||
@ -33,8 +33,12 @@ module Risc
|
||||
merge_label = Risc.label(compiler.method , "merge_label_#{builder.object_id}")
|
||||
builder.reduce_int( "#{operator} fix me", me )
|
||||
builder.reduce_int( "#{operator} fix arg", other )
|
||||
if(operator == :<)
|
||||
me , other = other , me
|
||||
end
|
||||
builder.add_code Risc.op( "#{operator} operator", :- , me , other)
|
||||
builder.add_code branch.new( "#{operator} if", false_label)
|
||||
builder.add_code IsMinus.new( "#{operator} if", false_label)
|
||||
builder.add_code IsZero.new( "#{operator} if", false_label)
|
||||
builder.add_load_constant("#{operator} new int", Parfait.object_space.true_object , other)
|
||||
builder.add_code Risc::Branch.new("jump over false", merge_label)
|
||||
builder.add_code false_label
|
||||
|
Reference in New Issue
Block a user