rubyx/lib/phisol/type.rb

45 lines
905 B
Ruby
Raw Normal View History

module Phisol
2015-09-27 13:07:02 +02:00
# Integer and (Object) References are the main derived classes, but float will come.
class Type
def == other
return false unless other.class == self.class
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
return type if type.is_a? Type
2015-09-23 17:35:37 +02:00
case type
when :int
self.int
2015-09-23 17:35:37 +02:00
when :ref
self.ref
2015-09-23 17:35:37 +02:00
else
raise "No type maps to:#{type} (#{type.class})"
2015-09-23 17:35:37 +02:00
end
end
def self.int
return Integer.new
end
def self.ref
return Reference.new
end
end
class Integer < Type
end
class Reference < Type
# possibly unknown value, but known class (as in methods)
def initialize clazz = nil
@of_class = clazz
end
attr_reader :of_class
end
end