rubyx/lib/ast/basic_expressions.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2014-05-05 09:02:02 +02:00
# collection of the simple ones, int and strings and such
2014-05-05 09:02:02 +02:00
module Ast
class IntegerExpression < Expression
# attr_reader :value
def compile context , into
Vm::IntegerConstant.new value
2014-05-10 09:58:25 +02:00
end
2014-05-05 09:02:02 +02:00
end
class NameExpression < Expression
# attr_reader :name
2014-06-07 22:22:32 +02:00
# compiling a variable resolves it. if it wasn't defined, raise an exception
def compile context , into
2014-06-07 22:22:32 +02:00
raise "Undefined variable #{name}, defined locals #{context.locals.keys.join('-')}" unless context.locals.has_key?(name)
context.locals[name]
end
2014-05-05 09:02:02 +02:00
end
class ModuleName < NameExpression
2014-06-07 22:22:32 +02:00
def compile context , into
clazz = context.object_space.get_or_create_class name
raise "uups #{clazz}.#{name}" unless clazz
#class qualifier, means call from metaclass
clazz = clazz.meta_class
value = clazz
puts "CLAZZ #{value}"
function = clazz.get_or_create_function(name)
end
end
2014-05-05 09:02:02 +02:00
class StringExpression < Expression
# attr_reader :string
def compile context , into
value = Vm::StringConstant.new(string)
context.object_space.add_object value
2014-05-06 20:36:28 +02:00
value
end
2014-05-05 09:02:02 +02:00
end
end