From d41ac863f451dae59ddcf336d62ed74f9db39958 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 17 Jun 2014 19:46:22 +0200 Subject: [PATCH] inline: support kernel_attr_ro --- artiq/compiler/inline.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/artiq/compiler/inline.py b/artiq/compiler/inline.py index 81b37ba72..25785f6d0 100644 --- a/artiq/compiler/inline.py +++ b/artiq/compiler/inline.py @@ -29,6 +29,11 @@ def _replace_global(obj, ref): _UserVariable = namedtuple("_UserVariable", "name") +def _is_in_attr_list(obj, attr, al): + if not hasattr(obj, al): + return False + return attr in getattr(obj, al).split() + class _ReferenceManager: def __init__(self): # (id(obj), funcname, local) -> _UserVariable(name) / ast / constant_object @@ -83,6 +88,20 @@ class _ReferenceManager: raise NotImplementedError("Cannot represent inlined value") return a + if isinstance(ref, ast.Attribute) and isinstance(ref.value, ast.Name): + try: + value = self.to_inlined[(id(obj), funcname, ref.value.id)] + except KeyError: + pass + else: + if _is_in_attr_list(value, ref.attr, "kernel_attr_ro"): + if isinstance(ref.ctx, ast.Store): + raise TypeError("Attempted to assign to read-only kernel attribute") + a = _value_to_ast(getattr(value, ref.attr)) + if a is None: + raise NotImplementedError("Cannot represent read-only kernel attribute") + return a + if not store: repl = _replace_global(obj, ref) if repl is not None: