diff --git a/docs/metaref.rst b/docs/metaref.rst index 8cdece065c..7a8c156142 100644 --- a/docs/metaref.rst +++ b/docs/metaref.rst @@ -38,3 +38,13 @@ Predefined types .. automodule:: cretonne.types :members: +Parametric polymorphism +----------------------- +.. currentmodule:: cretonne + +Instruction operands can be defined with *type variables* instead of concrete +types for their operands. This makes the instructions polymorphic. + +.. autoclass:: TypeVar + + diff --git a/meta/cretonne/__init__.py b/meta/cretonne/__init__.py index 216607c9dc..e8cdfe3f55 100644 --- a/meta/cretonne/__init__.py +++ b/meta/cretonne/__init__.py @@ -94,3 +94,19 @@ class FloatType(ScalarType): def __repr__(self): return 'FloatType(bits={})'.format(self.bits) + +# +# Parametric polymorphism. +# + +class TypeVar(object): + """ + A Type Variable. + + Type variables can be used in place of concrete types when defining + instructions. This makes the instructions *polymorphic*. + """ + + def __init__(self, name): + self.name = name +