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.
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py
index c3fa7b7..d9d294b 100644
--- a/Lib/compiler/pyassem.py
+++ b/Lib/compiler/pyassem.py
@@ -361,6 +361,10 @@
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 @@
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 @@
('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):