2014-05-05 09:02:02 +02:00
|
|
|
# collection of the simple ones, int and strings and such
|
2014-05-05 10:03:43 +02:00
|
|
|
|
2014-05-05 09:02:02 +02:00
|
|
|
module Ast
|
|
|
|
|
|
|
|
class IntegerExpression < Expression
|
|
|
|
attr_reader :value
|
|
|
|
def initialize val
|
|
|
|
@value = val
|
|
|
|
end
|
2014-05-10 11:54:10 +02:00
|
|
|
def inspect
|
|
|
|
self.class.name + ".new(" + value.to_s+ ")"
|
|
|
|
end
|
2014-05-13 09:49:26 +02:00
|
|
|
def to_s
|
|
|
|
value.to_s
|
|
|
|
end
|
2014-05-13 15:24:19 +02:00
|
|
|
def compile context , into
|
2014-05-13 17:21:24 +02:00
|
|
|
Vm::IntegerConstant.new value
|
2014-05-10 09:58:25 +02:00
|
|
|
end
|
2014-05-10 11:54:10 +02:00
|
|
|
def attributes
|
|
|
|
[:value]
|
2014-05-05 09:02:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class NameExpression < Expression
|
|
|
|
attr_reader :name
|
|
|
|
def initialize name
|
|
|
|
@name = name
|
|
|
|
end
|
2014-05-13 15:24:19 +02:00
|
|
|
# compiling a variable resolves it.
|
|
|
|
# if it wasn't defined, nli is returned
|
|
|
|
def compile context , into
|
|
|
|
context.locals[name]
|
2014-05-10 16:55:02 +02:00
|
|
|
end
|
2014-05-10 11:54:10 +02:00
|
|
|
def inspect
|
2014-05-10 18:11:32 +02:00
|
|
|
self.class.name + '.new("' + name + '")'
|
2014-05-10 11:54:10 +02:00
|
|
|
end
|
2014-05-13 09:49:26 +02:00
|
|
|
def to_s
|
|
|
|
name
|
|
|
|
end
|
2014-05-10 11:54:10 +02:00
|
|
|
def attributes
|
|
|
|
[:name]
|
2014-05-05 09:02:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-30 11:06:42 +02:00
|
|
|
class ModuleName < NameExpression
|
|
|
|
end
|
|
|
|
|
2014-05-05 09:02:02 +02:00
|
|
|
class StringExpression < Expression
|
|
|
|
attr_reader :string
|
|
|
|
def initialize str
|
|
|
|
@string = str
|
|
|
|
end
|
2014-05-10 20:41:46 +02:00
|
|
|
def inspect
|
|
|
|
self.class.name + '.new("' + string + '")'
|
2014-05-10 11:54:10 +02:00
|
|
|
end
|
2014-05-05 09:13:49 +02:00
|
|
|
|
2014-05-13 15:24:19 +02:00
|
|
|
def compile context , into
|
|
|
|
value = Vm::StringConstant.new(string)
|
2014-05-31 11:52:29 +02:00
|
|
|
context.object_space.add_object value
|
2014-05-06 20:36:28 +02:00
|
|
|
value
|
2014-05-05 09:13:49 +02:00
|
|
|
end
|
2014-05-10 11:54:10 +02:00
|
|
|
def attributes
|
|
|
|
[:string]
|
2014-05-05 09:02:02 +02:00
|
|
|
end
|
|
|
|
end
|
2014-05-05 09:13:49 +02:00
|
|
|
|
2014-05-05 09:02:02 +02:00
|
|
|
end
|