summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/pycodegen.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/pycodegen.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/pycodegen.py')
-rw-r--r--Lib/compiler/pycodegen.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py
index 2e98d4e..a697b55 100644
--- a/Lib/compiler/pycodegen.py
+++ b/Lib/compiler/pycodegen.py
@@ -9,6 +9,14 @@ from compiler import ast, parse, walk
from compiler import pyassem, misc
from compiler.pyassem import CO_VARARGS, CO_VARKEYWORDS, TupleArg
+callfunc_opcode_info = {
+ # (Have *args, Have **args) : opcode
+ (0,0) : "CALL_FUNCTION",
+ (1,0) : "CALL_FUNCTION_VAR",
+ (0,1) : "CALL_FUNCTION_KW",
+ (1,1) : "CALL_FUNCTION_VAR_KW",
+}
+
def compile(filename):
f = open(filename)
buf = f.read()
@@ -478,7 +486,14 @@ class CodeGenerator:
kw = kw + 1
else:
pos = pos + 1
- self.emit('CALL_FUNCTION', kw << 8 | pos)
+ if node.star_args is not None:
+ self.visit(node.star_args)
+ if node.dstar_args is not None:
+ self.visit(node.dstar_args)
+ have_star = node.star_args is not None
+ have_dstar = node.dstar_args is not None
+ opcode = callfunc_opcode_info[have_star, have_dstar]
+ self.emit(opcode, kw << 8 | pos)
def visitPrint(self, node):
self.emit('SET_LINENO', node.lineno)