diff --git a/lib/register/passes/call_implementation.rb b/lib/register/passes/call_implementation.rb new file mode 100644 index 00000000..81b37246 --- /dev/null +++ b/lib/register/passes/call_implementation.rb @@ -0,0 +1,27 @@ +module Register + + # Defines the method call, ie + # - move the new_message to message + # - unroll self and + # - register call + + # all in all, quite the reverse of a return + + class CallImplementation + def run block + block.codes.dup.each do |code| + next unless code.is_a? Virtual::MethodCall + new_codes = [] + slot = Virtual::Slot + # move the current new_message to message + new_codes << RegisterTransfer.new( slot::NEW_MESSAGE_REGISTER , slot::MESSAGE_REGISTER ) + # "roll out" self into its register + new_codes << GetSlot.new( slot::SELF_REGISTER ,slot::MESSAGE_REGISTER , slot::MESSAGE_SELF ) + # do the register call + new_codes << FunctionCall.new( code.method ) + block.replace(code , new_codes ) + end + end + end + Virtual::BootSpace.space.add_pass "Register::CallImplementation" +end diff --git a/lib/register/register_machine.rb b/lib/register/register_machine.rb index 89d25a42..d1f5e1d8 100644 --- a/lib/register/register_machine.rb +++ b/lib/register/register_machine.rb @@ -3,3 +3,4 @@ require_relative "register_reference" require_relative "assembler" require_relative "passes/set_implementation" require_relative "passes/return_implementation" +require_relative "passes/call_implementation"