diff --git a/lib/ast/module_expression.rb b/lib/ast/module_expression.rb index 6334eae4..5a599a27 100644 --- a/lib/ast/module_expression.rb +++ b/lib/ast/module_expression.rb @@ -27,7 +27,7 @@ module Ast #puts "compiled expression #{expression_value.inspect}" end - return nil + return clazz end end diff --git a/test/fragments/helper.rb b/test/fragments/helper.rb index 01c8d91f..e35026a7 100644 --- a/test/fragments/helper.rb +++ b/test/fragments/helper.rb @@ -27,7 +27,7 @@ module Fragments expr = part.compile( @object_space.context , @object_space.main ) else expr = part.compile( @object_space.context , nil ) - raise "should be function definition for now" unless expr.is_a? Vm::Function + raise "should be function definition for now, not #{part.inspect}#{expr.inspect}" unless expr.is_a? Vm::Function end end end diff --git a/test/fragments/test_class.rb b/test/fragments/test_class.rb index f38f42c4..da32ea95 100644 --- a/test/fragments/test_class.rb +++ b/test/fragments/test_class.rb @@ -20,10 +20,13 @@ class String def length() return @length end + def self.new_string( len ) + 4 + end def plus(str) my_length = @length str_len = str.length() - new_string = String.new(my_length + str_len) + new_string = String.new_string(my_length + str_len) i = 0 while( i < my_length) do char = self.get(i) @@ -45,5 +48,22 @@ HERE parse write "class" end + + def parse + parser = Parser::Crystal.new + syntax = parser.parse_with_debug(@string_input) + parts = Parser::Transform.new.apply(syntax) + # file is a list of expressions, all but the last must be a function + # and the last is wrapped as a main + parts.each_with_index do |part,index| + if index == (parts.length - 1) + expr = part.compile( @object_space.context , @object_space.main ) + else + expr = part.compile( @object_space.context , nil ) + raise "should be function definition for now, not #{part.inspect}#{expr.inspect}" unless expr.is_a? Vm::BootClass + end + end + end + end