Added arrays and tables to the bytecode inspector

Currently searching for an issue related to compounds.
This commit is contained in:
2026-04-22 14:31:17 +10:00
parent 9bb115f732
commit 63dfd33e5e
5 changed files with 71 additions and 11 deletions
+14 -4
View File
@@ -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)); unsigned int jumpValue = *((unsigned int*)(bytecode + jumps_addr + indexValue));
char* cstr = ((char*)(bytecode + data_addr + jumpValue)); 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; 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]); printf(MARKER "READ FUNCTION '%u' (%d params)\n", MARKER_VALUE(pc, unsigned char), *((unsigned int*)(bytecode + pc + 4)), bytecode[pc + 2]);
return 8; return 8;
case TOY_VALUE_ARRAY: case TOY_VALUE_ARRAY: {
case TOY_VALUE_TABLE: 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_OPAQUE:
case TOY_VALUE_ANY: case TOY_VALUE_ANY:
case TOY_VALUE_UNKNOWN: case TOY_VALUE_UNKNOWN:
default: { 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; return 4;
} }
} }
+6 -6
View File
@@ -265,17 +265,17 @@ static void debugStackPrint(Toy_Stack* stack) {
if (stack->count > 0) { if (stack->count > 0) {
Toy_Bucket* stringBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL); 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++) { for (unsigned int i = 0; i < stack->count; i++) {
Toy_Value v = ((Toy_Value*)(stack + 1))[i]; //'stack + 1' is a naughty trick Toy_Value v = ((Toy_Value*)(stack + 1))[i]; //'stack + 1' is a naughty trick
//print type //print type
printf("%s\t", Toy_private_getValueTypeAsCString(v.type)); printf("%-20s", Toy_private_getValueTypeAsCString(v.type));
//print value //print value
Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v)); Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v));
char* buffer = Toy_getStringRaw(string); char* buffer = Toy_getStringRaw(string);
printf("%s", buffer); printf("%-20s", buffer);
free(buffer); free(buffer);
Toy_freeString(string); Toy_freeString(string);
@@ -291,7 +291,7 @@ static void debugScopePrint(Toy_Scope* scope, int depth) {
if (scope->count > 0) { if (scope->count > 0) {
Toy_Bucket* stringBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL); 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++) { for (unsigned int i = 0; i < scope->capacity; i++) {
if (scope->data[i].key.info.length == 0) { if (scope->data[i].key.info.length == 0) {
continue; continue;
@@ -300,12 +300,12 @@ static void debugScopePrint(Toy_Scope* scope, int depth) {
Toy_String k = scope->data[i].key; Toy_String k = scope->data[i].key;
Toy_Value v = scope->data[i].value; 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 //print value
Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v)); Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v));
char* buffer = Toy_getStringRaw(string); char* buffer = Toy_getStringRaw(string);
printf("%s", buffer); printf("%-20s", buffer);
free(buffer); free(buffer);
Toy_freeString(string); Toy_freeString(string);
+35
View File
@@ -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;
+14
View File
@@ -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;
+2 -1
View File
@@ -5,7 +5,8 @@ a["beta"] = 6;
print a; print a;
assert a == ["alpha": 1, "beta": 6, "gamma": 3], "1-D tables failed"; 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 //nested
var b = [ var b = [
"outer": ["inner": true], "outer": ["inner": true],