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 09:58:25 +02:00
|
|
|
def compile context
|
|
|
|
Vm::Signed.new value
|
|
|
|
end
|
2014-05-05 09:02:02 +02:00
|
|
|
def == other
|
|
|
|
compare other , [:value]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class NameExpression < Expression
|
|
|
|
attr_reader :name
|
|
|
|
def initialize name
|
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
def == other
|
|
|
|
compare other , [:name]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class StringExpression < Expression
|
|
|
|
attr_reader :string
|
|
|
|
def initialize str
|
|
|
|
@string = str
|
|
|
|
end
|
2014-05-05 09:13:49 +02:00
|
|
|
|
|
|
|
def compile context
|
2014-05-06 20:36:28 +02:00
|
|
|
value = Vm::StringLiteral.new(string)
|
|
|
|
context.program.add_object value
|
|
|
|
value
|
2014-05-05 09:13:49 +02:00
|
|
|
end
|
2014-05-05 09:02:02 +02:00
|
|
|
def == other
|
|
|
|
compare other , [:string]
|
|
|
|
end
|
|
|
|
end
|
2014-05-05 09:13:49 +02:00
|
|
|
|
2014-05-05 09:02:02 +02:00
|
|
|
end
|