fix the resolve

without return and not being a function
This commit is contained in:
Torsten Ruger 2018-04-08 22:30:18 +03:00
parent e5d014b936
commit 580c53cdae
5 changed files with 58 additions and 84 deletions

View File

@ -33,10 +33,7 @@ module Mom
# directly called by to_risc # directly called by to_risc
# but also used directly in __init # but also used directly in __init
def build_with(builder) def build_with(builder)
from = method_source
builder.build { typed_method << from }
build_message_data(builder) build_message_data(builder)
builder.compiler.reset_regs
return builder.built return builder.built
end end
@ -49,7 +46,9 @@ module Mom
# also put it into next_message of current message (and reverse) # also put it into next_message of current message (and reverse)
# set name and type data in the message, from the method loaded # set name and type data in the message, from the method loaded
def build_message_data( builder ) def build_message_data( builder )
from = method_source
builder.build do builder.build do
typed_method << from
space << Parfait.object_space space << Parfait.object_space
next_message << space[:first_message] next_message << space[:first_message]
message[:next_message] << next_message message[:next_message] << next_message

View File

@ -20,46 +20,47 @@ module Mom
@cache_entry = cache_entry @cache_entry = cache_entry
end end
# resolve the method name of self, on the given object
# may seem wrong way around at first sight, but we know the type of string. And # When the method is resolved, a cache_entry is used to hold the result.
# thus resolving this method happens at compile time, whereas any method on an # That cache_entry (holding type and method) is checked before, and
# unknown self (the object given) needs resolving and that is just what we are doing # needs to be updated by this instruction.
# ( ie the snake bites it's tail) #
# This method is just a placeholder until boot is over and the real method is # We use the type stored in the cache_entry to check the methods if any of it's
# parsed. # names are the same as the given @name
#
# currently a fail results in sys exit
def to_risc( compiler ) def to_risc( compiler )
name = @name name_ = @name
cache_entry = @cache_entry cache_entry_ = @cache_entry
return Risc.label("hi" , "there")
builder = compiler.builder(false) builder = compiler.builder(false)
builder.build do builder.build do
word << name word << name_
cache_entry << cache_entry_
type << cache_entry type << cache_entry[:cached_type]
type << type[:cached_type]
typed_method << type[:methods] typed_method << type[:methods]
add while_start_label add_code while_start_label
space << Parfait.object_space space << Parfait.object_space
space << space[:nil_object] space << space[:nil_object]
space - typed_method space - typed_method
if_zero exit_label if_zero exit_label
name << typed_method[:name] name << typed_method[:name]
name - word name - word
if_not_zero false_label if_zero ok_label
message[:return_value] << typed_method
add Mom::ReturnSequence.new.to_risc(compiler)
add false_label
typed_method << typed_method[:next_method] typed_method << typed_method[:next_method]
branch while_start_label branch while_start_label
add exit_label add_code exit_label
Risc::Builtin::Object.emit_syscall( builder , :exit )
add_code ok_label
cache_entry[:cached_method] << typed_method
end end
Risc::Builtin::Object.emit_syscall( builder , :exit )
return builder.built return builder.built
end end

View File

@ -9,42 +9,40 @@ module Risc
@input = "@a.mod4" @input = "@a.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, @expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, SlotToReg, LoadConstant, RegToSlot, IsZero, SlotToReg, SlotToReg, LoadConstant, RegToSlot,
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, Label,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot, OperatorInstruction, IsZero, SlotToReg, Branch, Label,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, Transfer, Syscall, Transfer, Transfer, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label, Label, RegToSlot, Label, LoadConstant, LoadConstant,
SlotToReg, LoadConstant, RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, RegToSlot, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, DynamicJump]
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
DynamicJump]
end end
def test_send_instructions def test_send_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end
def test_function_call def test_sys
produced = produce_body produced = produce_body
assert_equal DynamicJump , produced.next(65).class assert_equal Syscall , produced.next(26).class
assert_equal :exit , produced.next(26).name
end end
def test_load_address def test_load_address
produced = produce_body produced = produce_body
assert_equal LoadConstant , produced.next(63).class assert_equal LoadConstant , produced.next(38).class
assert_equal Parfait::CacheEntry , produced.next(63).constant.class assert_equal Parfait::CacheEntry , produced.next(38).constant.class
end
def test_function_call
produced = produce_body
assert_equal DynamicJump , produced.next(59).class
end end
def test_cache_check def test_cache_check
produced = produce_body produced = produce_body
assert_equal IsZero , produced.next(5).class assert_equal IsZero , produced.next(5).class
assert_equal Label , produced.next(43).class assert_equal Label , produced.next(37).class
assert_equal produced.next(43) , produced.next(5).label assert_equal produced.next(37) , produced.next(5).label
end
def test_check_resolve
produced = produce_body
assert_equal FunctionCall , produced.next(38).class
assert_equal :resolve_method ,produced.next(38).method.name
end end
end end
end end

View File

@ -14,25 +14,11 @@ module Risc
check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero,
SlotToReg, SlotToReg, LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, LoadConstant, RegToSlot, LoadConstant,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, LoadConstant, SlotToReg, SlotToReg, Label, LoadConstant,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction,
SlotToReg, RegToSlot, SlotToReg, RegToSlot, LoadConstant, IsZero, SlotToReg, Branch, Label, LoadConstant,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, Label, Transfer,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, Syscall, NilClass]
SlotToReg, LoadConstant, FunctionCall, Label, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, Label,
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsNotZero, Label, SlotToReg, Branch,
Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
SlotToReg, OperatorInstruction, IsNotZero, Label, SlotToReg,
Branch, Label, LoadConstant, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, OperatorInstruction, IsNotZero, Label,
SlotToReg, Branch, Label, LoadConstant, SlotToReg,
OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, IsNotZero,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, LoadConstant, RegToSlot,
Label, LoadConstant, LoadConstant, SlotToReg, RegToSlot,
RegToSlot, SlotToReg, SlotToReg]
#assert_equal 1 , get_return #assert_equal 1 , get_return
end end
@ -41,24 +27,10 @@ module Risc
assert_equal FunctionCall , call_ins.class assert_equal FunctionCall , call_ins.class
assert_equal :main , call_ins.method.name assert_equal :main , call_ins.method.name
end end
def test_call_resolve def test_load_entry
call_ins = main_ticks(43) call_ins = main_ticks(5)
assert_equal FunctionCall , call_ins.class assert_equal LoadConstant , call_ins.class
assert_equal :resolve_method , call_ins.method.name assert_equal Parfait::CacheEntry , call_ins.constant.class
end
def test_label
call_ins = main_ticks(44)
assert_equal Label , call_ins.class
assert_equal "Word_Type.resolve_method" , call_ins.name
end
def test_arg_15_to_resolve
sl = main_ticks( 47 )
assert_equal SlotToReg , sl.class
assert_equal :r2 , sl.array.symbol #load from message
assert_equal 2 , sl.index
assert_equal :r2 , sl.register.symbol
assert_equal Parfait::Integer, @interpreter.get_register( :r2 ).class
assert_equal 15, @interpreter.get_register( :r2 ).value
end end
def est_dyn def est_dyn

View File

@ -21,6 +21,10 @@ module Risc
move = @r0 << Parfait.object_space move = @r0 << Parfait.object_space
assert_equal LoadConstant , move.class assert_equal LoadConstant , move.class
end end
def test_load_symbol
move = @r1 << :puts
assert_equal LoadConstant , move.class
end
def test_transfer def test_transfer
transfer = @r0 << @r1 transfer = @r0 << @r1
assert_equal Transfer , transfer.class assert_equal Transfer , transfer.class