2014-05-05 10:02:02 +03:00
|
|
|
# collection of the simple ones, int and strings and such
|
2014-05-05 11:03:43 +03:00
|
|
|
|
2014-05-05 10:02:02 +03:00
|
|
|
module Ast
|
|
|
|
|
|
|
|
class IntegerExpression < Expression
|
2014-06-04 22:03:45 +03:00
|
|
|
# attr_reader :value
|
2014-06-10 23:57:56 +03:00
|
|
|
def compile context
|
2014-05-13 18:21:24 +03:00
|
|
|
Vm::IntegerConstant.new value
|
2014-05-10 10:58:25 +03:00
|
|
|
end
|
2014-05-05 10:02:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
class NameExpression < Expression
|
2014-06-04 22:03:45 +03:00
|
|
|
# attr_reader :name
|
|
|
|
|
2014-06-07 23:22:32 +03:00
|
|
|
# compiling a variable resolves it. if it wasn't defined, raise an exception
|
2014-06-10 23:57:56 +03:00
|
|
|
def compile context
|
2014-06-07 23:22:32 +03:00
|
|
|
raise "Undefined variable #{name}, defined locals #{context.locals.keys.join('-')}" unless context.locals.has_key?(name)
|
2014-05-13 16:24:19 +03:00
|
|
|
context.locals[name]
|
2014-05-10 17:55:02 +03:00
|
|
|
end
|
2014-05-05 10:02:02 +03:00
|
|
|
end
|
|
|
|
|
2014-05-30 12:06:42 +03:00
|
|
|
class ModuleName < NameExpression
|
2014-06-07 23:22:32 +03:00
|
|
|
|
2014-06-10 23:57:56 +03:00
|
|
|
def compile context
|
2014-06-07 23:22:32 +03:00
|
|
|
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
|
2014-06-13 23:41:45 +03:00
|
|
|
puts "CLAZZ #{clazz}"
|
|
|
|
clazz
|
2014-06-07 23:22:32 +03:00
|
|
|
end
|
2014-05-30 12:06:42 +03:00
|
|
|
end
|
|
|
|
|
2014-05-05 10:02:02 +03:00
|
|
|
class StringExpression < Expression
|
2014-06-04 22:03:45 +03:00
|
|
|
# attr_reader :string
|
2014-06-10 23:57:56 +03:00
|
|
|
def compile context
|
2014-05-13 16:24:19 +03:00
|
|
|
value = Vm::StringConstant.new(string)
|
2014-05-31 12:52:29 +03:00
|
|
|
context.object_space.add_object value
|
2014-05-06 21:36:28 +03:00
|
|
|
value
|
2014-05-05 10:13:49 +03:00
|
|
|
end
|
2014-05-05 10:02:02 +03:00
|
|
|
end
|
|
|
|
end
|