diff Python/compile.c @ 12082:603db0d0aed1 legacy-trunk

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
author Jeremy Hylton <jeremy@alum.mit.edu>
date Tue, 28 Mar 2000 23:49:17 +0000
parents 28003afa1a2f
children 96ea1a800b23
line wrap: on
line diff
--- a/Python/compile.c	Tue Mar 28 21:45:46 2000 +0000
+++ b/Python/compile.c	Tue Mar 28 23:49:17 2000 +0000
@@ -1185,11 +1185,17 @@
 		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 @@
 				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);
 	}
 }