fix the resolve
without return and not being a function
This commit is contained in:
parent
e5d014b936
commit
580c53cdae
@ -33,10 +33,7 @@ module Mom
|
||||
# directly called by to_risc
|
||||
# but also used directly in __init
|
||||
def build_with(builder)
|
||||
from = method_source
|
||||
builder.build { typed_method << from }
|
||||
build_message_data(builder)
|
||||
builder.compiler.reset_regs
|
||||
return builder.built
|
||||
end
|
||||
|
||||
@ -49,7 +46,9 @@ module Mom
|
||||
# also put it into next_message of current message (and reverse)
|
||||
# set name and type data in the message, from the method loaded
|
||||
def build_message_data( builder )
|
||||
from = method_source
|
||||
builder.build do
|
||||
typed_method << from
|
||||
space << Parfait.object_space
|
||||
next_message << space[:first_message]
|
||||
message[:next_message] << next_message
|
||||
|
@ -20,46 +20,47 @@ module Mom
|
||||
@cache_entry = cache_entry
|
||||
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
|
||||
# thus resolving this method happens at compile time, whereas any method on an
|
||||
# unknown self (the object given) needs resolving and that is just what we are doing
|
||||
# ( ie the snake bites it's tail)
|
||||
# This method is just a placeholder until boot is over and the real method is
|
||||
# parsed.
|
||||
|
||||
# When the method is resolved, a cache_entry is used to hold the result.
|
||||
# That cache_entry (holding type and method) is checked before, and
|
||||
# needs to be updated by this instruction.
|
||||
#
|
||||
# We use the type stored in the cache_entry to check the methods if any of it's
|
||||
# names are the same as the given @name
|
||||
#
|
||||
# currently a fail results in sys exit
|
||||
def to_risc( compiler )
|
||||
name = @name
|
||||
cache_entry = @cache_entry
|
||||
return Risc.label("hi" , "there")
|
||||
name_ = @name
|
||||
cache_entry_ = @cache_entry
|
||||
builder = compiler.builder(false)
|
||||
builder.build do
|
||||
word << name
|
||||
word << name_
|
||||
cache_entry << cache_entry_
|
||||
|
||||
type << cache_entry
|
||||
type << type[:cached_type]
|
||||
type << cache_entry[:cached_type]
|
||||
typed_method << type[:methods]
|
||||
|
||||
add while_start_label
|
||||
add_code while_start_label
|
||||
|
||||
space << Parfait.object_space
|
||||
space << space[:nil_object]
|
||||
|
||||
space - typed_method
|
||||
if_zero exit_label
|
||||
|
||||
name << typed_method[:name]
|
||||
name - word
|
||||
|
||||
if_not_zero false_label
|
||||
message[:return_value] << typed_method
|
||||
add Mom::ReturnSequence.new.to_risc(compiler)
|
||||
if_zero ok_label
|
||||
|
||||
add false_label
|
||||
typed_method << typed_method[:next_method]
|
||||
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
|
||||
Risc::Builtin::Object.emit_syscall( builder , :exit )
|
||||
return builder.built
|
||||
end
|
||||
|
||||
|
@ -9,42 +9,40 @@ module Risc
|
||||
@input = "@a.mod4"
|
||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
|
||||
IsZero, SlotToReg, SlotToReg, LoadConstant, RegToSlot,
|
||||
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label,
|
||||
SlotToReg, LoadConstant, RegToSlot, Label, LoadConstant,
|
||||
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
|
||||
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
||||
SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
DynamicJump]
|
||||
LoadConstant, LoadConstant, SlotToReg, SlotToReg, Label,
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, SlotToReg, Branch, Label,
|
||||
Transfer, Syscall, Transfer, Transfer, LoadConstant,
|
||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot,
|
||||
Label, RegToSlot, Label, LoadConstant, LoadConstant,
|
||||
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
||||
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
||||
RegToSlot, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, DynamicJump]
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def test_function_call
|
||||
def test_sys
|
||||
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
|
||||
def test_load_address
|
||||
produced = produce_body
|
||||
assert_equal LoadConstant , produced.next(63).class
|
||||
assert_equal Parfait::CacheEntry , produced.next(63).constant.class
|
||||
assert_equal LoadConstant , produced.next(38).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
|
||||
def test_cache_check
|
||||
produced = produce_body
|
||||
assert_equal IsZero , produced.next(5).class
|
||||
assert_equal Label , produced.next(43).class
|
||||
assert_equal produced.next(43) , 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
|
||||
assert_equal Label , produced.next(37).class
|
||||
assert_equal produced.next(37) , produced.next(5).label
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,25 +14,11 @@ module Risc
|
||||
check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero,
|
||||
SlotToReg, SlotToReg, LoadConstant, RegToSlot, LoadConstant,
|
||||
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
|
||||
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
||||
SlotToReg, RegToSlot, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||
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]
|
||||
LoadConstant, SlotToReg, SlotToReg, Label, LoadConstant,
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction,
|
||||
IsZero, SlotToReg, Branch, Label, LoadConstant,
|
||||
SlotToReg, OperatorInstruction, IsZero, Label, Transfer,
|
||||
Syscall, NilClass]
|
||||
#assert_equal 1 , get_return
|
||||
end
|
||||
|
||||
@ -41,24 +27,10 @@ module Risc
|
||||
assert_equal FunctionCall , call_ins.class
|
||||
assert_equal :main , call_ins.method.name
|
||||
end
|
||||
def test_call_resolve
|
||||
call_ins = main_ticks(43)
|
||||
assert_equal FunctionCall , call_ins.class
|
||||
assert_equal :resolve_method , call_ins.method.name
|
||||
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
|
||||
def test_load_entry
|
||||
call_ins = main_ticks(5)
|
||||
assert_equal LoadConstant , call_ins.class
|
||||
assert_equal Parfait::CacheEntry , call_ins.constant.class
|
||||
end
|
||||
|
||||
def est_dyn
|
||||
|
@ -21,6 +21,10 @@ module Risc
|
||||
move = @r0 << Parfait.object_space
|
||||
assert_equal LoadConstant , move.class
|
||||
end
|
||||
def test_load_symbol
|
||||
move = @r1 << :puts
|
||||
assert_equal LoadConstant , move.class
|
||||
end
|
||||
def test_transfer
|
||||
transfer = @r0 << @r1
|
||||
assert_equal Transfer , transfer.class
|
||||
|
Loading…
Reference in New Issue
Block a user