mirror of https://github.com/python/cpython
more low-hanging fruit to make code compile under a C++ compiler. Not
entirely happy with the two new VISIT macros in compile.c, but I couldn't see a better approach.
This commit is contained in:
parent
9176fc1466
commit
7b782b61c5
|
@ -136,7 +136,7 @@ char *
|
||||||
PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
|
PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
|
||||||
{
|
{
|
||||||
size_t n = 1000;
|
size_t n = 1000;
|
||||||
char *p = PyMem_MALLOC(n);
|
char *p = (char *)PyMem_MALLOC(n);
|
||||||
char *q;
|
char *q;
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -149,7 +149,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
|
||||||
n = strlen(p);
|
n = strlen(p);
|
||||||
if (n > 0 && p[n-1] != '\n')
|
if (n > 0 && p[n-1] != '\n')
|
||||||
p[n-1] = '\n';
|
p[n-1] = '\n';
|
||||||
return PyMem_REALLOC(p, n+1);
|
return (char *)PyMem_REALLOC(p, n+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No-nonsense fgets */
|
/* No-nonsense fgets */
|
||||||
|
|
139
Python/compile.c
139
Python/compile.c
|
@ -197,19 +197,19 @@ static PyCodeObject *assemble(struct compiler *, int addNone);
|
||||||
static PyObject *__doc__;
|
static PyObject *__doc__;
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_Py_Mangle(PyObject *private, PyObject *ident)
|
_Py_Mangle(PyObject *privateobj, PyObject *ident)
|
||||||
{
|
{
|
||||||
/* Name mangling: __private becomes _classname__private.
|
/* Name mangling: __private becomes _classname__private.
|
||||||
This is independent from how the name is used. */
|
This is independent from how the name is used. */
|
||||||
const char *p, *name = PyString_AsString(ident);
|
const char *p, *name = PyString_AsString(ident);
|
||||||
char *buffer;
|
char *buffer;
|
||||||
size_t nlen, plen;
|
size_t nlen, plen;
|
||||||
if (private == NULL || name == NULL || name[0] != '_' ||
|
if (privateobj == NULL || name == NULL || name[0] != '_' ||
|
||||||
name[1] != '_') {
|
name[1] != '_') {
|
||||||
Py_INCREF(ident);
|
Py_INCREF(ident);
|
||||||
return ident;
|
return ident;
|
||||||
}
|
}
|
||||||
p = PyString_AsString(private);
|
p = PyString_AsString(privateobj);
|
||||||
nlen = strlen(name);
|
nlen = strlen(name);
|
||||||
if (name[nlen-1] == '_' && name[nlen-2] == '_') {
|
if (name[nlen-1] == '_' && name[nlen-2] == '_') {
|
||||||
Py_INCREF(ident);
|
Py_INCREF(ident);
|
||||||
|
@ -612,7 +612,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
|
||||||
static unsigned int *
|
static unsigned int *
|
||||||
markblocks(unsigned char *code, int len)
|
markblocks(unsigned char *code, int len)
|
||||||
{
|
{
|
||||||
unsigned int *blocks = PyMem_Malloc(len*sizeof(int));
|
unsigned int *blocks = (unsigned int *)PyMem_Malloc(len*sizeof(int));
|
||||||
int i,j, opcode, blockcnt = 0;
|
int i,j, opcode, blockcnt = 0;
|
||||||
|
|
||||||
if (blocks == NULL)
|
if (blocks == NULL)
|
||||||
|
@ -693,10 +693,11 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names,
|
||||||
goto exitUnchanged;
|
goto exitUnchanged;
|
||||||
|
|
||||||
/* Make a modifiable copy of the code string */
|
/* Make a modifiable copy of the code string */
|
||||||
codestr = PyMem_Malloc(codelen);
|
codestr = (unsigned char *)PyMem_Malloc(codelen);
|
||||||
if (codestr == NULL)
|
if (codestr == NULL)
|
||||||
goto exitUnchanged;
|
goto exitUnchanged;
|
||||||
codestr = memcpy(codestr, PyString_AS_STRING(code), codelen);
|
codestr = (unsigned char *)memcpy(codestr,
|
||||||
|
PyString_AS_STRING(code), codelen);
|
||||||
|
|
||||||
/* Verify that RETURN_VALUE terminates the codestring. This allows
|
/* Verify that RETURN_VALUE terminates the codestring. This allows
|
||||||
the various transformation patterns to look ahead several
|
the various transformation patterns to look ahead several
|
||||||
|
@ -707,7 +708,7 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names,
|
||||||
goto exitUnchanged;
|
goto exitUnchanged;
|
||||||
|
|
||||||
/* Mapping to new jump targets after NOPs are removed */
|
/* Mapping to new jump targets after NOPs are removed */
|
||||||
addrmap = PyMem_Malloc(codelen * sizeof(int));
|
addrmap = (int *)PyMem_Malloc(codelen * sizeof(int));
|
||||||
if (addrmap == NULL)
|
if (addrmap == NULL)
|
||||||
goto exitUnchanged;
|
goto exitUnchanged;
|
||||||
|
|
||||||
|
@ -1087,7 +1088,8 @@ compiler_enter_scope(struct compiler *c, identifier name, void *key,
|
||||||
{
|
{
|
||||||
struct compiler_unit *u;
|
struct compiler_unit *u;
|
||||||
|
|
||||||
u = PyObject_Malloc(sizeof(struct compiler_unit));
|
u = (struct compiler_unit *)PyObject_Malloc(sizeof(
|
||||||
|
struct compiler_unit));
|
||||||
if (!u) {
|
if (!u) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1243,8 +1245,8 @@ compiler_next_instr(struct compiler *c, basicblock *b)
|
||||||
{
|
{
|
||||||
assert(b != NULL);
|
assert(b != NULL);
|
||||||
if (b->b_instr == NULL) {
|
if (b->b_instr == NULL) {
|
||||||
b->b_instr = PyObject_Malloc(sizeof(struct instr) *
|
b->b_instr = (struct instr *)PyObject_Malloc(
|
||||||
DEFAULT_BLOCK_SIZE);
|
sizeof(struct instr) * DEFAULT_BLOCK_SIZE);
|
||||||
if (b->b_instr == NULL) {
|
if (b->b_instr == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1262,7 +1264,8 @@ compiler_next_instr(struct compiler *c, basicblock *b)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
b->b_ialloc <<= 1;
|
b->b_ialloc <<= 1;
|
||||||
b->b_instr = PyObject_Realloc((void *)b->b_instr, newsize);
|
b->b_instr = (struct instr *)PyObject_Realloc(
|
||||||
|
(void *)b->b_instr, newsize);
|
||||||
if (b->b_instr == NULL)
|
if (b->b_instr == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
memset((char *)b->b_instr + oldsize, 0, newsize - oldsize);
|
memset((char *)b->b_instr + oldsize, 0, newsize - oldsize);
|
||||||
|
@ -1720,6 +1723,16 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b, int absolute)
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define VISIT_SEQ_WITH_CAST(C, TYPE, SEQ, CAST) { \
|
||||||
|
int _i; \
|
||||||
|
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
|
||||||
|
for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \
|
||||||
|
TYPE ## _ty elt = (CAST)asdl_seq_GET(seq, _i); \
|
||||||
|
if (!compiler_visit_ ## TYPE((C), elt)) \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \
|
#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \
|
||||||
int _i; \
|
int _i; \
|
||||||
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
|
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
|
||||||
|
@ -1732,6 +1745,18 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b, int absolute)
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define VISIT_SEQ_IN_SCOPE_WITH_CAST(C, TYPE, SEQ, CAST) { \
|
||||||
|
int _i; \
|
||||||
|
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
|
||||||
|
for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \
|
||||||
|
TYPE ## _ty elt = (CAST)asdl_seq_GET(seq, _i); \
|
||||||
|
if (!compiler_visit_ ## TYPE((C), elt)) { \
|
||||||
|
compiler_exit_scope(c); \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
compiler_isdocstring(stmt_ty s)
|
compiler_isdocstring(stmt_ty s)
|
||||||
{
|
{
|
||||||
|
@ -1750,7 +1775,7 @@ compiler_body(struct compiler *c, asdl_seq *stmts)
|
||||||
|
|
||||||
if (!asdl_seq_LEN(stmts))
|
if (!asdl_seq_LEN(stmts))
|
||||||
return 1;
|
return 1;
|
||||||
st = asdl_seq_GET(stmts, 0);
|
st = (stmt_ty)asdl_seq_GET(stmts, 0);
|
||||||
if (compiler_isdocstring(st)) {
|
if (compiler_isdocstring(st)) {
|
||||||
i = 1;
|
i = 1;
|
||||||
VISIT(c, expr, st->v.Expr.value);
|
VISIT(c, expr, st->v.Expr.value);
|
||||||
|
@ -1758,7 +1783,7 @@ compiler_body(struct compiler *c, asdl_seq *stmts)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (; i < asdl_seq_LEN(stmts); i++)
|
for (; i < asdl_seq_LEN(stmts); i++)
|
||||||
VISIT(c, stmt, asdl_seq_GET(stmts, i));
|
VISIT(c, stmt, (stmt_ty)asdl_seq_GET(stmts, i));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1784,7 +1809,8 @@ compiler_mod(struct compiler *c, mod_ty mod)
|
||||||
break;
|
break;
|
||||||
case Interactive_kind:
|
case Interactive_kind:
|
||||||
c->c_interactive = 1;
|
c->c_interactive = 1;
|
||||||
VISIT_SEQ_IN_SCOPE(c, stmt, mod->v.Interactive.body);
|
VISIT_SEQ_IN_SCOPE_WITH_CAST(c, stmt,
|
||||||
|
mod->v.Interactive.body, stmt_ty);
|
||||||
break;
|
break;
|
||||||
case Expression_kind:
|
case Expression_kind:
|
||||||
VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
|
VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
|
||||||
|
@ -1901,7 +1927,7 @@ compiler_decorators(struct compiler *c, asdl_seq* decos)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
for (i = 0; i < asdl_seq_LEN(decos); i++) {
|
for (i = 0; i < asdl_seq_LEN(decos); i++) {
|
||||||
VISIT(c, expr, asdl_seq_GET(decos, i));
|
VISIT(c, expr, (expr_ty)asdl_seq_GET(decos, i));
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1913,7 +1939,7 @@ compiler_arguments(struct compiler *c, arguments_ty args)
|
||||||
int n = asdl_seq_LEN(args->args);
|
int n = asdl_seq_LEN(args->args);
|
||||||
/* Correctly handle nested argument lists */
|
/* Correctly handle nested argument lists */
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
expr_ty arg = asdl_seq_GET(args->args, i);
|
expr_ty arg = (expr_ty)asdl_seq_GET(args->args, i);
|
||||||
if (arg->kind == Tuple_kind) {
|
if (arg->kind == Tuple_kind) {
|
||||||
PyObject *id = PyString_FromFormat(".%d", i);
|
PyObject *id = PyString_FromFormat(".%d", i);
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
|
@ -1945,12 +1971,12 @@ compiler_function(struct compiler *c, stmt_ty s)
|
||||||
if (!compiler_decorators(c, decos))
|
if (!compiler_decorators(c, decos))
|
||||||
return 0;
|
return 0;
|
||||||
if (args->defaults)
|
if (args->defaults)
|
||||||
VISIT_SEQ(c, expr, args->defaults);
|
VISIT_SEQ_WITH_CAST(c, expr, args->defaults, expr_ty);
|
||||||
if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s,
|
if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s,
|
||||||
s->lineno))
|
s->lineno))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
st = asdl_seq_GET(s->v.FunctionDef.body, 0);
|
st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, 0);
|
||||||
docstring = compiler_isdocstring(st);
|
docstring = compiler_isdocstring(st);
|
||||||
if (docstring)
|
if (docstring)
|
||||||
first_const = st->v.Expr.value->v.Str.s;
|
first_const = st->v.Expr.value->v.Str.s;
|
||||||
|
@ -1966,7 +1992,7 @@ compiler_function(struct compiler *c, stmt_ty s)
|
||||||
n = asdl_seq_LEN(s->v.FunctionDef.body);
|
n = asdl_seq_LEN(s->v.FunctionDef.body);
|
||||||
/* if there was a docstring, we need to skip the first statement */
|
/* if there was a docstring, we need to skip the first statement */
|
||||||
for (i = docstring; i < n; i++) {
|
for (i = docstring; i < n; i++) {
|
||||||
stmt_ty s2 = asdl_seq_GET(s->v.FunctionDef.body, i);
|
stmt_ty s2 = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, i);
|
||||||
if (i == 0 && s2->kind == Expr_kind &&
|
if (i == 0 && s2->kind == Expr_kind &&
|
||||||
s2->v.Expr.value->kind == Str_kind)
|
s2->v.Expr.value->kind == Str_kind)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1998,7 +2024,7 @@ compiler_class(struct compiler *c, stmt_ty s)
|
||||||
/* push the tuple of base classes on the stack */
|
/* push the tuple of base classes on the stack */
|
||||||
n = asdl_seq_LEN(s->v.ClassDef.bases);
|
n = asdl_seq_LEN(s->v.ClassDef.bases);
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
VISIT_SEQ(c, expr, s->v.ClassDef.bases);
|
VISIT_SEQ_WITH_CAST(c, expr, s->v.ClassDef.bases, expr_ty);
|
||||||
ADDOP_I(c, BUILD_TUPLE, n);
|
ADDOP_I(c, BUILD_TUPLE, n);
|
||||||
if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s,
|
if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s,
|
||||||
s->lineno))
|
s->lineno))
|
||||||
|
@ -2082,7 +2108,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->defaults)
|
if (args->defaults)
|
||||||
VISIT_SEQ(c, expr, args->defaults);
|
VISIT_SEQ_WITH_CAST(c, expr, args->defaults, expr_ty);
|
||||||
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
|
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -2155,12 +2181,12 @@ compiler_if(struct compiler *c, stmt_ty s)
|
||||||
VISIT(c, expr, s->v.If.test);
|
VISIT(c, expr, s->v.If.test);
|
||||||
ADDOP_JREL(c, JUMP_IF_FALSE, next);
|
ADDOP_JREL(c, JUMP_IF_FALSE, next);
|
||||||
ADDOP(c, POP_TOP);
|
ADDOP(c, POP_TOP);
|
||||||
VISIT_SEQ(c, stmt, s->v.If.body);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.If.body, stmt_ty);
|
||||||
ADDOP_JREL(c, JUMP_FORWARD, end);
|
ADDOP_JREL(c, JUMP_FORWARD, end);
|
||||||
compiler_use_next_block(c, next);
|
compiler_use_next_block(c, next);
|
||||||
ADDOP(c, POP_TOP);
|
ADDOP(c, POP_TOP);
|
||||||
if (s->v.If.orelse)
|
if (s->v.If.orelse)
|
||||||
VISIT_SEQ(c, stmt, s->v.If.orelse);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.If.orelse, stmt_ty);
|
||||||
compiler_use_next_block(c, end);
|
compiler_use_next_block(c, end);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -2183,12 +2209,12 @@ compiler_for(struct compiler *c, stmt_ty s)
|
||||||
compiler_use_next_block(c, start);
|
compiler_use_next_block(c, start);
|
||||||
ADDOP_JREL(c, FOR_ITER, cleanup);
|
ADDOP_JREL(c, FOR_ITER, cleanup);
|
||||||
VISIT(c, expr, s->v.For.target);
|
VISIT(c, expr, s->v.For.target);
|
||||||
VISIT_SEQ(c, stmt, s->v.For.body);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.For.body, stmt_ty);
|
||||||
ADDOP_JABS(c, JUMP_ABSOLUTE, start);
|
ADDOP_JABS(c, JUMP_ABSOLUTE, start);
|
||||||
compiler_use_next_block(c, cleanup);
|
compiler_use_next_block(c, cleanup);
|
||||||
ADDOP(c, POP_BLOCK);
|
ADDOP(c, POP_BLOCK);
|
||||||
compiler_pop_fblock(c, LOOP, start);
|
compiler_pop_fblock(c, LOOP, start);
|
||||||
VISIT_SEQ(c, stmt, s->v.For.orelse);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.For.orelse, stmt_ty);
|
||||||
compiler_use_next_block(c, end);
|
compiler_use_next_block(c, end);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -2227,7 +2253,7 @@ compiler_while(struct compiler *c, stmt_ty s)
|
||||||
ADDOP_JREL(c, JUMP_IF_FALSE, anchor);
|
ADDOP_JREL(c, JUMP_IF_FALSE, anchor);
|
||||||
ADDOP(c, POP_TOP);
|
ADDOP(c, POP_TOP);
|
||||||
}
|
}
|
||||||
VISIT_SEQ(c, stmt, s->v.While.body);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.While.body, stmt_ty);
|
||||||
ADDOP_JABS(c, JUMP_ABSOLUTE, loop);
|
ADDOP_JABS(c, JUMP_ABSOLUTE, loop);
|
||||||
|
|
||||||
/* XXX should the two POP instructions be in a separate block
|
/* XXX should the two POP instructions be in a separate block
|
||||||
|
@ -2241,7 +2267,7 @@ compiler_while(struct compiler *c, stmt_ty s)
|
||||||
}
|
}
|
||||||
compiler_pop_fblock(c, LOOP, loop);
|
compiler_pop_fblock(c, LOOP, loop);
|
||||||
if (orelse != NULL) /* what if orelse is just pass? */
|
if (orelse != NULL) /* what if orelse is just pass? */
|
||||||
VISIT_SEQ(c, stmt, s->v.While.orelse);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.While.orelse, stmt_ty);
|
||||||
compiler_use_next_block(c, end);
|
compiler_use_next_block(c, end);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -2322,7 +2348,7 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
|
||||||
compiler_use_next_block(c, body);
|
compiler_use_next_block(c, body);
|
||||||
if (!compiler_push_fblock(c, FINALLY_TRY, body))
|
if (!compiler_push_fblock(c, FINALLY_TRY, body))
|
||||||
return 0;
|
return 0;
|
||||||
VISIT_SEQ(c, stmt, s->v.TryFinally.body);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.TryFinally.body, stmt_ty);
|
||||||
ADDOP(c, POP_BLOCK);
|
ADDOP(c, POP_BLOCK);
|
||||||
compiler_pop_fblock(c, FINALLY_TRY, body);
|
compiler_pop_fblock(c, FINALLY_TRY, body);
|
||||||
|
|
||||||
|
@ -2330,7 +2356,7 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
|
||||||
compiler_use_next_block(c, end);
|
compiler_use_next_block(c, end);
|
||||||
if (!compiler_push_fblock(c, FINALLY_END, end))
|
if (!compiler_push_fblock(c, FINALLY_END, end))
|
||||||
return 0;
|
return 0;
|
||||||
VISIT_SEQ(c, stmt, s->v.TryFinally.finalbody);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.TryFinally.finalbody, stmt_ty);
|
||||||
ADDOP(c, END_FINALLY);
|
ADDOP(c, END_FINALLY);
|
||||||
compiler_pop_fblock(c, FINALLY_END, end);
|
compiler_pop_fblock(c, FINALLY_END, end);
|
||||||
|
|
||||||
|
@ -2387,14 +2413,14 @@ compiler_try_except(struct compiler *c, stmt_ty s)
|
||||||
compiler_use_next_block(c, body);
|
compiler_use_next_block(c, body);
|
||||||
if (!compiler_push_fblock(c, EXCEPT, body))
|
if (!compiler_push_fblock(c, EXCEPT, body))
|
||||||
return 0;
|
return 0;
|
||||||
VISIT_SEQ(c, stmt, s->v.TryExcept.body);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.TryExcept.body, stmt_ty);
|
||||||
ADDOP(c, POP_BLOCK);
|
ADDOP(c, POP_BLOCK);
|
||||||
compiler_pop_fblock(c, EXCEPT, body);
|
compiler_pop_fblock(c, EXCEPT, body);
|
||||||
ADDOP_JREL(c, JUMP_FORWARD, orelse);
|
ADDOP_JREL(c, JUMP_FORWARD, orelse);
|
||||||
n = asdl_seq_LEN(s->v.TryExcept.handlers);
|
n = asdl_seq_LEN(s->v.TryExcept.handlers);
|
||||||
compiler_use_next_block(c, except);
|
compiler_use_next_block(c, except);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
excepthandler_ty handler = asdl_seq_GET(
|
excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET(
|
||||||
s->v.TryExcept.handlers, i);
|
s->v.TryExcept.handlers, i);
|
||||||
if (!handler->type && i < n-1)
|
if (!handler->type && i < n-1)
|
||||||
return compiler_error(c, "default 'except:' must be last");
|
return compiler_error(c, "default 'except:' must be last");
|
||||||
|
@ -2418,7 +2444,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
|
||||||
ADDOP(c, POP_TOP);
|
ADDOP(c, POP_TOP);
|
||||||
}
|
}
|
||||||
ADDOP(c, POP_TOP);
|
ADDOP(c, POP_TOP);
|
||||||
VISIT_SEQ(c, stmt, handler->body);
|
VISIT_SEQ_WITH_CAST(c, stmt, handler->body, stmt_ty);
|
||||||
ADDOP_JREL(c, JUMP_FORWARD, end);
|
ADDOP_JREL(c, JUMP_FORWARD, end);
|
||||||
compiler_use_next_block(c, except);
|
compiler_use_next_block(c, except);
|
||||||
if (handler->type)
|
if (handler->type)
|
||||||
|
@ -2426,7 +2452,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
|
||||||
}
|
}
|
||||||
ADDOP(c, END_FINALLY);
|
ADDOP(c, END_FINALLY);
|
||||||
compiler_use_next_block(c, orelse);
|
compiler_use_next_block(c, orelse);
|
||||||
VISIT_SEQ(c, stmt, s->v.TryExcept.orelse);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.TryExcept.orelse, stmt_ty);
|
||||||
compiler_use_next_block(c, end);
|
compiler_use_next_block(c, end);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -2474,7 +2500,7 @@ compiler_import(struct compiler *c, stmt_ty s)
|
||||||
int i, n = asdl_seq_LEN(s->v.Import.names);
|
int i, n = asdl_seq_LEN(s->v.Import.names);
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
alias_ty alias = asdl_seq_GET(s->v.Import.names, i);
|
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);
|
||||||
int r;
|
int r;
|
||||||
PyObject *level;
|
PyObject *level;
|
||||||
|
|
||||||
|
@ -2538,7 +2564,7 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
||||||
|
|
||||||
/* build up the names */
|
/* build up the names */
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
|
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i);
|
||||||
Py_INCREF(alias->name);
|
Py_INCREF(alias->name);
|
||||||
PyTuple_SET_ITEM(names, i, alias->name);
|
PyTuple_SET_ITEM(names, i, alias->name);
|
||||||
}
|
}
|
||||||
|
@ -2561,7 +2587,7 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
||||||
Py_DECREF(names);
|
Py_DECREF(names);
|
||||||
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
|
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
|
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i);
|
||||||
identifier store_name;
|
identifier store_name;
|
||||||
|
|
||||||
if (i == 0 && *PyString_AS_STRING(alias->name) == '*') {
|
if (i == 0 && *PyString_AS_STRING(alias->name) == '*') {
|
||||||
|
@ -2646,7 +2672,7 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
|
||||||
ADDOP(c, RETURN_VALUE);
|
ADDOP(c, RETURN_VALUE);
|
||||||
break;
|
break;
|
||||||
case Delete_kind:
|
case Delete_kind:
|
||||||
VISIT_SEQ(c, expr, s->v.Delete.targets)
|
VISIT_SEQ_WITH_CAST(c, expr, s->v.Delete.targets, expr_ty)
|
||||||
break;
|
break;
|
||||||
case Assign_kind:
|
case Assign_kind:
|
||||||
n = asdl_seq_LEN(s->v.Assign.targets);
|
n = asdl_seq_LEN(s->v.Assign.targets);
|
||||||
|
@ -3000,11 +3026,11 @@ compiler_boolop(struct compiler *c, expr_ty e)
|
||||||
s = e->v.BoolOp.values;
|
s = e->v.BoolOp.values;
|
||||||
n = asdl_seq_LEN(s) - 1;
|
n = asdl_seq_LEN(s) - 1;
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
VISIT(c, expr, asdl_seq_GET(s, i));
|
VISIT(c, expr, (expr_ty)asdl_seq_GET(s, i));
|
||||||
ADDOP_JREL(c, jumpi, end);
|
ADDOP_JREL(c, jumpi, end);
|
||||||
ADDOP(c, POP_TOP)
|
ADDOP(c, POP_TOP)
|
||||||
}
|
}
|
||||||
VISIT(c, expr, asdl_seq_GET(s, n));
|
VISIT(c, expr, (expr_ty)asdl_seq_GET(s, n));
|
||||||
compiler_use_next_block(c, end);
|
compiler_use_next_block(c, end);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -3016,7 +3042,7 @@ compiler_list(struct compiler *c, expr_ty e)
|
||||||
if (e->v.List.ctx == Store) {
|
if (e->v.List.ctx == Store) {
|
||||||
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
||||||
}
|
}
|
||||||
VISIT_SEQ(c, expr, e->v.List.elts);
|
VISIT_SEQ_WITH_CAST(c, expr, e->v.List.elts, expr_ty);
|
||||||
if (e->v.List.ctx == Load) {
|
if (e->v.List.ctx == Load) {
|
||||||
ADDOP_I(c, BUILD_LIST, n);
|
ADDOP_I(c, BUILD_LIST, n);
|
||||||
}
|
}
|
||||||
|
@ -3030,7 +3056,7 @@ compiler_tuple(struct compiler *c, expr_ty e)
|
||||||
if (e->v.Tuple.ctx == Store) {
|
if (e->v.Tuple.ctx == Store) {
|
||||||
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
||||||
}
|
}
|
||||||
VISIT_SEQ(c, expr, e->v.Tuple.elts);
|
VISIT_SEQ_WITH_CAST(c, expr, e->v.Tuple.elts, expr_ty);
|
||||||
if (e->v.Tuple.ctx == Load) {
|
if (e->v.Tuple.ctx == Load) {
|
||||||
ADDOP_I(c, BUILD_TUPLE, n);
|
ADDOP_I(c, BUILD_TUPLE, n);
|
||||||
}
|
}
|
||||||
|
@ -3051,7 +3077,8 @@ compiler_compare(struct compiler *c, expr_ty e)
|
||||||
cleanup = compiler_new_block(c);
|
cleanup = compiler_new_block(c);
|
||||||
if (cleanup == NULL)
|
if (cleanup == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, 0));
|
VISIT(c, expr,
|
||||||
|
(expr_ty)asdl_seq_GET(e->v.Compare.comparators, 0));
|
||||||
}
|
}
|
||||||
for (i = 1; i < n; i++) {
|
for (i = 1; i < n; i++) {
|
||||||
ADDOP(c, DUP_TOP);
|
ADDOP(c, DUP_TOP);
|
||||||
|
@ -3063,9 +3090,10 @@ compiler_compare(struct compiler *c, expr_ty e)
|
||||||
NEXT_BLOCK(c);
|
NEXT_BLOCK(c);
|
||||||
ADDOP(c, POP_TOP);
|
ADDOP(c, POP_TOP);
|
||||||
if (i < (n - 1))
|
if (i < (n - 1))
|
||||||
VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, i));
|
VISIT(c, expr,
|
||||||
|
(expr_ty)asdl_seq_GET(e->v.Compare.comparators, i));
|
||||||
}
|
}
|
||||||
VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, n - 1));
|
VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, n - 1));
|
||||||
ADDOP_I(c, COMPARE_OP,
|
ADDOP_I(c, COMPARE_OP,
|
||||||
/* XXX We're casting a void* to cmpop_ty in the next stmt. */
|
/* XXX We're casting a void* to cmpop_ty in the next stmt. */
|
||||||
cmpop((cmpop_ty)asdl_seq_GET(e->v.Compare.ops, n - 1)));
|
cmpop((cmpop_ty)asdl_seq_GET(e->v.Compare.ops, n - 1)));
|
||||||
|
@ -3089,9 +3117,9 @@ compiler_call(struct compiler *c, expr_ty e)
|
||||||
|
|
||||||
VISIT(c, expr, e->v.Call.func);
|
VISIT(c, expr, e->v.Call.func);
|
||||||
n = asdl_seq_LEN(e->v.Call.args);
|
n = asdl_seq_LEN(e->v.Call.args);
|
||||||
VISIT_SEQ(c, expr, e->v.Call.args);
|
VISIT_SEQ_WITH_CAST(c, expr, e->v.Call.args, expr_ty);
|
||||||
if (e->v.Call.keywords) {
|
if (e->v.Call.keywords) {
|
||||||
VISIT_SEQ(c, keyword, e->v.Call.keywords);
|
VISIT_SEQ_WITH_CAST(c, keyword, e->v.Call.keywords, keyword_ty);
|
||||||
n |= asdl_seq_LEN(e->v.Call.keywords) << 8;
|
n |= asdl_seq_LEN(e->v.Call.keywords) << 8;
|
||||||
}
|
}
|
||||||
if (e->v.Call.starargs) {
|
if (e->v.Call.starargs) {
|
||||||
|
@ -3140,7 +3168,7 @@ compiler_listcomp_generator(struct compiler *c, PyObject *tmpname,
|
||||||
anchor == NULL)
|
anchor == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
l = asdl_seq_GET(generators, gen_index);
|
l = (comprehension_ty)asdl_seq_GET(generators, gen_index);
|
||||||
VISIT(c, expr, l->iter);
|
VISIT(c, expr, l->iter);
|
||||||
ADDOP(c, GET_ITER);
|
ADDOP(c, GET_ITER);
|
||||||
compiler_use_next_block(c, start);
|
compiler_use_next_block(c, start);
|
||||||
|
@ -3151,7 +3179,7 @@ compiler_listcomp_generator(struct compiler *c, PyObject *tmpname,
|
||||||
/* XXX this needs to be cleaned up...a lot! */
|
/* XXX this needs to be cleaned up...a lot! */
|
||||||
n = asdl_seq_LEN(l->ifs);
|
n = asdl_seq_LEN(l->ifs);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
expr_ty e = asdl_seq_GET(l->ifs, i);
|
expr_ty e = (expr_ty)asdl_seq_GET(l->ifs, i);
|
||||||
VISIT(c, expr, e);
|
VISIT(c, expr, e);
|
||||||
ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup);
|
ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup);
|
||||||
NEXT_BLOCK(c);
|
NEXT_BLOCK(c);
|
||||||
|
@ -3236,7 +3264,7 @@ compiler_genexp_generator(struct compiler *c,
|
||||||
anchor == NULL || end == NULL)
|
anchor == NULL || end == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ge = asdl_seq_GET(generators, gen_index);
|
ge = (comprehension_ty)asdl_seq_GET(generators, gen_index);
|
||||||
ADDOP_JREL(c, SETUP_LOOP, end);
|
ADDOP_JREL(c, SETUP_LOOP, end);
|
||||||
if (!compiler_push_fblock(c, LOOP, start))
|
if (!compiler_push_fblock(c, LOOP, start))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3259,7 +3287,7 @@ compiler_genexp_generator(struct compiler *c,
|
||||||
/* XXX this needs to be cleaned up...a lot! */
|
/* XXX this needs to be cleaned up...a lot! */
|
||||||
n = asdl_seq_LEN(ge->ifs);
|
n = asdl_seq_LEN(ge->ifs);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
expr_ty e = asdl_seq_GET(ge->ifs, i);
|
expr_ty e = (expr_ty)asdl_seq_GET(ge->ifs, i);
|
||||||
VISIT(c, expr, e);
|
VISIT(c, expr, e);
|
||||||
ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup);
|
ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup);
|
||||||
NEXT_BLOCK(c);
|
NEXT_BLOCK(c);
|
||||||
|
@ -3472,7 +3500,7 @@ compiler_with(struct compiler *c, stmt_ty s)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BLOCK code */
|
/* BLOCK code */
|
||||||
VISIT_SEQ(c, stmt, s->v.With.body);
|
VISIT_SEQ_WITH_CAST(c, stmt, s->v.With.body, stmt_ty);
|
||||||
|
|
||||||
/* End of try block; start the finally block */
|
/* End of try block; start the finally block */
|
||||||
ADDOP(c, POP_BLOCK);
|
ADDOP(c, POP_BLOCK);
|
||||||
|
@ -3531,9 +3559,11 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
|
||||||
It wants the stack to look like (value) (dict) (key) */
|
It wants the stack to look like (value) (dict) (key) */
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
ADDOP(c, DUP_TOP);
|
ADDOP(c, DUP_TOP);
|
||||||
VISIT(c, expr, asdl_seq_GET(e->v.Dict.values, i));
|
VISIT(c, expr,
|
||||||
|
(expr_ty)asdl_seq_GET(e->v.Dict.values, i));
|
||||||
ADDOP(c, ROT_TWO);
|
ADDOP(c, ROT_TWO);
|
||||||
VISIT(c, expr, asdl_seq_GET(e->v.Dict.keys, i));
|
VISIT(c, expr,
|
||||||
|
(expr_ty)asdl_seq_GET(e->v.Dict.keys, i));
|
||||||
ADDOP(c, STORE_SUBSCR);
|
ADDOP(c, STORE_SUBSCR);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3900,7 +3930,8 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
|
||||||
if (ctx != AugStore) {
|
if (ctx != AugStore) {
|
||||||
int i, n = asdl_seq_LEN(s->v.ExtSlice.dims);
|
int i, n = asdl_seq_LEN(s->v.ExtSlice.dims);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
slice_ty sub = asdl_seq_GET(s->v.ExtSlice.dims, i);
|
slice_ty sub = (slice_ty)asdl_seq_GET(
|
||||||
|
s->v.ExtSlice.dims, i);
|
||||||
if (!compiler_visit_nested_slice(c, sub, ctx))
|
if (!compiler_visit_nested_slice(c, sub, ctx))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
|
||||||
|
|
||||||
names = s->v.ImportFrom.names;
|
names = s->v.ImportFrom.names;
|
||||||
for (i = 0; i < asdl_seq_LEN(names); i++) {
|
for (i = 0; i < asdl_seq_LEN(names); i++) {
|
||||||
alias_ty name = asdl_seq_GET(names, i);
|
alias_ty name = (alias_ty)asdl_seq_GET(names, i);
|
||||||
const char *feature = PyString_AsString(name->name);
|
const char *feature = PyString_AsString(name->name);
|
||||||
if (!feature)
|
if (!feature)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -73,7 +73,7 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename)
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < asdl_seq_LEN(mod->v.Module.body); i++) {
|
for (i = 0; i < asdl_seq_LEN(mod->v.Module.body); i++) {
|
||||||
stmt_ty s = asdl_seq_GET(mod->v.Module.body, i);
|
stmt_ty s = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i);
|
||||||
|
|
||||||
if (done && s->lineno > prev_line)
|
if (done && s->lineno > prev_line)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -105,14 +105,14 @@ block_alloc(block *b, size_t size)
|
||||||
the default block, allocate a one-off block that is
|
the default block, allocate a one-off block that is
|
||||||
exactly the right size. */
|
exactly the right size. */
|
||||||
/* TODO(jhylton): Think about space waste at end of block */
|
/* TODO(jhylton): Think about space waste at end of block */
|
||||||
block *new = block_new(
|
block *newbl = block_new(
|
||||||
size < DEFAULT_BLOCK_SIZE ?
|
size < DEFAULT_BLOCK_SIZE ?
|
||||||
DEFAULT_BLOCK_SIZE : size);
|
DEFAULT_BLOCK_SIZE : size);
|
||||||
if (!new)
|
if (!newbl)
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(!b->ab_next);
|
assert(!b->ab_next);
|
||||||
b->ab_next = new;
|
b->ab_next = newbl;
|
||||||
b = new;
|
b = newbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(b->ab_offset + size <= b->ab_size);
|
assert(b->ab_offset + size <= b->ab_size);
|
||||||
|
|
|
@ -297,23 +297,23 @@ PyThreadState_Get(void)
|
||||||
|
|
||||||
|
|
||||||
PyThreadState *
|
PyThreadState *
|
||||||
PyThreadState_Swap(PyThreadState *new)
|
PyThreadState_Swap(PyThreadState *newts)
|
||||||
{
|
{
|
||||||
PyThreadState *old = _PyThreadState_Current;
|
PyThreadState *oldts = _PyThreadState_Current;
|
||||||
|
|
||||||
_PyThreadState_Current = new;
|
_PyThreadState_Current = newts;
|
||||||
/* It should not be possible for more than one thread state
|
/* It should not be possible for more than one thread state
|
||||||
to be used for a thread. Check this the best we can in debug
|
to be used for a thread. Check this the best we can in debug
|
||||||
builds.
|
builds.
|
||||||
*/
|
*/
|
||||||
#if defined(Py_DEBUG) && defined(WITH_THREAD)
|
#if defined(Py_DEBUG) && defined(WITH_THREAD)
|
||||||
if (new) {
|
if (newts) {
|
||||||
PyThreadState *check = PyGILState_GetThisThreadState();
|
PyThreadState *check = PyGILState_GetThisThreadState();
|
||||||
if (check && check->interp == new->interp && check != new)
|
if (check && check->interp == newts->interp && check != newts)
|
||||||
Py_FatalError("Invalid thread state for this thread");
|
Py_FatalError("Invalid thread state for this thread");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return old;
|
return oldts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An extension mechanism to store arbitrary additional per-thread state.
|
/* An extension mechanism to store arbitrary additional per-thread state.
|
||||||
|
@ -491,7 +491,7 @@ PyGILState_Ensure(void)
|
||||||
called Py_Initialize() and usually PyEval_InitThreads().
|
called Py_Initialize() and usually PyEval_InitThreads().
|
||||||
*/
|
*/
|
||||||
assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */
|
assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */
|
||||||
tcur = PyThread_get_key_value(autoTLSkey);
|
tcur = (PyThreadState *)PyThread_get_key_value(autoTLSkey);
|
||||||
if (tcur == NULL) {
|
if (tcur == NULL) {
|
||||||
/* Create a new thread state for this thread */
|
/* Create a new thread state for this thread */
|
||||||
tcur = PyThreadState_New(autoInterpreterState);
|
tcur = PyThreadState_New(autoInterpreterState);
|
||||||
|
@ -518,7 +518,8 @@ PyGILState_Ensure(void)
|
||||||
void
|
void
|
||||||
PyGILState_Release(PyGILState_STATE oldstate)
|
PyGILState_Release(PyGILState_STATE oldstate)
|
||||||
{
|
{
|
||||||
PyThreadState *tcur = PyThread_get_key_value(autoTLSkey);
|
PyThreadState *tcur = (PyThreadState *)PyThread_get_key_value(
|
||||||
|
autoTLSkey);
|
||||||
if (tcur == NULL)
|
if (tcur == NULL)
|
||||||
Py_FatalError("auto-releasing thread-state, "
|
Py_FatalError("auto-releasing thread-state, "
|
||||||
"but no thread-state for this thread");
|
"but no thread-state for this thread");
|
||||||
|
|
Loading…
Reference in New Issue