From dd0d162ebfc66c04430fc97ebe4a21532406db74 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 7 Apr 2018 00:14:02 +0300 Subject: [PATCH] fix the init also, was using first message twice not advancing after first load --- lib/mom/instruction/message_setup.rb | 9 ++++++++- lib/risc.rb | 5 ----- lib/risc/builder.rb | 4 ++-- lib/risc/builtin/object.rb | 27 ++++++++++++++++----------- lib/risc/method_compiler.rb | 1 + 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index 5f085ed6..562312dd 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -28,12 +28,19 @@ module Mom # Get the message from Space and link it. def to_risc(compiler) builder = Risc::Builder.new(compiler) + build_with(builder) + end + + # directly called by to_risc + # but also used directly in __init + def build_with(builder) from = method_source risc = builder.build { typed_method << from } build_message_data(builder) - compiler.reset_regs + builder.compiler.reset_regs return risc end + private def source "method setup " diff --git a/lib/risc.rb b/lib/risc.rb index 6cda21c7..095363d0 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -6,11 +6,6 @@ class String self[0].capitalize + self[1..-1] end end -class Symbol - def camelize - self.to_s.camelize.to_sym - end -end # The RiscMachine, is an abstract machine with registers. Think of it as an arm machine with diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index 4ec0ed0a..ff94c9bd 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -2,7 +2,7 @@ module Risc class Builder - attr_reader :built + attr_reader :built , :compiler def initialize(compiler) @compiler = compiler @@ -75,7 +75,7 @@ module Risc when Parfait::Object type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type when Symbol - object = object.camelize + object = object.to_s.camelize.to_sym clazz = Parfait.object_space.get_class_by_name(object) raise "Not implemented/found object #{object}:#{object.class}" unless clazz type = clazz.instance_type diff --git a/lib/risc/builtin/object.rb b/lib/risc/builtin/object.rb index 42421123..e87b9381 100644 --- a/lib/risc/builtin/object.rb +++ b/lib/risc/builtin/object.rb @@ -46,17 +46,22 @@ module Risc def __init__ context compiler = Risc::MethodCompiler.create_method(:Object,:__init__ , Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({})) - space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init - compiler.add_load_constant("__init__ load Space", Parfait.object_space , space_reg) - message_ind = Risc.resolve_to_index( :Space , :first_message ) - #load the first_message (instance of space) - compiler.add_slot_to_reg( "__init__ load 1st message" , space_reg , message_ind , :message) - compiler.add_mom( Mom::MessageSetup.new(Parfait.object_space.get_main)) - # but use it's next message, so main can return normally - compiler.add_slot_to_reg( "__init__ load 2nd message" , :message , :next_message , :message) - compiler.add_load_constant("__init__ load Space", Parfait.object_space , space_reg) - compiler.add_reg_to_slot( "__init__ store Space in message", space_reg , :message , :receiver) - #fixme: should add arg type here, as done in call_site (which this sort of is) + builder = Risc::Builder.new(compiler) + risc = builder.build do + space << Parfait.object_space + message << space[:first_message] + next_message << message[:next_message] + space[:first_message] << next_message + end + compiler.add_code(risc) + + Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder ) + + builder.build do + message << message[:next_message] + message[:receiver] << space + end + exit_label = Risc.label("_exit_label for __init__" , "#{compiler.type.object_class.name}.#{compiler.method.name}" ) ret_tmp = compiler.use_reg(:Label) compiler.add_load_constant("__init__ load return", exit_label , ret_tmp) diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 859a9203..2fa99ecc 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -79,6 +79,7 @@ module Risc instruction = instruction.next end end + # add a risc instruction after the current (insertion point) # the added instruction will become the new insertion point def add_code( instruction )