rubyx/lib/ast/module_expression.rb

43 lines
1.4 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
# create the class or module
# check if it'sa 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
clazz = context.object_space.get_or_create_class name
2014-05-29 14:57:33 +02:00
expression_value = expression.compile(context , into)
puts "compiled return expression #{expression_value.inspect}, now return in 7"
# copied from function expression: TODO make function
return_reg = Vm::Integer.new(7)
if expression_value.is_a?(Vm::IntegerConstant) or expression_value.is_a?(Vm::StringConstant)
return_reg.load into , expression_value if expression_value.register != return_reg.register
else
return_reg.move( into, expression_value ) if expression_value.register != return_reg.register
end
#function.set_return return_reg
return return_reg
end
end
2014-05-30 09:59:49 +02:00
class ClassExpression < ModuleExpression
end
2014-05-29 14:57:33 +02:00
end