We can also put them on more basic types

This commit is contained in:
K. Lange 2020-12-28 09:17:00 +09:00
parent 3bcc5d5530
commit 369e0f84db
2 changed files with 14 additions and 0 deletions

View File

@ -10,3 +10,5 @@ class Test:
# Instances have a __class__ property synthesized by the VM
let test = Test()
print test.__class__
print (37.45).asInteger

12
vm.c
View File

@ -721,6 +721,18 @@ static KrkValue run() {
}
}
break;
case VAL_FLOATING: {
if (!strcmp(name->chars, "asInteger")) {
krk_push(INTEGER_VAL((int)AS_FLOATING(krk_pop())));
} else goto _undefined;
break;
}
case VAL_INTEGER: {
if (!strcmp(name->chars, "asFloating")) {
krk_push(FLOATING_VAL((int)AS_INTEGER(krk_pop())));
} else goto _undefined;
break;
}
default:
runtimeError("Don't know how to retreive properties for %s yet", typeName(krk_peek(0)));
return NONE_VAL();