better solution for initial jump

This commit is contained in:
Torsten Ruger 2014-10-07 12:01:33 +03:00
parent 5c90ad83e0
commit b7164b354d
4 changed files with 14 additions and 9 deletions

View File

@ -74,7 +74,7 @@ module Arm
operand = calculate_u8_with_rr( first )
raise "no fit for #{right}" unless operand
immediate = 1
@extra = ::Register::RegisterMachine.instance.add( to , to , (right.integer & 0xFF) )
@extra = ArmMachine.add( to , to , (right.integer & 0xFF) )
#TODO: this is still a hack, as it does not encode all possible values. The way it _should_ be done
# is to check that the first part is doabe with u8_with_rr AND leaves a u8 remainder
end

View File

@ -21,7 +21,8 @@ module Register
def link
add_object(@space)
at = 4 # first jump instruction
@space.init.set_position(0)
at = @space.init.mem_length # first jump instruction
# then all functions
@objects.each_value do | objekt|
next unless objekt.is_a? Virtual::CompiledMethod
@ -41,9 +42,10 @@ module Register
link
@stream = StringIO.new
mid , main = @objects.find{|k,objekt| objekt.is_a?(Virtual::CompiledMethod) and (objekt.name == :__init__ )}
initial_jump = RegisterMain.new( main )
initial_jump.set_position( 0)
initial_jump.assemble( @stream )
initial_jump = @space.init
initial_jump.codes.each do |code|
code.assemble( @stream )
end
@objects.each_value do |objekt|
next unless objekt.is_a? Virtual::CompiledMethod
assemble_object( objekt )
@ -188,6 +190,7 @@ module Register
end
def add_BootSpace(space)
add_object(space.main)
add_object(space.classes)
add_object(space.objects)
add_object(space.symbols)

View File

@ -17,7 +17,7 @@ module Virtual
def initialize
super()
@classes = Parfait::Hash.new
@main = Virtual::CompiledMethod.new("main" , [] )
@main = Virtual::CompiledMethod.main
#global objects (data)
@objects = []
@symbols = []
@ -27,11 +27,11 @@ module Virtual
@next_frame = frames.first
@passes = [ "Virtual::SendImplementation" ]
end
attr_reader :main , :classes , :objects , :symbols,:messages, :next_message , :next_frame
attr_reader :init , :main , :classes , :objects , :symbols,:messages, :next_message , :next_frame
def run_passes
@passes.each do |pass_class|
all = main.blocks
all = [@init] + main.blocks
@classes.values.each do |c|
c.instance_methods.each {|f| all += f.blocks }
end
@ -76,6 +76,8 @@ module Virtual
# CompiledMethods are grabbed from respective modules by sending the method name. This should return the
# implementation of the method (ie a method object), not actually try to implement it (as that's impossible in ruby)
def boot_classes!
@init = Virtual::Block.new(:_init_ , nil )
@init.add_code(Register::RegisterMain.new(@main))
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we have to define some
# dummies, just for the other to compile
obj = get_or_create_class :Object

View File

@ -3,7 +3,7 @@ require "parfait/message"
module Positioned
def position
raise "position accessed but not set at #{length} for #{self.inspect}" if @position == nil
raise "position accessed but not set at #{length} for #{self.inspect[0...500]}" if @position == nil
@position
end
def set_position pos