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
|
2014-05-31 11:52:29 +02:00
|
|
|
clazz = context.object_space.get_or_create_class name
|
2014-06-01 20:03:08 +02:00
|
|
|
puts "Created class #{clazz.name.inspect}"
|
2014-06-01 13:24:54 +02:00
|
|
|
context.current_class = clazz
|
2014-05-31 13:35:33 +02:00
|
|
|
expressions.each do |expression|
|
2014-06-01 13:24:54 +02:00
|
|
|
# check if it's a function definition and add
|
2014-05-31 13:35:33 +02:00
|
|
|
# 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
|
2014-06-02 14:11:48 +02:00
|
|
|
puts "compiling expression #{expression}"
|
2014-05-31 13:35:33 +02:00
|
|
|
expression_value = expression.compile(context , nil )
|
2014-06-01 20:03:08 +02:00
|
|
|
#puts "compiled expression #{expression_value.inspect}"
|
2014-05-29 14:57:33 +02:00
|
|
|
end
|
2014-05-31 13:35:33 +02:00
|
|
|
|
2014-06-02 12:45:08 +02:00
|
|
|
return clazz
|
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
|