From a5168ef818bb57355e2fe8bce5a5496d338aff32 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 19 Jul 2018 21:44:48 +0300 Subject: [PATCH] fix ruby class statement --- lib/ruby/class_statement.rb | 4 ++-- lib/ruby/statements.rb | 18 +++++------------- test/ruby/test_class_statement.rb | 24 +++++++++++++++++++++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/ruby/class_statement.rb b/lib/ruby/class_statement.rb index b602e0a1..20886e38 100644 --- a/lib/ruby/class_statement.rb +++ b/lib/ruby/class_statement.rb @@ -17,8 +17,8 @@ module Ruby end def to_vool - meths = body.statements.collect{|meth| meth.normalize} - ClassStatement.new(@name , @super_class_name, Statements.new(meths) ) + meths = body.statements.collect{|meth| meth.to_vool} + Vool::ClassStatement.new(@name , @super_class_name, Vool::Statements.new(meths) ) end def to_s(depth = 0) diff --git a/lib/ruby/statements.rb b/lib/ruby/statements.rb index 5a0e6c15..d425c79b 100644 --- a/lib/ruby/statements.rb +++ b/lib/ruby/statements.rb @@ -28,20 +28,12 @@ module Ruby self end - # create mom instructions - def to_mom( compiler ) - raise "Empty list ? #{statements.length}" if empty? - stats = @statements.dup - flat = stats.shift.to_mom(compiler) - while( nekst = stats.shift ) - flat.append nekst.to_mom(compiler) + def to_vool + if( single? ) + first.to_vool + else + vool_brother.new(@statements.collect{|s| s.to_vool}) end - flat - end - - def each(&block) - block.call(self) - @statements.each{|a| a.each(&block)} end def to_s(depth = 0) diff --git a/test/ruby/test_class_statement.rb b/test/ruby/test_class_statement.rb index 8f4482f5..4a5298d1 100644 --- a/test/ruby/test_class_statement.rb +++ b/test/ruby/test_class_statement.rb @@ -1,6 +1,27 @@ require_relative "helper" module Ruby + class TestClassStatementVool < MiniTest::Test + include RubyTests + + def setup + input = "class Tryout < Base;def meth; a = 5 ;end; end" + @vool = compile( input ).to_vool + end + def test_class + assert_equal Vool::ClassStatement , @vool.class + end + def test_body + assert_equal Vool::Statements , @vool.body.class + end + def test_compile_class_name + assert_equal :Tryout , @vool.name + end + def test_compile_class_super + assert_equal :Base , @vool.super_class_name + end + + end class TestEmptyClassStatement < MiniTest::Test include RubyTests @@ -12,15 +33,12 @@ module Ruby def test_compile_class assert_equal ClassStatement , @lst.class end - def test_compile_class_name assert_equal :Tryout , @lst.name end - def test_compile_class_super assert_equal :Base , @lst.super_class_name end - def test_compile_class_body assert @lst.body.empty? end