Created
January 31, 2021 01:01
-
-
Save klange/617e4462a444029faa15b5822f07eabb to your computer and use it in GitHub Desktop.
Kuroko Sandbox Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "src/vm.h" | |
#define S(c) (krk_copyString(c,sizeof(c)-1)) | |
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"))); | |
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()); | |
vm.frames[0].outSlots = 1; | |
krk_startModule("<module>"); | |
krk_attachNamedValue(&vm.module->fields,"__doc__", NONE_VAL()); | |
int retval = 0; | |
KrkValue result = krk_interpret(argv[1], 0, "<stdin>","<stdin>"); | |
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_callSimple(OBJECT_VAL(type->_reprer), 1, 0); | |
} | |
if (IS_STRING(result)) { | |
fprintf(stdout, "%s\n", AS_CSTRING(result)); | |
} | |
} else if (vm.flags & KRK_HAS_EXCEPTION) { | |
krk_dumpTraceback(); | |
retval = 1; | |
} | |
krk_freeVM(); | |
return retval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment