add reduce_int and fix bug
hardcoded operator, buh reduce_int to avoid that long constant
This commit is contained in:
parent
f5ea51c4d0
commit
78466090b3
@ -52,6 +52,13 @@ module Risc
|
|||||||
return index
|
return index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# reduce integer to fixnum and add instruction if builder is used
|
||||||
|
def reduce_int
|
||||||
|
reduce = Risc.slot_to_reg( "int -> fix" , self , Parfait::Integer.integer_index , self)
|
||||||
|
builder.add_code(reduce) if builder
|
||||||
|
reduce
|
||||||
|
end
|
||||||
|
|
||||||
# when following variables in resolve_and_add, get a new RegisterValue
|
# when following variables in resolve_and_add, get a new RegisterValue
|
||||||
# that represents the new value.
|
# that represents the new value.
|
||||||
# Ie in "normal case" a the same register, with the type of the slot
|
# Ie in "normal case" a the same register, with the type of the slot
|
||||||
@ -151,7 +158,7 @@ module Risc
|
|||||||
# create operator instruction for self and add
|
# create operator instruction for self and add
|
||||||
# doesn't read quite as smoothly as one would like, but better than the compiler version
|
# doesn't read quite as smoothly as one would like, but better than the compiler version
|
||||||
def op( operator , right)
|
def op( operator , right)
|
||||||
ret = Risc.op( "operator #{operator}" , :>> , self , right)
|
ret = Risc.op( "operator #{operator}" , operator , self , right)
|
||||||
builder.add_code(ret) if builder
|
builder.add_code(ret) if builder
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
@ -57,6 +57,7 @@ module Risc
|
|||||||
assert_equal OperatorInstruction , ret.class
|
assert_equal OperatorInstruction , ret.class
|
||||||
assert_equal @r0 , ret.left
|
assert_equal @r0 , ret.left
|
||||||
assert_equal @r1 , ret.right
|
assert_equal @r1 , ret.right
|
||||||
|
assert_equal :<< , ret.operator
|
||||||
end
|
end
|
||||||
def test_slot_to_reg
|
def test_slot_to_reg
|
||||||
instr = @r0 << @r1[:next_message]
|
instr = @r0 << @r1[:next_message]
|
||||||
|
@ -16,6 +16,11 @@ module Risc
|
|||||||
def test_resolves_index_fail
|
def test_resolves_index_fail
|
||||||
assert_raises {@r0.resolve_index(:something)}
|
assert_raises {@r0.resolve_index(:something)}
|
||||||
end
|
end
|
||||||
|
def test_reduce_int
|
||||||
|
ins = @r0.reduce_int
|
||||||
|
assert_equal SlotToReg , ins.class
|
||||||
|
assert_equal Parfait::Integer.integer_index , ins.index
|
||||||
|
end
|
||||||
def test_get_new_left_0
|
def test_get_new_left_0
|
||||||
assert_equal RegisterValue , @r0.get_new_left(:caller , @compiler).class
|
assert_equal RegisterValue , @r0.get_new_left(:caller , @compiler).class
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user