diff --git a/lib/vool/statements/local_statement.rb b/lib/vool/statements/local_statement.rb index dd2d4b66..2f261a79 100644 --- a/lib/vool/statements/local_statement.rb +++ b/lib/vool/statements/local_statement.rb @@ -7,7 +7,12 @@ module Vool end def to_mom( method ) - Mom::SlotConstant.new([:message , :frame , @name] , @value) + if method.args_type.variable_index(@name) + type = :arguments + else + type = :frame + end + Mom::SlotConstant.new([:message , type , @name] , @value) end end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 9f53b866..89ca6f04 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -12,6 +12,10 @@ module CompilerHelper def as_main(statements) in_Space("def main ; #{statements}; end") end + + def as_test_main( statements ) + in_Test("def main(arg) ; #{statements}; end") + end end diff --git a/test/vool/to_mom/helper.rb b/test/vool/to_mom/helper.rb index e639fd86..93f4dd6c 100644 --- a/test/vool/to_mom/helper.rb +++ b/test/vool/to_mom/helper.rb @@ -4,10 +4,10 @@ module MomCompile include CompilerHelper def compile_first_method input - lst = Vool::VoolCompiler.compile as_main( input ) + lst = Vool::VoolCompiler.compile as_test_main( input ) assert_equal Parfait::Class , lst.clazz.class , input - method = lst.clazz.get_method(:main) - assert method + @method = lst.clazz.get_method(:main) + assert @method lst.to_mom( nil ).first end diff --git a/test/vool/to_mom/test_all.rb b/test/vool/to_mom/test_all.rb index d19183d1..048d648a 100644 --- a/test/vool/to_mom/test_all.rb +++ b/test/vool/to_mom/test_all.rb @@ -1,3 +1,4 @@ require_relative "helper" require_relative "test_local" require_relative "test_ivar" +require_relative "test_args" diff --git a/test/vool/to_mom/test_args.rb b/test/vool/to_mom/test_args.rb new file mode 100644 index 00000000..8e4b7f6c --- /dev/null +++ b/test/vool/to_mom/test_args.rb @@ -0,0 +1,67 @@ +require_relative "helper" + +module Vool + class TestArgsMom < MiniTest::Test + include MomCompile + + def setup + Risc.machine.boot + @stats = compile_first_method( "arg = 5") + end + + def test_class_compiles + assert_equal Mom::SlotConstant , @stats.first.class , @stats + end + def test_slot_is_set + assert @stats.first.left + end + def test_slot_starts_at_message + assert_equal :message , @stats.first.left[0] + end + def test_slot_gets_self + assert_equal :arguments , @stats.first.left[1] + end + def test_slot_assigns_to_local + assert_equal :arg , @stats.first.left[-1] + end + def test_slot_assigns_something + assert @stats.first.right + end + def test_slot_assigns_int + assert_equal IntegerStatement , @stats.first.right.class + end + end + + #compiling to an argument should result in different second parameter in the slot array + class TestArgMom < MiniTest::Test + include MomCompile + + def setup + Risc.machine.boot + @stats = compile_first_method( "arg = 5") + end + + def test_class_compiles + assert_equal Mom::SlotConstant , @stats.first.class , @stats + end + def test_slot_is_set + assert @stats.first.left + end + def test_slot_starts_at_message + assert_equal :message , @stats.first.left[0] + end + def test_slot_gets_self + assert_equal :arguments , @stats.first.left[1] + end + def test_slot_assigns_to_local + assert_equal :arg , @stats.first.left[-1] + end + def test_slot_assigns_something + assert @stats.first.right + end + def test_slot_assigns_int + assert_equal IntegerStatement , @stats.first.right.class + end + end + +end diff --git a/test/vool/to_mom/test_local.rb b/test/vool/to_mom/test_local.rb index f84e2ad6..599afb3f 100644 --- a/test/vool/to_mom/test_local.rb +++ b/test/vool/to_mom/test_local.rb @@ -6,29 +6,29 @@ module Vool def setup Risc.machine.boot - @method = compile_first_method( "a = 5") + @stats = compile_first_method( "a = 5") end def test_class_compiles - assert_equal Mom::SlotConstant , @method.first.class , @method + assert_equal Mom::SlotConstant , @stats.first.class , @stats end def test_slot_is_set - assert @method.first.left + assert @stats.first.left end def test_slot_starts_at_message - assert_equal :message , @method.first.left[0] + assert_equal :message , @stats.first.left[0] end def test_slot_gets_self - assert_equal :frame , @method.first.left[1] + assert_equal :frame , @stats.first.left[1] end def test_slot_assigns_to_local - assert_equal :a , @method.first.left[-1] + assert_equal :a , @stats.first.left[-1] end def test_slot_assigns_something - assert @method.first.right + assert @stats.first.right end def test_slot_assigns_int - assert_equal IntegerStatement , @method.first.right.class + assert_equal IntegerStatement , @stats.first.right.class end end end