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