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: 56bba3009d57
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: 4b4805265d14
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Jun 13, 2015

  1. Split off builtins from types.

    builtins will contain attribute definitions as well.
    whitequark committed Jun 13, 2015
    Copy the full SHA
    61434a8 View commit details
  2. Split ASTTypedRewriter off Inferencer.

    whitequark committed Jun 13, 2015
    Copy the full SHA
    4c95647 View commit details
  3. Error out on unsupported statements.

    whitequark committed Jun 13, 2015
    Copy the full SHA
    5555171 View commit details
  4. Add support for Break and Continue.

    whitequark committed Jun 13, 2015
    Copy the full SHA
    4b48052 View commit details
Showing with 244 additions and 182 deletions.
  1. +63 −0 artiq/py2llvm/builtins.py
  2. +2 −56 artiq/py2llvm/types.py
  3. +160 −126 artiq/py2llvm/typing.py
  4. +19 −0 lit-test/py2llvm/typing/error_control_flow.py
63 changes: 63 additions & 0 deletions artiq/py2llvm/builtins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
The :mod:`builtins` module contains the builtin Python and ARTIQ
types, such as int or float.
"""

from . import types

class TNone(types.TMono):
def __init__(self):
super().__init__("NoneType")

class TBool(types.TMono):
def __init__(self):
super().__init__("bool")

class TInt(types.TMono):
def __init__(self, width=None):
if width is None:
width = types.TVar()
super().__init__("int", {"width": width})

class TFloat(types.TMono):
def __init__(self):
super().__init__("float")

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

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_numeric(typ):
return isinstance(typ, types.TMono) and \
typ.name in ('int', 'float')
58 changes: 2 additions & 56 deletions artiq/py2llvm/types.py
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ class TVar(Type):
folded into this class.
"""

attributes = ()

def __init__(self):
self.parent = self

@@ -99,34 +101,6 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

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

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
@@ -155,30 +129,6 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

def TNone():
"""The type of None."""
return TMono("NoneType")

def TBool():
"""A boolean type."""
return TMono("bool")

def TInt(width=None):
"""A generic integer type."""
if width is None:
width = TVar()
return TMono("int", {"width": width})

def TFloat():
"""A double-precision floating point type."""
return TMono("float")

def TList(elt=None):
"""A generic list type."""
if elt is None:
elt = TVar()
return TMono("list", {"elt": elt})


def is_var(typ):
return isinstance(typ, TVar)
@@ -190,10 +140,6 @@ def is_mono(typ, name, **params):
return isinstance(typ, TMono) and \
typ.name == name and params_match

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


class TypePrinter(object):
"""
Loading