2021-02-12 05:48:50 +03:00
|
|
|
#include <stdio.h>
|
2021-02-15 15:16:02 +03:00
|
|
|
#include <string.h>
|
2021-02-12 05:48:50 +03:00
|
|
|
#include <kuroko/kuroko.h>
|
|
|
|
#include <kuroko/vm.h>
|
|
|
|
#include <kuroko/util.h>
|
|
|
|
|
2021-02-15 15:16:02 +03:00
|
|
|
#include "simple-repl.h"
|
2021-02-12 05:48:50 +03:00
|
|
|
|
|
|
|
int main(int argc, char * argv[]) {
|
2022-07-29 06:24:23 +03:00
|
|
|
/* Disable automatic traceback printing, default modules */
|
|
|
|
krk_initVM(KRK_GLOBAL_CLEAN_OUTPUT|KRK_GLOBAL_NO_DEFAULT_MODULES);
|
2021-02-12 05:48:50 +03:00
|
|
|
|
2021-02-24 03:08:21 +03:00
|
|
|
/* Set up our module context. */
|
2021-02-25 02:17:19 +03:00
|
|
|
krk_startModule("__main__");
|
2021-02-24 03:08:21 +03:00
|
|
|
|
2021-02-12 05:48:50 +03:00
|
|
|
int retval = 0;
|
2021-02-15 15:16:02 +03:00
|
|
|
if (argc > 1) {
|
2021-02-25 02:17:19 +03:00
|
|
|
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);
|
2021-04-17 13:29:52 +03:00
|
|
|
result = krk_callDirect(type->_reprer, 1);
|
2021-02-15 15:16:02 +03:00
|
|
|
}
|
|
|
|
if (IS_STRING(result)) {
|
2021-03-20 16:51:17 +03:00
|
|
|
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
|
|
|
krk_dumpTraceback();
|
|
|
|
retval = 1;
|
2021-02-12 05:48:50 +03:00
|
|
|
}
|
2021-02-15 15:16:02 +03:00
|
|
|
} else {
|
|
|
|
runSimpleRepl();
|
2021-02-12 05:48:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
krk_freeVM();
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|