[Python-checkins] python/dist/src/Python newcompile.c,1.1.2.17,1.1.2.18
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
Mon, 24 Mar 2003 14:57:50 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv14382
Modified Files:
Tag: ast-branch
newcompile.c
Log Message:
Several fixes to get function arguments working correctly.
Set nameops using varnames instead of names. Initialize varnames from
ste_varnames at the outset, so that all local variables have the
correct offset.
Initialize newly allocated memory when a block gets resized.
Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.17
retrieving revision 1.1.2.18
diff -C2 -d -r1.1.2.17 -r1.1.2.18
*** newcompile.c 17 Feb 2003 04:31:27 -0000 1.1.2.17
--- newcompile.c 24 Mar 2003 22:57:46 -0000 1.1.2.18
***************
*** 193,196 ****
--- 193,219 ----
}
+ static PyObject *
+ list2dict(PyObject *list)
+ {
+ int i, n;
+ PyObject *v, *dict = PyDict_New();
+
+ n = PyList_Size(list);
+ for (i = 0; i < n; i++) {
+ v = PyInt_FromLong(i);
+ if (!v) {
+ Py_DECREF(dict);
+ return NULL;
+ }
+ if (PyDict_SetItem(dict, PyList_GET_ITEM(list, i), v) < 0) {
+ Py_DECREF(v);
+ Py_DECREF(dict);
+ return NULL;
+ }
+ Py_DECREF(v);
+ }
+ return dict;
+ }
+
static int
compiler_enter_scope(struct compiler *c, identifier name, void *key)
***************
*** 206,210 ****
Py_INCREF(name);
u->u_name = name;
! u->u_varnames = u->u_ste->ste_varnames;
Py_INCREF(u->u_varnames);
u->u_nblocks = 0;
--- 229,233 ----
Py_INCREF(name);
u->u_name = name;
! u->u_varnames = list2dict(u->u_ste->ste_varnames);
Py_INCREF(u->u_varnames);
u->u_nblocks = 0;
***************
*** 378,389 ****
if (b->b_iused == b->b_ialloc) {
void *ptr;
! int newsize;
! b->b_ialloc *= 2;
! newsize = sizeof(struct basicblock)
! + ((b->b_ialloc - DEFAULT_BLOCK_SIZE)
! * sizeof(struct instr));
ptr = PyObject_Realloc((void *)b, newsize);
if (ptr == NULL)
return -1;
if (ptr != (void *)b) {
fprintf(stderr, "resize block %d\n", block);
--- 401,419 ----
if (b->b_iused == b->b_ialloc) {
void *ptr;
! int oldsize, newsize;
! oldsize = sizeof(struct basicblock);
! if (b->b_ialloc > DEFAULT_BLOCK_SIZE)
! oldsize += ((b->b_ialloc - DEFAULT_BLOCK_SIZE)
! * sizeof(struct instr));
! newsize = oldsize + b->b_ialloc * sizeof(struct instr);
! if (newsize <= 0) {
! PyErr_NoMemory();
! return 0;
! }
! b->b_ialloc <<= 1;
ptr = PyObject_Realloc((void *)b, newsize);
if (ptr == NULL)
return -1;
+ memset(ptr + oldsize, 0, newsize - oldsize);
if (ptr != (void *)b) {
fprintf(stderr, "resize block %d\n", block);
***************
*** 957,960 ****
--- 987,992 ----
optype = OP_NAME;
scope = PyST_GetScope(c->u->u_ste, name);
+ fprintf(stderr, "nameop name=%s scope=%d\n",
+ PyString_AS_STRING(name), scope);
switch (scope) {
case FREE:
***************
*** 973,979 ****
optype = OP_GLOBAL;
break;
- default:
- assert(0);
}
switch (optype) {
--- 1005,1011 ----
optype = OP_GLOBAL;
break;
}
+ if (optype == OP_DEREF)
+ abort();
switch (optype) {
***************
*** 999,1002 ****
--- 1031,1036 ----
assert(0); /* impossible */
}
+ ADDOP_O(c, op, name, varnames);
+ return 1;
break;
case OP_GLOBAL:
***************
*** 1040,1048 ****
int end, jumpi, i, n;
asdl_seq *s;
!
if (e->v.BoolOp.op == And)
jumpi = JUMP_IF_FALSE;
else
jumpi = JUMP_IF_TRUE;
end = compiler_new_block(c);
if (end < 0)
--- 1074,1085 ----
int end, jumpi, i, n;
asdl_seq *s;
!
! assert(e->kind == BoolOp_kind);
if (e->v.BoolOp.op == And)
jumpi = JUMP_IF_FALSE;
else
jumpi = JUMP_IF_TRUE;
+ fprintf(stderr, "op = %d jump = %d\n",
+ e->v.BoolOp.op, jumpi);
end = compiler_new_block(c);
if (end < 0)
***************
*** 1053,1057 ****
VISIT(c, expr, asdl_seq_GET(s, i));
ADDOP_JREL(c, jumpi, end);
- NEXT_BLOCK(c);
ADDOP(c, POP_TOP)
}
--- 1090,1093 ----
***************
*** 1450,1454 ****
if (!names)
goto error;
! varnames = PySequence_Tuple(c->u->u_varnames);
if (!varnames)
goto error;
--- 1486,1490 ----
if (!names)
goto error;
! varnames = PySequence_Tuple(c->u->u_ste->ste_varnames);
if (!varnames)
goto error;