From db17a9b69678161b37a0a54cd61dede4ac61dead Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 19 Jul 2015 12:34:23 +0300 Subject: [PATCH] fix function and class compile also fix misconception: methods do not have to be added to class by called that is a side effect from compiling a method --- lib/virtual/compiler/function_expression.rb | 2 +- lib/virtual/compiler/module_expression.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/virtual/compiler/function_expression.rb b/lib/virtual/compiler/function_expression.rb index 518779a1..135cffcc 100644 --- a/lib/virtual/compiler/function_expression.rb +++ b/lib/virtual/compiler/function_expression.rb @@ -29,7 +29,7 @@ module Virtual raise return_type.inspect if return_type.is_a? Instruction end new_method.source.return_type = return_type - new_method + Return.new(return_type) end def scratch args = [] diff --git a/lib/virtual/compiler/module_expression.rb b/lib/virtual/compiler/module_expression.rb index 2eccdcf7..5bcf8f84 100644 --- a/lib/virtual/compiler/module_expression.rb +++ b/lib/virtual/compiler/module_expression.rb @@ -8,6 +8,7 @@ module Virtual def self.compile_class expression , method clazz = Parfait::Space.object_space.get_class_by_name! expression.name puts "Created class #{clazz.name.inspect}" + expression_value = nil expression.expressions.each do |expr| # check if it's a function definition and add # if not, execute it, but that does means we should be in salama (executable), not ruby. @@ -15,11 +16,10 @@ module Virtual raise "only functions for now #{expr.inspect}" unless expr.is_a? Ast::FunctionExpression #puts "compiling expression #{expression}" expression_value = Compiler.compile(expr,method ) - clazz.add_instance_method(expression_value) #puts "compiled expression #{expression_value.inspect}" end - return clazz + return expression_value end end end