From ad6be2676c0f645919a5d1fe0916b850031940bf Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 23 Aug 2014 23:37:33 +0300 Subject: [PATCH] start on call implementation, getting separation issues --- lib/boot/boot_space.rb | 7 +------ lib/register/call_implementation.rb | 22 ++++++++++++++++++++++ lib/register/get_implementation.rb | 7 ++++--- lib/register/register_machine.rb | 1 + lib/register/set_implementation.rb | 6 +++--- 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 lib/register/call_implementation.rb diff --git a/lib/boot/boot_space.rb b/lib/boot/boot_space.rb index b6102b4f..1495ee0f 100644 --- a/lib/boot/boot_space.rb +++ b/lib/boot/boot_space.rb @@ -31,6 +31,7 @@ module Boot def run_passes @passes.each do |pass| + puts "Runnning pass #{pass}" all = main.blocks @classes.each_value do |c| c.method_definitions.each {|f| all += f.blocks } @@ -55,12 +56,6 @@ module Boot raise "No such pass to add after: #{after}" unless index @passes.insert(index , pass) end - - def add_pass_after( pass , after) - index = @passes.index(after) - raise "No such pass to add after: #{after}" unless index - @passes.insert(index , pass) - end # boot the classes, ie create a minimal set of classes with a minimal set of functions # minimal means only that which can not be coded in ruby # MethodDefinitions are grabbed from respective modules by sending the method name. This should return the diff --git a/lib/register/call_implementation.rb b/lib/register/call_implementation.rb new file mode 100644 index 00000000..d384a17c --- /dev/null +++ b/lib/register/call_implementation.rb @@ -0,0 +1,22 @@ +module Register + # This implements call logic, which is simply like a c call (not send, that involves lookup and all sorts) + # + # The only target for a call is a MethodDefinition, so we just need to get the address for the code + # and call it. + # + # The only slight snag is that we would need to assemble before getting the address, but to assemble + # we'd have to have finished compiling. So we need a reference. + class CallImplementation + def run block + block.codes.dup.each do |code| + next unless code.is_a? Virtual::FunctionCall + to = RegisterReference.new(:r0) + tmp = RegisterReference.new(:r5) + move = RegisterMachine.instance.ldr( to , tmp , code.to.index ) + block.replace(code , [move] ) + + end + end + end + Virtual::Object.space.add_pass_after CallImplementation , SetImplementation +end diff --git a/lib/register/get_implementation.rb b/lib/register/get_implementation.rb index 66454b73..fdea7f3b 100644 --- a/lib/register/get_implementation.rb +++ b/lib/register/get_implementation.rb @@ -1,7 +1,8 @@ module Register - # This implements the send logic - # Send is so complicated that we actually code it in ruby and stick it in - # That off course opens up an endless loop possibility that we stop by reducing to Class and Module methods + # This implements instance variable get (not the opposite of Set, such a thing does not exists, their slots) + + # Ivar get needs to acces the layout, find the index of the name, and shuffle the data to return register + # In short it's so complicated we implement it in ruby and stick the implementation here class GetImplementation def run block block.codes.dup.each do |code| diff --git a/lib/register/register_machine.rb b/lib/register/register_machine.rb index c56d2e03..19d8b40b 100644 --- a/lib/register/register_machine.rb +++ b/lib/register/register_machine.rb @@ -148,4 +148,5 @@ require_relative "instruction" require_relative "register_reference" require_relative "get_implementation" require_relative "set_implementation" +require_relative "call_implementation" require "arm/arm_machine" diff --git a/lib/register/set_implementation.rb b/lib/register/set_implementation.rb index 241c5752..5750fc59 100644 --- a/lib/register/set_implementation.rb +++ b/lib/register/set_implementation.rb @@ -1,7 +1,7 @@ module Register - # This implements the send logic - # Send is so complicated that we actually code it in ruby and stick it in - # That off course opens up an endless loop possibility that we stop by reducing to Class and Module methods + # This implements setting of the various slot variables the vm defines. + # Basic mem moves, but have to shuffle the type nibbles + class SetImplementation def run block block.codes.dup.each do |code|