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: 4b4805265d14
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: 1c48874a2a2e
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Jun 13, 2015

  1. GeneratorExp also includes assignment context.

    whitequark committed Jun 13, 2015
    Copy the full SHA
    de6dff9 View commit details
  2. Documentation.

    whitequark committed Jun 13, 2015
    Copy the full SHA
    1c48874 View commit details
Showing with 35 additions and 6 deletions.
  1. +35 −6 artiq/py2llvm/typing.py
41 changes: 35 additions & 6 deletions artiq/py2llvm/typing.py
Original file line number Diff line number Diff line change
@@ -58,12 +58,13 @@ def visit_root(self, node):
self.in_root = True
self.generic_visit(node)

visit_ClassDef = visit_root # don't look at inner scopes
visit_FunctionDef = visit_root
visit_Lambda = visit_root
visit_DictComp = visit_root
visit_ListComp = visit_root
visit_SetComp = visit_root
visit_ClassDef = visit_root # don't look at inner scopes
visit_FunctionDef = visit_root
visit_Lambda = visit_root
visit_DictComp = visit_root
visit_ListComp = visit_root
visit_SetComp = visit_root
visit_GeneratorExp = visit_root

def _assignable(self, name):
if name not in self.typing_env and name not in self.nonlocal_:
@@ -127,6 +128,15 @@ def visit_ExceptHandler(self, node):


class ASTTypedRewriter(algorithm.Transformer):
"""
:class:`ASTTypedRewriter` converts an untyped AST to a typed AST
where all type fields of non-literals are filled with fresh type variables,
and type fields of literals are filled with corresponding types.
:class:`ASTTypedRewriter` also discovers the scope of variable bindings
via :class:`LocalExtractor`.
"""

def __init__(self, engine):
self.engine = engine
self.env_stack = []
@@ -294,6 +304,15 @@ def visit_unsupported(self, node):


class Inferencer(algorithm.Visitor):
"""
:class:`Inferencer` infers types by recursively applying the unification
algorithm. It does not treat inability to infer a concrete type as an error;
the result can still contain type variables.
:class:`Inferencer` is idempotent, but does not guarantee that it will
perform all possible inference in a single pass.
"""

def __init__(self, engine):
self.engine = engine
self.function = None # currently visited function, for Return inference
@@ -459,6 +478,16 @@ def makenotes(printer, typea, typeb, loca, locb):
self.function.name_loc, node.value.loc, makenotes)

class Printer(algorithm.Visitor):
"""
:class:`Printer` prints ``:`` and the node type after every typed node,
and ``->`` and the node type before the colon in a function definition.
In almost all cases (except function definition) this does not result
in valid Python syntax.
:ivar rewriter: (:class:`pythonparser.source.Rewriter`) rewriter instance
"""

def __init__(self, buf):
self.rewriter = source.Rewriter(buf)
self.type_printer = types.TypePrinter()