Commit 38fa581e authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add the stdlib dir to sys.path, so now the stdlib is importable!

(Though most libraries will probably crash)
parent e806062d
......@@ -453,7 +453,8 @@ BoxedModule* createModule(const std::string& name, const std::string& fn);
std::string getPythonFuncAt(void* ip, void* sp);
// TODO where to put this
void addToSysPath(const std::string& path);
void appendToSysPath(const std::string& path);
void prependToSysPath(const std::string& path);
void addToSysArgv(const char* str);
std::string formatException(Box* e);
......
......@@ -112,6 +112,16 @@ int main(int argc, char** argv) {
addToSysArgv("");
}
std::string self_path = llvm::sys::fs::getMainExecutable(argv[0], (void*)main);
assert(self_path.size());
llvm::SmallString<128> stdlib_dir(self_path);
llvm::sys::path::remove_filename(stdlib_dir); // executable name
llvm::sys::path::remove_filename(stdlib_dir); // "src/" dir
llvm::sys::path::append(stdlib_dir, "lib_python");
llvm::sys::path::append(stdlib_dir, "2.7");
appendToSysPath(stdlib_dir.c_str());
// end of argument parsing
_t.split("to run");
......@@ -130,7 +140,7 @@ int main(int argc, char** argv) {
llvm::sys::path::append(path, fn);
llvm::sys::path::remove_filename(path);
addToSysPath(path.str());
prependToSysPath(path.str());
int num_iterations = 1;
if (BENCH)
......
......@@ -58,11 +58,17 @@ void addToSysArgv(const char* str) {
listAppendInternal(sys_argv, boxStrConstant(str));
}
void addToSysPath(const std::string& path) {
void appendToSysPath(const std::string& path) {
BoxedList* sys_path = getSysPath();
listAppendInternal(sys_path, boxStringPtr(&path));
}
void prependToSysPath(const std::string& path) {
BoxedList* sys_path = getSysPath();
static std::string attr = "insert";
callattr(sys_path, &attr, false, ArgPassSpec(2), boxInt(0), new BoxedString(path), NULL, NULL, NULL);
}
void setupSys() {
sys_modules_dict = new BoxedDict();
gc::registerStaticRootObj(sys_modules_dict);
......
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