Added string type check

This commit is contained in:
2026-04-16 19:30:23 +10:00
parent f9790b99ce
commit 3a0f11ebb4
3 changed files with 11 additions and 5 deletions

View File

@@ -319,4 +319,4 @@ int inspect_read(unsigned char* bytecode, unsigned int pc, unsigned int jumps_ad
} }
} }
//URGENT: Check if strings are reused in the bytecode //TODO: Check if strings are reused in the bytecode

View File

@@ -9,5 +9,5 @@ var b = 69;
var c; var c;
var d; var d;
//URGENT: reverse the assignment bytecode order? //URGENT: reverse the assignment bytecode order
c, d = swap(a, b); c, d = swap(a, b);

View File

@@ -720,11 +720,17 @@ static void processPrint(Toy_VM* vm) {
//print the value on top of the stack, popping it //print the value on top of the stack, popping it
Toy_Value value = Toy_popStack(&vm->stack); Toy_Value value = Toy_popStack(&vm->stack);
Toy_String* string = Toy_stringifyValue(&vm->memoryBucket, value); Toy_String* string = Toy_stringifyValue(&vm->memoryBucket, value);
char* buffer = Toy_getStringRaw(string); //URGENT: check string type to skip this call
Toy_print(buffer); //check string type to skip a potential malloc
if (string->info.type == TOY_STRING_LEAF) {
Toy_print(string->leaf.data);
}
else {
char* buffer = Toy_getStringRaw(string);
Toy_print(buffer);
free(buffer);
}
free(buffer);
Toy_freeString(string); Toy_freeString(string);
Toy_freeValue(value); Toy_freeValue(value);
} }