rubyx/lib/ast/module_expression.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2014-05-29 14:57:33 +02:00
module Ast
class ModuleExpression < Expression
attr_reader :name ,:expressions
def initialize name , expressions
@name = name.to_sym
@expressions = expressions
end
def inspect
self.class.name + ".new(" + @name.inspect + " ," + @expressions.inspect + " )"
end
def to_s
"module #{name}\n #{expressions}\nend\n"
end
def attributes
[:name , :expressions]
end
def compile context , into
clazz = context.object_space.get_or_create_class name
context.current_class = clazz
expressions.each do |expression|
# check if it's a function definition and add
# if not, execute it, but that does means we should be in crystal (executable), not ruby. ie throw an error for now
raise "only functions for now #{expression.inspect}" unless expression.is_a? Ast::FunctionExpression
expression_value = expression.compile(context , nil )
puts "compiled return expression #{expression_value.inspect}, now return in 7"
2014-05-29 14:57:33 +02:00
end
return nil
2014-05-29 14:57:33 +02:00
end
end
2014-05-30 09:59:49 +02:00
class ClassExpression < ModuleExpression
end
2014-05-29 14:57:33 +02:00
end