more assembler refactor
This commit is contained in:
parent
90a808b1c5
commit
fffe814205
@ -41,7 +41,7 @@ module Register
|
|||||||
end
|
end
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_objects
|
def assemble_objects
|
||||||
at = @machine.init.byte_length
|
at = @machine.init.byte_length
|
||||||
at += 8 # thats the padding
|
at += 8 # thats the padding
|
||||||
@ -69,13 +69,7 @@ module Register
|
|||||||
# case we try again. Once.
|
# case we try again. Once.
|
||||||
def try_write
|
def try_write
|
||||||
assemble
|
assemble
|
||||||
all = @machine.objects.values.sort{|a,b| a.position <=> b.position}
|
try_write_debug
|
||||||
# debugging loop accesses all positions to force an error if it's not set
|
|
||||||
all.each do |objekt|
|
|
||||||
next if objekt.is_a?(Register::Label)
|
|
||||||
log.debug "Linked #{objekt.class}(#{objekt.object_id}) at #{objekt.position} / #{objekt.padded_length}"
|
|
||||||
objekt.position
|
|
||||||
end
|
|
||||||
try_write_create_binary
|
try_write_create_binary
|
||||||
try_write_objects
|
try_write_objects
|
||||||
try_write_method
|
try_write_method
|
||||||
@ -83,6 +77,16 @@ module Register
|
|||||||
return @stream.string
|
return @stream.string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# debugging loop accesses all positions to force an error if it's not set
|
||||||
|
def try_write_debug
|
||||||
|
all = @machine.objects.values.sort{|a,b| a.position <=> b.position}
|
||||||
|
all.each do |objekt|
|
||||||
|
next if objekt.is_a?(Register::Label)
|
||||||
|
log.debug "Linked #{objekt.class}(#{objekt.object_id}) at #{objekt.position} / #{objekt.padded_length}"
|
||||||
|
objekt.position
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def try_write_create_binary
|
def try_write_create_binary
|
||||||
# first we need to create the binary code for the methods
|
# first we need to create the binary code for the methods
|
||||||
@machine.objects.each do |id , objekt|
|
@machine.objects.each do |id , objekt|
|
||||||
@ -144,15 +148,18 @@ module Register
|
|||||||
if @stream.length != obj.position
|
if @stream.length != obj.position
|
||||||
raise "Write #{obj.class} #{obj.object_id} at #{stream_position} not #{obj.position}"
|
raise "Write #{obj.class} #{obj.object_id} at #{stream_position} not #{obj.position}"
|
||||||
end
|
end
|
||||||
|
write_any_out(obj)
|
||||||
|
log.debug "Wrote #{obj.class}(#{obj.object_id}) at stream #{stream_position} pos:#{obj.position} , len:#{obj.padded_length}"
|
||||||
|
obj.position
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_any_out(obj)
|
||||||
if obj.is_a?(Parfait::Word) or obj.is_a?(Symbol)
|
if obj.is_a?(Parfait::Word) or obj.is_a?(Symbol)
|
||||||
write_String obj
|
write_String obj
|
||||||
else
|
else
|
||||||
write_object obj
|
write_object obj
|
||||||
end
|
end
|
||||||
log.debug "Wrote #{obj.class}(#{obj.object_id}) at stream #{stream_position} pos:#{obj.position} , len:#{obj.padded_length}"
|
|
||||||
obj.position
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# write type of the instance, and the variables that are passed
|
# write type 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
|
# variables ar values, ie int or refs. For refs the object needs to save the object first
|
||||||
def write_object( object )
|
def write_object( object )
|
||||||
@ -204,6 +211,10 @@ module Register
|
|||||||
end
|
end
|
||||||
str = string.to_s if string.is_a? Symbol
|
str = string.to_s if string.is_a? Symbol
|
||||||
log.debug "#{string.class} is #{string} at #{string.position} length #{string.length}"
|
log.debug "#{string.class} is #{string} at #{string.position} length #{string.length}"
|
||||||
|
write_checked_string(string , str)
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_checked_string(string, str)
|
||||||
@stream.write_sint32( MARKER )
|
@stream.write_sint32( MARKER )
|
||||||
write_ref_for( string.get_type ) #ref
|
write_ref_for( string.get_type ) #ref
|
||||||
@stream.write_sint32( str.length ) #int
|
@stream.write_sint32( str.length ) #int
|
||||||
|
Loading…
Reference in New Issue
Block a user