diff --git a/lib/risc/block_compiler.rb b/lib/risc/block_compiler.rb index 2ec07e86..d211835c 100644 --- a/lib/risc/block_compiler.rb +++ b/lib/risc/block_compiler.rb @@ -40,7 +40,7 @@ module Risc slot_def = [:frame] elsif @method.arguments_type.variable_index(name) slot_def = [:caller , :arguments ] - elsif @method.arguments_type.variable_index(name) + elsif @method.frame_type.variable_index(name) slot_def = [:caller , :frame ] elsif raise "no variable #{name} , need to resolve at runtime" diff --git a/test/mom/test_block_statement.rb b/test/mom/test_block_statement.rb index 4d484882..239c253a 100644 --- a/test/mom/test_block_statement.rb +++ b/test/mom/test_block_statement.rb @@ -2,7 +2,7 @@ require_relative "helper" module Vool - class TestBlockStatement < MiniTest::Test + class TestBlockArg < MiniTest::Test include MomCompile def setup @@ -19,7 +19,7 @@ module Vool assert @ret.method_compilers.first.get_method.blocks , "No block created" end end - class TestBlockCreated < MiniTest::Test + class TestBlockLocal < MiniTest::Test include MomCompile def setup Parfait.boot! @@ -39,15 +39,19 @@ module Vool assert_equal 1, @block.frame_type.variable_index(:local) end end - class TestBlockMethod < MiniTest::Test + class TestBlockMethodArg < MiniTest::Test include MomCompile + def setup Parfait.boot! - @ret = compile_mom( as_test_main("arg.each {|elem| arg = 5 } ")) - @block = @ret.method_compilers.first.get_method.blocks end - def test_block_arg_type - assert_equal Parfait::Type, @block.arguments_type.class + def test_method_arg_compiles + ret = compile_mom( as_test_main("self.main {|elem| arg = 5 } ")) + assert ret + end + def test_method_local_compiles + ret = compile_mom( as_test_main("local = 5 ; self.main {|elem| local = 10 } ")) + assert ret end end end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index bc2f3e09..a5033068 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -37,8 +37,8 @@ module MomCompile assert_equal Risc::MethodCompiler , compiler.class @method.source.to_mom( compiler ) end - def compile_first_block( block_input ) - source = "main_local = 5 ; self.main{|val| #{block_input}}" + def compile_first_block( block_input , method_input = "main_local = 5") + source = "#{method_input} ; self.main{|val| #{block_input}}" vool = RubyX::RubyCompiler.compile( as_test_main(source) ).normalize mom_c = vool.to_mom(nil) compiler = mom_c.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test} diff --git a/test/vool/blocks/test_assign.rb b/test/vool/blocks/test_assign.rb index 7c31412e..783b01dc 100644 --- a/test/vool/blocks/test_assign.rb +++ b/test/vool/blocks/test_assign.rb @@ -13,22 +13,22 @@ module VoolBlocks def test_block_compiles assert_equal Mom::SlotLoad , @ins.class , @ins end - def pest_slot_is_set + def test_slot_is_set assert @ins.left end - def pest_slot_starts_at_message + def test_slot_starts_at_message assert_equal :message , @ins.left.known_object end - def pest_slot_gets_self + def test_slot_gets_self assert_equal :frame , @ins.left.slots[0] end - def pest_slot_assigns_to_local - assert_equal :main_local , @ins.left.slots[-1] + def test_slot_assigns_to_local + assert_equal :local , @ins.left.slots[-1] end - def pest_slot_assigns_something + def test_slot_assigns_something assert @ins.right end - def pest_slot_assigns_int + def test_slot_assigns_int assert_equal Mom::IntegerConstant , @ins.right.known_object.class end end @@ -38,10 +38,10 @@ module VoolBlocks include MomCompile def setup Parfait.boot! - @ins = compile_first_method( "@a = 5 ; local = @a") + @ins = compile_first_block( "local = @a" , "@a = 5") end - def pest_class_compiles - assert_equal Mom::SlotLoad , @ins.next.class , @ins + def test_class_compiles + assert_equal Mom::SlotLoad , @ins.class , @ins end end