From 50e36b7e81ffe32ee6c68344dae11f52d214b10c Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Tue, 28 Mar 2000 23:49:17 +0000 Subject: 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 --- Python/compile.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'Python/compile.c') diff --git a/Python/compile.c b/Python/compile.c index 72848fae36..1eed7c06b2 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); } } -- cgit v1.2.1