[Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.78,
1.1.2.79
nnorwitz at users.sourceforge.net
nnorwitz at users.sourceforge.net
Sun Mar 21 11:52:48 EST 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3460/Python
Modified Files:
Tag: ast-branch
newcompile.c
Log Message:
get closures working
Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.78
retrieving revision 1.1.2.79
diff -C2 -d -r1.1.2.78 -r1.1.2.79
*** newcompile.c 20 Mar 2004 19:46:51 -0000 1.1.2.78
--- newcompile.c 21 Mar 2004 16:52:46 -0000 1.1.2.79
***************
*** 24,28 ****
Inappropriate Exceptions:
- #: problem with cell objects (closures still have bugs)
#: Get this err msg: XXX rd_object called with exception set
From Python/marshal.c::PyMarshal_ReadLastObjectFromFile()
--- 24,27 ----
***************
*** 300,308 ****
static PyObject *
! dictbytype(PyObject *src, int scope_type)
{
! int pos = 0, i = 0, scope;
PyObject *k, *v, *dest = PyDict_New();
if (dest == NULL)
return NULL;
--- 299,308 ----
static PyObject *
! dictbytype(PyObject *src, int scope_type, int offset)
{
! int pos = 0, i = offset, scope;
PyObject *k, *v, *dest = PyDict_New();
+ assert(offset >= 0);
if (dest == NULL)
return NULL;
***************
*** 314,328 ****
if (scope == scope_type) {
! PyObject *item = PyInt_FromLong(i);
if (item == NULL) {
Py_DECREF(dest);
return NULL;
}
! if (PyDict_SetItem(dest, k, item) < 0) {
Py_DECREF(item);
Py_DECREF(dest);
return NULL;
}
Py_DECREF(item);
}
}
--- 314,332 ----
if (scope == scope_type) {
! PyObject *tuple, *item = PyInt_FromLong(i);
if (item == NULL) {
Py_DECREF(dest);
return NULL;
}
! i++;
! tuple = Py_BuildValue("(OO)", k, k->ob_type);
! if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) {
Py_DECREF(item);
Py_DECREF(dest);
+ Py_XDECREF(tuple);
return NULL;
}
Py_DECREF(item);
+ Py_DECREF(tuple);
}
}
***************
*** 379,384 ****
u->u_name = name;
u->u_varnames = list2dict(u->u_ste->ste_varnames);
! u->u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL);
! u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE);
u->u_nblocks = 0;
u->u_nalloc = DEFAULT_BLOCKS;
--- 383,390 ----
u->u_name = name;
u->u_varnames = list2dict(u->u_ste->ste_varnames);
! u->u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, 0);
! u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE,
! PyDict_Size(u->u_cellvars));
!
u->u_nblocks = 0;
u->u_nalloc = DEFAULT_BLOCKS;
***************
*** 669,673 ****
static int
! compiler_addop_name(struct compiler *c, int opcode, PyObject *o)
{
int arg;
--- 675,680 ----
static int
! compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
! PyObject *o)
{
int arg;
***************
*** 675,679 ****
if (!mangled)
return 0;
! arg = compiler_add_o(c, c->u->u_names, mangled);
Py_DECREF(mangled);
if (arg < 0)
--- 682,686 ----
if (!mangled)
return 0;
! arg = compiler_add_o(c, dict, mangled);
Py_DECREF(mangled);
if (arg < 0)
***************
*** 751,759 ****
}
! #define ADDOP_NAME(C, OP, O) { \
! if (!compiler_addop_name((C), (OP), (O))) { \
! Py_DECREF(O); \
return 0; \
- } \
}
--- 758,764 ----
}
! #define ADDOP_NAME(C, OP, O, TYPE) { \
! if (!compiler_addop_name((C), (OP), (C)->u->u_ ## TYPE, (O))) \
return 0; \
}
***************
*** 865,869 ****
compiler_lookup_arg(PyObject *dict, PyObject *name)
{
! PyObject *v = PyDict_GetItem(dict, name);
if (v == NULL)
return -1;
--- 870,878 ----
compiler_lookup_arg(PyObject *dict, PyObject *name)
{
! PyObject *k, *v;
! k = Py_BuildValue("(OO)", name, name->ob_type);
! if (k == NULL)
! return -1;
! v = PyDict_GetItem(dict, k);
if (v == NULL)
return -1;
***************
*** 1387,1391 ****
identifier store_name;
ADDOP_O(c, LOAD_CONST, Py_None, consts);
! ADDOP_NAME(c, IMPORT_NAME, alias->name);
/* XXX: handling of store_name should be cleaned up */
--- 1396,1400 ----
identifier store_name;
ADDOP_O(c, LOAD_CONST, Py_None, consts);
! ADDOP_NAME(c, IMPORT_NAME, alias->name, names);
/* XXX: handling of store_name should be cleaned up */
***************
*** 1432,1436 ****
ADDOP_O(c, LOAD_CONST, names, consts);
! ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module);
for (i = 0; i < n; i++) {
alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
--- 1441,1445 ----
ADDOP_O(c, LOAD_CONST, names, consts);
! ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
for (i = 0; i < n; i++) {
alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
***************
*** 1444,1448 ****
}
! ADDOP_NAME(c, IMPORT_FROM, alias->name);
store_name = alias->name;
if (alias->asname)
--- 1453,1457 ----
}
! ADDOP_NAME(c, IMPORT_FROM, alias->name, names);
store_name = alias->name;
if (alias->asname)
***************
*** 1723,1726 ****
--- 1732,1736 ----
enum { OP_FAST, OP_GLOBAL, OP_DEREF, OP_NAME } optype;
+ PyObject *dict = c->u->u_names;
/* XXX AugStore isn't used anywhere! */
op = 0;
***************
*** 1729,1733 ****
--- 1739,1747 ----
switch (scope) {
case FREE:
+ dict = c->u->u_freevars;
+ optype = OP_DEREF;
+ break;
case CELL:
+ dict = c->u->u_cellvars;
optype = OP_DEREF;
break;
***************
*** 1798,1803 ****
assert(op);
! ADDOP_NAME(c, op, name);
! return 1;
}
--- 1812,1816 ----
assert(op);
! return compiler_addop_name(c, op, dict, name);
}
***************
*** 2096,2100 ****
/* Fall through to load */
case Load:
! ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr);
break;
case AugStore:
--- 2109,2113 ----
/* Fall through to load */
case Load:
! ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names);
break;
case AugStore:
***************
*** 2102,2109 ****
/* Fall through to save */
case Store:
! ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr);
break;
case Del:
! ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr);
break;
case Param:
--- 2115,2122 ----
/* Fall through to save */
case Store:
! ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names);
break;
case Del:
! ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names);
break;
case Param:
***************
*** 2695,2698 ****
--- 2708,2712 ----
Py_INCREF(k);
assert((i - offset) < size);
+ assert((i - offset) >= 0);
PyTuple_SET_ITEM(tuple, i - offset, k);
}
***************
*** 2752,2760 ****
if (!consts || !names || !varnames)
goto error;
! freevars = PySequence_Tuple(c->u->u_freevars);
! cellvars = PySequence_Tuple(c->u->u_cellvars);
! if (!varnames || !freevars || !cellvars)
goto error;
-
filename = PyString_FromString(c->c_filename);
if (!filename)
--- 2766,2776 ----
if (!consts || !names || !varnames)
goto error;
!
! cellvars = dict_keys_inorder(c->u->u_cellvars, 0);
! if (!cellvars)
! goto error;
! freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_Size(cellvars));
! if (!freevars)
goto error;
filename = PyString_FromString(c->c_filename);
if (!filename)
More information about the Python-checkins
mailing list