self.generate_result_code(code)
if self.is_temp:
+ # If we are temp, need to wait until this node is disposed
+ # before disposing children.
self.generate_subexpr_disposal_code(code)
def generate_disposal_code(self, code):
subexprs = []
+class AtomicNewTempExprNode(NewTempExprNode):
+ # I do not dare to convert NameNode yet. This is now
+ # ancestor of all former AtomicExprNode except
+ # NameNode. Should be renamed to AtomicExprNode
+ # when done.
+
+ # Abstract base class for expression nodes which have
+ # no sub-expressions.
+
+ subexprs = []
+
+ # Override to optimize -- we know we have no children
+ def generate_evaluation_code(self, code):
+ if self.is_temp:
+ self.allocate_temp_result(code)
+ self.generate_result_code(code)
-class PyConstNode(AtomicExprNode):
+ def generate_disposal_code(self, code):
+ if self.is_temp:
+ if self.type.is_pyobject:
+ code.put_decref_clear(self.result(), self.ctype())
+ if not self.backwards_compatible_result:
+ self.release_temp_result(code)
+
+class PyConstNode(AtomicNewTempExprNode):
# Abstract base class for constant Python values.
is_literal = 1
return Ellipsis
-class ConstNode(AtomicExprNode):
+class ConstNode(AtomicNewTempExprNode):
# Abstract base type for literal constant nodes.
#
# value string C code fragment
return self.cname
-class LongNode(AtomicExprNode):
+class LongNode(AtomicNewTempExprNode):
# Python long integer literal
#
# value string
gil_message = "Constructing Python long int"
- def generate_evaluation_code(self, code):
+ def generate_result_code(self, code):
code.putln(
'%s = PyLong_FromString((char *)"%s", 0, 0); %s' % (
self.result(),
code.error_goto_if_null(self.result(), self.pos)))
-class ImagNode(AtomicExprNode):
+class ImagNode(AtomicNewTempExprNode):
# Imaginary number literal
#
# value float imaginary part
gil_message = "Constructing complex number"
- def generate_evaluation_code(self, code):
+ def generate_result_code(self, code):
code.putln(
"%s = PyComplex_FromDoubles(0.0, %s); %s" % (
self.result(),
code.putln("}")
-class NextNode(AtomicExprNode):
+class NextNode(AtomicNewTempExprNode):
# Used as part of for statement implementation.
# Implements result = iterator.next()
# Created during analyse_types phase.
code.putln("}")
-class ExcValueNode(AtomicExprNode):
+class ExcValueNode(AtomicNewTempExprNode):
# Node created during analyse_types phase
# of an ExceptClauseNode to fetch the current
# exception value.
pass
-class TempNode(AtomicExprNode):
+class TempNode(ExprNode):
# Node created during analyse_types phase
# of some nodes to hold a temporary value.
+
+ subexprs = []
def __init__(self, pos, type, env):
ExprNode.__init__(self, pos)
code.error_goto_if_null(self.result(), self.pos)))
-class PyCFunctionNode(AtomicExprNode):
+class PyCFunctionNode(AtomicNewTempExprNode):
# Helper class used in the implementation of Python
# class definitions. Constructs a PyCFunction object
# from a PyMethodDef struct.