summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/pyassem.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-05-02 22:32:59 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-05-02 22:32:59 (GMT)
commitbe317e615e9c25f3f38062266b9b8a7ad86a1c90 (patch)
treecbf3aed890a6896aa92505adcd6f89304edefd79 /Lib/compiler/pyassem.py
parent0a4f1ff64eeb50cdf0b81bd4cff5b2e1d159daa5 (diff)
downloadcpython-be317e615e9c25f3f38062266b9b8a7ad86a1c90.zip
cpython-be317e615e9c25f3f38062266b9b8a7ad86a1c90.tar.gz
cpython-be317e615e9c25f3f38062266b9b8a7ad86a1c90.tar.bz2
patches from Mark Hammond
Attached is a set of diffs for the .py compiler that adds support for the new extended call syntax. compiler/ast.py: CallFunc node gets 2 new children to support extended call syntax - "star_args" (for "*args") and "dstar_args" (for "**args") compiler/pyassem.py It appear that self.lnotab is supposed to be responsible for tracking line numbers, but self.firstlineno was still hanging around. Removed self.firstlineno completely. NOTE - I didnt actually test that the generated code has the correct line numbers!! Stack depth tracking appeared a little broken - the checks never made it beyond the "self.patterns" check - thus, the custom methods were never called! Fixed this. (XXX Jeremy notes: I think this code is still broken because it doesn't track stack effects across block bounaries.) Added support for the new extended call syntax opcodes for depth calculations. compiler/pycodegen.py Added support for the new extended call syntax opcodes. compiler/transformer.py Added support for the new extended call syntax.
Diffstat (limited to 'Lib/compiler/pyassem.py')
-rw-r--r--Lib/compiler/pyassem.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py
index 3272419..6e07987 100644
--- a/Lib/compiler/pyassem.py
+++ b/Lib/compiler/pyassem.py
@@ -149,7 +149,6 @@ class PyFlowGraph(FlowGraph):
self.flags = CO_OPTIMIZED | CO_NEWLOCALS
else:
self.flags = 0
- self.firstlineno = None
self.consts = []
self.names = []
self.varnames = list(args) or []
@@ -314,8 +313,6 @@ class PyFlowGraph(FlowGraph):
oparg = t[1]
if opname == "SET_LINENO":
lnotab.nextLine(oparg)
- if self.firstlineno is None:
- self.firstlineno = oparg
hi, lo = twobyte(oparg)
try:
lnotab.addCode(self.opnum[opname], lo, hi)
@@ -342,7 +339,7 @@ class PyFlowGraph(FlowGraph):
return new.code(argcount, nlocals, self.stacksize, self.flags,
self.lnotab.getCode(), self.getConsts(),
tuple(self.names), tuple(self.varnames),
- self.filename, self.name, self.firstlineno,
+ self.filename, self.name, self.lnotab.firstline,
self.lnotab.getTable())
def getConsts(self):
@@ -464,14 +461,16 @@ class StackDepthTracker:
if depth > maxDepth:
maxDepth = depth
# now check patterns
- for pat, delta in self.patterns:
+ for pat, pat_delta in self.patterns:
if opname[:len(pat)] == pat:
+ delta = pat_delta
depth = depth + delta
break
# if we still haven't found a match
if delta == 0:
- meth = getattr(self, opname)
- depth = depth + meth(i[1])
+ meth = getattr(self, opname, None)
+ if meth is not None:
+ depth = depth + meth(i[1])
if depth < 0:
depth = 0
return maxDepth
@@ -527,6 +526,12 @@ class StackDepthTracker:
def CALL_FUNCTION(self, argc):
hi, lo = divmod(argc, 256)
return lo + hi * 2
+ def CALL_FUNCTION_VAR(self, argc):
+ return self.CALL_FUNCTION(argc)+1
+ def CALL_FUNCTION_KW(self, argc):
+ return self.CALL_FUNCTION(argc)+1
+ def CALL_FUNCTION_VAR_KW(self, argc):
+ return self.CALL_FUNCTION(argc)+2
def MAKE_FUNCTION(self, argc):
return -argc
def BUILD_SLICE(self, argc):