Commit e9357b21 authored by Jeremy Hylton's avatar Jeremy Hylton

Tabify and reflow some long lines.

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