even more refactoring for assembler
This commit is contained in:
parent
fffe814205
commit
4ff684b6a4
@ -132,27 +132,34 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write_binary_method_to_stream(method, stream)
|
def write_binary_method_to_stream(method, stream)
|
||||||
|
write_binary_method_checks(method,stream)
|
||||||
index = 1
|
index = 1
|
||||||
stream.rewind
|
|
||||||
log.debug "Assembled code #{method.name} with length #{stream.length}"
|
|
||||||
raise "length error #{method.binary.char_length} != #{method.instructions.total_byte_length}" if method.binary.char_length != method.instructions.total_byte_length
|
|
||||||
raise "length error #{stream.length} != #{method.instructions.total_byte_length}" if method.instructions.total_byte_length != stream.length
|
|
||||||
stream.each_byte do |b|
|
stream.each_byte do |b|
|
||||||
method.binary.set_char(index , b )
|
method.binary.set_char(index , b )
|
||||||
index = index + 1
|
index = index + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def write_binary_method_checks(method,stream)
|
||||||
|
stream.rewind
|
||||||
|
log.debug "Assembled code #{method.name} with length #{stream.length}"
|
||||||
|
raise "length error #{method.binary.char_length} != #{method.instructions.total_byte_length}" if method.binary.char_length != method.instructions.total_byte_length
|
||||||
|
raise "length error #{stream.length} != #{method.instructions.total_byte_length}" if method.instructions.total_byte_length != stream.length
|
||||||
|
end
|
||||||
|
|
||||||
def write_any obj
|
def write_any obj
|
||||||
log.debug "Write #{obj.class}(#{obj.object_id}) at stream #{stream_position} pos:#{obj.position} , len:#{obj.padded_length}"
|
write_any_log( obj , "Write")
|
||||||
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)
|
write_any_out(obj)
|
||||||
log.debug "Wrote #{obj.class}(#{obj.object_id}) at stream #{stream_position} pos:#{obj.position} , len:#{obj.padded_length}"
|
write_any_log( obj , "Wrote")
|
||||||
obj.position
|
obj.position
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def write_any_log( obj , at)
|
||||||
|
log.debug "#{at} #{obj.class}(#{obj.object_id}) at stream #{stream_position} pos:#{obj.position} , len:#{obj.padded_length}"
|
||||||
|
end
|
||||||
|
|
||||||
def write_any_out(obj)
|
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
|
||||||
@ -163,18 +170,21 @@ module Register
|
|||||||
# 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 )
|
||||||
|
write_object_check(object)
|
||||||
|
obj_written = write_object_variables(object)
|
||||||
|
log.debug "instances=#{object.get_instance_variables.inspect} mem_len=#{object.padded_length}"
|
||||||
|
indexed_written = write_object_indexed(object)
|
||||||
|
log.debug "type #{obj_written} , total #{obj_written + indexed_written} (array #{indexed_written})"
|
||||||
|
log.debug "Len = #{object.get_length} , inst = #{object.get_type.instance_length}" if object.is_a? Parfait::Type
|
||||||
|
pad_after( obj_written + indexed_written )
|
||||||
|
object.position
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_object_check(object)
|
||||||
log.debug "Write object #{object.class} #{object.inspect}"
|
log.debug "Write object #{object.class} #{object.inspect}"
|
||||||
unless @machine.objects.has_key? object.object_id
|
unless @machine.objects.has_key? object.object_id
|
||||||
raise "Object(#{object.object_id}) not linked #{object.inspect}"
|
raise "Object(#{object.object_id}) not linked #{object.inspect}"
|
||||||
end
|
end
|
||||||
written = write_object_variables(object)
|
|
||||||
lay_len = written
|
|
||||||
log.debug "instances=#{object.get_instance_variables.inspect} mem_len=#{object.padded_length}"
|
|
||||||
written += write_object_indexed(object)
|
|
||||||
log.debug "type #{lay_len} , total #{written} (array #{written - lay_len})"
|
|
||||||
log.debug "Len = #{object.get_length} , inst = #{object.get_type.instance_length}" if object.is_a? Parfait::Type
|
|
||||||
pad_after( written )
|
|
||||||
object.position
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_object_indexed(object)
|
def write_object_indexed(object)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user