Changes to how uncaught exceptions are handled.
- Don't clear the HAS_EXCEPTION bit. - Reuse CLEAN_OUTPUT to disable printing the exception. - Don't reset the stack, repls should do that _on every call_. - Fix up sandbox and simple-repl.h, they don't need to do that silly stack thing to handle exceptions themselves.
This commit is contained in:
parent
361aeb3927
commit
3945e3865f
|
@ -688,8 +688,8 @@ _finishArgs:
|
|||
} else {
|
||||
fprintf(stdout, formatStr, AS_CSTRING(result));
|
||||
}
|
||||
krk_resetStack();
|
||||
}
|
||||
krk_resetStack();
|
||||
free(allData);
|
||||
}
|
||||
|
||||
|
@ -697,7 +697,8 @@ _finishArgs:
|
|||
}
|
||||
} else {
|
||||
krk_startModule("__main__");
|
||||
result = krk_runfile(argv[optind],1,"__main__",argv[optind]);
|
||||
result = krk_runfile(argv[optind],0,"__main__",argv[optind]);
|
||||
if (IS_NONE(result) && krk_currentThread.flags & KRK_THREAD_HAS_EXCEPTION) result = INTEGER_VAL(1);
|
||||
}
|
||||
|
||||
krk_freeVM();
|
||||
|
|
3
src/vm.c
3
src/vm.c
|
@ -1416,8 +1416,7 @@ static int handleException() {
|
|||
* VM stack state. It should still be safe to execute more code after
|
||||
* this reset, so the repl can throw errors and keep accepting new lines.
|
||||
*/
|
||||
krk_dumpTraceback();
|
||||
krk_resetStack();
|
||||
if (!(vm.globalFlags & KRK_GLOBAL_CLEAN_OUTPUT)) krk_dumpTraceback();
|
||||
krk_currentThread.frameCount = 0;
|
||||
}
|
||||
/* If exitSlot was not 0, there was an exception during a call to runNext();
|
||||
|
|
|
@ -7,18 +7,18 @@
|
|||
#include "simple-repl.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
krk_initVM(0);
|
||||
/* Initialize VM with traceback printing disabled (we'll print them ourselves) */
|
||||
krk_initVM(KRK_GLOBAL_CLEAN_OUTPUT);
|
||||
|
||||
/* Disable imports, ensure the system module is inaccessible, disable print */
|
||||
krk_tableDelete(&vm.system->fields, OBJECT_VAL(S("module_paths")));
|
||||
krk_tableDelete(&vm.modules, OBJECT_VAL(S("kuroko")));
|
||||
krk_tableDelete(&vm.builtins->fields, OBJECT_VAL(S("print")));
|
||||
|
||||
/* Don't automatically dump tracebacks. */
|
||||
krk_resetStack();
|
||||
krk_push(NONE_VAL());
|
||||
krk_currentThread.frames[0].outSlots = 1;
|
||||
|
||||
/* Set up our module context. */
|
||||
krk_startModule("<module>");
|
||||
|
||||
/* Attach a docstring so that we can interpret strings */
|
||||
krk_attachNamedValue(&krk_currentThread.module->fields,"__doc__", NONE_VAL());
|
||||
|
||||
int retval = 0;
|
||||
|
|
|
@ -115,10 +115,10 @@ static int runSimpleRepl(void) {
|
|||
} else {
|
||||
fprintf(stdout, formatStr, AS_CSTRING(result));
|
||||
}
|
||||
krk_resetStack();
|
||||
} else if (krk_currentThread.flags & KRK_THREAD_HAS_EXCEPTION) {
|
||||
krk_dumpTraceback();
|
||||
}
|
||||
krk_resetStack();
|
||||
free(allData);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue