Commit 6ee53629 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Convert low-hanging fruit to new temps. 12 down, 27 to go.

parent 6fb8b963
...@@ -641,6 +641,8 @@ class NewTempExprNode(ExprNode): ...@@ -641,6 +641,8 @@ class NewTempExprNode(ExprNode):
self.generate_result_code(code) self.generate_result_code(code)
if self.is_temp: 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) self.generate_subexpr_disposal_code(code)
def generate_disposal_code(self, code): def generate_disposal_code(self, code):
...@@ -669,8 +671,31 @@ class AtomicExprNode(ExprNode): ...@@ -669,8 +671,31 @@ class AtomicExprNode(ExprNode):
subexprs = [] 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.
class PyConstNode(AtomicExprNode): # 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)
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. # Abstract base class for constant Python values.
is_literal = 1 is_literal = 1
...@@ -705,7 +730,7 @@ class EllipsisNode(PyConstNode): ...@@ -705,7 +730,7 @@ class EllipsisNode(PyConstNode):
return Ellipsis return Ellipsis
class ConstNode(AtomicExprNode): class ConstNode(AtomicNewTempExprNode):
# Abstract base type for literal constant nodes. # Abstract base type for literal constant nodes.
# #
# value string C code fragment # value string C code fragment
...@@ -905,7 +930,7 @@ class IdentifierStringNode(ConstNode): ...@@ -905,7 +930,7 @@ class IdentifierStringNode(ConstNode):
return self.cname return self.cname
class LongNode(AtomicExprNode): class LongNode(AtomicNewTempExprNode):
# Python long integer literal # Python long integer literal
# #
# value string # value string
...@@ -922,7 +947,7 @@ class LongNode(AtomicExprNode): ...@@ -922,7 +947,7 @@ class LongNode(AtomicExprNode):
gil_message = "Constructing Python long int" gil_message = "Constructing Python long int"
def generate_evaluation_code(self, code): def generate_result_code(self, code):
code.putln( code.putln(
'%s = PyLong_FromString((char *)"%s", 0, 0); %s' % ( '%s = PyLong_FromString((char *)"%s", 0, 0); %s' % (
self.result(), self.result(),
...@@ -930,7 +955,7 @@ class LongNode(AtomicExprNode): ...@@ -930,7 +955,7 @@ class LongNode(AtomicExprNode):
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
class ImagNode(AtomicExprNode): class ImagNode(AtomicNewTempExprNode):
# Imaginary number literal # Imaginary number literal
# #
# value float imaginary part # value float imaginary part
...@@ -945,7 +970,7 @@ class ImagNode(AtomicExprNode): ...@@ -945,7 +970,7 @@ class ImagNode(AtomicExprNode):
gil_message = "Constructing complex number" gil_message = "Constructing complex number"
def generate_evaluation_code(self, code): def generate_result_code(self, code):
code.putln( code.putln(
"%s = PyComplex_FromDoubles(0.0, %s); %s" % ( "%s = PyComplex_FromDoubles(0.0, %s); %s" % (
self.result(), self.result(),
...@@ -1408,7 +1433,7 @@ class IteratorNode(NewTempExprNode): ...@@ -1408,7 +1433,7 @@ class IteratorNode(NewTempExprNode):
code.putln("}") code.putln("}")
class NextNode(AtomicExprNode): class NextNode(AtomicNewTempExprNode):
# Used as part of for statement implementation. # Used as part of for statement implementation.
# Implements result = iterator.next() # Implements result = iterator.next()
# Created during analyse_types phase. # Created during analyse_types phase.
...@@ -1466,7 +1491,7 @@ class NextNode(AtomicExprNode): ...@@ -1466,7 +1491,7 @@ class NextNode(AtomicExprNode):
code.putln("}") code.putln("}")
class ExcValueNode(AtomicExprNode): class ExcValueNode(AtomicNewTempExprNode):
# Node created during analyse_types phase # Node created during analyse_types phase
# of an ExceptClauseNode to fetch the current # of an ExceptClauseNode to fetch the current
# exception value. # exception value.
...@@ -1486,10 +1511,12 @@ class ExcValueNode(AtomicExprNode): ...@@ -1486,10 +1511,12 @@ class ExcValueNode(AtomicExprNode):
pass pass
class TempNode(AtomicExprNode): class TempNode(ExprNode):
# Node created during analyse_types phase # Node created during analyse_types phase
# of some nodes to hold a temporary value. # of some nodes to hold a temporary value.
subexprs = []
def __init__(self, pos, type, env): def __init__(self, pos, type, env):
ExprNode.__init__(self, pos) ExprNode.__init__(self, pos)
self.type = type self.type = type
...@@ -3277,7 +3304,7 @@ class UnboundMethodNode(ExprNode): ...@@ -3277,7 +3304,7 @@ class UnboundMethodNode(ExprNode):
code.error_goto_if_null(self.result(), 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 # Helper class used in the implementation of Python
# class definitions. Constructs a PyCFunction object # class definitions. Constructs a PyCFunction object
# from a PyMethodDef struct. # from a PyMethodDef struct.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment