diff --git a/lib/arm/passes/main_implementation.rb b/lib/arm/passes/main_implementation.rb index a458d598..fd0f0cf4 100644 --- a/lib/arm/passes/main_implementation.rb +++ b/lib/arm/passes/main_implementation.rb @@ -1,6 +1,8 @@ module Arm # "Boot" the register machine at the function given + # meaning jump to that function currently. Maybe better to do some machine setup + # and possibly some cleanup/exit has to tie in, but that is not this day class MainImplementation def run block diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index f7156326..c98d5516 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -28,7 +28,10 @@ module Register # should be fill_to_length (with zeros) objekt.code.set_length(objekt.info.byte_length , 0) end - at = 0 + #need the initial jump at 0 and then functions + @machine.init.set_position(0) + at = @machine.init.byte_length + # then we make sure we really get the binary codes first @machine.objects.each do |objekt| next unless objekt.is_a? Parfait::BinaryCode @@ -65,11 +68,10 @@ module Register assemble_binary_method(objekt) end @stream = StringIO.new - #TODOmid , main = @objects.find{|k,objekt| objekt.is_a?(Virtual::CompiledMethod) and (objekt.name == :__init__ )} -# initial_jump = @machine.init -# initial_jump.codes.each do |code| -# code.assemble( @stream ) -# end + @machine.init.codes.each do |code| + code.assemble( @stream ) + end + # then write the methods to file @machine.objects.each do |objekt| next unless objekt.is_a? Parfait::BinaryCode diff --git a/lib/register/instructions/register_main.rb b/lib/register/instructions/register_main.rb index 1381e1bb..e751e4cc 100644 --- a/lib/register/instructions/register_main.rb +++ b/lib/register/instructions/register_main.rb @@ -1,14 +1,19 @@ module Register # This starts the register machine machine at the given function. - + # The implementation is most likely a jump/branch , but since we have the extra layer # we make good use of it, ie give things descriptive names (what they do, not how) class RegisterMain < Instruction + include Positioned + def initialize method @method = method end attr_reader :method + def word_length + 4 + end end -end \ No newline at end of file +end diff --git a/lib/virtual/boot.rb b/lib/virtual/boot.rb index f23cec87..6f02e00b 100644 --- a/lib/virtual/boot.rb +++ b/lib/virtual/boot.rb @@ -113,10 +113,6 @@ module Virtual obj.add_instance_method Builtin::Integer.send(f , nil) end - # and the @init block in turn _jumps_ to __init__ - # the point of which is that by the time main executes, all is :normal: - @init = Block.new(:_init_ , nil ) - @init.add_code(Register::RegisterMain.new(underscore_init)) end end end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index c17d562d..9b940ded 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -44,6 +44,8 @@ module Virtual attr_reader :passes , :space , :class_mappings , :init , :objects def run_passes + @init = Block.new("init",nil) + @init.add_code Register::RegisterMain.new( self.space.get_main ) Minimizer.new.run Collector.new.run @passes.each do |pass_class| @@ -51,12 +53,12 @@ module Virtual @space.classes.values.each do |c| c.instance_methods.each do |f| nb = f.info.blocks - raise "nil blocks " unless nb blocks += nb end end #puts "running #{pass_class}" blocks.each do |block| + raise "nil block " unless block pass = eval pass_class raise "no such pass-class as #{pass_class}" unless pass pass.new.run(block)