Add type variables.

This commit is contained in:
Jakob Olesen
2016-02-12 10:11:52 -08:00
parent d9ba9480c9
commit 3d67d4d6b9
2 changed files with 26 additions and 0 deletions

View File

@@ -38,3 +38,13 @@ Predefined types
.. automodule:: cretonne.types .. automodule:: cretonne.types
:members: :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

View File

@@ -94,3 +94,19 @@ class FloatType(ScalarType):
def __repr__(self): def __repr__(self):
return 'FloatType(bits={})'.format(self.bits) 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