From 595e032edf092559ee030a8d970ebd372119a1fc Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 6 Aug 2018 13:03:33 +0300 Subject: [PATCH] add function_return helper to risc_value create a function_return from within builder --- lib/mom/instruction/message_setup.rb | 2 +- lib/risc/register_value.rb | 8 ++++++++ test/risc/test_register_value.rb | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index d8f3eb8f..ecea38e8 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -6,7 +6,7 @@ module Mom # MessageSetup does Setup before a call can be made, acquiring and filling the message # basically.Only after MessageSetup is the next_message safe to use. # - # The space keeps a linked list of Messages, from which we take and currenty also return. + # The Space keeps a linked list of Messages, from which we take and currenty also return. # # Message setup set the name to the called method's name, and also set the arg and local # types on the new message, currently for debugging but later for dynamic checking diff --git a/lib/risc/register_value.rb b/lib/risc/register_value.rb index 02d9ce97..2d6b5180 100644 --- a/lib/risc/register_value.rb +++ b/lib/risc/register_value.rb @@ -134,6 +134,14 @@ module Risc op end + # generate a Function return instruction + # using the register as the parameter where the return address is passed + def function_return + ret = Risc::FunctionReturn.new("return", self) + builder.add_code(ret) if builder + ret + end + # just capture the values in an intermediary object (RValue) # The RValue then gets used in a RegToSlot ot SlotToReg, where # the values are unpacked to call Risc.reg_to_slot or Risc.slot_to_reg diff --git a/test/risc/test_register_value.rb b/test/risc/test_register_value.rb index e99bdc0e..4c484814 100644 --- a/test/risc/test_register_value.rb +++ b/test/risc/test_register_value.rb @@ -41,6 +41,11 @@ module Risc assert_equal :next_message , message.index assert_equal @r0 , message.register end + def test_return + ret = @r0.function_return + assert_equal FunctionReturn , ret.class + assert_equal @r0 , ret.register + end def test_slot_to_reg instr = @r0 << @r1[:next_message] assert_equal SlotToReg , instr.class