fix comparison operator

< implemented <=
This commit is contained in:
Torsten Ruger
2018-04-23 19:39:16 +03:00
parent ef5854c4df
commit 7a2160e9b4
5 changed files with 117 additions and 32 deletions

View File

@ -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