From 4ddfcc490048565484cd45b51e973d3fe19a17ae Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 3 Jun 2015 10:01:59 +0300 Subject: [PATCH] assembles more already --- lib/parfait/binary_code.rb | 6 +++++- lib/parfait/layout.rb | 4 ++++ lib/parfait/method.rb | 2 +- lib/parfait/object.rb | 4 ++++ lib/register/assembler.rb | 12 ++++++++---- lib/virtual/parfait_adapter.rb | 2 +- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index 9eaf37cb..cf66f7e9 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -15,7 +15,7 @@ module Parfait @name = name end attr_reader :name - + # this is a sof check if there are instance variables or "structure" # have to override false, as word answers true def is_value? @@ -24,5 +24,9 @@ module Parfait def to_s "BinaryCode #{@name}" end + + def == other + self.object_id == other.object_id + end end end diff --git a/lib/parfait/layout.rb b/lib/parfait/layout.rb index 440a3953..65909983 100644 --- a/lib/parfait/layout.rb +++ b/lib/parfait/layout.rb @@ -28,6 +28,10 @@ module Parfait @object_class = object_class end + def == other + self.object_id == other.object_id + end + # add the name of an instance variable # The index will be returned and can subsequently be searched with index_of # The index of the name is the index of the data in the object diff --git a/lib/parfait/method.rb b/lib/parfait/method.rb index 4cda023b..fe67e4e0 100644 --- a/lib/parfait/method.rb +++ b/lib/parfait/method.rb @@ -61,7 +61,7 @@ module Parfait index = has_local name return index if index @locals.push name - @locals.length + @locals.get_length end def get_var name diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index 599c46e3..9a4bd977 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -23,6 +23,10 @@ module Parfait object end + def == other + self.object_id == other.object_id + end + def get_type_of( index ) type_word = internal_object_get( TYPE_WORD ) res = type_word >> (index*4) diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index 1f056e7a..5d14740b 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -24,7 +24,7 @@ module Register # binary code (array) to right length @machine.objects.each do |objekt| next unless objekt.is_a? Parfait::Method - objekt.code.set_length(objekt.info.mem_length / 4 , 0) + objekt.code.set_length(objekt.info.mem_length , 0) end at = 0 # then we make sure we really get the binary codes first @@ -100,10 +100,13 @@ module Register end method.code.fill_with 0 index = 1 + stream.rewind + puts "Assembled #{method.name} with length #{stream.length}" + raise "length error #{method.code.length} != #{method.info.mem_length}" if method.code.length != method.info.mem_length + raise "length error #{stream.length} != #{method.info.mem_length}" if method.info.mem_length - stream.length > 32 stream.each_byte do |b| - method.set_char(index , b ) + method.code.set_char(index , b ) index = index + 1 - raise "length error #{method.code.get_length}" if index > method.info.get_length end end @@ -203,13 +206,14 @@ module Register end def assemble_String( string ) - str = string.to_s if string.is_a? Parfait::Word + str = string.to_string if string.is_a? Parfait::Word str = string.to_s if string.is_a? Symbol word = (str.length + 7) / 32 # all object are multiple of 8 words (7 for header) raise "String too long (implement split string!) #{word}" if word > 15 # first line is integers, convention is that following lines are the same TYPE_LENGTH.times { word = ((word << TYPE_BITS) + TYPE_INT) } @stream.write_uint32( word ) + puts "String is #{string} at #{string.position} length #{string.length}" write_ref_for( string.get_layout ) #ref @stream.write str pad_after(str.length) diff --git a/lib/virtual/parfait_adapter.rb b/lib/virtual/parfait_adapter.rb index 5fa7dc73..1ba9ea55 100644 --- a/lib/virtual/parfait_adapter.rb +++ b/lib/virtual/parfait_adapter.rb @@ -198,7 +198,7 @@ module Parfait as_string == other end - def to_s + def to_string string = "" index = 1 while( index <= self.length)