2019-10-03 20:07:55 +02:00
|
|
|
module SlotMachine
|
|
|
|
# just name scoping the same stuff to slot
|
2018-03-13 08:00:51 +01:00
|
|
|
# so we know we are on the way down, keeping our layers seperated
|
2019-10-03 23:36:49 +02:00
|
|
|
# and we can put constant adding into the to_risc methods (instead of on sol classes)
|
2018-03-13 08:00:51 +01:00
|
|
|
class Constant
|
|
|
|
end
|
|
|
|
|
2019-08-19 10:33:12 +02:00
|
|
|
class LambdaConstant < Constant
|
|
|
|
attr_reader :lambda
|
2018-07-09 15:48:23 +02:00
|
|
|
def initialize(bl)
|
2019-08-19 10:33:12 +02:00
|
|
|
@lambda = bl
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
def to_parfait(compiler)
|
2019-08-19 10:33:12 +02:00
|
|
|
@lambda
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-13 08:00:51 +01:00
|
|
|
class IntegerConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
2018-03-31 12:25:59 +02:00
|
|
|
def to_parfait(compiler)
|
2018-08-24 17:49:21 +02:00
|
|
|
value = Parfait.object_space.get_factory_for(:Integer).get_next_object
|
2018-05-29 19:26:00 +02:00
|
|
|
value.set_value(@value)
|
2018-03-31 12:25:59 +02:00
|
|
|
compiler.add_constant(value)
|
|
|
|
value
|
|
|
|
end
|
2018-03-13 08:00:51 +01:00
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:Integer)
|
2018-03-13 08:00:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
class FloatConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
def ct_type
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class TrueConstant < Constant
|
2018-03-31 12:47:02 +02:00
|
|
|
def to_parfait(compiler)
|
|
|
|
Parfait.object_space.true_object
|
|
|
|
end
|
2018-03-13 08:00:51 +01:00
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:TrueClass)
|
2018-03-13 08:00:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
class FalseConstant < Constant
|
2018-03-31 12:47:02 +02:00
|
|
|
def to_parfait(compiler)
|
|
|
|
Parfait.object_space.false_object
|
|
|
|
end
|
2018-03-13 08:00:51 +01:00
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:FalseClass)
|
2018-03-13 08:00:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
class NilConstant < Constant
|
2018-03-31 12:47:02 +02:00
|
|
|
def to_parfait(compiler)
|
|
|
|
Parfait.object_space.nil_object
|
|
|
|
end
|
2018-03-13 08:00:51 +01:00
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:NilClass)
|
2018-03-13 08:00:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
class StringConstant < Constant
|
|
|
|
attr_reader :value
|
|
|
|
def initialize(value)
|
|
|
|
@value = value
|
|
|
|
end
|
2018-03-31 12:47:02 +02:00
|
|
|
def to_parfait(compiler)
|
|
|
|
value = Parfait.new_word(@value)
|
|
|
|
compiler.add_constant(value)
|
|
|
|
value
|
|
|
|
end
|
2018-03-13 08:00:51 +01:00
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:Word)
|
2018-03-13 08:00:51 +01:00
|
|
|
end
|
|
|
|
end
|
2018-03-25 12:27:15 +02:00
|
|
|
class SymbolConstant < Constant
|
2018-03-13 08:00:51 +01:00
|
|
|
def ct_type
|
2018-07-13 20:50:40 +02:00
|
|
|
Parfait.object_space.get_type_by_class_name(:Word)
|
2018-03-13 08:00:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|