From f91c9fabe882bda8623be5eeb18a1e256938638c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 26 Jul 2015 18:28:39 +0300 Subject: [PATCH] fix block initialization --- lib/virtual/block.rb | 1 + lib/virtual/machine.rb | 2 +- lib/virtual/method_source.rb | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/virtual/block.rb b/lib/virtual/block.rb index d16c721b..c574406b 100644 --- a/lib/virtual/block.rb +++ b/lib/virtual/block.rb @@ -12,6 +12,7 @@ module Virtual def initialize(name , method ) super() @method = method + raise "Method is not Method, but #{method.class}" unless method == :dummy or method.is_a?(Parfait::Method) @name = name.to_sym @branch = nil @codes = [] diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 51c0ce0d..6ca9a118 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -123,7 +123,7 @@ module Virtual return self end boot_parfait! - @init = Block.new("init",nil) + @init = Block.new("init", :dummy ) @init.add_code Virtual::VirtualMain.new( self.space.get_init ) @booted = true self diff --git a/lib/virtual/method_source.rb b/lib/virtual/method_source.rb index 5d0a2ddc..98a6fbab 100644 --- a/lib/virtual/method_source.rb +++ b/lib/virtual/method_source.rb @@ -46,7 +46,7 @@ module Virtual # just passing the method object in for Instructions to make decisions (later) def initialize method , return_type = Virtual::Unknown # first block we have to create with .new , as new_block assumes a current - enter = Block.new( "enter" , self ).add_code(MethodEnter.new( method )) + enter = Block.new( "enter" , method ).add_code(MethodEnter.new( method )) @return_type = return_type @blocks = [enter] @current = enter @@ -110,7 +110,7 @@ module Virtual # In code generation , the new_block is written after this one, ie zero runtime cost # This does _not_ change the insertion point, that has do be done with insert_at(block) def new_block new_name - new_b = Block.new( new_name , self ) + new_b = Block.new( new_name , @blocks.first.method ) index = @blocks.index( @current ) @blocks.insert( index + 1 , new_b ) # + one because we want the ne after the insert_at return new_b