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: 77adf2f6b557
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: 20e0e6935848
Choose a head ref
  • 3 commits
  • 8 files changed
  • 1 contributor

Commits on Jun 15, 2015

  1. Add support for ListComp.

    whitequark committed Jun 15, 2015
    Copy the full SHA
    d27bb31 View commit details
  2. Add check for duplicate parameter names.

    whitequark committed Jun 15, 2015
    Copy the full SHA
    dbfdbc3 View commit details
  3. Add support for function types and LambdaT.

    Also fix scoping of Nonlocal.
    whitequark committed Jun 15, 2015
    Copy the full SHA
    20e0e69 View commit details
2 changes: 1 addition & 1 deletion artiq/py2llvm/asttyped.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ class argT(ast.arg, commontyped):
class ClassDefT(ast.ClassDef, scoped):
pass
class FunctionDefT(ast.FunctionDef, scoped):
pass
_types = ("signature_type",)
class ModuleT(ast.Module, scoped):
pass

2 changes: 1 addition & 1 deletion artiq/py2llvm/builtins.py
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ def is_int(typ, width=None):

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

def is_float(typ):
return types.is_mono(typ, "float")
64 changes: 59 additions & 5 deletions artiq/py2llvm/types.py
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ def unify(self, other):

def __repr__(self):
if self.parent is self:
return "TVar(%d)" % id(self)
return "<py2llvm.types.TVar %d>" % id(self)
else:
return repr(self.find())

@@ -88,7 +88,7 @@ def unify(self, other):
raise UnificationError(self, other)

def __repr__(self):
return "TMono(%s, %s)" % (repr(self.name), repr(self.params))
return "py2llvm.types.TMono(%s, %s)" % (repr(self.name), repr(self.params))

def __getitem__(self, param):
return self.params[param]
@@ -102,7 +102,11 @@ def __ne__(self, other):
return not (self == other)

class TTuple(Type):
"""A tuple type."""
"""
A tuple type.
:ivar elts: (list of :class:`Type`) elements
"""

attributes = {}

@@ -122,7 +126,7 @@ def unify(self, other):
raise UnificationError(self, other)

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

def __eq__(self, other):
return isinstance(other, TTuple) and \
@@ -131,6 +135,51 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

class TFunction(Type):
"""
A function type.
:ivar args: (:class:`collections.OrderedDict` of string to :class:`Type`)
mandatory arguments
:ivar optargs: (:class:`collections.OrderedDict` of string to :class:`Type`)
optional arguments
:ivar ret: (:class:`Type`)
return type
"""

attributes = {}

def __init__(self, args, optargs, ret):
self.args, self.optargs, self.ret = args, optargs, ret

def find(self):
return self

def unify(self, other):
if isinstance(other, TFunction) and \
self.args.keys() == other.args.keys() and \
self.optargs.keys() == other.optargs.keys():
for selfarg, otherarg in zip(self.args.values() + self.optargs.values(),
other.args.values() + other.optargs.values()):
selfarg.unify(otherarg)
self.ret.unify(other.ret)
elif isinstance(other, TVar):
other.unify(self)
else:
raise UnificationError(self, other)

def __repr__(self):
return "py2llvm.types.TFunction(%s, %s, %s)" % \
(repr(self.args), repr(self.optargs), repr(self.ret))

def __eq__(self, other):
return isinstance(other, TFunction) and \
self.args == other.args and \
self.optargs == other.optargs

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

class TValue(Type):
"""
A type-level value (such as the integer denoting width of
@@ -150,7 +199,7 @@ def unify(self, other):
raise UnificationError(self, other)

def __repr__(self):
return "TValue(%s)" % repr(self.value)
return "py2llvm.types.TValue(%s)" % repr(self.value)

def __eq__(self, other):
return isinstance(other, TValue) and \
@@ -216,6 +265,11 @@ def name(self, typ):
return "(%s,)" % self.name(typ.elts[0])
else:
return "(%s)" % ", ".join(list(map(self.name, typ.elts)))
elif isinstance(typ, TFunction):
args = []
args += [ "%s:%s" % (arg, self.name(typ.args[arg])) for arg in typ.args]
args += ["?%s:%s" % (arg, self.name(typ.optargs[arg])) for arg in typ.optargs]
return "(%s)->%s" % (", ".join(args), self.name(typ.ret))
elif isinstance(typ, TValue):
return repr(typ.value)
else:
Loading