do or do not, there is not try
This commit is contained in:
parent
b24b65520d
commit
25c5b6dbbd
@ -10,7 +10,7 @@ module Risc
|
|||||||
|
|
||||||
class Assembler
|
class Assembler
|
||||||
include Logging
|
include Logging
|
||||||
log_level :info
|
log_level :debug
|
||||||
|
|
||||||
MARKER = 0xA51AF00D
|
MARKER = 0xA51AF00D
|
||||||
|
|
||||||
@ -21,16 +21,15 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assemble
|
def assemble
|
||||||
at = 0
|
|
||||||
#need the initial jump at 0 and then functions
|
#need the initial jump at 0 and then functions
|
||||||
@machine.cpu_init.set_position( 0)
|
@machine.cpu_init.set_position( 0 )
|
||||||
at = @machine.cpu_init.byte_length
|
at = @machine.cpu_init.byte_length
|
||||||
at = assemble_objects( at )
|
at = position_objects( at )
|
||||||
# and then everything code
|
# and then everything code
|
||||||
asseble_code_from( at )
|
position_code_from( at )
|
||||||
end
|
end
|
||||||
|
|
||||||
def asseble_code_from( at )
|
def position_code_from( at )
|
||||||
@objects.each do |id , objekt|
|
@objects.each do |id , objekt|
|
||||||
next unless objekt.is_a? Parfait::TypedMethod
|
next unless objekt.is_a? Parfait::TypedMethod
|
||||||
log.debug "CODE1 #{objekt.name}"
|
log.debug "CODE1 #{objekt.name}"
|
||||||
@ -54,7 +53,7 @@ module Risc
|
|||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_objects( at )
|
def position_objects( at )
|
||||||
at += 8 # thats the padding
|
at += 8 # thats the padding
|
||||||
# want to have the objects first in the executable
|
# want to have the objects first in the executable
|
||||||
@objects.each do | id , objekt|
|
@objects.each do | id , objekt|
|
||||||
@ -69,30 +68,19 @@ module Risc
|
|||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# objects must be written in same order as positioned / assembled
|
||||||
def write_as_string
|
def write_as_string
|
||||||
# must be same order as assemble
|
|
||||||
begin
|
|
||||||
return try_write
|
|
||||||
rescue LinkException
|
|
||||||
# knowing that we fix the problem, we hope to get away with retry.
|
|
||||||
retry
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# private method to implement write_as_string. May throw link Exception in which
|
|
||||||
# case we try again. Once.
|
|
||||||
def try_write
|
|
||||||
assemble
|
assemble
|
||||||
try_write_debug
|
write_debug
|
||||||
try_write_create_binary
|
write_create_binary
|
||||||
try_write_objects
|
write_objects
|
||||||
try_write_method
|
write_method
|
||||||
log.debug "Assembled #{stream_position} bytes"
|
log.debug "Assembled #{stream_position} bytes"
|
||||||
return @stream.string
|
return @stream.string
|
||||||
end
|
end
|
||||||
|
|
||||||
# debugging loop accesses all positions to force an error if it's not set
|
# debugging loop accesses all positions to force an error if it's not set
|
||||||
def try_write_debug
|
def write_debug
|
||||||
all = @objects.values.sort{|a,b| Positioned.position(a) <=> Positioned.position(b)}
|
all = @objects.values.sort{|a,b| Positioned.position(a) <=> Positioned.position(b)}
|
||||||
all.each do |objekt|
|
all.each do |objekt|
|
||||||
next if objekt.is_a?(Risc::Label)
|
next if objekt.is_a?(Risc::Label)
|
||||||
@ -101,7 +89,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_write_create_binary
|
def 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
|
||||||
@objects.each do |id , objekt|
|
@objects.each do |id , objekt|
|
||||||
next unless objekt.is_a? Parfait::TypedMethod
|
next unless objekt.is_a? Parfait::TypedMethod
|
||||||
@ -114,7 +102,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_write_objects
|
def write_objects
|
||||||
# then the objects , not code yet
|
# then the objects , not code yet
|
||||||
@objects.each do | id, objekt|
|
@objects.each do | id, objekt|
|
||||||
next if objekt.is_a? Parfait::BinaryCode
|
next if objekt.is_a? Parfait::BinaryCode
|
||||||
@ -123,7 +111,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_write_method
|
def write_method
|
||||||
# then write the methods to file
|
# then write the methods to file
|
||||||
@objects.each do |id, objekt|
|
@objects.each do |id, objekt|
|
||||||
next unless objekt.is_a? Parfait::BinaryCode
|
next unless objekt.is_a? Parfait::BinaryCode
|
||||||
@ -218,7 +206,7 @@ module Risc
|
|||||||
|
|
||||||
def write_object_variables(object)
|
def write_object_variables(object)
|
||||||
@stream.write_signed_int_32( MARKER )
|
@stream.write_signed_int_32( MARKER )
|
||||||
written = 0 # compensate for the "secrect" marker
|
written = 0 # compensate for the "secret" marker
|
||||||
object.get_instance_variables.each do |var|
|
object.get_instance_variables.each do |var|
|
||||||
inst = object.get_instance_variable(var)
|
inst = object.get_instance_variable(var)
|
||||||
#puts "Nil for #{object.class}.#{var}" unless inst
|
#puts "Nil for #{object.class}.#{var}" unless inst
|
||||||
|
Loading…
x
Reference in New Issue
Block a user