def trigger_cg_hook(self, name, g, header=None, *args, **kwargs): if header is not None: g << "# ___" + header + "___\n" appended_context = False if g not in self.__appended_context: # check so there aren't extra copies wasting time g._append_context(self._name_lookup) self.__appended_context[g] = appended_context = True method = getattr(self, name, None) if cypy.is_callable(method): method(g, *args, **kwargs) try: children = self.children except AttributeError: return else: if children is not None: for child in children: method = getattr(child, 'trigger_cg_hook', None) if cypy.is_callable(method): method(name, g, None, *args, **kwargs) else: method = getattr(child, name, None) if cypy.is_callable(method): method(*args, **kwargs) if appended_context: g.pop_context() del self.__appended_context[g]
def _process_nonstrings(self, code): if code is not None and code is not self: expr = getattr(code, '_CG_expression', None) if expr is not None: # Push the value's context onto stack context = getattr(code, '_CG_context', None) if context: self._append_context(context) else: context = None self.append(expr) if context: self.pop_context() elif cypy.is_callable(code): code = self._call_callable(code) if code is not None and code is not self: self.append(code) elif cypy.is_iterable(code): for item in code: self.append(item) else: self.append(self._convert(code))