1
0
Fork 0
forked from fun/fun
This commit is contained in:
Johannes Findeisen 2025-09-15 08:39:41 +02:00
commit 0e7fffcfe0
67 changed files with 154 additions and 65 deletions

16
src/vm_case_len.c Normal file
View file

@ -0,0 +1,16 @@
case OP_LEN: {
Value a = pop_value(vm);
int len = 0;
if (a.type == VAL_STRING) {
len = (int)(a.s ? (int)strlen(a.s) : 0);
} else if (a.type == VAL_ARRAY) {
len = array_length(&a);
if (len < 0) len = 0;
} else {
fprintf(stderr, "Runtime type error: LEN expects array or string\n");
exit(1);
}
free_value(a);
push_value(vm, make_int(len));
break;
}