From 5d870ef154a1e97ed8ded46745ba6d01ff56aaed Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 31 May 2015 17:54:36 +0300 Subject: [PATCH] got it down to string equality/identity --- lib/parfait/module.rb | 2 +- lib/register/assembler.rb | 9 +++++++++ lib/register/instructions/load_constant.rb | 6 +++--- lib/virtual/machine.rb | 1 + lib/virtual/parfait_adapter.rb | 8 ++++---- lib/virtual/passes/send_implementation.rb | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/parfait/module.rb b/lib/parfait/module.rb index ecbf17f2..d2a9cf7c 100644 --- a/lib/parfait/module.rb +++ b/lib/parfait/module.rb @@ -19,7 +19,7 @@ module Parfait @instance_methods = List.new_object @name = name @super_class = superclass - @meta_class = MetaClass.new(self) + @meta_class = nil#MetaClass.new(self) end def name diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index 7d5ab91e..c2c213d7 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -45,6 +45,10 @@ module Register objekt.set_position at at += objekt.mem_length end + @machine.objects.each do |objekt| + objekt.position + end + end def assemble @@ -84,11 +88,16 @@ module Register # and then plonk that binary data into the method.code array def assemble_binary_method method stream = StringIO.new + begin method.info.blocks.each do |block| block.codes.each do |code| code.assemble( stream ) end end + rescue => e + puts "Method error #{method.name}\n#{Sof::Writer.write(method.info.blocks).to_s[0...2000]}" + raise e + end method.code.fill_with 0 index = 1 stream.each_byte do |b| diff --git a/lib/register/instructions/load_constant.rb b/lib/register/instructions/load_constant.rb index 205f3b78..4efd805c 100644 --- a/lib/register/instructions/load_constant.rb +++ b/lib/register/instructions/load_constant.rb @@ -1,14 +1,14 @@ module Register # load a constant into a register # - # first arguemnt is the register the constant is loaded into + # first arguemnt is the register the constant is loaded into # second is the actual constant - + class LoadConstant < Instruction def initialize value , constant @value = value @constant = constant end - attr_accessor :value , :constant + attr_accessor :value , :constant end end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 6b915c72..382f3a58 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -60,6 +60,7 @@ module Virtual raise "no such pass-class as #{pass_class}" unless pass pass.new.run(block) end + #puts @space.get_main if pass_class == "Virtual::SendImplementation" end end diff --git a/lib/virtual/parfait_adapter.rb b/lib/virtual/parfait_adapter.rb index d474fa47..fa35cd98 100644 --- a/lib/virtual/parfait_adapter.rb +++ b/lib/virtual/parfait_adapter.rb @@ -9,8 +9,6 @@ module FakeMem super() @memory = [0,nil] @position = nil - @length = -1 - # Virtual::Machine.instance.add_object self if Virtual::Machine.instance.class_mappings init_layout else @@ -26,12 +24,14 @@ module FakeMem end #TODO, this is copied from module Positioned, maybe avoid duplication ? def position - if @position == nil - raise "position not set for #{self.class} at #{mem_length} for #{self.inspect[0...1000]}" + if @position.nil? + str = "IN machine #{Virtual::Machine.instance.objects.include?(self)}\n" + raise str + "position not set for #{self.class} at #{mem_length} for #{self.inspect[0...100]}" end @position end def set_position pos + raise "Setting of nil not allowed" if pos.nil? # resetting of position used to be error, but since relink and dynamic instruction size it is ok. # in measures (of 32) if @position != nil and ((@position - pos).abs > 32) diff --git a/lib/virtual/passes/send_implementation.rb b/lib/virtual/passes/send_implementation.rb index 326a928d..9ab72dbc 100644 --- a/lib/virtual/passes/send_implementation.rb +++ b/lib/virtual/passes/send_implementation.rb @@ -39,7 +39,7 @@ module Virtual if ref.type.is_a?(Reference) and ref.type.of_class #find method and call clazz = ref.type.of_class - method = clazz.resolve_method code.name + method = clazz.resolve_method code.name.to_s raise "No method found #{code.name}" unless method new_codes << MethodCall.new( method ) else