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));
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;
}
}
+6 -6
View File
@@ -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);