Update of /cvsroot/python/python/dist/src/Python In directory usw-pr-cvs1:/tmp/cvs-serv27294/Python Modified Files: Tag: ast-branch symtable.c Log Message: Hook up symbol table analysis code. After analyzing the AST, call symtable_analyze() to determine what variables are free and what variables are globals. The analysis hasn't been tested thoroughly, but it is much simpler than the old symtable analysis code. Add st_top alias for the first ste. The symtable_analyze() function mistakenly passed st_globals, which is a dictionary of symbols not a symbol table entry. (The cast should have been a warning.) Remove two Python-visible attributes of a symtable, because I changed them to bitfields. XXX I'm probably going to remove the Python-level API entirely. Index: symtable.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v retrieving revision 2.10.8.9 retrieving revision 2.10.8.10 diff -C2 -d -r2.10.8.9 -r2.10.8.10 *** symtable.c 2 Oct 2002 11:50:14 -0000 2.10.8.9 --- symtable.c 21 Oct 2002 21:31:11 -0000 2.10.8.10 *************** *** 97,102 **** {"type", T_INT, OFF(ste_type), READONLY}, {"lineno", T_INT, OFF(ste_lineno), READONLY}, - {"optimized",T_INT, OFF(ste_optimized), READONLY}, - {"nested", T_INT, OFF(ste_nested), READONLY}, {NULL} }; --- 97,100 ---- *************** *** 144,147 **** --- 142,146 ---- }; + static int symtable_analyze(struct symtable *st); static int symtable_enter_block(struct symtable *st, identifier name, block_ty block, void *ast, int lineno); *************** *** 198,201 **** --- 197,201 ---- symtable_enter_block(st, GET_IDENTIFIER(top), ModuleBlock, (void *)mod, 0); + st->st_top = st->st_cur; /* Any other top-level initialization? */ switch (mod->kind) { *************** *** 226,229 **** --- 226,231 ---- } symtable_exit_block(st, (void *)mod); + if (!symtable_analyze(st)) + goto error; return st; error: *************** *** 237,241 **** Py_XDECREF(st->st_symbols); Py_XDECREF(st->st_stack); - Py_XDECREF(st->st_cur); PyMem_Free((void *)st); } --- 239,242 ---- *************** *** 417,421 **** flags |= (i << SCOPE_OFF); u = PyInt_FromLong(flags); ! if (!PyDict_SetItem(symbols, name, u)) { Py_DECREF(u); return 0; --- 418,422 ---- flags |= (i << SCOPE_OFF); u = PyInt_FromLong(flags); ! if (PyDict_SetItem(symbols, name, u) < 0) { Py_DECREF(u); return 0; *************** *** 439,442 **** --- 440,445 ---- goto error; + assert(PySTEntry_Check(ste)); + assert(PyDict_Check(ste->ste_symbols)); while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) { flags = PyInt_AS_LONG(v); *************** *** 458,466 **** } - /* call analyze_block() on each child */ for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) { ! PyObject *c; ! c = PyDict_GetItem(ste->ste_table->st_symbols, ! PyList_GET_ITEM(ste->ste_children, i)); assert(c && PySTEntry_Check(c)); if (!analyze_block((PySTEntryObject *)c, local, free)) --- 461,466 ---- } for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) { ! PyObject *c = PyList_GET_ITEM(ste->ste_children, i); assert(c && PySTEntry_Check(c)); if (!analyze_block((PySTEntryObject *)c, local, free)) *************** *** 477,485 **** Py_XDECREF(scope); Py_XDECREF(newbound); return success; } int ! PySymtable_Analyze(struct symtable *st) { PyObject *free; --- 477,487 ---- Py_XDECREF(scope); Py_XDECREF(newbound); + if (!success) + assert(PyErr_Occurred()); return success; } int ! symtable_analyze(struct symtable *st) { PyObject *free; *************** *** 489,493 **** if (!free) return 0; ! r = analyze_block((PySTEntryObject *)st->st_global, NULL, free); Py_DECREF(free); return r; --- 491,495 ---- if (!free) return 0; ! r = analyze_block(st->st_top, NULL, free); Py_DECREF(free); return r; *************** *** 521,524 **** --- 523,529 ---- { PySTEntryObject *prev = NULL; + + fprintf(stderr, "enter block %s %d\n", + PyString_AS_STRING(name), lineno); if (st->st_cur) {
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4