diff --git a/lib/parfait/message.rb b/lib/parfait/message.rb index 2e5de9af..52d0603b 100644 --- a/lib/parfait/message.rb +++ b/lib/parfait/message.rb @@ -1,6 +1,9 @@ # this is not a "normal" ruby file, ie it is not required by salama # instead it is parsed by salama to define part of the program that runs +class Frame #just for now +end + class Message def get_type_for(name) @@ -8,7 +11,7 @@ class Message get_at(index) end - def __send__ + def __send typ = get_type_for( :receiver ) # TODO: this will obviously be recoded as case, once that is done :-) # depending on value type get method diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index 1396357a..3321be3a 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -164,6 +164,10 @@ module Register send("add_#{clazz}".to_sym , object) end + def add_Message m + end + def add_Frame f + end def add_Array( array ) # also array has constant overhead, the padded helper fixes it to multiple of 8 array.each do |elem| diff --git a/lib/register/enter_implementation.rb b/lib/register/enter_implementation.rb index 89eb4828..715ceaf4 100644 --- a/lib/register/enter_implementation.rb +++ b/lib/register/enter_implementation.rb @@ -4,11 +4,12 @@ module Register def run block block.codes.dup.each do |code| next unless code.is_a? Virtual::MethodEnter + new_codes = [] # save return register and create a new frame - to = RegisterReference.new(:r0) # message base - pc = RegisterReference.new(:pc) - move1 = RegisterMachine.instance.str( pc , to , Virtual::Slot::MESSAGE_RETURN_VALUE ) - block.replace(code , [move1] ) + # lr is link register, ie where arm stores the return address when call is issued + new_codes << RegisterMachine.instance.str( :lr , Virtual::Slot::MESSAGE_REGISTER , Virtual::Slot::MESSAGE_RETURN_ADDRESS ) + new_codes << Virtual::NewFrame.new + block.replace(code , new_codes ) end end end diff --git a/lib/virtual/boot_space.rb b/lib/virtual/boot_space.rb index d92a0706..1a0aa368 100644 --- a/lib/virtual/boot_space.rb +++ b/lib/virtual/boot_space.rb @@ -14,17 +14,17 @@ module Virtual class BootSpace < Virtual::Object - # Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX - # with a XXXMachine in it that derives from Virtual::RegisterMachine - def initialize machine = nil + def initialize super() @classes = Parfait::Hash.new @main = Virtual::CompiledMethod.new("main" , [] ) #global objects (data) @objects = [] @symbols = [] - @messages = [] - @frames = [] + @messages = 100.times.collect{ ::Message.new } + @frames = 100.times.collect{ ::Frame.new } + @next_message = @messages.first + @next_frame = @frames.first @passes = [ Virtual::SendImplementation ] end attr_reader :main , :classes , :objects , :symbols,:messages,:frames @@ -77,7 +77,7 @@ module Virtual obj.add_instance_method Builtin::Object.send(f , @context) end obj = get_or_create_class :Kernel - [:main , :__init__,:putstring,:exit,:__send__].each do |f| + [:main , :__init__,:putstring,:exit,:__send].each do |f| obj.add_instance_method Builtin::Kernel.send(f , @context) end obj = get_or_create_class :Integer diff --git a/lib/virtual/message.rb b/lib/virtual/message.rb index ca8d19da..dd3725c4 100644 --- a/lib/virtual/message.rb +++ b/lib/virtual/message.rb @@ -44,6 +44,7 @@ module Virtual end # def compile_get method , name + raise "CALLED" if method.has_arg(name) method.add_code MessageGet.new(name) else diff --git a/lib/virtual/object.rb b/lib/virtual/object.rb index 253d5a79..f2346412 100644 --- a/lib/virtual/object.rb +++ b/lib/virtual/object.rb @@ -1,4 +1,5 @@ require_relative "type" +require "parfait/message" module Virtual # our machine is made up of objects, some of which are code, some data @@ -80,6 +81,22 @@ module Virtual end end end +::Message.class_eval do + def layout + Virtual::Object.layout + end + def mem_length + Virtual::Object.new.padded_words(2) + end +end +::Frame.class_eval do + def layout + Virtual::Object.layout + end + def mem_length + Virtual::Object.new.padded_words(2) + end +end Parfait::Hash.class_eval do HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]} def layout diff --git a/lib/virtual/send_implementation.rb b/lib/virtual/send_implementation.rb index b104f197..28703f90 100644 --- a/lib/virtual/send_implementation.rb +++ b/lib/virtual/send_implementation.rb @@ -27,7 +27,7 @@ module Virtual # note: this is the current view: call internal send, even the method name says else # but send is "special" and accesses the internal method name and resolves. kernel = Virtual::BootSpace.space.get_or_create_class(:Kernel) - method = kernel.get_instance_method(:__send__) + method = kernel.get_instance_method(:__send) new_codes << FunctionCall.new( method ) raise "unimplemented #{code}" end