From 59e6298879d37fe548dd68a01b13739d1a646515 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 8 Apr 2018 23:45:23 +0300 Subject: [PATCH] first resolved call running though and returning an int, as it should just the value . . . --- lib/mom/instruction/message_setup.rb | 16 ++++++++-- lib/risc/interpreter.rb | 6 ++-- test/mom/send/test_send_dynamic.rb | 12 ++++---- test/risc/interpreter/test_dynamic_call.rb | 36 +++++++++++++++++----- 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index 698aa0cb..ab432b3e 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -27,12 +27,24 @@ module Mom # Move method name, frame and arguemnt types from the method to the next_message # Get the message from Space and link it. def to_risc(compiler) - build_with(compiler.builder(false)) + builder = compiler.builder(false) + build_with(builder) end # directly called by to_risc # but also used directly in __init def build_with(builder) + case from = method_source + when Parfait::TypedMethod + builder.build { typed_method << from } + when Parfait::CacheEntry + builder.build do + cache_entry << from + typed_method << cache_entry[:cached_method] + end + else + raise "unknown source #{method_source}" + end build_message_data(builder) return builder.built end @@ -46,9 +58,7 @@ 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 diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index d93db209..aa58b12c 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -91,11 +91,11 @@ module Risc def execute_Label true end + # Instruction interpretation starts here def execute_DynamicJump - label = get_register(@instruction.register) - puts "Jump to :#{label}:" - set_instruction label + method = get_register(@instruction.register) + set_instruction( method.risc_instructions ) end def execute_Branch label = @instruction.label diff --git a/test/mom/send/test_send_dynamic.rb b/test/mom/send/test_send_dynamic.rb index 366412aa..d9378ff5 100644 --- a/test/mom/send/test_send_dynamic.rb +++ b/test/mom/send/test_send_dynamic.rb @@ -15,11 +15,11 @@ module Risc 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] + LoadConstant, SlotToReg, 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 @@ -37,7 +37,7 @@ module Risc end def test_function_call produced = produce_body - assert_equal DynamicJump , produced.next(61).class + assert_equal DynamicJump , produced.next(62).class end def test_cache_check produced = produce_body diff --git a/test/risc/interpreter/test_dynamic_call.rb b/test/risc/interpreter/test_dynamic_call.rb index f1a6835a..2474e653 100644 --- a/test/risc/interpreter/test_dynamic_call.rb +++ b/test/risc/interpreter/test_dynamic_call.rb @@ -12,14 +12,34 @@ module Risc def test_chain #show_main_ticks # get output of what is check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, - SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, - SlotToReg, SlotToReg, LoadConstant, RegToSlot, LoadConstant, - 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 + SlotToReg, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, + IsZero, SlotToReg, SlotToReg, SlotToReg, LoadConstant, + RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, + Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero, + SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, + Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero, + SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, + Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero, + SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, + Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero, + SlotToReg, OperatorInstruction, IsZero, Label, RegToSlot, + Label, LoadConstant, SlotToReg, LoadConstant, SlotToReg, + RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, RegToSlot, + SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, DynamicJump, Label, + SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + SlotToReg, LoadData, OperatorInstruction, LoadData, OperatorInstruction, + OperatorInstruction, LoadData, Transfer, OperatorInstruction, OperatorInstruction, + LoadData, Transfer, OperatorInstruction, OperatorInstruction, LoadData, + Transfer, OperatorInstruction, OperatorInstruction, LoadData, OperatorInstruction, + LoadData, Transfer, OperatorInstruction, OperatorInstruction, Transfer, + LoadData, OperatorInstruction, LoadData, OperatorInstruction, OperatorInstruction, + LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, FunctionReturn, Transfer, Syscall, NilClass] + assert_equal Parfait::Integer , get_return.class + #assert_equal 1 , get_return.value end def test_call_main