2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2018-09-01 14:54:25 +02:00
|
|
|
#Marker class for different constants
|
2018-06-29 21:46:39 +02:00
|
|
|
class Constant < Expression
|
|
|
|
end
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
# An integer at the sol level
|
2018-06-29 21:46:39 +02:00
|
|
|
class IntegerConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot_definition(_)
|
2020-02-15 15:02:03 +01:00
|
|
|
return SlotMachine::Slotted.for(SlotMachine::IntegerConstant.new(@value) , [])
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2019-08-19 10:33:12 +02:00
|
|
|
def to_s(depth = 0)
|
2018-06-29 21:46:39 +02:00
|
|
|
value.to_s
|
|
|
|
end
|
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
# An float at the sol level
|
2018-06-29 21:46:39 +02:00
|
|
|
class FloatConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
def ct_type
|
|
|
|
true
|
|
|
|
end
|
2019-08-19 10:33:12 +02:00
|
|
|
def to_s(depth = 0)
|
2018-09-01 14:54:25 +02:00
|
|
|
value.to_s
|
|
|
|
end
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
# True at the sol level
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot_definition(_)
|
2020-02-15 15:02:03 +01:00
|
|
|
return SlotMachine::Slotted.for(Parfait.object_space.true_object , [])
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2019-10-03 23:36:49 +02:00
|
|
|
# False at the sol level
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot_definition(_)
|
2020-02-15 15:02:03 +01:00
|
|
|
return SlotMachine::Slotted.for(Parfait.object_space.false_object , [])
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2019-10-03 23:36:49 +02:00
|
|
|
# Nil at the sol level
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot_definition(_)
|
2020-02-15 15:02:03 +01:00
|
|
|
return SlotMachine::Slotted.for(Parfait.object_space.nil_object , [])
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2018-09-01 14:54:25 +02:00
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
# Self at the sol level
|
2018-06-29 21:46:39 +02:00
|
|
|
class SelfExpression < Expression
|
|
|
|
attr_reader :my_type
|
|
|
|
def initialize(type = nil)
|
|
|
|
@my_type = type
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot_definition(compiler)
|
2018-07-16 11:03:40 +02:00
|
|
|
@my_type = compiler.receiver_type
|
2020-02-15 15:02:03 +01:00
|
|
|
SlotMachine::Slotted.for(:message , [:receiver])
|
2018-06-29 21:46:39 +02:00
|
|
|
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 StringConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot_definition(_)
|
2020-02-15 15:02:03 +01:00
|
|
|
return SlotMachine::Slotted.for(SlotMachine::StringConstant.new(@value),[])
|
2018-06-29 21:46:39 +02:00
|
|
|
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
|
2019-09-13 19:34:41 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
":#{@value}"
|
|
|
|
end
|
2018-06-29 21:46:39 +02:00
|
|
|
end
|
|
|
|
end
|