fix allocate in builder
which accessed unknown types. also moved assert_allocate to support
This commit is contained in:
parent
c9fedec230
commit
8abcaa330b
@ -144,13 +144,13 @@ module Risc
|
|||||||
null = load_object Parfait.object_space.nil_object
|
null = load_object Parfait.object_space.nil_object
|
||||||
int = nil
|
int = nil
|
||||||
build do
|
build do
|
||||||
int = factory[:next_object].to_reg
|
int = factory[:next_object].to_reg.known_type(:Integer)
|
||||||
null.op :- , int
|
null.op :- , int
|
||||||
if_not_zero cont_label
|
if_not_zero cont_label
|
||||||
factory[:next_object] << factory[:reserve]
|
factory[:next_object] << factory[:reserve]
|
||||||
call_get_more
|
call_get_more
|
||||||
add_code cont_label
|
add_code cont_label
|
||||||
factory[:next_object] << factory[:next_object][:next_integer]
|
factory[:next_object] << int[:next_integer]
|
||||||
end
|
end
|
||||||
int
|
int
|
||||||
end
|
end
|
||||||
|
@ -14,8 +14,8 @@ module SlotMachine
|
|||||||
# the code is added to compiler
|
# the code is added to compiler
|
||||||
# the register returned
|
# the register returned
|
||||||
def to_register(compiler, source)
|
def to_register(compiler, source)
|
||||||
slots = @slots
|
|
||||||
left = Risc.message_named_reg
|
left = Risc.message_named_reg
|
||||||
|
slots = @slots
|
||||||
while( slots )
|
while( slots )
|
||||||
left = left.resolve_and_add( slots.name , compiler)
|
left = left.resolve_and_add( slots.name , compiler)
|
||||||
slots = slots.next_slot
|
slots = slots.next_slot
|
||||||
@ -30,7 +30,6 @@ module SlotMachine
|
|||||||
# They are very similar (apart from the final reg_to_slot here) and should
|
# They are very similar (apart from the final reg_to_slot here) and should
|
||||||
# most likely be united
|
# most likely be united
|
||||||
def reduce_and_load(const_reg , compiler , original_source )
|
def reduce_and_load(const_reg , compiler , original_source )
|
||||||
raise "Not Message #{object}" unless known_object == :message
|
|
||||||
left = Risc.message_named_reg
|
left = Risc.message_named_reg
|
||||||
slot = slots
|
slot = slots
|
||||||
while( slot.next_slot )
|
while( slot.next_slot )
|
||||||
|
@ -3,6 +3,8 @@ require_relative "../helper"
|
|||||||
module Risc
|
module Risc
|
||||||
class TestCompilerBuilder < MiniTest::Test
|
class TestCompilerBuilder < MiniTest::Test
|
||||||
include Parfait::MethodHelper
|
include Parfait::MethodHelper
|
||||||
|
include HasCompiler
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@method = SlotMachine::SlotCollection.compiler_for( :Space , :main,{},{}).callable
|
@method = SlotMachine::SlotCollection.compiler_for( :Space , :main,{},{}).callable
|
||||||
@ -18,7 +20,11 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_allocate_len
|
def test_allocate_len
|
||||||
int = @builder.allocate_int
|
int = @builder.allocate_int
|
||||||
assert_equal 23 , @builder.compiler.risc_instructions.length
|
assert_equal 22 , @builder.compiler.risc_instructions.length
|
||||||
|
end
|
||||||
|
def test_allocate
|
||||||
|
int = @builder.allocate_int
|
||||||
|
assert_allocate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,41 +18,6 @@ module SlotMachine
|
|||||||
@risc_i.next( at )
|
@risc_i.next( at )
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_return(at)
|
|
||||||
assert_label at , "return_label"
|
|
||||||
assert_slot_to_reg at + 1 , :message , 6 , "message.caller"
|
|
||||||
assert_slot_to_reg at + 2 , "message" , 5 , "message.return_value"
|
|
||||||
assert_reg_to_slot at + 3 ,"message.return_value" , "message.caller" , 5
|
|
||||||
assert_slot_to_reg at + 4 , :message , 4 , "message.return_address"
|
|
||||||
assert_slot_to_reg at + 5 , :message , 6 , :message
|
|
||||||
assert_equal Risc::FunctionReturn , risc(at + 6).class
|
|
||||||
assert_label at + 7 , "unreachable"
|
|
||||||
end
|
|
||||||
def assert_allocate
|
|
||||||
assert_load 1 , Parfait::Factory , "id_factory_"
|
|
||||||
assert_load 2 , Parfait::NilClass , "id_nilclass_"
|
|
||||||
assert_slot_to_reg 3 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
||||||
assert_operator 4 , :- , "id_nilclass_" , "id_factory_.next_object"
|
|
||||||
assert_not_zero 5 , "cont_label"
|
|
||||||
assert_slot_to_reg 6 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
||||||
assert_reg_to_slot 7 , "id_factory_.next_object" , "id_factory_" , 2
|
|
||||||
assert_load 8 , Parfait::Factory , "id_factory_"
|
|
||||||
assert_load 9 , Parfait::CallableMethod , "id_callablemethod"
|
|
||||||
assert_slot_to_reg 10 , :message , 1 , "message.next_message"
|
|
||||||
assert_reg_to_slot 11 , "id_callablemethod_" , "message.next_message" , 7
|
|
||||||
assert_reg_to_slot 12 , "id_factory_" , :message , 2
|
|
||||||
assert_load 13 , Risc::Label , "id_label"
|
|
||||||
assert_slot_to_reg 14 , :message , 1 , "message.next_message"
|
|
||||||
assert_reg_to_slot 15 , "id_label" , "message.next_message" , 4
|
|
||||||
assert_slot_to_reg 16 ,:message , 1 , :message
|
|
||||||
assert_equal Risc::FunctionCall, risc(17).class
|
|
||||||
assert_equal :main, risc(17).method.name
|
|
||||||
assert_label 18 , "after_main_"
|
|
||||||
assert_label 19 , "cont_label"
|
|
||||||
assert_slot_to_reg 20 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
||||||
assert_slot_to_reg 21 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
||||||
assert_reg_to_slot 22 , "id_factory_.next_object" , "id_factory_" , 2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -136,5 +136,43 @@ module Minitest
|
|||||||
assert_equal Risc::LoadData , ins.class, "Class at:#{ins_i}"
|
assert_equal Risc::LoadData , ins.class, "Class at:#{ins_i}"
|
||||||
assert_equal data , ins.constant , "Data at:#{ins_i}"
|
assert_equal data , ins.constant , "Data at:#{ins_i}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_return(at)
|
||||||
|
assert_label at , "return_label"
|
||||||
|
assert_slot_to_reg at + 1 , :message , 6 , "message.caller"
|
||||||
|
assert_slot_to_reg at + 2 , "message" , 5 , "message.return_value"
|
||||||
|
assert_reg_to_slot at + 3 ,"message.return_value" , "message.caller" , 5
|
||||||
|
assert_slot_to_reg at + 4 , :message , 4 , "message.return_address"
|
||||||
|
assert_slot_to_reg at + 5 , :message , 6 , :message
|
||||||
|
assert_equal Risc::FunctionReturn , risc(at + 6).class
|
||||||
|
assert_label at + 7 , "unreachable"
|
||||||
|
end
|
||||||
|
def assert_allocate
|
||||||
|
assert_load 1 , Parfait::Factory , "id_factory_"
|
||||||
|
assert_load 2 , Parfait::NilClass , "id_nilclass_"
|
||||||
|
assert_slot_to_reg 3 , "id_factory_" , 2 , "id_factory_.next_object"
|
||||||
|
assert_operator 4 , :- , "id_nilclass_" , "id_factory_.next_object"
|
||||||
|
assert_not_zero 5 , "cont_label"
|
||||||
|
assert_slot_to_reg 6 , "id_factory_" , 3 , "id_factory_.reserve"
|
||||||
|
assert_reg_to_slot 7 , "id_factory_.reserve" , "id_factory_" , 2
|
||||||
|
assert_load 8 , Parfait::Factory , "id_factory_"
|
||||||
|
assert_load 9 , Parfait::CallableMethod , "id_callablemethod"
|
||||||
|
assert_slot_to_reg 10 , :message , 1 , "message.next_message"
|
||||||
|
assert_reg_to_slot 11 , "id_callablemethod_" , "message.next_message" , 7
|
||||||
|
assert_reg_to_slot 12 , "id_factory_" , :message , 2
|
||||||
|
assert_load 13 , Risc::Label , "id_label"
|
||||||
|
assert_slot_to_reg 14 , :message , 1 , "message.next_message"
|
||||||
|
assert_reg_to_slot 15 , "id_label" , "message.next_message" , 4
|
||||||
|
assert_slot_to_reg 16 ,:message , 1 , :message
|
||||||
|
assert_equal Risc::FunctionCall, risc(17).class
|
||||||
|
assert_equal :main, risc(17).method.name
|
||||||
|
assert_label 18 , "after_main_"
|
||||||
|
assert_label 19 , "cont_label"
|
||||||
|
assert_slot_to_reg 20 , "id_factory_.next_object" , 1 , "id_factory_.next_object.next_integer"
|
||||||
|
assert_reg_to_slot 21 , "id_factory_.next_object.next_integer" , "id_factory_" , 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def Risc.allocate_length
|
||||||
|
21
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user