summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-03-28 23:49:17 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-03-28 23:49:17 (GMT)
commit7690151c7e95f38b91a9c572ce29b4d8a4ca671d (patch)
treefb8eb51104f6aaa895c37c4c144072be016674f5 /Python/compile.c
parent93a7c0fe6b2186448ebe35a5af0ac3880d8f16fc (diff)
downloadcpython-7690151c7e95f38b91a9c572ce29b4d8a4ca671d.zip
cpython-7690151c7e95f38b91a9c572ce29b4d8a4ca671d.tar.gz
cpython-7690151c7e95f38b91a9c572ce29b4d8a4ca671d.tar.bz2
slightly modified version of Greg Ewing's extended call syntax patch
executive summary: Instead of typing 'apply(f, args, kwargs)' you can type 'f(*arg, **kwargs)'. Some file-by-file details follow. Grammar/Grammar: simplify varargslist, replacing '*' '*' with '**' add * & ** options to arglist Include/opcode.h & Lib/dis.py: define three new opcodes CALL_FUNCTION_VAR CALL_FUNCTION_KW CALL_FUNCTION_VAR_KW Python/ceval.c: extend TypeError "keyword parameter redefined" message to include the name of the offending keyword reindent CALL_FUNCTION using four spaces add handling of sequences and dictionaries using extend calls fix function import_from to use PyErr_Format
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 72848fa..1eed7c0 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1185,11 +1185,17 @@ com_call_function(c, n)
PyObject *keywords = NULL;
int i, na, nk;
int lineno = n->n_lineno;
+ int star_flag = 0;
+ int starstar_flag = 0;
+ int opcode;
REQ(n, arglist);
na = 0;
nk = 0;
for (i = 0; i < NCH(n); i += 2) {
node *ch = CHILD(n, i);
+ if (TYPE(ch) == STAR ||
+ TYPE(ch) == DOUBLESTAR)
+ break;
if (ch->n_lineno != lineno) {
lineno = ch->n_lineno;
com_addoparg(c, SET_LINENO, lineno);
@@ -1201,12 +1207,27 @@ com_call_function(c, n)
nk++;
}
Py_XDECREF(keywords);
+ while (i < NCH(n)) {
+ node *tok = CHILD(n, i);
+ node *ch = CHILD(n, i+1);
+ i += 3;
+ switch (TYPE(tok)) {
+ case STAR: star_flag = 1; break;
+ case DOUBLESTAR: starstar_flag = 1; break;
+ }
+ com_node(c, ch);
+ }
if (na > 255 || nk > 255) {
com_error(c, PyExc_SyntaxError,
"more than 255 arguments");
}
- com_addoparg(c, CALL_FUNCTION, na | (nk << 8));
- com_pop(c, na + 2*nk);
+ if (star_flag || starstar_flag)
+ opcode = CALL_FUNCTION_STAR - 1 +
+ star_flag + (starstar_flag << 1);
+ else
+ opcode = CALL_FUNCTION;
+ com_addoparg(c, opcode, na | (nk << 8));
+ com_pop(c, na + 2*nk + star_flag + starstar_flag);
}
}