Commit e806062d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix 'python -i' mode

parent bfdd8844
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "core/threading.h" #include "core/threading.h"
#include "core/types.h" #include "core/types.h"
#include "core/util.h" #include "core/util.h"
#include "runtime/types.h"
#ifndef GITREV #ifndef GITREV
...@@ -114,8 +115,9 @@ int main(int argc, char** argv) { ...@@ -114,8 +115,9 @@ int main(int argc, char** argv) {
// end of argument parsing // end of argument parsing
_t.split("to run"); _t.split("to run");
BoxedModule* main_module = NULL;
if (fn != NULL) { if (fn != NULL) {
BoxedModule* main = createModule("__main__", fn); main_module = createModule("__main__", fn);
llvm::SmallString<128> path; llvm::SmallString<128> path;
...@@ -148,7 +150,7 @@ int main(int argc, char** argv) { ...@@ -148,7 +150,7 @@ int main(int argc, char** argv) {
} }
try { try {
compileAndRunModule(m, main); compileAndRunModule(m, main_module);
} catch (Box* b) { } catch (Box* b) {
std::string msg = formatException(b); std::string msg = formatException(b);
printLastTraceback(); printLastTraceback();
...@@ -159,7 +161,11 @@ int main(int argc, char** argv) { ...@@ -159,7 +161,11 @@ int main(int argc, char** argv) {
} }
if (repl && BENCH) { if (repl && BENCH) {
BoxedModule* main = createModule("__main__", "<bench>"); if (!main_module) {
main_module = createModule("__main__", "<bench>");
} else {
main_module->fn = "<bench>";
}
timeval start, end; timeval start, end;
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
...@@ -170,7 +176,7 @@ int main(int argc, char** argv) { ...@@ -170,7 +176,7 @@ int main(int argc, char** argv) {
run++; run++;
AST_Module* m = new AST_Module(); AST_Module* m = new AST_Module();
compileAndRunModule(m, main); compileAndRunModule(m, main_module);
if (run >= MAX_RUNS) { if (run >= MAX_RUNS) {
printf("Quitting after %d iterations\n", run); printf("Quitting after %d iterations\n", run);
...@@ -193,7 +199,11 @@ int main(int argc, char** argv) { ...@@ -193,7 +199,11 @@ int main(int argc, char** argv) {
printf("Pyston v0.1 (rev " STRINGIFY(GITREV) ")"); printf("Pyston v0.1 (rev " STRINGIFY(GITREV) ")");
printf(", targeting Python %d.%d.%d\n", PYTHON_VERSION_MAJOR, PYTHON_VERSION_MINOR, PYTHON_VERSION_MICRO); printf(", targeting Python %d.%d.%d\n", PYTHON_VERSION_MAJOR, PYTHON_VERSION_MINOR, PYTHON_VERSION_MICRO);
BoxedModule* main = createModule("__main__", "<stdin>"); if (!main_module) {
main_module = createModule("__main__", "<stdin>");
} else {
main_module->fn = "<stdin>";
}
while (repl) { while (repl) {
char* line = readline(">> "); char* line = readline(">> ");
...@@ -240,7 +250,7 @@ int main(int argc, char** argv) { ...@@ -240,7 +250,7 @@ int main(int argc, char** argv) {
} }
try { try {
compileAndRunModule(m, main); compileAndRunModule(m, main_module);
} catch (Box* b) { } catch (Box* b) {
std::string msg = formatException(b); std::string msg = formatException(b);
printLastTraceback(); printLastTraceback();
......
...@@ -286,7 +286,7 @@ public: ...@@ -286,7 +286,7 @@ public:
class BoxedModule : public Box { class BoxedModule : public Box {
public: public:
HCAttrs attrs; HCAttrs attrs;
const std::string fn; // for traceback purposes; not the same as __file__ std::string fn; // for traceback purposes; not the same as __file__
BoxedModule(const std::string& name, const std::string& fn); BoxedModule(const std::string& name, const std::string& fn);
std::string name(); std::string name();
......
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