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:
Thomas Wouters 2000-08-12 20:32:46 +00:00
parent 81f7eb6c6b
commit 46cc7c0f7b
6 changed files with 692 additions and 690 deletions

View File

@ -513,11 +513,9 @@ class StackDepthTracker:
]
# special cases:
# UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
# UNPACK_SEQUENCE, BUILD_TUPLE,
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
def UNPACK_TUPLE(self, count):
return count
def UNPACK_LIST(self, count):
def UNPACK_SEQUENCE(self, count):
return count
def BUILD_TUPLE(self, count):
return -count

View File

@ -7,7 +7,7 @@ from cStringIO import StringIO
from compiler import ast, parse, walk
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 = {
# (Have *args, Have **args) : opcode
@ -44,7 +44,7 @@ class Module:
f.write(self.getPycHeader())
marshal.dump(self.code, f)
MAGIC = (20121 | (ord('\r')<<16) | (ord('\n')<<24))
MAGIC = (50811 | (ord('\r')<<16) | (ord('\n')<<24))
def getPycHeader(self):
# compile.c uses marshal to write a long directly, with
@ -470,7 +470,7 @@ class CodeGenerator:
def visitAssTuple(self, node):
if findOp(node) != 'OP_DELETE':
self.emit('UNPACK_TUPLE', len(node.nodes))
self.emit('UNPACK_SEQUENCE', len(node.nodes))
for child in node.nodes:
self.visit(child)
@ -714,16 +714,18 @@ class FunctionCodeGenerator(CodeGenerator):
if type(arg) == types.TupleType:
self.emit('LOAD_FAST', '.nested%d' % count)
count = count + 1
self.unpackTuple(arg)
self.unpackSequence(arg)
def unpackTuple(self, tup):
self.emit('UNPACK_TUPLE', len(tup))
def unpackSequence(self, tup):
self.emit('UNPACK_SEQUENCE', len(tup))
for elt in tup:
if type(elt) == types.TupleType:
self.unpackTuple(elt)
self.unpackSequence(elt)
else:
self.emit('STORE_FAST', elt)
unpackTuple = unpackSequence
class ClassCodeGenerator(CodeGenerator):
super_init = CodeGenerator.__init__
@ -733,6 +735,7 @@ class ClassCodeGenerator(CodeGenerator):
self.super_init(filename)
lnf = walk(klass.code, LocalNameFinder(), 0)
self.locals.push(lnf.getLocals())
self.graph.setFlag(CO_NEWLOCALS)
def finish(self):
self.graph.startExitBlock()

View File

@ -513,11 +513,9 @@ class StackDepthTracker:
]
# special cases:
# UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
# UNPACK_SEQUENCE, BUILD_TUPLE,
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
def UNPACK_TUPLE(self, count):
return count
def UNPACK_LIST(self, count):
def UNPACK_SEQUENCE(self, count):
return count
def BUILD_TUPLE(self, count):
return -count

View File

@ -7,7 +7,7 @@ from cStringIO import StringIO
from compiler import ast, parse, walk
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 = {
# (Have *args, Have **args) : opcode
@ -44,7 +44,7 @@ class Module:
f.write(self.getPycHeader())
marshal.dump(self.code, f)
MAGIC = (20121 | (ord('\r')<<16) | (ord('\n')<<24))
MAGIC = (50811 | (ord('\r')<<16) | (ord('\n')<<24))
def getPycHeader(self):
# compile.c uses marshal to write a long directly, with
@ -470,7 +470,7 @@ class CodeGenerator:
def visitAssTuple(self, node):
if findOp(node) != 'OP_DELETE':
self.emit('UNPACK_TUPLE', len(node.nodes))
self.emit('UNPACK_SEQUENCE', len(node.nodes))
for child in node.nodes:
self.visit(child)
@ -714,16 +714,18 @@ class FunctionCodeGenerator(CodeGenerator):
if type(arg) == types.TupleType:
self.emit('LOAD_FAST', '.nested%d' % count)
count = count + 1
self.unpackTuple(arg)
self.unpackSequence(arg)
def unpackTuple(self, tup):
self.emit('UNPACK_TUPLE', len(tup))
def unpackSequence(self, tup):
self.emit('UNPACK_SEQUENCE', len(tup))
for elt in tup:
if type(elt) == types.TupleType:
self.unpackTuple(elt)
self.unpackSequence(elt)
else:
self.emit('STORE_FAST', elt)
unpackTuple = unpackSequence
class ClassCodeGenerator(CodeGenerator):
super_init = CodeGenerator.__init__
@ -733,6 +735,7 @@ class ClassCodeGenerator(CodeGenerator):
self.super_init(filename)
lnf = walk(klass.code, LocalNameFinder(), 0)
self.locals.push(lnf.getLocals())
self.graph.setFlag(CO_NEWLOCALS)
def finish(self):
self.graph.startExitBlock()