diff --git a/repl/bytecode_inspector.c b/repl/bytecode_inspector.c index c403261..6ae7d29 100644 --- a/repl/bytecode_inspector.c +++ b/repl/bytecode_inspector.c @@ -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 \ No newline at end of file +//TODO: Check if strings are reused in the bytecode \ No newline at end of file diff --git a/scripts/hello_world.toy b/scripts/hello_world.toy index cf64973..564a4f8 100644 --- a/scripts/hello_world.toy +++ b/scripts/hello_world.toy @@ -9,5 +9,5 @@ var b = 69; var c; var d; -//URGENT: reverse the assignment bytecode order? +//URGENT: reverse the assignment bytecode order c, d = swap(a, b); \ No newline at end of file diff --git a/source/toy_vm.c b/source/toy_vm.c index 1b802d8..9e657d3 100644 --- a/source/toy_vm.c +++ b/source/toy_vm.c @@ -720,11 +720,17 @@ static void processPrint(Toy_VM* vm) { //print the value on top of the stack, popping it Toy_Value value = Toy_popStack(&vm->stack); 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_freeValue(value); }