mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Bring Tools/compiler almost up to date. Specifically:
- fix tab space issues (SF patch #101167 by Neil Schemenauer) - fix co_flags for classes to include CO_NEWLOCALS (SF patch #101145 by Neil) - fix for merger of UNPACK_LIST and UNPACK_TUPLE into UNPACK_SEQUENCE, (SF patch #101168 by, well, Neil :) - Adjust bytecode MAGIC to current bytecode. TODO: teach compile.py about list comprehensions.
This commit is contained in:
parent
81f7eb6c6b
commit
46cc7c0f7b
6 changed files with 692 additions and 690 deletions
|
@ -513,11 +513,9 @@ class StackDepthTracker:
|
||||||
]
|
]
|
||||||
|
|
||||||
# special cases:
|
# special cases:
|
||||||
# UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
|
# UNPACK_SEQUENCE, BUILD_TUPLE,
|
||||||
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
|
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
|
||||||
def UNPACK_TUPLE(self, count):
|
def UNPACK_SEQUENCE(self, count):
|
||||||
return count
|
|
||||||
def UNPACK_LIST(self, count):
|
|
||||||
return count
|
return count
|
||||||
def BUILD_TUPLE(self, count):
|
def BUILD_TUPLE(self, count):
|
||||||
return -count
|
return -count
|
||||||
|
|
|
@ -7,7 +7,7 @@ from cStringIO import StringIO
|
||||||
|
|
||||||
from compiler import ast, parse, walk
|
from compiler import ast, parse, walk
|
||||||
from compiler import pyassem, misc
|
from compiler import pyassem, misc
|
||||||
from compiler.pyassem import CO_VARARGS, CO_VARKEYWORDS, TupleArg
|
from compiler.pyassem import CO_VARARGS, CO_VARKEYWORDS, CO_NEWLOCALS, TupleArg
|
||||||
|
|
||||||
callfunc_opcode_info = {
|
callfunc_opcode_info = {
|
||||||
# (Have *args, Have **args) : opcode
|
# (Have *args, Have **args) : opcode
|
||||||
|
@ -44,7 +44,7 @@ class Module:
|
||||||
f.write(self.getPycHeader())
|
f.write(self.getPycHeader())
|
||||||
marshal.dump(self.code, f)
|
marshal.dump(self.code, f)
|
||||||
|
|
||||||
MAGIC = (20121 | (ord('\r')<<16) | (ord('\n')<<24))
|
MAGIC = (50811 | (ord('\r')<<16) | (ord('\n')<<24))
|
||||||
|
|
||||||
def getPycHeader(self):
|
def getPycHeader(self):
|
||||||
# compile.c uses marshal to write a long directly, with
|
# compile.c uses marshal to write a long directly, with
|
||||||
|
@ -470,7 +470,7 @@ class CodeGenerator:
|
||||||
|
|
||||||
def visitAssTuple(self, node):
|
def visitAssTuple(self, node):
|
||||||
if findOp(node) != 'OP_DELETE':
|
if findOp(node) != 'OP_DELETE':
|
||||||
self.emit('UNPACK_TUPLE', len(node.nodes))
|
self.emit('UNPACK_SEQUENCE', len(node.nodes))
|
||||||
for child in node.nodes:
|
for child in node.nodes:
|
||||||
self.visit(child)
|
self.visit(child)
|
||||||
|
|
||||||
|
@ -714,16 +714,18 @@ class FunctionCodeGenerator(CodeGenerator):
|
||||||
if type(arg) == types.TupleType:
|
if type(arg) == types.TupleType:
|
||||||
self.emit('LOAD_FAST', '.nested%d' % count)
|
self.emit('LOAD_FAST', '.nested%d' % count)
|
||||||
count = count + 1
|
count = count + 1
|
||||||
self.unpackTuple(arg)
|
self.unpackSequence(arg)
|
||||||
|
|
||||||
def unpackTuple(self, tup):
|
def unpackSequence(self, tup):
|
||||||
self.emit('UNPACK_TUPLE', len(tup))
|
self.emit('UNPACK_SEQUENCE', len(tup))
|
||||||
for elt in tup:
|
for elt in tup:
|
||||||
if type(elt) == types.TupleType:
|
if type(elt) == types.TupleType:
|
||||||
self.unpackTuple(elt)
|
self.unpackSequence(elt)
|
||||||
else:
|
else:
|
||||||
self.emit('STORE_FAST', elt)
|
self.emit('STORE_FAST', elt)
|
||||||
|
|
||||||
|
unpackTuple = unpackSequence
|
||||||
|
|
||||||
class ClassCodeGenerator(CodeGenerator):
|
class ClassCodeGenerator(CodeGenerator):
|
||||||
super_init = CodeGenerator.__init__
|
super_init = CodeGenerator.__init__
|
||||||
|
|
||||||
|
@ -733,6 +735,7 @@ class ClassCodeGenerator(CodeGenerator):
|
||||||
self.super_init(filename)
|
self.super_init(filename)
|
||||||
lnf = walk(klass.code, LocalNameFinder(), 0)
|
lnf = walk(klass.code, LocalNameFinder(), 0)
|
||||||
self.locals.push(lnf.getLocals())
|
self.locals.push(lnf.getLocals())
|
||||||
|
self.graph.setFlag(CO_NEWLOCALS)
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
self.graph.startExitBlock()
|
self.graph.startExitBlock()
|
||||||
|
|
|
@ -513,11 +513,9 @@ class StackDepthTracker:
|
||||||
]
|
]
|
||||||
|
|
||||||
# special cases:
|
# special cases:
|
||||||
# UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
|
# UNPACK_SEQUENCE, BUILD_TUPLE,
|
||||||
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
|
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
|
||||||
def UNPACK_TUPLE(self, count):
|
def UNPACK_SEQUENCE(self, count):
|
||||||
return count
|
|
||||||
def UNPACK_LIST(self, count):
|
|
||||||
return count
|
return count
|
||||||
def BUILD_TUPLE(self, count):
|
def BUILD_TUPLE(self, count):
|
||||||
return -count
|
return -count
|
||||||
|
|
|
@ -7,7 +7,7 @@ from cStringIO import StringIO
|
||||||
|
|
||||||
from compiler import ast, parse, walk
|
from compiler import ast, parse, walk
|
||||||
from compiler import pyassem, misc
|
from compiler import pyassem, misc
|
||||||
from compiler.pyassem import CO_VARARGS, CO_VARKEYWORDS, TupleArg
|
from compiler.pyassem import CO_VARARGS, CO_VARKEYWORDS, CO_NEWLOCALS, TupleArg
|
||||||
|
|
||||||
callfunc_opcode_info = {
|
callfunc_opcode_info = {
|
||||||
# (Have *args, Have **args) : opcode
|
# (Have *args, Have **args) : opcode
|
||||||
|
@ -44,7 +44,7 @@ class Module:
|
||||||
f.write(self.getPycHeader())
|
f.write(self.getPycHeader())
|
||||||
marshal.dump(self.code, f)
|
marshal.dump(self.code, f)
|
||||||
|
|
||||||
MAGIC = (20121 | (ord('\r')<<16) | (ord('\n')<<24))
|
MAGIC = (50811 | (ord('\r')<<16) | (ord('\n')<<24))
|
||||||
|
|
||||||
def getPycHeader(self):
|
def getPycHeader(self):
|
||||||
# compile.c uses marshal to write a long directly, with
|
# compile.c uses marshal to write a long directly, with
|
||||||
|
@ -470,7 +470,7 @@ class CodeGenerator:
|
||||||
|
|
||||||
def visitAssTuple(self, node):
|
def visitAssTuple(self, node):
|
||||||
if findOp(node) != 'OP_DELETE':
|
if findOp(node) != 'OP_DELETE':
|
||||||
self.emit('UNPACK_TUPLE', len(node.nodes))
|
self.emit('UNPACK_SEQUENCE', len(node.nodes))
|
||||||
for child in node.nodes:
|
for child in node.nodes:
|
||||||
self.visit(child)
|
self.visit(child)
|
||||||
|
|
||||||
|
@ -714,16 +714,18 @@ class FunctionCodeGenerator(CodeGenerator):
|
||||||
if type(arg) == types.TupleType:
|
if type(arg) == types.TupleType:
|
||||||
self.emit('LOAD_FAST', '.nested%d' % count)
|
self.emit('LOAD_FAST', '.nested%d' % count)
|
||||||
count = count + 1
|
count = count + 1
|
||||||
self.unpackTuple(arg)
|
self.unpackSequence(arg)
|
||||||
|
|
||||||
def unpackTuple(self, tup):
|
def unpackSequence(self, tup):
|
||||||
self.emit('UNPACK_TUPLE', len(tup))
|
self.emit('UNPACK_SEQUENCE', len(tup))
|
||||||
for elt in tup:
|
for elt in tup:
|
||||||
if type(elt) == types.TupleType:
|
if type(elt) == types.TupleType:
|
||||||
self.unpackTuple(elt)
|
self.unpackSequence(elt)
|
||||||
else:
|
else:
|
||||||
self.emit('STORE_FAST', elt)
|
self.emit('STORE_FAST', elt)
|
||||||
|
|
||||||
|
unpackTuple = unpackSequence
|
||||||
|
|
||||||
class ClassCodeGenerator(CodeGenerator):
|
class ClassCodeGenerator(CodeGenerator):
|
||||||
super_init = CodeGenerator.__init__
|
super_init = CodeGenerator.__init__
|
||||||
|
|
||||||
|
@ -733,6 +735,7 @@ class ClassCodeGenerator(CodeGenerator):
|
||||||
self.super_init(filename)
|
self.super_init(filename)
|
||||||
lnf = walk(klass.code, LocalNameFinder(), 0)
|
lnf = walk(klass.code, LocalNameFinder(), 0)
|
||||||
self.locals.push(lnf.getLocals())
|
self.locals.push(lnf.getLocals())
|
||||||
|
self.graph.setFlag(CO_NEWLOCALS)
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
self.graph.startExitBlock()
|
self.graph.startExitBlock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue