Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: faaf189961cf
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fe69c5b46582
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Jun 14, 2015

  1. Add support for BinOp.

    whitequark committed Jun 14, 2015
    Copy the full SHA
    7b78e7d View commit details
  2. Implement BinOp coercion rules for AugAssign.

    whitequark committed Jun 14, 2015
    Copy the full SHA
    fe69c5b View commit details
5 changes: 5 additions & 0 deletions artiq/py2llvm/asttyped.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ class scoped(object):
list of variables resolved as globals
"""

# Typed versions of untyped nodes
class argT(ast.arg, commontyped):
pass

@@ -82,3 +83,7 @@ class YieldT(ast.Yield, commontyped):
pass
class YieldFromT(ast.YieldFrom, commontyped):
pass

# Novel typed nodes
class CoerceT(ast.expr, commontyped):
_fields = ('expr',) # other_expr deliberately not in _fields
55 changes: 25 additions & 30 deletions artiq/py2llvm/builtins.py
Original file line number Diff line number Diff line change
@@ -23,49 +23,44 @@ class TFloat(types.TMono):
def __init__(self):
super().__init__("float")

class TTuple(types.Type):
"""A tuple type."""

attributes = {}

def __init__(self, elts=[]):
self.elts = elts

def find(self):
return self

def unify(self, other):
if isinstance(other, TTuple) and len(self.elts) == len(other.elts):
for selfelt, otherelt in zip(self.elts, other.elts):
selfelt.unify(otherelt)
elif isinstance(other, TVar):
other.unify(self)
else:
raise UnificationError(self, other)

def __repr__(self):
return "TTuple(%s)" % (", ".join(map(repr, self.elts)))

def __eq__(self, other):
return isinstance(other, TTuple) and \
self.elts == other.elts

def __ne__(self, other):
return not (self == other)

class TList(types.TMono):
def __init__(self, elt=None):
if elt is None:
elt = types.TVar()
super().__init__("list", {"elt": elt})


def is_none(typ):
return types.is_mono(typ, "NoneType")

def is_bool(typ):
return types.is_mono(typ, "bool")

def is_int(typ, width=None):
if width:
return types.is_mono(typ, "int", {"width": width})
else:
return types.is_mono(typ, "int")

def get_int_width(typ):
if is_int(typ):
return types.get_value(typ["width"])

def is_float(typ):
return types.is_mono(typ, "float")

def is_numeric(typ):
typ = typ.find()
return isinstance(typ, types.TMono) and \
typ.name in ('int', 'float')

def is_list(typ, elt=None):
if elt:
return types.is_mono(typ, "list", {"elt": elt})
else:
return types.is_mono(typ, "list")

def is_collection(typ):
typ = typ.find()
return isinstance(typ, types.TTuple) or \
types.is_mono(typ, "list")
49 changes: 48 additions & 1 deletion artiq/py2llvm/types.py
Original file line number Diff line number Diff line change
@@ -101,6 +101,36 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

class TTuple(Type):
"""A tuple type."""

attributes = {}

def __init__(self, elts=[]):
self.elts = elts

def find(self):
return self

def unify(self, other):
if isinstance(other, TTuple) and len(self.elts) == len(other.elts):
for selfelt, otherelt in zip(self.elts, other.elts):
selfelt.unify(otherelt)
elif isinstance(other, TVar):
other.unify(self)
else:
raise UnificationError(self, other)

def __repr__(self):
return "TTuple(%s)" % (", ".join(map(repr, self.elts)))

def __eq__(self, other):
return isinstance(other, TTuple) and \
self.elts == other.elts

def __ne__(self, other):
return not (self == other)

class TValue(Type):
"""
A type-level value (such as the integer denoting width of
@@ -131,15 +161,32 @@ def __ne__(self, other):


def is_var(typ):
return isinstance(typ, TVar)
return isinstance(typ.find(), TVar)

def is_mono(typ, name, **params):
typ = typ.find()
params_match = True
for param in params:
params_match = params_match and typ.params[param] == params[param]
return isinstance(typ, TMono) and \
typ.name == name and params_match

def is_tuple(typ, elts=None):
typ = typ.find()
if elts:
return isinstance(typ, TTuple) and \
elts == typ.elts
else:
return isinstance(typ, TTuple)

def get_value(typ):
typ = typ.find()
if isinstance(typ, TVar):
return None
elif isinstance(typ, TValue):
return typ.value
else:
assert False

class TypePrinter(object):
"""
Loading