Commit 237396d2 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Upgraded NewTempExprNode, converted PrimaryCmpNode to it

parent ca5a8207
......@@ -569,9 +569,23 @@ class ExprNode(Node):
return None
class RemoveAllocateTemps(type):
def __init__(cls, name, bases, dct):
super(RemoveAllocateTemps, cls).__init__(name, bases, dct)
def noop(self, env): pass
setattr(cls, 'allocate_temps', noop)
setattr(cls, 'allocate_temp', noop)
setattr(cls, 'release_temps', noop)
setattr(cls, 'release_temp', noop)
class NewTempExprNode(ExprNode):
backwards_compatible_result = None
# Do not enable this unless you are trying to make all ExprNodes
# NewTempExprNodes (child nodes reached via recursion may not have
# transferred).
# __metaclass__ = RemoveAllocateTemps
def result(self):
if self.is_temp:
return self.temp_code
......@@ -598,15 +612,7 @@ class NewTempExprNode(ExprNode):
else:
self.release_subexpr_temps(env)
def generate_evaluation_code(self, code):
code.mark_pos(self.pos)
# Generate code to evaluate this node and
# its sub-expressions, and dispose of any
# temporary results of its sub-expressions.
self.generate_subexpr_evaluation_code(code)
if self.is_temp:
def allocate_temp_result(self, code):
type = self.type
if not type.is_void:
if type.is_pyobject:
......@@ -619,6 +625,20 @@ class NewTempExprNode(ExprNode):
else:
self.temp_code = None
def release_temp_result(self, code):
code.funcstate.release_temp(self.temp_code)
def generate_evaluation_code(self, code):
code.mark_pos(self.pos)
# Generate code to evaluate this node and
# its sub-expressions, and dispose of any
# temporary results of its sub-expressions.
self.generate_subexpr_evaluation_code(code)
if self.is_temp:
self.allocate_temp_result(code)
self.generate_result_code(code)
if self.is_temp:
self.generate_subexpr_disposal_code(code)
......@@ -628,7 +648,7 @@ class NewTempExprNode(ExprNode):
if self.type.is_pyobject:
code.put_decref_clear(self.result(), self.ctype())
if not self.backwards_compatible_result:
code.funcstate.release_temp(self.temp_code)
self.release_temp_result(code)
else:
self.generate_subexpr_disposal_code(code)
......@@ -641,8 +661,7 @@ class NewTempExprNode(ExprNode):
else:
self.generate_subexpr_disposal_code(code)
# ExprNode = NewTempExprNode
class AtomicExprNode(ExprNode):
# Abstract base class for expression nodes which have
......@@ -4228,7 +4247,7 @@ class CmpNode:
return op
class PrimaryCmpNode(ExprNode, CmpNode):
class PrimaryCmpNode(NewTempExprNode, CmpNode):
# Non-cascaded comparison or first comparison of
# a cascaded sequence.
#
......@@ -4332,6 +4351,7 @@ class PrimaryCmpNode(ExprNode, CmpNode):
self.operand1.generate_evaluation_code(code)
self.operand2.generate_evaluation_code(code)
if self.is_temp:
self.allocate_temp_result(code)
self.generate_operation_code(code, self.result(),
self.operand1, self.operator, self.operand2)
if self.cascade:
......
......@@ -87,6 +87,15 @@ class Context:
from Buffer import IntroduceBufferAuxiliaryVars
from ModuleNode import check_c_declarations
# Temporary hack that can be used to ensure that all result_code's
# are generated at code generation time.
import Visitor
class ClearResultCodes(Visitor.CythonTransform):
def visit_ExprNode(self, node):
self.visitchildren(node)
node.result_code = "<cleared>"
return node
if pxd:
_check_c_declarations = None
_specific_post_parse = PxdPostParse(self)
......@@ -118,6 +127,7 @@ class Context:
DictIterTransform(),
SwitchTransform(),
FinalOptimizePhase(self),
# ClearResultCodes(self),
# SpecialFunctions(self),
# CreateClosureClasses(context),
]
......
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