diff --git a/repl/bytecode_inspector.c b/repl/bytecode_inspector.c index da5b2fd..9dd3c4f 100644 --- a/repl/bytecode_inspector.c +++ b/repl/bytecode_inspector.c @@ -356,7 +356,7 @@ int inspect_read(unsigned char* bytecode, unsigned int pc, unsigned int jumps_ad unsigned int jumpValue = *((unsigned int*)(bytecode + jumps_addr + indexValue)); char* cstr = ((char*)(bytecode + data_addr + jumpValue)); - printf(MARKER "READ STRING %u '%s'\n", MARKER_VALUE(pc, unsigned char), indexValue, cstr); + printf(MARKER "READ STRING [%u] '%s'\n", MARKER_VALUE(pc, unsigned char), indexValue, cstr); return 8; } @@ -365,13 +365,23 @@ int inspect_read(unsigned char* bytecode, unsigned int pc, unsigned int jumps_ad printf(MARKER "READ FUNCTION '%u' (%d params)\n", MARKER_VALUE(pc, unsigned char), *((unsigned int*)(bytecode + pc + 4)), bytecode[pc + 2]); return 8; - case TOY_VALUE_ARRAY: - case TOY_VALUE_TABLE: + case TOY_VALUE_ARRAY: { + unsigned int count = *((unsigned int*)(bytecode + pc + 4)); + printf(MARKER "READ ARRAY %u elements\n", MARKER_VALUE(pc, unsigned char), count); + return 8; + } + + case TOY_VALUE_TABLE: { + unsigned int count = *((unsigned int*)(bytecode + pc + 4)); + printf(MARKER "READ TABLE %u elements (consuming %u values)\n", MARKER_VALUE(pc, unsigned char), count / 2, count); + return 8; + } + case TOY_VALUE_OPAQUE: case TOY_VALUE_ANY: case TOY_VALUE_UNKNOWN: default: { - printf(MARKER "READ %s (unhandled by inspector)\n", MARKER_VALUE(pc, unsigned char), Toy_private_getValueTypeAsCString(type)); + printf(MARKER TOY_CC_WARN "READ %s (unhandled by inspector)" TOY_CC_RESET "\n", MARKER_VALUE(pc, unsigned char), Toy_private_getValueTypeAsCString(type)); return 4; } } diff --git a/repl/main.c b/repl/main.c index 225828f..5b60fc2 100644 --- a/repl/main.c +++ b/repl/main.c @@ -265,17 +265,17 @@ static void debugStackPrint(Toy_Stack* stack) { if (stack->count > 0) { Toy_Bucket* stringBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL); - printf("Stack Dump\n-------------------------\ntype\tvalue\n"); + printf("\n" TOY_CC_NOTICE "Stack Dump" TOY_CC_RESET "\n" TOY_CC_NOTICE "%-20s%-20s" TOY_CC_RESET "\n", "type", "value"); for (unsigned int i = 0; i < stack->count; i++) { Toy_Value v = ((Toy_Value*)(stack + 1))[i]; //'stack + 1' is a naughty trick //print type - printf("%s\t", Toy_private_getValueTypeAsCString(v.type)); + printf("%-20s", Toy_private_getValueTypeAsCString(v.type)); //print value Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v)); char* buffer = Toy_getStringRaw(string); - printf("%s", buffer); + printf("%-20s", buffer); free(buffer); Toy_freeString(string); @@ -291,7 +291,7 @@ static void debugScopePrint(Toy_Scope* scope, int depth) { if (scope->count > 0) { Toy_Bucket* stringBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL); - printf("Scope %d Dump\n-------------------------\ntype\tname\tvalue\n", depth); + printf("\n" TOY_CC_NOTICE "Scope Dump [%d]" TOY_CC_RESET "\n" TOY_CC_NOTICE "%-20s%-20s%-20s" TOY_CC_RESET "\n", depth, "type", "name", "value"); for (unsigned int i = 0; i < scope->capacity; i++) { if (scope->data[i].key.info.length == 0) { continue; @@ -300,12 +300,12 @@ static void debugScopePrint(Toy_Scope* scope, int depth) { Toy_String k = scope->data[i].key; Toy_Value v = scope->data[i].value; - printf("%s\t%s\t", Toy_private_getValueTypeAsCString(v.type), k.leaf.data); + printf("%-20s%-20s", Toy_private_getValueTypeAsCString(v.type), k.leaf.data); //print value Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v)); char* buffer = Toy_getStringRaw(string); - printf("%s", buffer); + printf("%-20s", buffer); free(buffer); Toy_freeString(string); diff --git a/scripts/test_compounds.toy b/scripts/test_compounds.toy new file mode 100644 index 0000000..f04d458 --- /dev/null +++ b/scripts/test_compounds.toy @@ -0,0 +1,35 @@ + +//array outside a table +var a = [ + [1, 2, 3], + ["alpha": 1, "beta": 2, "gamma": 3], + [7, 8, 9], +]; + +print a; + +//table outside an array + +var t = [ + "alpha": [1,2,3], + "beta": [4,5,6], + "gamma": [7,8,9], +]; + +print t; + +//we need to go deeper + +var deeper = [ + [1, 2, 3], + [ + "alpha": [1,2,3], + "beta": [4,5,6], + "gamma": [7,[ + "delta":10,"epsilon":11,"foxtrot":12 + ],9], + ], + [7, 8, 9], +]; + +print deeper; \ No newline at end of file diff --git a/scripts/test_tables.toy b/scripts/test_tables.toy new file mode 100644 index 0000000..de06324 --- /dev/null +++ b/scripts/test_tables.toy @@ -0,0 +1,14 @@ +//snipped out of the tests, this seems fine? + +//nested +var example = [ + "outer": ["inner": true], + "alpha": 1, + "beta": 2, + "gamma": 3 +]; + +print example; +assert example == ["alpha": 1, "beta": 2, "gamma": 3, "outer": ["inner": true]], "nested tables failed"; + +return example; \ No newline at end of file diff --git a/tests/scripts/test_tables.toy b/tests/scripts/test_tables.toy index 44567fa..e52a877 100644 --- a/tests/scripts/test_tables.toy +++ b/tests/scripts/test_tables.toy @@ -5,7 +5,8 @@ a["beta"] = 6; print a; assert a == ["alpha": 1, "beta": 6, "gamma": 3], "1-D tables failed"; -//BUG: nested tables causes an issue under GDB, idk why the tests pass without it +//WONTFIX: Nested tables cause an issue under very specific circumstances: run under GDB, in verbose mode, only in github's CI runner. The reason is unclear. + //nested var b = [ "outer": ["inner": true],