assembles more already

This commit is contained in:
Torsten Ruger 2015-06-03 10:01:59 +03:00
parent 3cdb3d513c
commit 4ddfcc4900
6 changed files with 23 additions and 7 deletions

View File

@ -24,5 +24,9 @@ module Parfait
def to_s def to_s
"BinaryCode #{@name}" "BinaryCode #{@name}"
end end
def == other
self.object_id == other.object_id
end
end end
end end

View File

@ -28,6 +28,10 @@ module Parfait
@object_class = object_class @object_class = object_class
end end
def == other
self.object_id == other.object_id
end
# add the name of an instance variable # add the name of an instance variable
# The index will be returned and can subsequently be searched with index_of # 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 # The index of the name is the index of the data in the object

View File

@ -61,7 +61,7 @@ module Parfait
index = has_local name index = has_local name
return index if index return index if index
@locals.push name @locals.push name
@locals.length @locals.get_length
end end
def get_var name def get_var name

View File

@ -23,6 +23,10 @@ module Parfait
object object
end end
def == other
self.object_id == other.object_id
end
def get_type_of( index ) def get_type_of( index )
type_word = internal_object_get( TYPE_WORD ) type_word = internal_object_get( TYPE_WORD )
res = type_word >> (index*4) res = type_word >> (index*4)

View File

@ -24,7 +24,7 @@ module Register
# binary code (array) to right length # binary code (array) to right length
@machine.objects.each do |objekt| @machine.objects.each do |objekt|
next unless objekt.is_a? Parfait::Method 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 end
at = 0 at = 0
# then we make sure we really get the binary codes first # then we make sure we really get the binary codes first
@ -100,10 +100,13 @@ module Register
end end
method.code.fill_with 0 method.code.fill_with 0
index = 1 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| stream.each_byte do |b|
method.set_char(index , b ) method.code.set_char(index , b )
index = index + 1 index = index + 1
raise "length error #{method.code.get_length}" if index > method.info.get_length
end end
end end
@ -203,13 +206,14 @@ module Register
end end
def assemble_String( string ) 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 str = string.to_s if string.is_a? Symbol
word = (str.length + 7) / 32 # all object are multiple of 8 words (7 for header) 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 raise "String too long (implement split string!) #{word}" if word > 15
# first line is integers, convention is that following lines are the same # first line is integers, convention is that following lines are the same
TYPE_LENGTH.times { word = ((word << TYPE_BITS) + TYPE_INT) } TYPE_LENGTH.times { word = ((word << TYPE_BITS) + TYPE_INT) }
@stream.write_uint32( word ) @stream.write_uint32( word )
puts "String is #{string} at #{string.position} length #{string.length}"
write_ref_for( string.get_layout ) #ref write_ref_for( string.get_layout ) #ref
@stream.write str @stream.write str
pad_after(str.length) pad_after(str.length)

View File

@ -198,7 +198,7 @@ module Parfait
as_string == other as_string == other
end end
def to_s def to_string
string = "" string = ""
index = 1 index = 1
while( index <= self.length) while( index <= self.length)