fix module handling at ruby level

Was returning arrays instead of Statements, which messed things up
This commit is contained in:
Torsten Rüger 2019-09-06 21:00:37 +03:00
parent 646797301e
commit 363d1cb36f
5 changed files with 29 additions and 13 deletions

View File

@ -26,6 +26,8 @@ module Ruby
sendd.arguments << lambda
ret
end
def to_s(depth = 0)
at_depth(depth , "{|#{@args.join(',')}| #{@body}}")
end
end
end

View File

@ -38,7 +38,7 @@ module Ruby
begin
self.new.process(ast)
rescue => e
puts "Error processing #{ast}"
puts "Error processing \n#{ast}"
raise e
end
end
@ -139,7 +139,11 @@ module Ruby
not_implemented(expression)
end
def on_kwbegin statement
ScopeStatement.new process_all( statement.children )
scope = ScopeStatement.new([])
statement.children.each do |kid| #do the loop to catch errors (not process_all)
scope << process(kid)
end
scope
end
alias :on_begin :on_kwbegin
@ -268,8 +272,13 @@ module Ruby
kids = statement.children.dup
name = kids.shift
if(name.type == :const and
name.children[1] == :Parfait)
process_all(kids)
name.children[1] == :Parfait)
raise "No empty modules for now #{statement}" if kids.empty?
if(kids.length == 1)
process(kids.first)
else
on_kwbegin(kids)
end
else
not_implemented(statement)
end

View File

@ -2,7 +2,8 @@ module Ruby
class Statements < Statement
attr_reader :statements
def initialize(statements)
@statements = statements
@statements = []
statements.each{|st| self << st}
end
def empty?
@ -30,6 +31,7 @@ module Ruby
@statements[i]
end
def <<(o)
raise "Not Statement #{o.class}=#{o.to_s[0..100]}" unless o.is_a?(Statement)
@statements << o
self
end

View File

@ -9,12 +9,12 @@ module Ruby
def to_vool
vool_brother.new(@name)
end
def to_s(depth=0)
name.to_s
end
end
class LocalVariable < Variable
def to_s
name.to_s
end
end
class InstanceVariable < Variable
@ -24,7 +24,7 @@ module Ruby
array << @name
end
def to_s(depth = 0)
at_depth(depth , "@#{name}" )
"@#{name}"
end
end

View File

@ -4,11 +4,14 @@ module Ruby
class ModuleNameTest < Minitest::Test
include RubyTests
def test_parfait_module
assert_equal [nil], compile("module Parfait ; end")
def test_parfait_module_scoped
lst = compile("module Parfait ; 1 ; 1 ; end")
assert_equal ScopeStatement, lst.class
assert_equal IntegerConstant, lst.first.class
assert_equal 2, lst.length
end
def test_parfait_module_const
assert_equal IntegerConstant, compile("module Parfait ; 1;end").first.class
assert_equal IntegerConstant, compile("module Parfait ; 1;end").class
end
def test_module_parfait_removed