2014-05-29 15:57:33 +03:00
|
|
|
module Ast
|
|
|
|
class ModuleExpression < Expression
|
2014-06-04 22:03:45 +03:00
|
|
|
# attr_reader :name ,:expressions
|
2014-06-10 23:57:56 +03:00
|
|
|
def compile context
|
2014-05-31 12:52:29 +03:00
|
|
|
clazz = context.object_space.get_or_create_class name
|
2014-06-01 21:03:08 +03:00
|
|
|
puts "Created class #{clazz.name.inspect}"
|
2014-06-01 14:24:54 +03:00
|
|
|
context.current_class = clazz
|
2014-05-31 14:35:33 +03:00
|
|
|
expressions.each do |expression|
|
2014-06-01 14:24:54 +03:00
|
|
|
# check if it's a function definition and add
|
2014-05-31 14:35:33 +03: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 15:11:48 +03:00
|
|
|
puts "compiling expression #{expression}"
|
2014-06-10 23:57:56 +03:00
|
|
|
expression_value = expression.compile(context )
|
2014-06-01 21:03:08 +03:00
|
|
|
#puts "compiled expression #{expression_value.inspect}"
|
2014-05-29 15:57:33 +03:00
|
|
|
end
|
2014-05-31 14:35:33 +03:00
|
|
|
|
2014-06-02 13:45:08 +03:00
|
|
|
return clazz
|
2014-05-29 15:57:33 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-30 10:59:49 +03:00
|
|
|
class ClassExpression < ModuleExpression
|
|
|
|
|
|
|
|
end
|
2014-05-29 15:57:33 +03:00
|
|
|
end
|