From 94afe32b5eabf962c872850b10886f4545b02614 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Wed, 29 Aug 2001 18:14:39 +0000 Subject: [PATCH] Support // and //= Generate SET_LINENO for del statements. Define klass=1 for PyFlowGraph constructor for a class statement. A class has no varnames. --- Lib/compiler/pycodegen.py | 7 ++++++- Tools/compiler/compiler/pycodegen.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index 882e6b1a2bf..b0bddb71a84 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -671,6 +671,7 @@ class CodeGenerator: if node.flags == 'OP_ASSIGN': self.storeName(node.name) elif node.flags == 'OP_DELETE': + self.set_lineno(node) self.delName(node.name) else: print "oops", node.flags @@ -716,6 +717,7 @@ class CodeGenerator: '-=' : 'INPLACE_SUBTRACT', '*=' : 'INPLACE_MULTIPLY', '/=' : 'INPLACE_DIVIDE', + '//=': 'INPLACE_FLOOR_DIVIDE', '%=' : 'INPLACE_MODULO', '**=': 'INPLACE_POWER', '>>=': 'INPLACE_RSHIFT', @@ -889,6 +891,9 @@ class CodeGenerator: def visitDiv(self, node): return self.binaryOp(node, 'BINARY_DIVIDE') + def visitFloorDiv(self, node): + return self.binaryOp(node, 'BINARY_FLOOR_DIVIDE') + def visitMod(self, node): return self.binaryOp(node, 'BINARY_MODULO') @@ -1168,7 +1173,7 @@ class AbstractClassCode: def __init__(self, klass, filename, scopes): self.class_name = klass.name self.graph = pyassem.PyFlowGraph(klass.name, filename, - optimized=0) + optimized=0, klass=1) self.super_init(filename) lnf = walk(klass.code, self.NameFinder(), verbose=0) self.locals.push(lnf.getLocals()) diff --git a/Tools/compiler/compiler/pycodegen.py b/Tools/compiler/compiler/pycodegen.py index 882e6b1a2bf..b0bddb71a84 100644 --- a/Tools/compiler/compiler/pycodegen.py +++ b/Tools/compiler/compiler/pycodegen.py @@ -671,6 +671,7 @@ class CodeGenerator: if node.flags == 'OP_ASSIGN': self.storeName(node.name) elif node.flags == 'OP_DELETE': + self.set_lineno(node) self.delName(node.name) else: print "oops", node.flags @@ -716,6 +717,7 @@ class CodeGenerator: '-=' : 'INPLACE_SUBTRACT', '*=' : 'INPLACE_MULTIPLY', '/=' : 'INPLACE_DIVIDE', + '//=': 'INPLACE_FLOOR_DIVIDE', '%=' : 'INPLACE_MODULO', '**=': 'INPLACE_POWER', '>>=': 'INPLACE_RSHIFT', @@ -889,6 +891,9 @@ class CodeGenerator: def visitDiv(self, node): return self.binaryOp(node, 'BINARY_DIVIDE') + def visitFloorDiv(self, node): + return self.binaryOp(node, 'BINARY_FLOOR_DIVIDE') + def visitMod(self, node): return self.binaryOp(node, 'BINARY_MODULO') @@ -1168,7 +1173,7 @@ class AbstractClassCode: def __init__(self, klass, filename, scopes): self.class_name = klass.name self.graph = pyassem.PyFlowGraph(klass.name, filename, - optimized=0) + optimized=0, klass=1) self.super_init(filename) lnf = walk(klass.code, self.NameFinder(), verbose=0) self.locals.push(lnf.getLocals())