def _get_ast_str(self, top): if not self._cache.is_empty( ): # Data already computed and cached; could a "false-like" cached value return str(self._cache._data) if self._cache.is_scalar( ) else self._cache._id if self._cache._id is not None: return self._cache._id # Data already computed under ID, but not cached assert isinstance(self._children, tuple) exec_str = "({} {})".format( self._op, " ".join([ExprNode._arg_to_expr(ast) for ast in self._children])) def is_ast_expr(ref): return isinstance(ref, list) and any( map(lambda r: isinstance(r, ASTId), ref)) referrers = gc.get_referrers(self) # removing frames from the referrers to get a consistent behaviour accross Py versions # as stack frames don't appear in the referrers from Py 3.7. # also removing the AST expressions built in astfun.py # as they keep a reference to self if the lambda itself is using a free variable. proper_ref = [ r for r in referrers if not (inspect.isframe(r) or is_ast_expr(r)) ] ref_cnt = len(proper_ref) del referrers, proper_ref # if this self node is referenced by at least one other node (nested expr), then create a tmp frame if top or ref_cnt > 1: self._cache._id = _py_tmp_key(append=h2o.connection().session_id) exec_str = "(tmp= {} {})".format(self._cache._id, exec_str) return exec_str
def _do_it(self, top): if not self._cache.is_empty(): # Data already computed and cached; could a "false-like" cached value return str(self._cache._data) if self._cache.is_scalar() else self._cache._id if self._cache._id is not None: return self._cache._id # Data already computed under ID, but not cached # assert isinstance(self._children,tuple) exec_str = "({} {})".format(self._op, " ".join([ExprNode._arg_to_expr(ast) for ast in self._children])) gc_ref_cnt = len(gc.get_referrers(self)) if top or gc_ref_cnt >= ExprNode.MAGIC_REF_COUNT: self._cache._id = _py_tmp_key(append=h2o.conn().session_id) exec_str = "(tmp= {} {})".format(self._cache._id, exec_str) return exec_str
def _get_ast_str(self, top): if not self._cache.is_empty(): # Data already computed and cached; could a "false-like" cached value return str(self._cache._data) if self._cache.is_scalar() else self._cache._id if self._cache._id is not None: return self._cache._id # Data already computed under ID, but not cached # assert isinstance(self._children,tuple) exec_str = "({} {})".format(self._op, " ".join([ExprNode._arg_to_expr(ast) for ast in self._children])) gc_ref_cnt = len(gc.get_referrers(self)) if top or gc_ref_cnt >= ExprNode.MAGIC_REF_COUNT: self._cache._id = _py_tmp_key(append=h2o.connection().session_id) exec_str = "(tmp= {} {})".format(self._cache._id, exec_str) return exec_str