2014-07-15 08:31:25 +02:00
|
|
|
|
2015-10-10 18:14:27 +02:00
|
|
|
module Phisol
|
2015-09-27 13:07:02 +02:00
|
|
|
# Integer and (Object) References are the main derived classes, but float will come.
|
2015-10-10 18:14:27 +02:00
|
|
|
|
2014-07-15 08:31:25 +02:00
|
|
|
class Type
|
2014-07-15 08:34:45 +02:00
|
|
|
def == other
|
2015-05-24 12:55:05 +02:00
|
|
|
return false unless other.class == self.class
|
2014-07-15 08:34:45 +02:00
|
|
|
return true
|
|
|
|
end
|
2015-09-23 17:35:37 +02:00
|
|
|
|
|
|
|
# map from a type sym (currently :int/:ref) to a class of subtype of Type
|
2015-09-27 13:07:02 +02:00
|
|
|
# TODO needs to be made extensible in a defined way.
|
2015-09-23 17:35:37 +02:00
|
|
|
def self.from_sym type
|
2015-10-10 18:14:27 +02:00
|
|
|
return type if type.is_a? Type
|
2015-09-23 17:35:37 +02:00
|
|
|
case type
|
|
|
|
when :int
|
2015-10-10 18:14:27 +02:00
|
|
|
self.int
|
2015-09-23 17:35:37 +02:00
|
|
|
when :ref
|
2015-10-10 18:14:27 +02:00
|
|
|
self.ref
|
2015-09-23 17:35:37 +02:00
|
|
|
else
|
2015-10-10 18:14:27 +02:00
|
|
|
raise "No type maps to:#{type} (#{type.class})"
|
2015-09-23 17:35:37 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-10 18:14:27 +02:00
|
|
|
|
|
|
|
def self.int
|
|
|
|
return Integer.new
|
|
|
|
end
|
|
|
|
def self.ref
|
|
|
|
return Reference.new
|
|
|
|
end
|
2014-07-15 08:31:25 +02:00
|
|
|
end
|
2015-05-24 12:55:05 +02:00
|
|
|
|
2014-07-15 08:31:25 +02:00
|
|
|
class Integer < Type
|
|
|
|
end
|
2015-05-24 12:55:05 +02:00
|
|
|
|
2014-07-15 08:31:25 +02:00
|
|
|
class Reference < Type
|
2015-05-24 12:55:05 +02:00
|
|
|
# possibly unknown value, but known class (as in methods)
|
|
|
|
def initialize clazz = nil
|
|
|
|
@of_class = clazz
|
|
|
|
end
|
|
|
|
attr_reader :of_class
|
2014-07-15 08:31:25 +02:00
|
|
|
end
|
2015-05-24 12:55:05 +02:00
|
|
|
|
2014-07-15 08:31:25 +02:00
|
|
|
end
|