Simple user-defined meta-level to manipulate types of instances as object.
Unfortunately, since the meta-objects are user-defined they are provided without any pre-defined information or behavior. For the same reasons, the Nit OO mechanisms do not rely on this user-defined meta-level.
meta permits the definition of user-defined meta-classes at any level
of meta, even with user-defined meta-loops.
Meta-classes can be defined easily in 3 steps:
- define a root for the class hierarchy (eg
- define a meta-class (eq
XClass[E: XObject] super Class[E])
class_factoryin the root
class XObject redef CLASS: XClass[SELF] redef class_factory(name) do return new XClass[SELF](name) end class XClass[E: XObject] super Class[E] end var x1 = new XObject var x2 = new XObject assert x1.get_class == x2.get_class assert x1.get_class isa XClass[XObject] assert x1.get_class.get_class isa Class[XClass[XObject]]
Currently works only with the interpreter
nit and the compiler with
--rta will try to detect all the runtime types, and will infinitely discover
Moreover, the interpreter and
--erasure have a different behavior with generics since
--erasure a single meta-instance is shared for all type variations of a same generic class.
Class names are used as a primary key to identify classes. But name conflicts are not managed and will make the program crashes at runtime (on some cast error)
- meta: Simple user-defined meta-level to manipulate types of instances as object. (lib/meta/meta.nit)