kuroko/tools/sandbox.c

42 lines
879 B
C
Raw Normal View History

#include <stdio.h>
2021-02-15 15:16:02 +03:00
#include <string.h>
#include <kuroko/kuroko.h>
#include <kuroko/vm.h>
#include <kuroko/util.h>
2021-02-15 15:16:02 +03:00
#include "simple-repl.h"
int main(int argc, char * argv[]) {
/* Disable default modules */
krk_initVM(KRK_GLOBAL_NO_DEFAULT_MODULES);
/* Set up our module context. */
krk_startModule("__main__");
int retval = 0;
2021-02-15 15:16:02 +03:00
if (argc > 1) {
KrkValue result = krk_interpret(argv[1], "<stdin>");
2021-02-15 15:16:02 +03:00
if (!IS_NONE(result)) {
if (IS_INTEGER(result)) {
retval = AS_INTEGER(result);
}
KrkClass * type = krk_getType(result);
if (type->_reprer) {
krk_push(result);
result = krk_callDirect(type->_reprer, 1);
2021-02-15 15:16:02 +03:00
}
if (IS_STRING(result)) {
fprintf(stdout, " => %s\n", AS_CSTRING(result));
2021-02-15 15:16:02 +03:00
}
2021-02-19 06:30:39 +03:00
} else if (krk_currentThread.flags & KRK_THREAD_HAS_EXCEPTION) {
2021-02-15 15:16:02 +03:00
retval = 1;
}
2021-02-15 15:16:02 +03:00
} else {
runSimpleRepl();
}
krk_freeVM();
return retval;
}