diff --git a/lib/vool/ruby_compiler.rb b/lib/vool/ruby_compiler.rb index 6d448fb7..2866d47a 100644 --- a/lib/vool/ruby_compiler.rb +++ b/lib/vool/ruby_compiler.rb @@ -129,7 +129,7 @@ module Vool def on_ivasgn expression name = expression.children[0] value = process(expression.children[1]) - InstanceAssignment.new(instance_name(name),value) + IvarAssignment.new(instance_name(name),value) end def on_return statement diff --git a/lib/vool/statement.rb b/lib/vool/statement.rb index beca3004..bd0be25d 100644 --- a/lib/vool/statement.rb +++ b/lib/vool/statement.rb @@ -51,11 +51,11 @@ end require_relative "statements/array_statement" -require_relative "statements/assignment_statement" require_relative "statements/basic_values" require_relative "statements/class_statement" require_relative "statements/hash_statement" require_relative "statements/if_statement" +require_relative "statements/ivar_statement" require_relative "statements/logical_statement" require_relative "statements/local_statement" require_relative "statements/method_statement" diff --git a/lib/vool/statements/assignment_statement.rb b/lib/vool/statements/ivar_statement.rb similarity index 70% rename from lib/vool/statements/assignment_statement.rb rename to lib/vool/statements/ivar_statement.rb index e9ad05d6..a1130a97 100644 --- a/lib/vool/statements/assignment_statement.rb +++ b/lib/vool/statements/ivar_statement.rb @@ -1,4 +1,5 @@ module Vool + class Assignment < Statement attr_reader :name , :value def initialize(name , value ) @@ -10,10 +11,15 @@ module Vool end end - class InstanceAssignment < Assignment + class IvarAssignment < Assignment # used to collect type information def add_ivar( array ) array << @name end + + def to_mom( method ) + Mom::SlotConstant.new([:message , :self , @name] , @value) + end + end end diff --git a/lib/vool/statements/local_statement.rb b/lib/vool/statements/local_statement.rb index 0d39f8bf..dd2d4b66 100644 --- a/lib/vool/statements/local_statement.rb +++ b/lib/vool/statements/local_statement.rb @@ -7,7 +7,7 @@ module Vool end def to_mom( method ) - Mom::SlotConstant.new([:message , :self , @name] , @value) + Mom::SlotConstant.new([:message , :frame , @name] , @value) end end diff --git a/test/vool/statements/test_all.rb b/test/vool/statements/test_all.rb index 2638b7b2..9f20a1e2 100644 --- a/test/vool/statements/test_all.rb +++ b/test/vool/statements/test_all.rb @@ -1,9 +1,9 @@ require_relative "test_array_statement" -require_relative "test_assignment_statement" require_relative "test_basic_values" require_relative "test_class_statement" require_relative "test_hash_statement" require_relative "test_if_statement" +require_relative "test_ivar" require_relative "test_logical_statement" require_relative "test_method_statement" require_relative "test_return_statement" diff --git a/test/vool/statements/test_assignment_statement.rb b/test/vool/statements/test_ivar.rb similarity index 91% rename from test/vool/statements/test_assignment_statement.rb rename to test/vool/statements/test_ivar.rb index 2410dae2..9ae8df32 100644 --- a/test/vool/statements/test_assignment_statement.rb +++ b/test/vool/statements/test_ivar.rb @@ -14,7 +14,7 @@ module Vool def test_instance lst = RubyCompiler.compile( "@foo = bar") - assert_equal InstanceAssignment , lst.class + assert_equal IvarAssignment , lst.class end def test_instance_name lst = RubyCompiler.compile( "@foo = bar") diff --git a/test/vool/to_mom/helper.rb b/test/vool/to_mom/helper.rb index 26258082..e639fd86 100644 --- a/test/vool/to_mom/helper.rb +++ b/test/vool/to_mom/helper.rb @@ -1 +1,14 @@ require_relative "../helper" + +module MomCompile + include CompilerHelper + + def compile_first_method input + lst = Vool::VoolCompiler.compile as_main( input ) + assert_equal Parfait::Class , lst.clazz.class , input + method = lst.clazz.get_method(:main) + assert method + lst.to_mom( nil ).first + end + +end diff --git a/test/vool/to_mom/test_all.rb b/test/vool/to_mom/test_all.rb index 8fb58fb5..d19183d1 100644 --- a/test/vool/to_mom/test_all.rb +++ b/test/vool/to_mom/test_all.rb @@ -1,3 +1,3 @@ require_relative "helper" require_relative "test_local" -require_relative "test_ivar_assignment" +require_relative "test_ivar" diff --git a/test/vool/to_mom/test_ivar.rb b/test/vool/to_mom/test_ivar.rb new file mode 100644 index 00000000..c365989b --- /dev/null +++ b/test/vool/to_mom/test_ivar.rb @@ -0,0 +1,34 @@ +require_relative "helper" + +module Vool + class TestIvarMom < MiniTest::Test + include MomCompile + + def setup + Risc.machine.boot + @method = compile_first_method( "@a = 5") + end + + def test_class_compiles + assert_equal Mom::SlotConstant , @method.first.class , @method + end + def test_slot_is_set + assert @method.first.left + end + def test_slot_starts_at_message + assert_equal :message , @method.first.left[0] + end + def test_slot_gets_self + assert_equal :self , @method.first.left[1] + end + def test_slot_assigns_to_local + assert_equal :a , @method.first.left[-1] + end + def test_slot_assigns_something + assert @method.first.right + end + def test_slot_assigns_int + assert_equal IntegerStatement , @method.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 435d4a1a..f84e2ad6 100644 --- a/test/vool/to_mom/test_local.rb +++ b/test/vool/to_mom/test_local.rb @@ -2,21 +2,13 @@ require_relative "helper" module Vool class TestLocalMom < MiniTest::Test - include CompilerHelper + include MomCompile def setup Risc.machine.boot @method = compile_first_method( "a = 5") end - def compile_first_method input - lst = VoolCompiler.compile as_main( input ) - assert_equal Parfait::Class , lst.clazz.class , input - method = lst.clazz.get_method(:main) - assert method - lst.to_mom( nil ).first - end - def test_class_compiles assert_equal Mom::SlotConstant , @method.first.class , @method end @@ -27,7 +19,7 @@ module Vool assert_equal :message , @method.first.left[0] end def test_slot_gets_self - assert_equal :self , @method.first.left[1] + assert_equal :frame , @method.first.left[1] end def test_slot_assigns_to_local assert_equal :a , @method.first.left[-1]