Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 288a60f

Browse files
committed
New argument passing.
1 parent 9c7b861 commit 288a60f

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

Python/compile.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static int com_add PROTO((struct compiling *, object *, object *));
193193
static int com_addconst PROTO((struct compiling *, object *));
194194
static int com_addname PROTO((struct compiling *, object *));
195195
static void com_addopname PROTO((struct compiling *, int, node *));
196+
static void com_list PROTO((struct compiling *, node *, int));
196197

197198
static int
198199
com_init(c, filename)
@@ -655,10 +656,13 @@ com_call_function(c, n)
655656
node *n; /* EITHER testlist OR ')' */
656657
{
657658
if (TYPE(n) == RPAR) {
658-
com_addbyte(c, UNARY_CALL);
659+
com_addoparg(c, BUILD_TUPLE, 0);
660+
com_addbyte(c, BINARY_CALL);
659661
}
660662
else {
661-
com_node(c, n);
663+
int i;
664+
REQ(n, testlist);
665+
com_list(c, n, 1);
662666
com_addbyte(c, BINARY_CALL);
663667
}
664668
}
@@ -1047,12 +1051,13 @@ com_test(c, n)
10471051
}
10481052

10491053
static void
1050-
com_list(c, n)
1054+
com_list(c, n, toplevel)
10511055
struct compiling *c;
10521056
node *n;
1057+
int toplevel; /* If nonzero, *always* build a tuple */
10531058
{
10541059
/* exprlist: expr (',' expr)* [',']; likewise for testlist */
1055-
if (NCH(n) == 1) {
1060+
if (NCH(n) == 1 && !toplevel) {
10561061
com_node(c, CHILD(n, 0));
10571062
}
10581063
else {
@@ -1864,7 +1869,7 @@ com_node(c, n)
18641869
/* Expression nodes */
18651870

18661871
case testlist:
1867-
com_list(c, n);
1872+
com_list(c, n, 0);
18681873
break;
18691874
case test:
18701875
com_test(c, n);
@@ -1879,7 +1884,7 @@ com_node(c, n)
18791884
com_comparison(c, n);
18801885
break;
18811886
case exprlist:
1882-
com_list(c, n);
1887+
com_list(c, n, 0);
18831888
break;
18841889
case expr:
18851890
com_expr(c, n);
@@ -1970,10 +1975,13 @@ compile_funcdef(c, n)
19701975
ch = CHILD(n, 2); /* parameters: '(' [fplist] ')' */
19711976
ch = CHILD(ch, 1); /* ')' | fplist */
19721977
if (TYPE(ch) == RPAR)
1973-
com_addbyte(c, REFUSE_ARGS);
1978+
com_addoparg(c, UNPACK_ARG, 0);
19741979
else {
1975-
com_addbyte(c, REQUIRE_ARGS);
1976-
com_fplist(c, ch);
1980+
int i;
1981+
REQ(ch, fplist); /* fplist: fpdef (',' fpdef)* */
1982+
com_addoparg(c, UNPACK_ARG, (NCH(ch)+1)/2);
1983+
for (i = 0; i < NCH(ch); i += 2)
1984+
com_fpdef(c, CHILD(ch, i));
19771985
}
19781986
c->c_infunction = 1;
19791987
com_node(c, CHILD(n, 4));
@@ -1993,7 +2001,6 @@ compile_node(c, n)
19932001

19942002
case single_input: /* One interactive command */
19952003
/* NEWLINE | simple_stmt | compound_stmt NEWLINE */
1996-
com_addbyte(c, REFUSE_ARGS);
19972004
n = CHILD(n, 0);
19982005
if (TYPE(n) != NEWLINE)
19992006
com_node(c, n);
@@ -2002,20 +2009,17 @@ compile_node(c, n)
20022009
break;
20032010

20042011
case file_input: /* A whole file, or built-in function exec() */
2005-
com_addbyte(c, REFUSE_ARGS);
20062012
com_file_input(c, n);
20072013
com_addoparg(c, LOAD_CONST, com_addconst(c, None));
20082014
com_addbyte(c, RETURN_VALUE);
20092015
break;
20102016

20112017
case expr_input: /* Built-in function eval() */
2012-
com_addbyte(c, REFUSE_ARGS);
20132018
com_node(c, CHILD(n, 0));
20142019
com_addbyte(c, RETURN_VALUE);
20152020
break;
20162021

20172022
case eval_input: /* Built-in function input() */
2018-
com_addbyte(c, REFUSE_ARGS);
20192023
com_node(c, CHILD(n, 0));
20202024
com_addbyte(c, RETURN_VALUE);
20212025
break;
@@ -2028,7 +2032,6 @@ compile_node(c, n)
20282032
/* classdef: 'class' NAME
20292033
['(' testlist ')' |'(' ')' ['=' baselist]]
20302034
':' suite */
2031-
com_addbyte(c, REFUSE_ARGS);
20322035
com_node(c, CHILD(n, NCH(n)-1)); /* The suite */
20332036
com_addbyte(c, LOAD_LOCALS);
20342037
com_addbyte(c, RETURN_VALUE);

0 commit comments

Comments
 (0)