Commit 189b1150 authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Add sys.exit()

parent 520dd6e6
......@@ -321,7 +321,7 @@ NONSTDLIB_SRCS := $(MAIN_SRCS) $(OPTIONAL_SRCS) $(TOOL_SRCS) $(UNITTEST_SRCS)
# all: pyston_dbg pyston_release pyston_oprof pyston_prof $(OPTIONAL_SRCS:.cpp=.o) ext_python ext_pyston
all: pyston_dbg pyston_release pyston_prof ext_python ext_pyston unittests
ALL_HEADERS := $(wildcard src/*/*.h) $(wildcard src/*/*/*.h) $(wildcard ./include/*.h)
ALL_HEADERS := $(wildcard src/*/*.h) $(wildcard src/*/*/*.h) $(wildcard cpython2.7/Include/*.h)
tags: $(SRCS) $(OPTIONAL_SRCS) $(FROM_CPYTHON_SRCS) $(ALL_HEADERS)
$(ECHO) Calculating tags...
$(VERB) ctags $^
......
......@@ -290,6 +290,8 @@ static ConcreteCompilerType* getTypeAtBlockStart(TypeAnalysis* types, const std:
return GENERATOR;
else if (name == PASSED_CLOSURE_NAME)
return CLOSURE;
else if (name == CREATED_CLOSURE_NAME)
return CLOSURE;
else
return types->getTypeAtBlockStart(name, block);
}
......
......@@ -37,6 +37,7 @@
#include "core/threading.h"
#include "core/types.h"
#include "core/util.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......@@ -150,11 +151,15 @@ int main(int argc, char** argv) {
try {
main_module = createAndRunModule("__main__", fn);
} catch (Box* b) {
std::string msg = formatException(b);
printLastTraceback();
fprintf(stderr, "%s\n", msg.c_str());
return 1;
if (isInstance(b, SystemExit)) {
printf("Warning: ignoring SystemExit code\n");
return 1;
} else {
std::string msg = formatException(b);
printLastTraceback();
fprintf(stderr, "%s\n", msg.c_str());
return 1;
}
}
}
......@@ -218,9 +223,14 @@ int main(int argc, char** argv) {
try {
compileAndRunModule(m, main_module);
} catch (Box* b) {
std::string msg = formatException(b);
printLastTraceback();
fprintf(stderr, "%s\n", msg.c_str());
if (isInstance(b, SystemExit)) {
printf("Warning: ignoring SystemExit code\n");
return 1;
} else {
std::string msg = formatException(b);
printLastTraceback();
fprintf(stderr, "%s\n", msg.c_str());
}
}
}
}
......
......@@ -38,6 +38,13 @@ Box* sysExcInfo() {
threading::cur_thread_state.exc_traceback ? threading::cur_thread_state.exc_traceback : None });
}
static Box* sysExit(Box* arg) {
if (arg)
raiseExc(exceptionNew1(SystemExit));
else
raiseExc(exceptionNew2(SystemExit, arg));
}
BoxedDict* getSysModulesDict() {
// PyPy's behavior: fetch from sys.modules each time:
// Box *_sys_modules = sys_module->getattr("modules");
......@@ -142,6 +149,7 @@ void setupSys() {
sys_module->giveAttr("stderr", new BoxedFile(stderr, "<stderr>", "w"));
sys_module->giveAttr("exc_info", new BoxedFunction(boxRTFunction((void*)sysExcInfo, BOXED_TUPLE, 0)));
sys_module->giveAttr("exit", new BoxedFunction(boxRTFunction((void*)sysExit, NONE, 1, 1, false, false), { None }));
sys_module->giveAttr("warnoptions", new BoxedList());
sys_module->giveAttr("py3kwarning", False);
......
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