Skip to content

Instantly share code, notes, and snippets.

@nishio
Created August 24, 2010 14:34
Show Gist options
  • Save nishio/547651 to your computer and use it in GitHub Desktop.
Save nishio/547651 to your computer and use it in GitHub Desktop.
Index: ../Python/pythonrun.c
===================================================================
--- ../Python/pythonrun.c (revision 82245)
+++ ../Python/pythonrun.c (working copy)
@@ -1334,6 +1334,7 @@
return ret;
}
+bool toplevel = true;
static PyObject *
run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
PyCompilerFlags *flags, PyArena *arena)
@@ -1343,6 +1344,29 @@
co = PyAST_Compile(mod, filename, flags, arena);
if (co == NULL)
return NULL;
+
+ char* s;
+ if((s = getenv("PYTHON_AUTOAST")) && strcmp(s, "")){
+ if(toplevel){
+ printf("===== AST =====\n");
+ toplevel = false;
+ PyObject_SetItem(globals, PyString_FromString("_mod"), PyAST_mod2obj(mod));
+ PyRun_SimpleString("__import__('pprint').pprint(_mod)");
+ toplevel = true;
+ printf("===== END AST =====\n");
+ }
+ }
+ if((s = getenv("PYTHON_AUTODIS")) && strcmp(s, "")){
+ if(toplevel){
+ printf("===== DIS =====\n");
+ toplevel = false;
+ PyObject_SetItem(globals, PyString_FromString("_co"), co);
+ PyRun_SimpleString("__import__('dis').dis(_co)");
+ toplevel = true;
+ printf("===== END DIS =====\n");
+ }
+ }
+
v = PyEval_EvalCode(co, globals, locals);
Py_DECREF(co);
return v;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment