Add simple repl to krk-sandbox
This commit is contained in:
parent
9b3f311688
commit
3cef9d05e8
@ -1,14 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <kuroko/kuroko.h>
|
||||
#include <kuroko/vm.h>
|
||||
#include <kuroko/util.h>
|
||||
|
||||
#include "simple-repl.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "expected a string to evaluate\n");
|
||||
return 1;
|
||||
}
|
||||
krk_initVM(0);
|
||||
|
||||
krk_tableDelete(&vm.system->fields, OBJECT_VAL(S("module_paths")));
|
||||
@ -25,6 +23,7 @@ int main(int argc, char * argv[]) {
|
||||
|
||||
int retval = 0;
|
||||
|
||||
if (argc > 1) {
|
||||
KrkValue result = krk_interpret(argv[1], 0, "<stdin>","<stdin>");
|
||||
if (!IS_NONE(result)) {
|
||||
if (IS_INTEGER(result)) {
|
||||
@ -42,6 +41,9 @@ int main(int argc, char * argv[]) {
|
||||
krk_dumpTraceback();
|
||||
retval = 1;
|
||||
}
|
||||
} else {
|
||||
runSimpleRepl();
|
||||
}
|
||||
|
||||
krk_freeVM();
|
||||
return retval;
|
||||
|
@ -116,6 +116,8 @@ static int runSimpleRepl(void) {
|
||||
fprintf(stdout, formatStr, AS_CSTRING(result));
|
||||
}
|
||||
krk_resetStack();
|
||||
} else if (krk_currentThread.flags & KRK_HAS_EXCEPTION) {
|
||||
krk_dumpTraceback();
|
||||
}
|
||||
free(allData);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user