From 98788b52d3e9426badd91e1761ba4de98469bbd6 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 20 Jul 2018 14:22:26 +0300 Subject: [PATCH] fix ruby variables --- lib/ruby/variables.rb | 3 ++ .../{assign_statement.rb => assignment.rb} | 10 ------ lib/vool/ivar_assignment.rb | 12 +++++++ lib/vool/statement.rb | 3 +- test/ruby/test_variables.rb | 36 +++++++++++++++++++ 5 files changed, 53 insertions(+), 11 deletions(-) rename lib/vool/{assign_statement.rb => assignment.rb} (55%) create mode 100644 lib/vool/ivar_assignment.rb diff --git a/lib/ruby/variables.rb b/lib/ruby/variables.rb index 551ec994..2ef81960 100644 --- a/lib/ruby/variables.rb +++ b/lib/ruby/variables.rb @@ -6,6 +6,9 @@ module Ruby end def each(&block) end + def to_vool + vool_brother.new(@name) + end end class LocalVariable < Statement diff --git a/lib/vool/assign_statement.rb b/lib/vool/assignment.rb similarity index 55% rename from lib/vool/assign_statement.rb rename to lib/vool/assignment.rb index f0d014fe..1c44135f 100644 --- a/lib/vool/assign_statement.rb +++ b/lib/vool/assignment.rb @@ -16,14 +16,4 @@ module Vool end end - - class IvarAssignment < Assignment - - def to_mom( compiler ) - to = Mom::SlotDefinition.new(:message ,[ :receiver , @name]) - from = @value.slot_definition(compiler) - return chain_assign( Mom::SlotLoad.new(to,from) , compiler) - end - - end end diff --git a/lib/vool/ivar_assignment.rb b/lib/vool/ivar_assignment.rb new file mode 100644 index 00000000..da9da94a --- /dev/null +++ b/lib/vool/ivar_assignment.rb @@ -0,0 +1,12 @@ +module Vool + + class IvarAssignment < Assignment + + def to_mom( compiler ) + to = Mom::SlotDefinition.new(:message ,[ :receiver , @name]) + from = @value.slot_definition(compiler) + return chain_assign( Mom::SlotLoad.new(to,from) , compiler) + end + + end +end diff --git a/lib/vool/statement.rb b/lib/vool/statement.rb index f0d22944..bc233131 100644 --- a/lib/vool/statement.rb +++ b/lib/vool/statement.rb @@ -61,7 +61,7 @@ module Vool end -require_relative "assign_statement" +require_relative "assignment" require_relative "array_statement" require_relative "basic_values" require_relative "block_statement" @@ -69,6 +69,7 @@ require_relative "class_statement" require_relative "hash_statement" require_relative "if_statement" require_relative "logical_statement" +require_relative "ivar_assignment" require_relative "local_assignment" require_relative "method_statement" require_relative "return_statement" diff --git a/test/ruby/test_variables.rb b/test/ruby/test_variables.rb index d1a2726b..1dc1e32a 100644 --- a/test/ruby/test_variables.rb +++ b/test/ruby/test_variables.rb @@ -55,4 +55,40 @@ module Ruby assert_raises {compile( "M::Module" ) } end end + class TestVariablesVool < MiniTest::Test + include RubyTests + def test_local_basic + lst = compile( "foo = 1 ; foo").to_vool + assert_equal Vool::LocalVariable , lst.statements[1].class + end + + def test_instance_basic + lst = compile( "@var" ).to_vool + assert_equal Vool::InstanceVariable , lst.class + assert_equal :var , lst.name + end + + def test_instance_return + lst = compile( "return @var" ).to_vool + assert_equal InstanceVariable , lst.return_value.class + end + + def test_class_basic + lst = compile( "@@var" ).to_vool + assert_equal Vool::ClassVariable , lst.class + assert_equal :var , lst.name + end + + def test_class_return + lst = compile( "return @@var" ).to_vool + assert_equal ClassVariable , lst.return_value.class + end + + def test_module_basic + lst = compile( "Module" ).to_vool + assert_equal Vool::ModuleName , lst.class + assert_equal :Module , lst.name + end + + end end