more fix for multilevel constant load

was ignoring first level which is already the second for a constant
as the constant is the first load.
first interpreter test working but looking dodgy
This commit is contained in:
Torsten Ruger 2018-03-22 19:14:22 +02:00
parent 34903829ca
commit 55832315eb
6 changed files with 47 additions and 33 deletions

View File

@ -78,6 +78,8 @@ module Mom
type = compiler.method.arguments
when :receiver
type = compiler.method.for_type
when Parfait::Object
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
else
raise "Not implemented/found object #{object}"
end
@ -98,6 +100,7 @@ module Mom
@known_object , @slots = object , slots
slot = [slot] unless slot.is_a?(Array)
raise "Not known #{slots}" unless object
raise "No slots #{object}" unless slots
end
def to_register(compiler, instruction)
@ -106,6 +109,11 @@ module Mom
case known_object
when Constant , Parfait::Object , Risc::Label
const = Risc.load_constant(instruction, known_object , right)
if slots.length > 0
# desctructively replace the existing value to be loaded if more slots
index = SlotLoad.resolve_to_index(known_object , slots[0] ,compiler)
const << Risc::SlotToReg.new( instruction , right ,index, right)
end
when Symbol
const = Risc::SlotToReg.new( instruction , Risc.resolve_to_register(known_object) ,
Risc.resolve_to_index(:message , slots[0]), right)

View File

@ -17,10 +17,10 @@ module Mom
def to_risc(compiler)
false_label = @false_jump.to_risc(compiler)
left = @condition.to_register(compiler,self)
false_load = SlotDefinition.new( FalseConstant.new , nil ).to_register(compiler,self)
false_load = SlotDefinition.new( FalseConstant.new , [] ).to_register(compiler,self)
left << false_load
left << Risc::IsSame.new(self , left.register , false_load.register , false_label)
nil_load = SlotDefinition.new( NilConstant.new , nil ).to_register(compiler,self)
nil_load = SlotDefinition.new( NilConstant.new , [] ).to_register(compiler,self)
left << nil_load
left << Risc::IsSame.new(self , left.register , nil_load.register , false_label)
left

View File

@ -7,10 +7,11 @@ module Risc
def setup
super
@input = "r = 5.mod4"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant ,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg ,
LoadConstant, FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot]
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant ,
FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot]
end
def test_local_assign_instructions
assert_nil msg = check_nil , msg
@ -18,7 +19,7 @@ module Risc
def test_constant_load
produced = produce_body
assert_equal 5 , produced.next(11).constant.value
assert_equal 5 , produced.next(16).constant.value
end
end
end

View File

@ -7,15 +7,17 @@ module Risc
def setup
super
@input = "@a.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, NotSame, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, NotSame, SlotToReg ,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot ,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot ,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot ,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant ,
FunctionCall, Label, SlotToReg, RegToSlot, Label, LoadConstant ,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot ,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, DynamicJump]
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg ,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, DynamicJump]
end
def test_send_instructions
@ -23,21 +25,22 @@ module Risc
end
def test_function_call
produced = produce_body
assert_equal DynamicJump , produced.next(52).class
assert_equal DynamicJump , produced.next(63).class
end
def test_load_address
produced = produce_body
assert_equal Parfait::CacheEntry , produced.next(50).constant.class
assert_equal LoadConstant , produced.next(61).class
assert_equal Parfait::CacheEntry , produced.next(61).constant.class
end
def test_cache_check
produced = produce_body
assert_equal NotSame , produced.next(3).class
assert_equal produced.next(34) , produced.next(3).label
assert_equal NotSame , produced.next(4).class
assert_equal produced.next(40) , produced.next(4).label
end
def test_check_resolve
produced = produce_body
assert_equal FunctionCall , produced.next(30).class
assert_equal :resolve_method ,produced.next(30).method.name
assert_equal FunctionCall , produced.next(36).class
assert_equal :resolve_method ,produced.next(36).method.name
end
end
end

View File

@ -7,10 +7,11 @@ module Risc
def setup
super
@input = "5.mod4"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant ,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg ,
LoadConstant, FunctionCall, Label]
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant ,
FunctionCall, Label]
end
def test_send_instructions
@ -18,24 +19,24 @@ module Risc
end
def test_function_call
produced = produce_body
assert_equal FunctionCall , produced.next(19).class
assert_equal :mod4 , produced.next(19).method.name
assert_equal FunctionCall , produced.next(24).class
assert_equal :mod4 , produced.next(24).method.name
end
def test_check_continue
produced = produce_body
assert produced.next(20).name.start_with?("continue_")
assert produced.next(25).name.start_with?("continue_")
end
def test_load_label
produced = produce_body
assert_equal Label , produced.next(14).constant.class
assert_equal Label , produced.next(19).constant.class
end
def test_load_5
produced = produce_body
assert_equal 5 , produced.next(11).constant.value
assert_equal 5 , produced.next(16).constant.value
end
def test_call_reg_setup
produced = produce_body
assert_equal produced.next(18).register , produced.next(19).register
assert_equal produced.next(23).register , produced.next(24).register
end
#TODO check the message setup, type and frame moves
end

View File

@ -19,11 +19,12 @@ HERE
#show_ticks # get output of what is
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant,
FunctionCall, Label, Label, NilClass]
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label,
Label, NilClass]
end
def pest_get