2018-06-29 21:46:39 +02:00
|
|
|
module Vool
|
|
|
|
class Constant < Expression
|
|
|
|
#gobble it up
|
|
|
|
def each(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class IntegerConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-06-29 21:46:39 +02:00
|
|
|
return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , [])
|
|
|
|
end
|
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:Integer)
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
def to_s
|
|
|
|
value.to_s
|
|
|
|
end
|
|
|
|
def each(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class FloatConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
def ct_type
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class TrueConstant < Constant
|
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:True)
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-06-29 21:46:39 +02:00
|
|
|
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
|
|
|
|
end
|
2018-07-04 07:28:29 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
"true"
|
|
|
|
end
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
class FalseConstant < Constant
|
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:False)
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-06-29 21:46:39 +02:00
|
|
|
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
|
|
|
|
end
|
2018-07-04 07:28:29 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
"false"
|
|
|
|
end
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
class NilConstant < Constant
|
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:Nil)
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-06-29 21:46:39 +02:00
|
|
|
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
|
|
|
|
end
|
2018-07-04 07:28:29 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
"nil"
|
|
|
|
end
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
class SelfExpression < Expression
|
|
|
|
attr_reader :my_type
|
|
|
|
def initialize(type = nil)
|
|
|
|
@my_type = type
|
|
|
|
end
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-07-09 18:32:17 +02:00
|
|
|
@my_type = compiler.resolve_type(:receiver)
|
2018-06-29 21:46:39 +02:00
|
|
|
Mom::SlotDefinition.new(:message , [:receiver])
|
|
|
|
end
|
|
|
|
def ct_type
|
|
|
|
@my_type
|
|
|
|
end
|
2018-07-04 07:28:29 +02:00
|
|
|
def to_s(depth = 0)
|
2018-06-29 21:46:39 +02:00
|
|
|
"self"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class SuperExpression < Statement
|
2018-07-04 07:28:29 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
"super"
|
|
|
|
end
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
class StringConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-06-29 21:46:39 +02:00
|
|
|
return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[])
|
|
|
|
end
|
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:Word)
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
2018-07-04 07:28:29 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
"'#{@value}'"
|
|
|
|
end
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
class SymbolConstant < StringConstant
|
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:Word)
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|