Tabify and reflow some long lines.

Much of the peephole optimizer is now indented badly, but it's about
to be revised anyway.
This commit is contained in:
Jeremy Hylton 2006-03-01 15:47:05 +00:00
parent 224003baef
commit e9357b21c0

View file

@ -13,10 +13,10 @@
* Note that compiler_mod() suggests module, but the module ast type
* (mod_ty) has cases for expressions and interactive statements.
*
* CAUTION: The VISIT_* macros abort the current function when they encounter
* a problem. So don't invoke them when there is memory which needs to be
* released. Code blocks are OK, as the compiler structure takes care of
* releasing those.
* CAUTION: The VISIT_* macros abort the current function when they
* encounter a problem. So don't invoke them when there is memory
* which needs to be released. Code blocks are OK, as the compiler
* structure takes care of releasing those.
*/
#include "Python.h"
@ -85,9 +85,9 @@ typedef struct basicblock_ {
/* fblockinfo tracks the current frame block.
A frame block is used to handle loops, try/except, and try/finally.
It's called a frame block to distinguish it from a basic block in the
compiler IR.
A frame block is used to handle loops, try/except, and try/finally.
It's called a frame block to distinguish it from a basic block in the
compiler IR.
*/
enum fblocktype { LOOP, EXCEPT, FINALLY_TRY, FINALLY_END };
@ -132,9 +132,9 @@ struct compiler_unit {
/* This struct captures the global state of a compilation.
The u pointer points to the current compilation unit, while units
for enclosing blocks are stored in c_stack. The u and c_stack are
managed by compiler_enter_scope() and compiler_exit_scope().
The u pointer points to the current compilation unit, while units
for enclosing blocks are stored in c_stack. The u and c_stack are
managed by compiler_enter_scope() and compiler_exit_scope().
*/
struct compiler {
@ -204,7 +204,8 @@ _Py_Mangle(PyObject *private, PyObject *ident)
const char *p, *name = PyString_AsString(ident);
char *buffer;
size_t nlen, plen;
if (private == NULL || name == NULL || name[0] != '_' || name[1] != '_') {
if (private == NULL || name == NULL || name[0] != '_' ||
name[1] != '_') {
Py_INCREF(ident);
return ident;
}
@ -346,10 +347,10 @@ list2dict(PyObject *list)
/* Return new dict containing names from src that match scope(s).
src is a symbol table dictionary. If the scope of a name matches
either scope_type or flag is set, insert it into the new dict. The
values are integers, starting at offset and increasing by one for
each key.
src is a symbol table dictionary. If the scope of a name matches
either scope_type or flag is set, insert it into the new dict. The
values are integers, starting at offset and increasing by one for
each key.
*/
static PyObject *
@ -396,7 +397,8 @@ dictbytype(PyObject *src, int scope_type, int flag, int offset)
#define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3))
#define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255
#define CODESIZE(op) (HAS_ARG(op) ? 3 : 1)
#define ISBASICBLOCK(blocks, start, bytes) (blocks[start]==blocks[start+bytes-1])
#define ISBASICBLOCK(blocks, start, bytes) \
(blocks[start]==blocks[start+bytes-1])
/* Replace LOAD_CONST c1. LOAD_CONST c2 ... LOAD_CONST cn BUILD_TUPLE n
with LOAD_CONST (c1, c2, ... cn).
@ -482,7 +484,8 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
break;
case BINARY_DIVIDE:
/* Cannot fold this operation statically since
the result can depend on the run-time presence of the -Qnew flag */
the result can depend on the run-time presence
of the -Qnew flag */
return 0;
case BINARY_TRUE_DIVIDE:
newconst = PyNumber_TrueDivide(v, w);
@ -656,7 +659,8 @@ markblocks(unsigned char *code, int len)
a single pass. Line numbering is adjusted accordingly. */
static PyObject *
optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *lineno_obj)
optimize_code(PyObject *code, PyObject* consts, PyObject *names,
PyObject *lineno_obj)
{
Py_ssize_t i, j, codelen;
int nops, h, adj;
@ -665,7 +669,7 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
unsigned char *lineno;
int *addrmap = NULL;
int new_line, cum_orig_line, last_line, tabsiz;
int cumlc=0, lastlc=0; /* Count runs of consecutive LOAD_CONST codes */
int cumlc=0, lastlc=0; /* Count runs of consecutive LOAD_CONSTs */
unsigned int *blocks = NULL;
char *name;
@ -750,7 +754,8 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
codestr[i+3] = NOP;
break;
/* Replace LOAD_GLOBAL/LOAD_NAME None with LOAD_CONST None */
/* Replace LOAD_GLOBAL/LOAD_NAME None
with LOAD_CONST None */
case LOAD_NAME:
case LOAD_GLOBAL:
j = GETARG(codestr, i);
@ -767,7 +772,8 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
}
break;
/* Skip over LOAD_CONST trueconst JUMP_IF_FALSE xx POP_TOP */
/* Skip over LOAD_CONST trueconst
JUMP_IF_FALSE xx POP_TOP */
case LOAD_CONST:
cumlc = lastlc + 1;
j = GETARG(codestr, i);
@ -974,7 +980,7 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
PyMem_Free(blocks);
return code;
exitUnchanged:
exitUnchanged:
if (blocks != NULL)
PyMem_Free(blocks);
if (addrmap != NULL)
@ -994,36 +1000,36 @@ Leave this debugging code for just a little longer.
static void
compiler_display_symbols(PyObject *name, PyObject *symbols)
{
PyObject *key, *value;
int flags;
Py_ssize_t pos = 0;
PyObject *key, *value;
int flags;
Py_ssize_t pos = 0;
fprintf(stderr, "block %s\n", PyString_AS_STRING(name));
while (PyDict_Next(symbols, &pos, &key, &value)) {
flags = PyInt_AsLong(value);
fprintf(stderr, "var %s:", PyString_AS_STRING(key));
if (flags & DEF_GLOBAL)
fprintf(stderr, " declared_global");
if (flags & DEF_LOCAL)
fprintf(stderr, " local");
if (flags & DEF_PARAM)
fprintf(stderr, " param");
if (flags & DEF_STAR)
fprintf(stderr, " stararg");
if (flags & DEF_DOUBLESTAR)
fprintf(stderr, " starstar");
if (flags & DEF_INTUPLE)
fprintf(stderr, " tuple");
if (flags & DEF_FREE)
fprintf(stderr, " free");
if (flags & DEF_FREE_GLOBAL)
fprintf(stderr, " global");
if (flags & DEF_FREE_CLASS)
fprintf(stderr, " free/class");
if (flags & DEF_IMPORT)
fprintf(stderr, " import");
fprintf(stderr, "\n");
}
fprintf(stderr, "block %s\n", PyString_AS_STRING(name));
while (PyDict_Next(symbols, &pos, &key, &value)) {
flags = PyInt_AsLong(value);
fprintf(stderr, "var %s:", PyString_AS_STRING(key));
if (flags & DEF_GLOBAL)
fprintf(stderr, " declared_global");
if (flags & DEF_LOCAL)
fprintf(stderr, " local");
if (flags & DEF_PARAM)
fprintf(stderr, " param");
if (flags & DEF_STAR)
fprintf(stderr, " stararg");
if (flags & DEF_DOUBLESTAR)
fprintf(stderr, " starstar");
if (flags & DEF_INTUPLE)
fprintf(stderr, " tuple");
if (flags & DEF_FREE)
fprintf(stderr, " free");
if (flags & DEF_FREE_GLOBAL)
fprintf(stderr, " global");
if (flags & DEF_FREE_CLASS)
fprintf(stderr, " free/class");
if (flags & DEF_IMPORT)
fprintf(stderr, " import");
fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
}
*/