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

Commits on Aug 10, 2015

  1. compiler.ir.Function: add loc field.

    whitequark committed Aug 10, 2015
    Copy the full SHA
    8f510a4 View commit details
  2. compiler.types: make all hashable.

    whitequark committed Aug 10, 2015
    Copy the full SHA
    4f02f6e View commit details
Showing with 33 additions and 8 deletions.
  1. +2 −1 artiq/compiler/embedding.py
  2. +7 −2 artiq/compiler/ir.py
  3. +4 −2 artiq/compiler/transforms/artiq_ir_generator.py
  4. +20 −3 artiq/compiler/types.py
3 changes: 2 additions & 1 deletion artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -184,9 +184,10 @@ def _iterate(self):
inferencer.visit(self.typedtree)

# After we have found all functions, synthesize a module to hold them.
source_buffer = source.Buffer("", "<synthesized>")
self.typedtree = asttyped.ModuleT(
typing_env=self.globals, globals_in_scope=set(),
body=self.typedtree, loc=None)
body=self.typedtree, loc=source.Range(source_buffer, 0, 0))

def _quote_embedded_function(self, function):
if not hasattr(function, "artiq_embedded"):
9 changes: 7 additions & 2 deletions artiq/compiler/ir.py
Original file line number Diff line number Diff line change
@@ -138,6 +138,9 @@ def replace_uses_of(self, value, replacement):
class Instruction(User):
"""
An SSA instruction.
:ivar loc: (:class:`pythonparser.source.Range` or None)
source location
"""

def __init__(self, operands, typ, name=""):
@@ -388,13 +391,15 @@ class Function:
"""
A function containing SSA IR.
:ivar loc: (:class:`pythonparser.source.Range` or None)
source location of function definition
:ivar is_internal:
(bool) if True, the function should not be accessible from outside
the module it is contained in
"""

def __init__(self, typ, name, arguments):
self.type, self.name = typ, name
def __init__(self, typ, name, arguments, loc=None):
self.type, self.name, self.loc = typ, name, loc
self.names, self.arguments, self.basic_blocks = set(), [], []
self.next_name = 1
self.set_arguments(arguments)
6 changes: 4 additions & 2 deletions artiq/compiler/transforms/artiq_ir_generator.py
Original file line number Diff line number Diff line change
@@ -129,7 +129,8 @@ def visit_ModuleT(self, node):

try:
typ = types.TFunction(OrderedDict(), OrderedDict(), builtins.TNone())
func = ir.Function(typ, ".".join(self.name + ['__modinit__']), [])
func = ir.Function(typ, ".".join(self.name + ['__modinit__']), [],
loc=node.loc.begin())
self.functions.append(func)
old_func, self.current_function = self.current_function, func

@@ -184,7 +185,8 @@ def visit_function(self, node, is_lambda, is_internal):
for arg_name in typ.optargs:
optargs.append(ir.Argument(ir.TOption(typ.optargs[arg_name]), "arg." + arg_name))

func = ir.Function(typ, ".".join(self.name), [env_arg] + args + optargs)
func = ir.Function(typ, ".".join(self.name), [env_arg] + args + optargs,
loc=node.keyword_loc)
func.is_internal = is_internal
self.functions.append(func)
old_func, self.current_function = self.current_function, func
23 changes: 20 additions & 3 deletions artiq/compiler/types.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,12 @@
import string
from collections import OrderedDict


class UnificationError(Exception):
def __init__(self, typea, typeb):
self.typea, self.typeb = typea, typeb


def genalnum():
ident = ["a"]
while True:
@@ -22,9 +28,8 @@ def genalnum():
if pos < 0:
ident = ["a"] + ident

class UnificationError(Exception):
def __init__(self, typea, typeb):
self.typea, self.typeb = typea, typeb
def _freeze(dict_):
return tuple((key, dict_[key]) for key in dict_)

def _map_find(elts):
if isinstance(elts, list):
@@ -34,6 +39,7 @@ def _map_find(elts):
else:
assert False


class Type(object):
pass

@@ -93,6 +99,7 @@ class TMono(Type):
attributes = OrderedDict()

def __init__(self, name, params={}):
assert isinstance(params, dict)
self.name, self.params = name, params

def find(self):
@@ -127,6 +134,9 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

def __hash__(self):
return hash((self.name, _freeze(self.params)))

class TTuple(Type):
"""
A tuple type.
@@ -181,6 +191,9 @@ class TFunction(Type):
attributes = OrderedDict()

def __init__(self, args, optargs, ret):
assert isinstance(args, OrderedDict)
assert isinstance(optargs, OrderedDict)
assert isinstance(ret, Type)
self.args, self.optargs, self.ret = args, optargs, ret

def arity(self):
@@ -222,6 +235,9 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

def __hash__(self):
return hash((_freeze(self.args), _freeze(self.optargs), self.ret))

class TRPCFunction(TFunction):
"""
A function type of a remote function.
@@ -249,6 +265,7 @@ class TBuiltin(Type):
"""

def __init__(self, name):
assert isinstance(name, str)
self.name = name
self.attributes = OrderedDict()