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: 2dcb7445193f
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: f28549a11a5f
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jul 17, 2015

  1. Copy the full SHA
    3b661b2 View commit details
  2. Add builtins.is_exception.

    whitequark committed Jul 17, 2015
    Copy the full SHA
    f28549a View commit details
Showing with 15 additions and 9 deletions.
  1. +6 −3 artiq/compiler/builtins.py
  2. +8 −2 artiq/compiler/transforms/asttyped_rewriter.py
  3. +1 −1 artiq/compiler/transforms/inferencer.py
  4. +0 −3 artiq/compiler/types.py
9 changes: 6 additions & 3 deletions artiq/compiler/builtins.py
Original file line number Diff line number Diff line change
@@ -71,11 +71,11 @@ class TException(types.TMono):
def __init__(self, name="Exception"):
super().__init__(name)

class TIndexError(types.TMono):
class TIndexError(TException):
def __init__(self):
super().__init__("IndexError")

class TValueError(types.TMono):
class TValueError(TException):
def __init__(self):
super().__init__("ValueError")

@@ -150,14 +150,17 @@ def is_range(typ, elt=None):
else:
return types.is_mono(typ, "range")

def is_exception(typ):
return isinstance(typ.find(), TException)

def is_iterable(typ):
typ = typ.find()
return isinstance(typ, types.TMono) and \
typ.name in ('list', 'range')

def get_iterable_elt(typ):
if is_iterable(typ):
return typ.find()["elt"]
return typ.find()["elt"].find()

def is_collection(typ):
typ = typ.find()
10 changes: 8 additions & 2 deletions artiq/compiler/transforms/asttyped_rewriter.py
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ def visit_FunctionDef(self, node):
self.visit_root(node)

def _assignable(self, name):
assert name is not None
if name not in self.typing_env and name not in self.nonlocal_:
self.typing_env[name] = types.TVar()

@@ -177,7 +178,8 @@ def visit_Nonlocal(self, node):

def visit_ExceptHandler(self, node):
self.visit(node.type)
self._assignable(node.name)
if node.name is not None:
self._assignable(node.name)
for stmt in node.body:
self.visit(stmt)

@@ -383,8 +385,12 @@ def visit_Lambda(self, node):

def visit_ExceptHandler(self, node):
node = self.generic_visit(node)
if node.name is not None:
name_type = self._find_name(node.name, node.name_loc)
else:
name_type = types.TVar()
node = asttyped.ExceptHandlerT(
name_type=self._find_name(node.name, node.name_loc),
name_type=name_type,
filter=node.type, name=node.name, body=node.body,
except_loc=node.except_loc, as_loc=node.as_loc, name_loc=node.name_loc,
colon_loc=node.colon_loc, loc=node.loc)
2 changes: 1 addition & 1 deletion artiq/compiler/transforms/inferencer.py
Original file line number Diff line number Diff line change
@@ -827,7 +827,7 @@ def makenotes(printer, typea, typeb, loca, locb):
{"typeb": printer.name(typeb)},
locb)
]
self._unify(node.name_type, node.filter.type.to_exception_type(),
self._unify(node.name_type, builtins.TException(node.filter.type.name),
node.name_loc, node.filter.loc, makenotes)

def _type_from_arguments(self, node, ret):
3 changes: 0 additions & 3 deletions artiq/compiler/types.py
Original file line number Diff line number Diff line change
@@ -268,9 +268,6 @@ class TExceptionConstructor(TBuiltin):
Note that this is not the same as the type of an instance of
the class, which is ``TMono("Exception", ...)``.
"""
def to_exception_type(self):
# Exceptions currently can't have type parameters
return TMono(self.name, {})

class TValue(Type):
"""