2014-05-29 14:57:33 +02:00
|
|
|
module Ast
|
|
|
|
class ModuleExpression < Expression
|
2014-06-04 21:03:45 +02:00
|
|
|
# attr_reader :name ,:expressions
|
2014-06-10 22:57:56 +02:00
|
|
|
def compile context
|
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-06-10 22:57:56 +02:00
|
|
|
expression_value = expression.compile(context )
|
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
|