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
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)

View File

@ -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)

View File

@ -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