mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-20 01:04:08 +10:00
Added string type check
This commit is contained in:
@@ -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
|
||||||
@@ -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);
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
//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);
|
Toy_print(buffer);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
Toy_freeString(string);
|
Toy_freeString(string);
|
||||||
Toy_freeValue(value);
|
Toy_freeValue(value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user