Merged revisions 55328-55341 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/p3yk

........
  r55329 | brett.cannon | 2007-05-14 16:36:56 -0700 (Mon, 14 May 2007) | 3 lines

  Implement the removal of tuple parameter unpacking (PEP 3113).
  Thanks, Tony Lownds for the patch.
........
  r55331 | neal.norwitz | 2007-05-14 16:40:30 -0700 (Mon, 14 May 2007) | 1 line

  Update to use Python 3.0
........
  r55332 | brett.cannon | 2007-05-14 16:47:18 -0700 (Mon, 14 May 2007) | 2 lines

  Mention PEP 3113.  And thanks to Tony Lownds for the PEP 3113 patch.
........
  r55333 | neal.norwitz | 2007-05-14 16:57:06 -0700 (Mon, 14 May 2007) | 1 line

  Fix exception printing (no more exceptions module)
........
  r55334 | neal.norwitz | 2007-05-14 17:11:10 -0700 (Mon, 14 May 2007) | 1 line

  Remove popen* functions from os
........
  r55335 | neal.norwitz | 2007-05-14 18:03:38 -0700 (Mon, 14 May 2007) | 1 line

  Get rid of most of popen.  There are still some uses I need to cleanup.
........
  r55336 | neal.norwitz | 2007-05-14 21:11:34 -0700 (Mon, 14 May 2007) | 1 line

  Remove a few more remnants of the compiler package
........
  r55337 | neal.norwitz | 2007-05-14 22:28:27 -0700 (Mon, 14 May 2007) | 1 line

  Get test_[cx]pickle working on 64-bit platforms (avoid overflow int/long)
........
This commit is contained in:
Guido van Rossum 2007-05-15 18:46:22 +00:00
parent 360e4b8fb1
commit 1bc535dc78
64 changed files with 1614 additions and 2842 deletions

View file

