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

Skip to content

Commit 49d6dc4

Browse files
committed
Added varargs code.
1 parent 92df0c6 commit 49d6dc4

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

Python/compile.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,30 @@ com_fplist(c, n)
19551955
}
19561956
}
19571957

1958+
static void
1959+
com_arglist(c, n)
1960+
struct compiling *c;
1961+
node *n;
1962+
{
1963+
int i, nargs, op;
1964+
REQ(n, varargslist);
1965+
/* varargslist: (fpdef ',')* '+' NAME | fpdef (',' fpdef)* [','] */
1966+
op = UNPACK_ARG;
1967+
nargs = (NCH(n) + 1) / 2;
1968+
for (i = 0; i < NCH(n); i += 2) {
1969+
if (TYPE(CHILD(n, i)) == PLUS) {
1970+
op = UNPACK_VARARG;
1971+
nargs = i/2;
1972+
break;
1973+
}
1974+
}
1975+
com_addoparg(c, op, nargs);
1976+
for (i = 0; i < 2*nargs; i += 2)
1977+
com_fpdef(c, CHILD(n, i));
1978+
if (op == UNPACK_VARARG)
1979+
com_addopname(c, STORE_NAME, CHILD(n, 2*nargs+1));
1980+
}
1981+
19581982
static void
19591983
com_file_input(c, n)
19601984
struct compiling *c;
@@ -1978,17 +2002,12 @@ compile_funcdef(c, n)
19782002
{
19792003
node *ch;
19802004
REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
1981-
ch = CHILD(n, 2); /* parameters: '(' [fplist] ')' */
1982-
ch = CHILD(ch, 1); /* ')' | fplist */
2005+
ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */
2006+
ch = CHILD(ch, 1); /* ')' | varargslist */
19832007
if (TYPE(ch) == RPAR)
19842008
com_addoparg(c, UNPACK_ARG, 0);
1985-
else {
1986-
int i;
1987-
REQ(ch, fplist); /* fplist: fpdef (',' fpdef)* */
1988-
com_addoparg(c, UNPACK_ARG, (NCH(ch)+1)/2);
1989-
for (i = 0; i < NCH(ch); i += 2)
1990-
com_fpdef(c, CHILD(ch, i));
1991-
}
2009+
else
2010+
com_arglist(c, ch);
19922011
c->c_infunction = 1;
19932012
com_node(c, CHILD(n, 4));
19942013
c->c_infunction = 0;

0 commit comments

Comments
 (0)