diff --git a/lib/parfait/callable_method.rb b/lib/parfait/callable_method.rb index f1982dbc..2de2674a 100644 --- a/lib/parfait/callable_method.rb +++ b/lib/parfait/callable_method.rb @@ -38,7 +38,10 @@ module Parfait end def create_block(args , frame) - bl = Block.new(self_type , args , frame) + add_block( Block.new(self_type , args , frame)) + end + + def add_block(bl) block = self.blocks bl.next = block if(block) @blocks = bl diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 56948cb6..87d83af4 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -45,7 +45,7 @@ module Risc method = type.create_method( method_name , args , frame) self.new(method) end - + # convert the given mom instruction to_risc and then add it (see add_code) # continue down the instruction chain unti depleted # (adding moves the insertion point so the whole mom chain is added as a risc chain) diff --git a/lib/vool/block_statement.rb b/lib/vool/block_statement.rb index 8f775014..682c50ce 100644 --- a/lib/vool/block_statement.rb +++ b/lib/vool/block_statement.rb @@ -15,7 +15,6 @@ module Vool # fact never called) def slot_definition(compiler) @parfait_block = to_parfait(compiler) - compiler.add_constant(@parfait_block) return Mom::SlotDefinition.new(Mom::IntegerConstant.new(1) , []) end @@ -34,7 +33,7 @@ module Vool private def to_parfait(compiler) - Parfait::Block.new(compiler.method.self_type , make_arg_type , make_frame) + compiler.method.create_block( make_arg_type , make_frame) end def make_arg_type( ) type_hash = {} diff --git a/test/vool/test_block_statement.rb b/test/vool/test_block_statement.rb index 847e69d1..2c41033c 100644 --- a/test/vool/test_block_statement.rb +++ b/test/vool/test_block_statement.rb @@ -9,14 +9,34 @@ module Vool Parfait.boot! @ret = compile_mom( as_test_main("self.main {|elem| elem } ")) end - def test_is_compiler -# assert_equal Mom::MomCompiler , @ret.class + assert_equal Mom::MomCompiler , @ret.class end - - def est_has_compilers - assert_equal Risc::MethodCompiler , @ret.method_compilers.first.class + def test_has_method + assert_equal Parfait::CallableMethod , @ret.method_compilers.first.method.class + end + def test_method_has_block + assert @ret.method_compilers.first.method.blocks , "No block created" + end + end + class TestBlockCreated < MiniTest::Test + include MomCompile + def setup + Parfait.boot! + @ret = compile_mom( as_test_main("self.main {|elem| local = 5 } ")) + @block = @ret.method_compilers.first.method.blocks + end + def test_block_arg_type + assert_equal Parfait::Type, @block.arguments_type.class + end + def test_block_arg_type_name + assert_equal 1, @block.arguments_type.variable_index(:elem) + end + def test_block_local_type + assert_equal Parfait::Type, @block.frame_type.class + end + def test_block_frame_type_name + assert_equal 1, @block.frame_type.variable_index(:local) end - end end