fix ruby class statement

This commit is contained in:
Torsten Ruger 2018-07-19 21:44:48 +03:00
parent 238f09b5ad
commit a5168ef818
3 changed files with 28 additions and 18 deletions

View File

@ -17,8 +17,8 @@ module Ruby
end end
def to_vool def to_vool
meths = body.statements.collect{|meth| meth.normalize} meths = body.statements.collect{|meth| meth.to_vool}
ClassStatement.new(@name , @super_class_name, Statements.new(meths) ) Vool::ClassStatement.new(@name , @super_class_name, Vool::Statements.new(meths) )
end end
def to_s(depth = 0) def to_s(depth = 0)

View File

@ -28,20 +28,12 @@ module Ruby
self self
end end
# create mom instructions def to_vool
def to_mom( compiler ) if( single? )
raise "Empty list ? #{statements.length}" if empty? first.to_vool
stats = @statements.dup else
flat = stats.shift.to_mom(compiler) vool_brother.new(@statements.collect{|s| s.to_vool})
while( nekst = stats.shift )
flat.append nekst.to_mom(compiler)
end end
flat
end
def each(&block)
block.call(self)
@statements.each{|a| a.each(&block)}
end end
def to_s(depth = 0) def to_s(depth = 0)

View File

@ -1,6 +1,27 @@
require_relative "helper" require_relative "helper"
module Ruby 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 class TestEmptyClassStatement < MiniTest::Test
include RubyTests include RubyTests
@ -12,15 +33,12 @@ module Ruby
def test_compile_class def test_compile_class
assert_equal ClassStatement , @lst.class assert_equal ClassStatement , @lst.class
end end
def test_compile_class_name def test_compile_class_name
assert_equal :Tryout , @lst.name assert_equal :Tryout , @lst.name
end end
def test_compile_class_super def test_compile_class_super
assert_equal :Base , @lst.super_class_name assert_equal :Base , @lst.super_class_name
end end
def test_compile_class_body def test_compile_class_body
assert @lst.body.empty? assert @lst.body.empty?
end end