mirror of
https://github.com/python/cpython.git
synced 2025-10-18 04:38:07 +00:00
Various sundry changes for 2.2 compatibility
Remove the option to have nested scopes or old LGB scopes. This has a large impact on the code base, by removing the need for two variants of each CodeGenerator. Add a get_module() method to CodeGenerator objects, used to get the future features for the current module. Set CO_GENERATOR, CO_GENERATOR_ALLOWED, and CO_FUTURE_DIVISION flags as appropriate. Attempt to fix the value of nlocals in newCodeObject(), assuming that nlocals is 0 if CO_NEWLOCALS is not defined.
This commit is contained in:
parent
652a22437a
commit
1e99a77120
4 changed files with 188 additions and 274 deletions
|
@ -361,6 +361,10 @@ class PyFlowGraph(FlowGraph):
|
|||
if flag == CO_VARARGS:
|
||||
self.argcount = self.argcount - 1
|
||||
|
||||
def checkFlag(self, flag):
|
||||
if self.flags & flag:
|
||||
return 1
|
||||
|
||||
def setFreeVars(self, names):
|
||||
self.freevars = list(names)
|
||||
|
||||
|
@ -564,7 +568,7 @@ class PyFlowGraph(FlowGraph):
|
|||
|
||||
def newCodeObject(self):
|
||||
assert self.stage == DONE
|
||||
if self.flags == 0:
|
||||
if (self.flags & CO_NEWLOCALS) == 0:
|
||||
nlocals = 0
|
||||
else:
|
||||
nlocals = len(self.varnames)
|
||||
|
@ -761,9 +765,6 @@ class StackDepthTracker:
|
|||
('LOAD_', 1),
|
||||
]
|
||||
|
||||
# special cases:
|
||||
# UNPACK_SEQUENCE, BUILD_TUPLE,
|
||||
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
|
||||
def UNPACK_SEQUENCE(self, count):
|
||||
return count-1
|
||||
def BUILD_TUPLE(self, count):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue