Changes for slice and ellipses

This commit is contained in:
Guido van Rossum 1996-07-30 16:49:37 +00:00
parent 3ecebf1732
commit 8861b74445
6 changed files with 389 additions and 215 deletions

View File

@ -879,6 +879,28 @@ builtin_list(self, args)
return NULL; return NULL;
} }
static PyObject *
builtin_slice(self, args)
PyObject *self;
PyObject *args;
{
PyObject *start, *stop, *step;
start = stop = step = NULL;
if (!PyArg_ParseTuple(args, "O|OO:slice", &start, &stop, &step))
return NULL;
/*This swapping of stop and start is to maintain compatibility with
the range builtin.*/
if (stop == NULL) {
stop = start;
start = NULL;
}
return PySlice_New(start, stop, step);
}
static object * static object *
builtin_locals(self, args) builtin_locals(self, args)
object *self; object *self;
@ -1514,6 +1536,7 @@ static struct methodlist builtin_methods[] = {
{"repr", builtin_repr, 1}, {"repr", builtin_repr, 1},
{"round", builtin_round, 1}, {"round", builtin_round, 1},
{"setattr", builtin_setattr, 1}, {"setattr", builtin_setattr, 1},
{"slice", builtin_slice, 1},
{"str", builtin_str, 1}, {"str", builtin_str, 1},
{"tuple", builtin_tuple, 1}, {"tuple", builtin_tuple, 1},
{"type", builtin_type, 1}, {"type", builtin_type, 1},

View File

@ -87,6 +87,7 @@ static object *apply_subscript PROTO((object *, object *));
static object *loop_subscript PROTO((object *, object *)); static object *loop_subscript PROTO((object *, object *));
static int slice_index PROTO((object *, int, int *)); static int slice_index PROTO((object *, int, int *));
static object *apply_slice PROTO((object *, object *, object *)); static object *apply_slice PROTO((object *, object *, object *));
static object *build_slice PROTO((object *, object *, object *));
static int assign_subscript PROTO((object *, object *, object *)); static int assign_subscript PROTO((object *, object *, object *));
static int assign_slice PROTO((object *, object *, object *, object *)); static int assign_slice PROTO((object *, object *, object *, object *));
static int cmp_exception PROTO((object *, object *)); static int cmp_exception PROTO((object *, object *));
@ -187,6 +188,8 @@ restore_thread(x)
thread (the main thread) ever takes things out of the queue. thread (the main thread) ever takes things out of the queue.
*/ */
static int ticker = 0; /* main loop counter to do periodic things */
#define NPENDINGCALLS 32 #define NPENDINGCALLS 32
static struct { static struct {
int (*func) PROTO((ANY *)); int (*func) PROTO((ANY *));
@ -215,6 +218,7 @@ Py_AddPendingCall(func, arg)
pendingcalls[i].func = func; pendingcalls[i].func = func;
pendingcalls[i].arg = arg; pendingcalls[i].arg = arg;
pendinglast = j; pendinglast = j;
ticker = 0; /* Signal main loop */
busy = 0; busy = 0;
/* XXX End critical section */ /* XXX End critical section */
return 0; return 0;
@ -225,11 +229,15 @@ Py_MakePendingCalls()
{ {
static int busy = 0; static int busy = 0;
#ifdef WITH_THREAD #ifdef WITH_THREAD
if (get_thread_ident() != main_thread) if (get_thread_ident() != main_thread) {
ticker = 0; /* We're not done yet */
return 0; return 0;
}
#endif #endif
if (busy) if (busy) {
ticker = 0; /* We're not done yet */
return 0; return 0;
}
busy = 1; busy = 1;
for (;;) { for (;;) {
int i; int i;
@ -243,6 +251,7 @@ Py_MakePendingCalls()
pendingfirst = (i + 1) % NPENDINGCALLS; pendingfirst = (i + 1) % NPENDINGCALLS;
if (func(arg) < 0) { if (func(arg) < 0) {
busy = 0; busy = 0;
ticker = 0; /* We're not done yet */
return -1; return -1;
} }
} }
@ -281,6 +290,12 @@ eval_code(co, globals, locals)
/* Interpreter main loop */ /* Interpreter main loop */
#ifndef MAX_RECURSION_DEPTH
#define MAX_RECURSION_DEPTH 10000
#endif
static int recursion_depth = 0;
static object * static object *
eval_code2(co, globals, locals, eval_code2(co, globals, locals,
args, argcount, kws, kwcount, defs, defcount, owner) args, argcount, kws, kwcount, defs, defcount, owner)
@ -355,6 +370,13 @@ eval_code2(co, globals, locals,
#define SETLOCAL(i, value) do { XDECREF(GETLOCAL(i)); \ #define SETLOCAL(i, value) do { XDECREF(GETLOCAL(i)); \
GETLOCAL(i) = value; } while (0) GETLOCAL(i) = value; } while (0)
#ifdef USE_STACKCHECK
if (recursion_depth%10 == 0 && PyOS_CheckStack()) {
err_setstr(MemoryError, "Stack overflow");
return NULL;
}
#endif
if (globals == NULL) { if (globals == NULL) {
err_setstr(SystemError, "eval_code2: NULL globals"); err_setstr(SystemError, "eval_code2: NULL globals");
return NULL; return NULL;
@ -514,6 +536,14 @@ eval_code2(co, globals, locals,
} }
} }
if (++recursion_depth > MAX_RECURSION_DEPTH) {
--recursion_depth;
err_setstr(RuntimeError, "Maximum recursion depth exceeded");
current_frame = f->f_back;
DECREF(f);
return NULL;
}
next_instr = GETUSTRINGVALUE(f->f_code->co_code); next_instr = GETUSTRINGVALUE(f->f_code->co_code);
stack_pointer = f->f_valuestack; stack_pointer = f->f_valuestack;
@ -522,22 +552,23 @@ eval_code2(co, globals, locals,
x = None; /* Not a reference, just anything non-NULL */ x = None; /* Not a reference, just anything non-NULL */
for (;;) { for (;;) {
static int ticker;
/* Do periodic things. /* Do periodic things.
Doing this every time through the loop would add Doing this every time through the loop would add
too much overhead (a function call per instruction). too much overhead (a function call per instruction).
So we do it only every Nth instruction. */ So we do it only every Nth instruction.
if (pendingfirst != pendinglast) { The ticker is reset to zero if there are pending
if (Py_MakePendingCalls() < 0) { calls (see Py_AddPendingCalls() and
why = WHY_EXCEPTION; Py_MakePendingCalls() above). */
goto on_error;
}
}
if (--ticker < 0) { if (--ticker < 0) {
ticker = sys_checkinterval; ticker = sys_checkinterval;
if (pendingfirst != pendinglast) {
if (Py_MakePendingCalls() < 0) {
why = WHY_EXCEPTION;
goto on_error;
}
}
if (sigcheck()) { if (sigcheck()) {
why = WHY_EXCEPTION; why = WHY_EXCEPTION;
goto on_error; goto on_error;
@ -1630,7 +1661,22 @@ eval_code2(co, globals, locals,
} }
PUSH(x); PUSH(x);
break; break;
case BUILD_SLICE:
if (oparg == 3)
w = POP();
else
w = NULL;
v = POP();
u = POP();
x = build_slice(u,v,w);
DECREF(u);
DECREF(v);
XDECREF(w);
PUSH(x);
break;
default: default:
fprintf(stderr, fprintf(stderr,
"XXX lineno: %d, opcode: %d\n", "XXX lineno: %d, opcode: %d\n",
@ -1793,6 +1839,7 @@ eval_code2(co, globals, locals,
current_frame = f->f_back; current_frame = f->f_back;
DECREF(f); DECREF(f);
--recursion_depth;
return retval; return retval;
} }
@ -2548,6 +2595,13 @@ slice_index(v, isize, pi)
return 0; return 0;
} }
static object *
build_slice(u, v, w) /* u:v:w */
object *u, *v, *w;
{
return PySlice_New(u,v,w);
}
static object * static object *
apply_slice(u, v, w) /* return u[v:w] */ apply_slice(u, v, w) /* return u[v:w] */
object *u, *v, *w; object *u, *v, *w;

View File

@ -47,6 +47,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#define OP_DELETE 0
#define OP_ASSIGN 1
#define OP_APPLY 2
#define OFF(x) offsetof(codeobject, x) #define OFF(x) offsetof(codeobject, x)
static struct memberlist code_memberlist[] = { static struct memberlist code_memberlist[] = {
@ -821,31 +825,6 @@ com_slice(c, n, op)
} }
} }
static void
com_apply_subscript(c, n)
struct compiling *c;
node *n;
{
REQ(n, subscript);
if (TYPE(CHILD(n, 0)) == COLON || (NCH(n) > 1 && TYPE(CHILD(n, 1)) == COLON)) {
/* It's a slice: [expr] ':' [expr] */
com_slice(c, n, SLICE);
}
else {
/* It's a list of subscripts */
if (NCH(n) == 1)
com_node(c, CHILD(n, 0));
else {
int i;
int len = (NCH(n)+1)/2;
for (i = 0; i < NCH(n); i += 2)
com_node(c, CHILD(n, i));
com_addoparg(c, BUILD_TUPLE, len);
}
com_addbyte(c, BINARY_SUBSCR);
}
}
static int static int
com_argument(c, n, inkeywords) com_argument(c, n, inkeywords)
struct compiling *c; struct compiling *c;
@ -923,6 +902,107 @@ com_select_member(c, n)
com_addopname(c, LOAD_ATTR, n); com_addopname(c, LOAD_ATTR, n);
} }
static void
com_sliceobj(c, n)
struct compiling *c;
node *n;
{
int i=0;
int ns=2; /* number of slice arguments */
int first_missing=0;
node *ch;
/* first argument */
if (TYPE(CHILD(n,i)) == COLON) {
com_addoparg(c, LOAD_CONST, com_addconst(c, None));
i++;
}
else {
com_node(c, CHILD(n,i));
i++;
REQ(CHILD(n,i),COLON);
i++;
}
/* second argument */
if (i < NCH(n) && TYPE(CHILD(n,i)) == test) {
com_node(c, CHILD(n,i));
i++;
}
else com_addoparg(c, LOAD_CONST, com_addconst(c, None));
/* remaining arguments */
for (; i < NCH(n); i++) {
ns++;
ch=CHILD(n,i);
REQ(ch, sliceop);
if (NCH(ch) == 1) {
/* right argument of ':' missing */
com_addoparg(c, LOAD_CONST, com_addconst(c, None));
}
else
com_node(c, CHILD(ch,1));
}
com_addoparg(c, BUILD_SLICE, ns);
}
static void
com_subscript(c, n)
struct compiling *c;
node *n;
{
node *ch;
REQ(n, subscript);
ch = CHILD(n,0);
/* check for rubber index */
if (TYPE(ch) == DOT && TYPE(CHILD(n,1)) == DOT)
com_addoparg(c, LOAD_CONST, com_addconst(c, Py_Ellipses));
else {
/* check for slice */
if ((TYPE(ch) == COLON || NCH(n) > 1))
com_sliceobj(c, n);
else {
REQ(ch, test);
com_node(c, ch);
}
}
}
static void
com_subscriptlist(c, n, assigning)
struct compiling *c;
node *n;
int assigning;
{
int i, op;
REQ(n, subscriptlist);
/* Check to make backward compatible slice behavior for '[i:j]' */
if (NCH(n) == 1) {
node *sub = CHILD(n, 0); /* subscript */
/* Make it is a simple slice.
should have exactly one colon. */
if ((TYPE(CHILD(sub, 0)) == COLON
|| (NCH(sub) > 1 && TYPE(CHILD(sub, 1)) == COLON))
&& (TYPE(CHILD(sub,NCH(sub)-1)) != sliceop)) {
if (assigning == OP_APPLY)
op = SLICE;
else
op = ((assigning == OP_ASSIGN) ? STORE_SLICE : DELETE_SLICE);
com_slice(c, sub, op);
return;
}
}
/* Else normal subscriptlist. Compile each subscript. */
for (i = 0; i < NCH(n); i += 2)
com_subscript(c, CHILD(n, i));
/* Put multiple subscripts into a tuple */
if (NCH(n) > 1)
com_addoparg(c, BUILD_TUPLE, (NCH(n)+1) / 2);
if (assigning == OP_APPLY)
op = BINARY_SUBSCR;
else
op = ((assigning == OP_ASSIGN) ? STORE_SUBSCR : DELETE_SUBSCR);
com_addbyte(c, op);
}
static void static void
com_apply_trailer(c, n) com_apply_trailer(c, n)
struct compiling *c; struct compiling *c;
@ -937,7 +1017,7 @@ com_apply_trailer(c, n)
com_select_member(c, CHILD(n, 1)); com_select_member(c, CHILD(n, 1));
break; break;
case LSQB: case LSQB:
com_apply_subscript(c, CHILD(n, 1)); com_subscriptlist(c, CHILD(n, 1), OP_APPLY);
break; break;
default: default:
err_setstr(SystemError, err_setstr(SystemError,
@ -970,6 +1050,7 @@ com_factor(c, n)
struct compiling *c; struct compiling *c;
node *n; node *n;
{ {
int i;
REQ(n, factor); REQ(n, factor);
if (TYPE(CHILD(n, 0)) == PLUS) { if (TYPE(CHILD(n, 0)) == PLUS) {
com_factor(c, CHILD(n, 1)); com_factor(c, CHILD(n, 1));
@ -1364,33 +1445,6 @@ com_assign_attr(c, n, assigning)
com_addopname(c, assigning ? STORE_ATTR : DELETE_ATTR, n); com_addopname(c, assigning ? STORE_ATTR : DELETE_ATTR, n);
} }
static void
com_assign_slice(c, n, assigning)
struct compiling *c;
node *n;
int assigning;
{
com_slice(c, n, assigning ? STORE_SLICE : DELETE_SLICE);
}
static void
com_assign_subscript(c, n, assigning)
struct compiling *c;
node *n;
int assigning;
{
if (NCH(n) == 1)
com_node(c, CHILD(n, 0));
else {
int i;
int len = (NCH(n)+1)/2;
for (i = 0; i < NCH(n); i += 2)
com_node(c, CHILD(n, i));
com_addoparg(c, BUILD_TUPLE, len);
}
com_addbyte(c, assigning ? STORE_SUBSCR : DELETE_SUBSCR);
}
static void static void
com_assign_trailer(c, n, assigning) com_assign_trailer(c, n, assigning)
struct compiling *c; struct compiling *c;
@ -1406,13 +1460,8 @@ com_assign_trailer(c, n, assigning)
case DOT: /* '.' NAME */ case DOT: /* '.' NAME */
com_assign_attr(c, CHILD(n, 1), assigning); com_assign_attr(c, CHILD(n, 1), assigning);
break; break;
case LSQB: /* '[' subscript ']' */ case LSQB: /* '[' subscriptlist ']' */
n = CHILD(n, 1); com_subscriptlist(c, CHILD(n, 1), assigning);
REQ(n, subscript); /* subscript: expr (',' expr)* | [expr] ':' [expr] */
if (TYPE(CHILD(n, 0)) == COLON || (NCH(n) > 1 && TYPE(CHILD(n, 1)) == COLON))
com_assign_slice(c, n, assigning);
else
com_assign_subscript(c, n, assigning);
break; break;
default: default:
err_setstr(SystemError, "unknown trailer type"); err_setstr(SystemError, "unknown trailer type");
@ -1585,7 +1634,7 @@ com_expr_stmt(c, n)
for (i = 0; i < NCH(n)-2; i+=2) { for (i = 0; i < NCH(n)-2; i+=2) {
if (i+2 < NCH(n)-2) if (i+2 < NCH(n)-2)
com_addbyte(c, DUP_TOP); com_addbyte(c, DUP_TOP);
com_assign(c, CHILD(n, i), 1/*assign*/); com_assign(c, CHILD(n, i), OP_ASSIGN);
} }
} }
} }
@ -1896,7 +1945,7 @@ com_for_stmt(c, n)
c->c_begin = c->c_nexti; c->c_begin = c->c_nexti;
com_addoparg(c, SET_LINENO, n->n_lineno); com_addoparg(c, SET_LINENO, n->n_lineno);
com_addfwref(c, FOR_LOOP, &anchor); com_addfwref(c, FOR_LOOP, &anchor);
com_assign(c, CHILD(n, 1), 1/*assigning*/); com_assign(c, CHILD(n, 1), OP_ASSIGN);
c->c_loops++; c->c_loops++;
com_node(c, CHILD(n, 5)); com_node(c, CHILD(n, 5));
c->c_loops--; c->c_loops--;
@ -2015,7 +2064,7 @@ com_try_except(c, n)
} }
com_addbyte(c, POP_TOP); com_addbyte(c, POP_TOP);
if (NCH(ch) > 3) if (NCH(ch) > 3)
com_assign(c, CHILD(ch, 3), 1/*assigning*/); com_assign(c, CHILD(ch, 3), OP_ASSIGN);
else else
com_addbyte(c, POP_TOP); com_addbyte(c, POP_TOP);
com_addbyte(c, POP_TOP); com_addbyte(c, POP_TOP);
@ -2342,7 +2391,7 @@ com_node(c, n)
com_print_stmt(c, n); com_print_stmt(c, n);
break; break;
case del_stmt: /* 'del' exprlist */ case del_stmt: /* 'del' exprlist */
com_assign(c, CHILD(n, 1), 0/*delete*/); com_assign(c, CHILD(n, 1), OP_DELETE);
break; break;
case pass_stmt: case pass_stmt:
break; break;

View File

@ -1031,169 +1031,204 @@ static state states_48[7] = {
{1, arcs_48_5}, {1, arcs_48_5},
{1, arcs_48_6}, {1, arcs_48_6},
}; };
static arc arcs_49_0[2] = { static arc arcs_49_0[1] = {
{21, 1}, {121, 1},
{14, 2},
}; };
static arc arcs_49_1[3] = { static arc arcs_49_1[2] = {
{22, 3}, {22, 2},
{14, 2},
{0, 1}, {0, 1},
}; };
static arc arcs_49_2[2] = { static arc arcs_49_2[2] = {
{21, 4}, {121, 1},
{0, 2}, {0, 2},
}; };
static arc arcs_49_3[2] = { static state states_49[3] = {
{21, 5}, {1, arcs_49_0},
{0, 3}, {2, arcs_49_1},
};
static arc arcs_49_4[1] = {
{0, 4},
};
static arc arcs_49_5[2] = {
{22, 3},
{0, 5},
};
static state states_49[6] = {
{2, arcs_49_0},
{3, arcs_49_1},
{2, arcs_49_2}, {2, arcs_49_2},
{2, arcs_49_3},
{1, arcs_49_4},
{2, arcs_49_5},
}; };
static arc arcs_50_0[1] = { static arc arcs_50_0[3] = {
{57, 1}, {52, 1},
{21, 2},
{14, 3},
}; };
static arc arcs_50_1[2] = { static arc arcs_50_1[1] = {
{22, 2}, {52, 4},
{0, 1},
}; };
static arc arcs_50_2[2] = { static arc arcs_50_2[2] = {
{57, 1}, {14, 3},
{0, 2}, {0, 2},
}; };
static state states_50[3] = { static arc arcs_50_3[3] = {
{1, arcs_50_0}, {21, 5},
{2, arcs_50_1}, {122, 6},
{0, 3},
};
static arc arcs_50_4[1] = {
{52, 6},
};
static arc arcs_50_5[2] = {
{122, 6},
{0, 5},
};
static arc arcs_50_6[1] = {
{0, 6},
};
static state states_50[7] = {
{3, arcs_50_0},
{1, arcs_50_1},
{2, arcs_50_2}, {2, arcs_50_2},
{3, arcs_50_3},
{1, arcs_50_4},
{2, arcs_50_5},
{1, arcs_50_6},
}; };
static arc arcs_51_0[1] = { static arc arcs_51_0[1] = {
{21, 1}, {14, 1},
}; };
static arc arcs_51_1[2] = { static arc arcs_51_1[2] = {
{22, 2}, {21, 2},
{0, 1}, {0, 1},
}; };
static arc arcs_51_2[2] = { static arc arcs_51_2[1] = {
{21, 1},
{0, 2}, {0, 2},
}; };
static state states_51[3] = { static state states_51[3] = {
{1, arcs_51_0}, {1, arcs_51_0},
{2, arcs_51_1}, {2, arcs_51_1},
{2, arcs_51_2}, {1, arcs_51_2},
}; };
static arc arcs_52_0[1] = { static arc arcs_52_0[1] = {
{21, 1}, {57, 1},
}; };
static arc arcs_52_1[1] = { static arc arcs_52_1[2] = {
{14, 2},
};
static arc arcs_52_2[1] = {
{21, 3},
};
static arc arcs_52_3[2] = {
{22, 4},
{0, 3},
};
static arc arcs_52_4[2] = {
{21, 1},
{0, 4},
};
static state states_52[5] = {
{1, arcs_52_0},
{1, arcs_52_1},
{1, arcs_52_2},
{2, arcs_52_3},
{2, arcs_52_4},
};
static arc arcs_53_0[1] = {
{121, 1},
};
static arc arcs_53_1[1] = {
{12, 2},
};
static arc arcs_53_2[2] = {
{16, 3},
{14, 4},
};
static arc arcs_53_3[1] = {
{9, 5},
};
static arc arcs_53_4[1] = {
{15, 6},
};
static arc arcs_53_5[1] = {
{18, 7},
};
static arc arcs_53_6[1] = {
{0, 6},
};
static arc arcs_53_7[1] = {
{14, 4},
};
static state states_53[8] = {
{1, arcs_53_0},
{1, arcs_53_1},
{2, arcs_53_2},
{1, arcs_53_3},
{1, arcs_53_4},
{1, arcs_53_5},
{1, arcs_53_6},
{1, arcs_53_7},
};
static arc arcs_54_0[1] = {
{122, 1},
};
static arc arcs_54_1[2] = {
{22, 2}, {22, 2},
{0, 1}, {0, 1},
}; };
static arc arcs_54_2[2] = { static arc arcs_52_2[2] = {
{122, 1}, {57, 1},
{0, 2}, {0, 2},
}; };
static state states_54[3] = { static state states_52[3] = {
{1, arcs_54_0}, {1, arcs_52_0},
{2, arcs_54_1}, {2, arcs_52_1},
{2, arcs_54_2}, {2, arcs_52_2},
}; };
static arc arcs_55_0[1] = { static arc arcs_53_0[1] = {
{21, 1}, {21, 1},
}; };
static arc arcs_55_1[2] = { static arc arcs_53_1[2] = {
{22, 2},
{0, 1},
};
static arc arcs_53_2[2] = {
{21, 1},
{0, 2},
};
static state states_53[3] = {
{1, arcs_53_0},
{2, arcs_53_1},
{2, arcs_53_2},
};
static arc arcs_54_0[1] = {
{21, 1},
};
static arc arcs_54_1[1] = {
{14, 2},
};
static arc arcs_54_2[1] = {
{21, 3},
};
static arc arcs_54_3[2] = {
{22, 4},
{0, 3},
};
static arc arcs_54_4[2] = {
{21, 1},
{0, 4},
};
static state states_54[5] = {
{1, arcs_54_0},
{1, arcs_54_1},
{1, arcs_54_2},
{2, arcs_54_3},
{2, arcs_54_4},
};
static arc arcs_55_0[1] = {
{123, 1},
};
static arc arcs_55_1[1] = {
{12, 2},
};
static arc arcs_55_2[2] = {
{16, 3},
{14, 4},
};
static arc arcs_55_3[1] = {
{9, 5},
};
static arc arcs_55_4[1] = {
{15, 6},
};
static arc arcs_55_5[1] = {
{18, 7},
};
static arc arcs_55_6[1] = {
{0, 6},
};
static arc arcs_55_7[1] = {
{14, 4},
};
static state states_55[8] = {
{1, arcs_55_0},
{1, arcs_55_1},
{2, arcs_55_2},
{1, arcs_55_3},
{1, arcs_55_4},
{1, arcs_55_5},
{1, arcs_55_6},
{1, arcs_55_7},
};
static arc arcs_56_0[1] = {
{124, 1},
};
static arc arcs_56_1[2] = {
{22, 2},
{0, 1},
};
static arc arcs_56_2[2] = {
{124, 1},
{0, 2},
};
static state states_56[3] = {
{1, arcs_56_0},
{2, arcs_56_1},
{2, arcs_56_2},
};
static arc arcs_57_0[1] = {
{21, 1},
};
static arc arcs_57_1[2] = {
{20, 2}, {20, 2},
{0, 1}, {0, 1},
}; };
static arc arcs_55_2[1] = { static arc arcs_57_2[1] = {
{21, 3}, {21, 3},
}; };
static arc arcs_55_3[1] = { static arc arcs_57_3[1] = {
{0, 3}, {0, 3},
}; };
static state states_55[4] = { static state states_57[4] = {
{1, arcs_55_0}, {1, arcs_57_0},
{2, arcs_55_1}, {2, arcs_57_1},
{1, arcs_55_2}, {1, arcs_57_2},
{1, arcs_55_3}, {1, arcs_57_3},
}; };
static dfa dfas[56] = { static dfa dfas[58] = {
{256, "single_input", 0, 3, states_0, {256, "single_input", 0, 3, states_0,
"\004\030\001\000\140\341\153\001\071\000\001\000\140\104\171\002"}, "\004\030\001\000\140\341\153\001\071\000\001\000\140\104\171\010"},
{257, "file_input", 0, 2, states_1, {257, "file_input", 0, 2, states_1,
"\204\030\001\000\140\341\153\001\071\000\001\000\140\104\171\002"}, "\204\030\001\000\140\341\153\001\071\000\001\000\140\104\171\010"},
{258, "eval_input", 0, 3, states_2, {258, "eval_input", 0, 3, states_2,
"\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"}, "\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"},
{259, "funcdef", 0, 6, states_3, {259, "funcdef", 0, 6, states_3,
@ -1207,7 +1242,7 @@ static dfa dfas[56] = {
{263, "fplist", 0, 3, states_7, {263, "fplist", 0, 3, states_7,
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\000"}, "\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\000"},
{264, "stmt", 0, 2, states_8, {264, "stmt", 0, 2, states_8,
"\000\030\001\000\140\341\153\001\071\000\001\000\140\104\171\002"}, "\000\030\001\000\140\341\153\001\071\000\001\000\140\104\171\010"},
{265, "simple_stmt", 0, 4, states_9, {265, "simple_stmt", 0, 4, states_9,
"\000\020\001\000\140\341\153\001\000\000\001\000\140\104\171\000"}, "\000\020\001\000\140\341\153\001\000\000\001\000\140\104\171\000"},
{266, "small_stmt", 0, 2, states_10, {266, "small_stmt", 0, 2, states_10,
@ -1243,7 +1278,7 @@ static dfa dfas[56] = {
{281, "exec_stmt", 0, 7, states_25, {281, "exec_stmt", 0, 7, states_25,
"\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"}, "\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
{282, "compound_stmt", 0, 2, states_26, {282, "compound_stmt", 0, 2, states_26,
"\000\010\000\000\000\000\000\000\071\000\000\000\000\000\000\002"}, "\000\010\000\000\000\000\000\000\071\000\000\000\000\000\000\010"},
{283, "if_stmt", 0, 8, states_27, {283, "if_stmt", 0, 8, states_27,
"\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000"}, "\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000"},
{284, "while_stmt", 0, 8, states_28, {284, "while_stmt", 0, 8, states_28,
@ -1288,22 +1323,26 @@ static dfa dfas[56] = {
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\100\000"}, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\100\000"},
{304, "trailer", 0, 7, states_48, {304, "trailer", 0, 7, states_48,
"\000\000\001\000\000\000\020\000\000\000\000\000\000\100\000\000"}, "\000\000\001\000\000\000\020\000\000\000\000\000\000\100\000\000"},
{305, "subscript", 0, 6, states_49, {305, "subscriptlist", 0, 3, states_49,
"\000\120\001\000\000\000\000\000\000\000\001\000\140\104\171\000"}, "\000\120\001\000\000\000\020\000\000\000\001\000\140\104\171\000"},
{306, "exprlist", 0, 3, states_50, {306, "subscript", 0, 7, states_50,
"\000\120\001\000\000\000\020\000\000\000\001\000\140\104\171\000"},
{307, "sliceop", 0, 3, states_51,
"\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
{308, "exprlist", 0, 3, states_52,
"\000\020\001\000\000\000\000\000\000\000\000\000\140\104\071\000"}, "\000\020\001\000\000\000\000\000\000\000\000\000\140\104\071\000"},
{307, "testlist", 0, 3, states_51, {309, "testlist", 0, 3, states_53,
"\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"}, "\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"},
{308, "dictmaker", 0, 5, states_52, {310, "dictmaker", 0, 5, states_54,
"\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"}, "\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"},
{309, "classdef", 0, 8, states_53, {311, "classdef", 0, 8, states_55,
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\002"}, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\010"},
{310, "arglist", 0, 3, states_54, {312, "arglist", 0, 3, states_56,
"\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"}, "\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"},
{311, "argument", 0, 4, states_55, {313, "argument", 0, 4, states_57,
"\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"}, "\000\020\001\000\000\000\000\000\000\000\001\000\140\104\171\000"},
}; };
static label labels[123] = { static label labels[125] = {
{0, "EMPTY"}, {0, "EMPTY"},
{256, 0}, {256, 0},
{4, 0}, {4, 0},
@ -1313,7 +1352,7 @@ static label labels[123] = {
{264, 0}, {264, 0},
{0, 0}, {0, 0},
{258, 0}, {258, 0},
{307, 0}, {309, 0},
{259, 0}, {259, 0},
{1, "def"}, {1, "def"},
{1, 0}, {1, 0},
@ -1343,7 +1382,7 @@ static label labels[123] = {
{281, 0}, {281, 0},
{1, "print"}, {1, "print"},
{1, "del"}, {1, "del"},
{306, 0}, {308, 0},
{1, "pass"}, {1, "pass"},
{272, 0}, {272, 0},
{273, 0}, {273, 0},
@ -1367,7 +1406,7 @@ static label labels[123] = {
{284, 0}, {284, 0},
{285, 0}, {285, 0},
{286, 0}, {286, 0},
{309, 0}, {311, 0},
{1, "if"}, {1, "if"},
{1, "elif"}, {1, "elif"},
{1, "else"}, {1, "else"},
@ -1417,20 +1456,22 @@ static label labels[123] = {
{9, 0}, {9, 0},
{10, 0}, {10, 0},
{26, 0}, {26, 0},
{308, 0}, {310, 0},
{27, 0}, {27, 0},
{25, 0}, {25, 0},
{2, 0}, {2, 0},
{3, 0}, {3, 0},
{1, "lambda"}, {1, "lambda"},
{310, 0}, {312, 0},
{305, 0}, {305, 0},
{306, 0},
{307, 0},
{1, "class"}, {1, "class"},
{311, 0}, {313, 0},
}; };
grammar gram = { grammar gram = {
56, 58,
dfas, dfas,
{123, labels}, {125, labels},
256 256
}; };

View File

@ -55,7 +55,7 @@ extern long getmtime(); /* In getmtime.c */
Apple MPW compiler swaps their values, botching string constants */ Apple MPW compiler swaps their values, botching string constants */
/* XXX Perhaps the magic number should be frozen and a version field /* XXX Perhaps the magic number should be frozen and a version field
added to the .pyc file header? */ added to the .pyc file header? */
#define MAGIC (1895 | ((long)'\r'<<16) | ((long)'\n'<<24)) #define MAGIC (5892 | ((long)'\r'<<16) | ((long)'\n'<<24))
object *import_modules; /* This becomes sys.modules */ object *import_modules; /* This becomes sys.modules */

View File

@ -37,6 +37,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define TYPE_NULL '0' #define TYPE_NULL '0'
#define TYPE_NONE 'N' #define TYPE_NONE 'N'
#define TYPE_ELLIPSES '.'
#define TYPE_INT 'i' #define TYPE_INT 'i'
#define TYPE_FLOAT 'f' #define TYPE_FLOAT 'f'
#define TYPE_COMPLEX 'x' #define TYPE_COMPLEX 'x'
@ -129,6 +130,8 @@ w_object(v, p)
w_byte(TYPE_NULL, p); w_byte(TYPE_NULL, p);
else if (v == None) else if (v == None)
w_byte(TYPE_NONE, p); w_byte(TYPE_NONE, p);
else if (v == Py_Ellipses)
w_byte(TYPE_ELLIPSES, p);
else if (is_intobject(v)) { else if (is_intobject(v)) {
w_byte(TYPE_INT, p); w_byte(TYPE_INT, p);
w_long(getintvalue(v), p); w_long(getintvalue(v), p);
@ -322,6 +325,10 @@ r_object(p)
INCREF(None); INCREF(None);
return None; return None;
case TYPE_ELLIPSES:
INCREF(Py_Ellipses);
return Py_Ellipses;
case TYPE_INT: case TYPE_INT:
return newintobject(r_long(p)); return newintobject(r_long(p));