@ -2,7 +2,7 @@
/*
__version__ 54835.
__version__ 55270.
This module must be committed separately after each AST grammar change;
The __version__ number is set to the revision number of the commit
@ -367,15 +367,10 @@ static char *arguments_fields[]={
};
static PyTypeObject *arg_type;
static PyObject* ast2obj_arg(void*);
static PyTypeObject *SimpleArg_type;
static char *SimpleArg_fields[]={
static char *arg_fields[]={
"arg",
"annotation",
};
static PyTypeObject *NestedArgs_type;
static char *NestedArgs_fields[]={
"args",
};
static PyTypeObject *keyword_type;
static PyObject* ast2obj_keyword(void*);
static char *keyword_fields[]={
@ -752,14 +747,8 @@ static int init_types(void)
if (!excepthandler_type) return 0;
arguments_type = make_type("arguments", AST_type, arguments_fields, 8);
if (!arguments_type) return 0;
arg_type = make_type("arg", AST_type, NULL, 0);
arg_type = make_type("arg", AST_type, arg_fields, 2);
if (!arg_type) return 0;
if (!add_attributes(arg_type, NULL, 0)) return 0;
SimpleArg_type = make_type("SimpleArg", arg_type, SimpleArg_fields, 2);
if (!SimpleArg_type) return 0;
NestedArgs_type = make_type("NestedArgs", arg_type, NestedArgs_fields,
1);
if (!NestedArgs_type) return 0;
keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
if (!keyword_type) return 0;
alias_type = make_type("alias", AST_type, alias_fields, 2);
@ -1865,32 +1854,19 @@ arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
}
arg_ty
SimpleArg(identifier arg, expr_ty annotation, PyArena *arena)
arg(identifier arg, expr_ty annotation, PyArena *arena)
{
arg_ty p;
if (!arg) {
PyErr_SetString(PyExc_ValueError,
"field arg is required for SimpleArg");
"field arg is required for arg");
return NULL;
}
p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
p->kind = SimpleArg_kind;
p->v.SimpleArg.arg = arg;
p->v.SimpleArg.annotation = annotation;
return p;
}
arg_ty
NestedArgs(asdl_seq * args, PyArena *arena)
{
arg_ty p;
p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
p->kind = NestedArgs_kind;
p->v.NestedArgs.args = args;
p->arg = arg;
p->annotation = annotation;
return p;
}
@ -3048,31 +3024,18 @@ ast2obj_arg(void* _o)
return Py_None;
}
switch (o->kind) {
case SimpleArg_kind:
result = PyType_GenericNew(SimpleArg_type, NULL, NULL);
if (!result) goto failed;
value = ast2obj_identifier(o->v.SimpleArg.arg);
if (!value) goto failed;
if (PyObject_SetAttrString(result, "arg", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.SimpleArg.annotation);
if (!value) goto failed;
if (PyObject_SetAttrString(result, "annotation", value) == -1)
goto failed;
Py_DECREF(value);
break;
case NestedArgs_kind:
result = PyType_GenericNew(NestedArgs_type, NULL, NULL);
if (!result) goto failed;
value = ast2obj_list(o->v.NestedArgs.args, ast2obj_arg);
if (!value) goto failed;
if (PyObject_SetAttrString(result, "args", value) == -1)
goto failed;
Py_DECREF(value);
break;
}
result = PyType_GenericNew(arg_type, NULL, NULL);
if (!result) return NULL;
value = ast2obj_identifier(o->arg);
if (!value) goto failed;
if (PyObject_SetAttrString(result, "arg", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->annotation);
if (!value) goto failed;
if (PyObject_SetAttrString(result, "annotation", value) == -1)
goto failed;
Py_DECREF(value);
return result;
failed:
Py_XDECREF(value);
@ -3150,7 +3113,7 @@ init_ast(void)
if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
return;
if (PyModule_AddStringConstant(m, "__version__", "54835") < 0)
if (PyModule_AddStringConstant(m, "__version__", "55270") < 0)
return;
if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
@ -3295,10 +3258,6 @@ init_ast(void)
if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
0) return;
if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return;
if (PyDict_SetItemString(d, "SimpleArg", (PyObject*)SimpleArg_type) <
0) return;
if (PyDict_SetItemString(d, "NestedArgs", (PyObject*)NestedArgs_type) <
0) return;
if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
return;
if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;

View file

@ -566,13 +566,13 @@ seq_for_testlist(struct compiling *c, const node *n)
}
static arg_ty
compiler_simple_arg(struct compiling *c, const node *n)
compiler_arg(struct compiling *c, const node *n)
{
identifier name;
expr_ty annotation = NULL;
node *ch;
assert(TYPE(n) == tname || TYPE(n) == vname);
assert(TYPE(n) == tfpdef || TYPE(n) == vfpdef);
ch = CHILD(n, 0);
if (!strcmp(STR(ch), "None")) {
ast_error(ch, "assignment to None");
@ -588,51 +588,12 @@ compiler_simple_arg(struct compiling *c, const node *n)
return NULL;
}
return SimpleArg(name, annotation, c->c_arena);
}
static arg_ty
compiler_complex_args(struct compiling *c, const node *n)
{
int i, len = (NCH(n) + 1) / 2;
arg_ty arg;
asdl_seq *args = asdl_seq_new(len, c->c_arena);
if (!args)
return NULL;
assert(TYPE(n) == tfplist || TYPE(n) == vfplist);
for (i = 0; i < len; i++) {
const node *child = CHILD(n, 2*i);
/* def foo(((x), y)): -- x is not nested complex, special case. */
while (NCH(child) == 3 && NCH(CHILD(child, 1)) == 1)
child = CHILD(CHILD(child, 1), 0);
/* child either holds a tname or '(', a tfplist, ')' */
switch (TYPE(CHILD(child, 0))) {
case tname:
case vname:
arg = compiler_simple_arg(c, CHILD(child, 0));
break;
case LPAR:
arg = compiler_complex_args(c, CHILD(child, 1));
break;
default:
PyErr_Format(PyExc_SystemError,
"unexpected node in args: %d @ %d",
TYPE(CHILD(child, 0)), i);
arg = NULL;
}
if (!arg)
return NULL;
asdl_seq_SET(args, i, arg);
}
return NestedArgs(args, c->c_arena);
return arg(name, annotation, c->c_arena);
}
/* returns -1 if failed to handle keyword only arguments
returns new position to keep processing if successful
(',' tname ['=' test])*
(',' tfpdef ['=' test])*
^^^
start pointing here
*/
@ -650,8 +611,8 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
while (i < NCH(n)) {
ch = CHILD(n, i);
switch (TYPE(ch)) {
case vname:
case tname:
case vfpdef:
case tfpdef:
if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
expression = ast_for_expr(c, CHILD(n, i + 2));
if (!expression) {
@ -680,7 +641,7 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
ast_error(ch, "assignment to None");
goto error;
}
arg = SimpleArg(NEW_IDENTIFIER(ch), annotation, c->c_arena);
arg = arg(NEW_IDENTIFIER(ch), annotation, c->c_arena);
if (!arg) {
ast_error(ch, "expecting name");
goto error;
@ -710,13 +671,15 @@ ast_for_arguments(struct compiling *c, const node *n)
parameters: '(' [typedargslist] ')'
typedargslist: ((tfpdef ['=' test] ',')*
('*' [tname] (',' tname ['=' test])* [',' '**' tname]
| '**' tname)
('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef]
| '**' tfpdef)
| tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
tfpdef: NAME [':' test]
varargslist: ((vfpdef ['=' test] ',')*
('*' [vname] (',' vname ['=' test])* [',' '**' vname]
| '**' vname)
('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef]
| '**' vfpdef)
| vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
vfpdef: NAME
*/
int i, j, k, nposargs = 0, nkwonlyargs = 0;
int nposdefaults = 0, found_default = 0;
@ -738,17 +701,13 @@ ast_for_arguments(struct compiling *c, const node *n)
for (i = 0; i < NCH(n); i++) {
ch = CHILD(n, i);
if (TYPE(ch) == STAR) {
if (TYPE(CHILD(n, i+1)) == tname
|| TYPE(CHILD(n, i+1)) == vname) {
/* skip NAME of vararg */
/* so that following can count only keyword only args */
i += 2;
}
else {
i++;
}
/* skip star and possible argument */
i++;
i += (TYPE(CHILD(n, i)) == tfpdef
|| TYPE(CHILD(n, i)) == vfpdef);
break;
}
if (TYPE(ch) == DOUBLESTAR) break;
if (TYPE(ch) == vfpdef || TYPE(ch) == tfpdef) nposargs++;
if (TYPE(ch) == EQUAL) nposdefaults++;
}
@ -757,9 +716,8 @@ ast_for_arguments(struct compiling *c, const node *n)
for ( ; i < NCH(n); ++i) {
ch = CHILD(n, i);
if (TYPE(ch) == DOUBLESTAR) break;
if (TYPE(ch) == tname || TYPE(ch) == vname) nkwonlyargs++;
if (TYPE(ch) == tfpdef || TYPE(ch) == vfpdef) nkwonlyargs++;
}
posargs = (nposargs ? asdl_seq_new(nposargs, c->c_arena) : NULL);
if (!posargs && nposargs)
goto error;
@ -784,12 +742,8 @@ ast_for_arguments(struct compiling *c, const node *n)
return NULL;
}
/* tname: NAME [':' test]
tfpdef: tname | '(' tfplist ')'
tfplist: tfpdef (',' tfpdef)* [',']
vname: NAME
vfpdef: NAME | '(' vfplist ')'
vfplist: vfpdef (',' vfpdef)* [',']
/* tfpdef: NAME [':' test]
vfpdef: NAME
*/
i = 0;
j = 0; /* index for defaults */
@ -816,14 +770,7 @@ ast_for_arguments(struct compiling *c, const node *n)
"non-default argument follows default argument");
goto error;
}
/* def foo((x)): is not complex, special case. */
while (NCH(ch) == 3 && NCH(CHILD(ch, 1)) == 1)
ch = CHILD(CHILD(ch, 1), 0);
if (NCH(ch) != 1)
arg = compiler_complex_args(c, CHILD(ch, 1));
else
arg = compiler_simple_arg(c, CHILD(ch, 0));
arg = compiler_arg(c, ch);
if (!arg)
goto error;
asdl_seq_SET(posargs, k++, arg);
@ -835,7 +782,7 @@ ast_for_arguments(struct compiling *c, const node *n)
ast_error(CHILD(n, i), "no name for vararg");
goto error;
}
ch = CHILD(n, i+1); /* tname or COMMA */
ch = CHILD(n, i+1); /* tfpdef or COMMA */
if (TYPE(ch) == COMMA) {
int res = 0;
i += 2; /* now follows keyword only arguments */
@ -851,12 +798,12 @@ ast_for_arguments(struct compiling *c, const node *n)
else {
vararg = NEW_IDENTIFIER(CHILD(ch, 0));
if (NCH(ch) > 1) {
/* there is an annotation on the vararg */
varargannotation = ast_for_expr(c, CHILD(ch, 2));
/* there is an annotation on the vararg */
varargannotation = ast_for_expr(c, CHILD(ch, 2));
}
i += 3;
if (i < NCH(n) && (TYPE(CHILD(n, i)) == tname
|| TYPE(CHILD(n, i)) == vname)) {
if (i < NCH(n) && (TYPE(CHILD(n, i)) == tfpdef
|| TYPE(CHILD(n, i)) == vfpdef)) {
int res = 0;
res = handle_keywordonly_args(c, n, i,
kwonlyargs, kwdefaults);
@ -866,8 +813,8 @@ ast_for_arguments(struct compiling *c, const node *n)
}
break;
case DOUBLESTAR:
ch = CHILD(n, i+1); /* tname */
assert(TYPE(ch) == tname || TYPE(ch) == vname);
ch = CHILD(n, i+1); /* tfpdef */
assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef);
if (!strcmp(STR(CHILD(ch, 0)), "None")) {
ast_error(CHILD(ch, 0), "assignment to None");
goto error;

View file

@ -1282,54 +1282,6 @@ compiler_decorators(struct compiler *c, asdl_seq* decos)
return 1;
}
static int
compiler_unpack_nested(struct compiler *c, asdl_seq *args) {
int i, len;
len = asdl_seq_LEN(args);
ADDOP_I(c, UNPACK_SEQUENCE, len);
for (i = 0; i < len; i++) {
arg_ty elt = (arg_ty)asdl_seq_GET(args, i);
switch (elt->kind) {
case SimpleArg_kind:
if (!compiler_nameop(c, elt->v.SimpleArg.arg, Store))
return 0;
break;
case NestedArgs_kind:
if (!compiler_unpack_nested(c, elt->v.NestedArgs.args))
return 0;
break;
default:
return 0;
}
}
return 1;
}
static int
compiler_arguments(struct compiler *c, arguments_ty args)
{
int i;
int n = asdl_seq_LEN(args->args);
for (i = 0; i < n; i++) {
arg_ty arg = (arg_ty)asdl_seq_GET(args->args, i);
if (arg->kind == NestedArgs_kind) {
PyObject *id = PyString_FromFormat(".%d", i);
if (id == NULL) {
return 0;
}
if (!compiler_nameop(c, id, Load)) {
Py_DECREF(id);
return 0;
}
Py_DECREF(id);
if (!compiler_unpack_nested(c, arg->v.NestedArgs.args))
return 0;
}
}
return 1;
}
static int
compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs,
asdl_seq *kw_defaults)
@ -1339,7 +1291,7 @@ compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs,
arg_ty arg = asdl_seq_GET(kwonlyargs, i);
expr_ty default_ = asdl_seq_GET(kw_defaults, i);
if (default_) {
ADDOP_O(c, LOAD_CONST, arg->v.SimpleArg.arg, consts);
ADDOP_O(c, LOAD_CONST, arg->arg, consts);
if (!compiler_visit_expr(c, default_)) {
return -1;
}
@ -1368,17 +1320,11 @@ compiler_visit_argannotations(struct compiler *c, asdl_seq* args,
int i, error;
for (i = 0; i < asdl_seq_LEN(args); i++) {
arg_ty arg = (arg_ty)asdl_seq_GET(args, i);
if (arg->kind == NestedArgs_kind)
error = compiler_visit_argannotations(
c,
arg->v.NestedArgs.args,
names);
else
error = compiler_visit_argannotation(
c,
arg->v.SimpleArg.arg,
arg->v.SimpleArg.annotation,
names);
error = compiler_visit_argannotation(
c,
arg->arg,
arg->annotation,
names);
if (error)
return error;
}
@ -1498,9 +1444,6 @@ compiler_function(struct compiler *c, stmt_ty s)
return 0;
}
/* unpack nested arguments */
compiler_arguments(c, args);
c->u->u_argcount = asdl_seq_LEN(args->args);
c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs);
n = asdl_seq_LEN(s->v.FunctionDef.body);
@ -1690,9 +1633,6 @@ compiler_lambda(struct compiler *c, expr_ty e)
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
return 0;
/* unpack nested arguments */
compiler_arguments(c, args);
c->u->u_argcount = asdl_seq_LEN(args->args);
c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs);
VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);

