diff --git a/Gemfile b/Gemfile index bb452ad5..4f10a271 100644 --- a/Gemfile +++ b/Gemfile @@ -5,9 +5,11 @@ gem "salama" , :path => "." gem "rake" gem "salama-reader" , :github => "salama/salama-reader" +#gem "salama-reader" , :path => "../salama-reader" gem "salama-object-file" , :github => "salama/salama-object-file" #gem "salama-object-file" , :path => "../salama-object-file" gem "salama-arm" , :github => "salama/salama-arm" +#gem "salama-arm" , :path => "../salama-arm" gem "codeclimate-test-reporter", require: nil diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 807a9eb9..424fd959 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -32,7 +32,7 @@ module Elf # add_symbol "main@#{b.name}" , b.position # end # add_symbol "#register@#{@object_machine.space.init.name}" , @object_machine.space.init.position - @object_machine.objects.each do |slot| + @object_machine.objects.each do |id,slot| if( slot.respond_to? :sof_reference_name ) label = "#{slot.sof_reference_name}" else diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index d6be8c61..7842576b 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -25,7 +25,7 @@ module Register # want to have the methods first in the executable # so first we determine the code length for the methods and set the # binary code (array) to right length - @machine.objects.each do |objekt| + @machine.objects.each do |id , objekt| next unless objekt.is_a? Parfait::Method # should be fill_to_length (with zeros) objekt.code.set_length(objekt.source.byte_length , 0) @@ -36,14 +36,14 @@ module Register at += 8 # thats the padding # then we make sure we really get the binary codes first - @machine.objects.each do |objekt| + @machine.objects.each do |id , objekt| next unless objekt.is_a? Parfait::BinaryCode objekt.set_position at #puts "CODE #{objekt.name} at #{objekt.position}" at += objekt.word_length end # and then everything else - @machine.objects.each do | objekt| + @machine.objects.each do | id , objekt| # have to tell the code that will be assembled where it is to # get the jumps/calls right if objekt.is_a? Parfait::Method @@ -69,14 +69,14 @@ module Register # case we try again. Once. def try_write assemble - all = @machine.objects.sort{|a,b| a.position <=> b.position} + all = @machine.objects.values.sort{|a,b| a.position <=> b.position} # debugging loop accesses all positions to force an error if it's not set all.each do |objekt| #puts "Linked #{objekt.class}(#{objekt.object_id.to_s(16)}) at #{objekt.position.to_s(16)} / #{objekt.word_length.to_s(16)}" objekt.position end # first we need to create the binary code for the methods - @machine.objects.each do |objekt| + @machine.objects.each do |id , objekt| next unless objekt.is_a? Parfait::Method assemble_binary_method(objekt) end @@ -89,12 +89,12 @@ module Register end # then write the methods to file - @machine.objects.each do |objekt| + @machine.objects.each do |id, objekt| next unless objekt.is_a? Parfait::BinaryCode write_any( objekt ) end # and then the rest of the object machine - @machine.objects.each do | objekt| + @machine.objects.each do | id, objekt| next if objekt.is_a? Parfait::BinaryCode write_any( objekt ) end @@ -159,7 +159,7 @@ module Register # write type and layout of the instance, and the variables that are passed # variables ar values, ie int or refs. For refs the object needs to save the object first def write_object( object ) - unless @machine.objects.include? object + unless @machine.objects.has_key? object.object_id raise "Object(#{object.object_id}) not linked #{object.inspect}" end layout = object.get_layout diff --git a/lib/register/builtin/object.rb b/lib/register/builtin/object.rb index 84177f0b..b7a33dbe 100644 --- a/lib/register/builtin/object.rb +++ b/lib/register/builtin/object.rb @@ -18,7 +18,7 @@ module Register # The at_index is just "below" the api, something we need but don't want to expose, # so we can't code the above in ruby def _get_instance_variable context , name = Virtual::Integer - get_function = Virtual::MethodSource.create_method(:Object,:_get_instance_variable , [ Virtual::Reference ] ) + get_function = Virtual::MethodSource.create_method(:Object,:_get_instance_variable , [ ] ) return get_function me = get_function.receiver var_name = get_function.args.first @@ -39,7 +39,7 @@ module Register end def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer ) - set_function = Virtual::MethodSource.create_method(:Object,:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference] ) + set_function = Virtual::MethodSource.create_method(:Object,:_set_instance_variable ,[] ) return set_function receiver set_function me = set_function.receiver diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index bc0d3379..873d7ad5 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -93,6 +93,7 @@ module Virtual # Objects are data and get assembled after functions def add_object o return false if @objects[o.object_id] + raise "adding non parfait #{o.class}" unless o.is_a? Parfait::Object or o.is_a? Symbol @objects[o.object_id] = o true end diff --git a/lib/virtual/parfait_adapter.rb b/lib/virtual/parfait_adapter.rb index 2d943c5f..6df1cabf 100644 --- a/lib/virtual/parfait_adapter.rb +++ b/lib/virtual/parfait_adapter.rb @@ -25,7 +25,7 @@ class Symbol end def get_layout l = Virtual.machine.space.classes[:Word].object_layout - puts "LL #{l.class}" + #puts "LL #{l.class}" l end def word_length @@ -42,7 +42,7 @@ class Symbol pos = cache_positions[self] if pos == nil str = "position accessed but not set, " - str += "Machine has object=#{Virtual.machine.objects.include?(self)} " + str += "Machine has object=#{Virtual.machine.objects.has_key?(self.object_id)} " raise str + " for Symbol:#{self}" end pos @@ -168,7 +168,7 @@ module Parfait # name comes in as a ruby @var name def instance_variable_get name var = get_instance_variable name.to_s[1 .. -1].to_sym - puts "getting #{name} #{var}" + #puts "getting #{name} #{var}" var end end diff --git a/lib/virtual/passes/collector.rb b/lib/virtual/passes/collector.rb index a9505b0d..0036aa2a 100644 --- a/lib/virtual/passes/collector.rb +++ b/lib/virtual/passes/collector.rb @@ -12,17 +12,17 @@ module Virtual return unless Virtual.machine.add_object object #puts "adding #{object.class}" return unless object.respond_to? :has_layout? - unless object.has_layout? - object.init_layout - end if( object.is_a? Parfait::Method) - object.source.constants.each{|c| keep(c) } + object.source.constants.each{|c| + puts "keeping constant #{c.class}" + keep(c) + } end layout = object.get_layout keep layout - #puts "Layout #{layout.object_class.name} #{Machine.instance.objects.include?(layout)}" + #puts "Layout #{layout.object_class.name} #{Machine.instance.objects.has_key?(layout.object_id)}" layout.object_instance_names.each do |name| - inst = object.instance_variable_get "@#{name}".to_sym + inst = object.get_instance_variable name keep inst end if object.is_a? Parfait::List diff --git a/lib/virtual/positioned.rb b/lib/virtual/positioned.rb index 0b9fac92..105d9dcd 100644 --- a/lib/virtual/positioned.rb +++ b/lib/virtual/positioned.rb @@ -3,7 +3,7 @@ require_relative "type" module Positioned def position if @position.nil? - str = "IN machine #{Virtual.machine.objects.include?(self)}, at #{self.object_id.to_s(16)}\n" + str = "IN machine #{Virtual.machine.objects.has_key?(self.object_id)}, at #{self.object_id.to_s(16)}\n" raise str + "position not set for #{self.class} len #{word_length} for #{self.inspect[0...100]}" end @position diff --git a/test/compiler/test_hello.rb b/test/compiler/test_hello.rb index 040f6391..b697b644 100644 --- a/test/compiler/test_hello.rb +++ b/test/compiler/test_hello.rb @@ -30,7 +30,7 @@ HERE check end - def ttest_string_put + def test_string_put @string_input = <