mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
New argument passing.
This commit is contained in:
parent
9c7b861a00
commit
288a60f973
1 changed files with 17 additions and 14 deletions
|
@ -193,6 +193,7 @@ static int com_add PROTO((struct compiling *, object *, object *));
|
||||||
static int com_addconst PROTO((struct compiling *, object *));
|
static int com_addconst PROTO((struct compiling *, object *));
|
||||||
static int com_addname PROTO((struct compiling *, object *));
|
static int com_addname PROTO((struct compiling *, object *));
|
||||||
static void com_addopname PROTO((struct compiling *, int, node *));
|
static void com_addopname PROTO((struct compiling *, int, node *));
|
||||||
|
static void com_list PROTO((struct compiling *, node *, int));
|
||||||
|
|
||||||
static int
|
static int
|
||||||
com_init(c, filename)
|
com_init(c, filename)
|
||||||
|
@ -655,10 +656,13 @@ com_call_function(c, n)
|
||||||
node *n; /* EITHER testlist OR ')' */
|
node *n; /* EITHER testlist OR ')' */
|
||||||
{
|
{
|
||||||
if (TYPE(n) == RPAR) {
|
if (TYPE(n) == RPAR) {
|
||||||
com_addbyte(c, UNARY_CALL);
|
com_addoparg(c, BUILD_TUPLE, 0);
|
||||||
|
com_addbyte(c, BINARY_CALL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
com_node(c, n);
|
int i;
|
||||||
|
REQ(n, testlist);
|
||||||
|
com_list(c, n, 1);
|
||||||
com_addbyte(c, BINARY_CALL);
|
com_addbyte(c, BINARY_CALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1047,12 +1051,13 @@ com_test(c, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
com_list(c, n)
|
com_list(c, n, toplevel)
|
||||||
struct compiling *c;
|
struct compiling *c;
|
||||||
node *n;
|
node *n;
|
||||||
|
int toplevel; /* If nonzero, *always* build a tuple */
|
||||||
{
|
{
|
||||||
/* exprlist: expr (',' expr)* [',']; likewise for testlist */
|
/* exprlist: expr (',' expr)* [',']; likewise for testlist */
|
||||||
if (NCH(n) == 1) {
|
if (NCH(n) == 1 && !toplevel) {
|
||||||
com_node(c, CHILD(n, 0));
|
com_node(c, CHILD(n, 0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1864,7 +1869,7 @@ com_node(c, n)
|
||||||
/* Expression nodes */
|
/* Expression nodes */
|
||||||
|
|
||||||
case testlist:
|
case testlist:
|
||||||
com_list(c, n);
|
com_list(c, n, 0);
|
||||||
break;
|
break;
|
||||||
case test:
|
case test:
|
||||||
com_test(c, n);
|
com_test(c, n);
|
||||||
|
@ -1879,7 +1884,7 @@ com_node(c, n)
|
||||||
com_comparison(c, n);
|
com_comparison(c, n);
|
||||||
break;
|
break;
|
||||||
case exprlist:
|
case exprlist:
|
||||||
com_list(c, n);
|
com_list(c, n, 0);
|
||||||
break;
|
break;
|
||||||
case expr:
|
case expr:
|
||||||
com_expr(c, n);
|
com_expr(c, n);
|
||||||
|
@ -1970,10 +1975,13 @@ compile_funcdef(c, n)
|
||||||
ch = CHILD(n, 2); /* parameters: '(' [fplist] ')' */
|
ch = CHILD(n, 2); /* parameters: '(' [fplist] ')' */
|
||||||
ch = CHILD(ch, 1); /* ')' | fplist */
|
ch = CHILD(ch, 1); /* ')' | fplist */
|
||||||
if (TYPE(ch) == RPAR)
|
if (TYPE(ch) == RPAR)
|
||||||
com_addbyte(c, REFUSE_ARGS);
|
com_addoparg(c, UNPACK_ARG, 0);
|
||||||
else {
|
else {
|
||||||
com_addbyte(c, REQUIRE_ARGS);
|
int i;
|
||||||
com_fplist(c, ch);
|
REQ(ch, fplist); /* fplist: fpdef (',' fpdef)* */
|
||||||
|
com_addoparg(c, UNPACK_ARG, (NCH(ch)+1)/2);
|
||||||
|
for (i = 0; i < NCH(ch); i += 2)
|
||||||
|
com_fpdef(c, CHILD(ch, i));
|
||||||
}
|
}
|
||||||
c->c_infunction = 1;
|
c->c_infunction = 1;
|
||||||
com_node(c, CHILD(n, 4));
|
com_node(c, CHILD(n, 4));
|
||||||
|
@ -1993,7 +2001,6 @@ compile_node(c, n)
|
||||||
|
|
||||||
case single_input: /* One interactive command */
|
case single_input: /* One interactive command */
|
||||||
/* NEWLINE | simple_stmt | compound_stmt NEWLINE */
|
/* NEWLINE | simple_stmt | compound_stmt NEWLINE */
|
||||||
com_addbyte(c, REFUSE_ARGS);
|
|
||||||
n = CHILD(n, 0);
|
n = CHILD(n, 0);
|
||||||
if (TYPE(n) != NEWLINE)
|
if (TYPE(n) != NEWLINE)
|
||||||
com_node(c, n);
|
com_node(c, n);
|
||||||
|
@ -2002,20 +2009,17 @@ compile_node(c, n)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case file_input: /* A whole file, or built-in function exec() */
|
case file_input: /* A whole file, or built-in function exec() */
|
||||||
com_addbyte(c, REFUSE_ARGS);
|
|
||||||
com_file_input(c, n);
|
com_file_input(c, n);
|
||||||
com_addoparg(c, LOAD_CONST, com_addconst(c, None));
|
com_addoparg(c, LOAD_CONST, com_addconst(c, None));
|
||||||
com_addbyte(c, RETURN_VALUE);
|
com_addbyte(c, RETURN_VALUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case expr_input: /* Built-in function eval() */
|
case expr_input: /* Built-in function eval() */
|
||||||
com_addbyte(c, REFUSE_ARGS);
|
|
||||||
com_node(c, CHILD(n, 0));
|
com_node(c, CHILD(n, 0));
|
||||||
com_addbyte(c, RETURN_VALUE);
|
com_addbyte(c, RETURN_VALUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case eval_input: /* Built-in function input() */
|
case eval_input: /* Built-in function input() */
|
||||||
com_addbyte(c, REFUSE_ARGS);
|
|
||||||
com_node(c, CHILD(n, 0));
|
com_node(c, CHILD(n, 0));
|
||||||
com_addbyte(c, RETURN_VALUE);
|
com_addbyte(c, RETURN_VALUE);
|
||||||
break;
|
break;
|
||||||
|
@ -2028,7 +2032,6 @@ compile_node(c, n)
|
||||||
/* classdef: 'class' NAME
|
/* classdef: 'class' NAME
|
||||||
['(' testlist ')' |'(' ')' ['=' baselist]]
|
['(' testlist ')' |'(' ')' ['=' baselist]]
|
||||||
':' suite */
|
':' suite */
|
||||||
com_addbyte(c, REFUSE_ARGS);
|
|
||||||
com_node(c, CHILD(n, NCH(n)-1)); /* The suite */
|
com_node(c, CHILD(n, NCH(n)-1)); /* The suite */
|
||||||
com_addbyte(c, LOAD_LOCALS);
|
com_addbyte(c, LOAD_LOCALS);
|
||||||
com_addbyte(c, RETURN_VALUE);
|
com_addbyte(c, RETURN_VALUE);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue