don't explode on bad repr print?

This commit is contained in:
K. Lange 2021-01-12 14:07:16 +09:00
parent cc236b8da3
commit 76b0b50154
2 changed files with 3 additions and 1 deletions

View File

@ -59,10 +59,12 @@ void krk_printValue(FILE * f, KrkValue printable) {
if (type->_tostr) {
krk_push(printable);
printable = krk_callSimple(OBJECT_VAL(type->_tostr), 1, 0);
if (!IS_STRING(printable)) return;
fprintf(f, "%s", AS_CSTRING(printable));
} else if (type->_reprer) {
krk_push(printable);
printable = krk_callSimple(OBJECT_VAL(type->_reprer), 1, 0);
if (!IS_STRING(printable)) return;
fprintf(f, "%s", AS_CSTRING(printable));
} else {
fprintf(f, "%s", krk_typeName(printable));

2
vm.c
View File

@ -1470,7 +1470,7 @@ static KrkValue _char_to_int(int argc, KrkValue argv[]) {
}
/* TODO unicode strings? Interpret as UTF-8 and return codepoint? */
return INTEGER_VAL(AS_CSTRING(argv[0])[0]);
return INTEGER_VAL(((unsigned char)AS_CSTRING(argv[0])[0]));
}
static KrkValue _print(int argc, KrkValue argv[], int hasKw) {