rubyx/lib/ast/basic_expressions.rb

57 lines
1.2 KiB
Ruby
Raw Normal View History

# collection of the simple ones, int and strings and such
module Ast
class IntegerExpression < Expression
# attr_reader :value
2014-06-29 18:05:35 +02:00
def compile frame
2014-06-26 16:52:15 +02:00
Virtual::IntegerConstant.new value
end
end
2014-07-01 14:57:13 +02:00
class TrueExpression
def compile frame
Virtual::TrueValue.new
end
end
class FalseExpression
def compile frame
Virtual::FalseValue.new
end
end
class NilExpression
def compile frame
Virtual::NilValue.new
end
end
class NameExpression < Expression
# attr_reader :name
2014-07-01 17:58:25 +02:00
# compiling a variable resolves it. If it's not defined look call it as a menthod (which may raise NoMethodFound)
2014-06-29 18:05:35 +02:00
def compile frame
frame.get(name)
end
end
class ModuleName < NameExpression
def compile context
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
puts "CLAZZ #{clazz}"
clazz
end
end
class StringExpression < Expression
# attr_reader :string
def compile context
2014-06-26 16:52:15 +02:00
value = Virtual::StringConstant.new(string)
context.object_space.add_object value
value
end
end
end