File diff suppressed because it is too large Load diff

View file

@ -180,10 +180,8 @@ static int symtable_visit_alias(struct symtable *st, alias_ty);
static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
static int symtable_visit_keyword(struct symtable *st, keyword_ty);
static int symtable_visit_slice(struct symtable *st, slice_ty);
static int symtable_visit_params(struct symtable *st, asdl_seq *args, int top,
int annotations);
static int symtable_visit_params_nested(struct symtable *st, asdl_seq *args,
int annotations);
static int symtable_visit_params(struct symtable *st, asdl_seq *args);
static int symtable_visit_argannotations(struct symtable *st, asdl_seq *args);
static int symtable_implicit_arg(struct symtable *st, int pos);
static int symtable_visit_annotations(struct symtable *st, stmt_ty s);
@ -1328,79 +1326,51 @@ symtable_implicit_arg(struct symtable *st, int pos)
}
static int
symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel,
int annotations)
symtable_visit_params(struct symtable *st, asdl_seq *args)
{
int i;
if (!args)
return -1;
/* go through all the toplevel arguments first */
for (i = 0; i < asdl_seq_LEN(args); i++) {
arg_ty arg = (arg_ty)asdl_seq_GET(args, i);
if (arg->kind == SimpleArg_kind) {
if (!annotations) {
if (!symtable_add_def(st,
arg->v.SimpleArg.arg,
DEF_PARAM))
return 0;
}
else if (arg->v.SimpleArg.annotation)
VISIT(st, expr, arg->v.SimpleArg.annotation);
}
else if (arg->kind == NestedArgs_kind) {
if (toplevel && !annotations) {
if (!symtable_implicit_arg(st, i))
return 0;
}
}
else {
PyErr_SetString(PyExc_SyntaxError,
"invalid expression in parameter list");
PyErr_SyntaxLocation(st->st_filename,
st->st_cur->ste_lineno);
return 0;
}
}
if (!toplevel) {
if (!symtable_visit_params_nested(st, args, annotations))
if (!symtable_add_def(st, arg->arg, DEF_PARAM))
return 0;
}
return 1;
}
static int
symtable_visit_params_nested(struct symtable *st, asdl_seq *args,
int annotations)
static int
symtable_visit_argannotations(struct symtable *st, asdl_seq *args)
{
int i;
if (!args)
return -1;
for (i = 0; i < asdl_seq_LEN(args); i++) {
arg_ty arg = (arg_ty)asdl_seq_GET(args, i);
if (arg->kind == NestedArgs_kind &&
!symtable_visit_params(st, arg->v.NestedArgs.args, 0,
annotations))
return 0;
if (arg->annotation)
VISIT(st, expr, arg->annotation);
}
return 1;
}
static int
symtable_visit_annotations(struct symtable *st, stmt_ty s)
{
arguments_ty a = s->v.FunctionDef.args;
if (a->args && !symtable_visit_params(st, a->args, 1, 1))
if (a->args && !symtable_visit_argannotations(st, a->args))
return 0;
if (a->varargannotation)
VISIT(st, expr, a->varargannotation);
if (a->kwargannotation)
VISIT(st, expr, a->kwargannotation);
if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs, 1, 1))
if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs))
return 0;
if (s->v.FunctionDef.returns)
VISIT(st, expr, s->v.FunctionDef.returns);
@ -1413,9 +1383,9 @@ symtable_visit_arguments(struct symtable *st, arguments_ty a)
/* skip default arguments inside function block
XXX should ast be different?
*/
if (a->args && !symtable_visit_params(st, a->args, 1, 0))
if (a->args && !symtable_visit_params(st, a->args))
return 0;
if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs, 1, 0))
if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs))
return 0;
if (a->vararg) {
if (!symtable_add_def(st, a->vararg, DEF_PARAM))
@ -1427,8 +1397,6 @@ symtable_visit_arguments(struct symtable *st, arguments_ty a)
return 0;
st->st_cur->ste_varkeywords = 1;
}
if (a->args && !symtable_visit_params_nested(st, a->args, 0))
return 0;
return 1;
}