Quick fix for some self-referential table bugs

This commit is contained in:
2024-12-24 16:47:58 +11:00
parent b092b8ce50
commit 9e2cbb1f59

View File

@@ -283,7 +283,7 @@ static void processAssignCompound(Toy_VM* vm) {
Toy_Table* table = TOY_VALUE_AS_TABLE(target);
//set the value
Toy_insertTable(&table, key, Toy_copyValue(Toy_unwrapValue(value)));
Toy_insertTable(&table, Toy_copyValue(Toy_unwrapValue(key)), Toy_copyValue(Toy_unwrapValue(value)));
//cleanup
Toy_freeValue(value);
@@ -751,6 +751,14 @@ static void processIndex(Toy_VM* vm) {
Toy_Table* table = TOY_VALUE_AS_TABLE(value);
Toy_TableEntry* entry = Toy_private_lookupTableEntryPtr(&table, index);
if (entry == NULL) {
Toy_error("Table key not found");
Toy_freeValue(value);
Toy_freeValue(index);
Toy_freeValue(length);
return;
}
//in the event of a certain subset of types, create references instead (these should only exist on the stack)
if (TOY_VALUE_IS_REFERENCE(entry->value) || TOY_VALUE_IS_ARRAY(entry->value) || TOY_VALUE_IS_TABLE(entry->value)) {
//TODO: more types to be implemented as stack-only references