Skip to content

Commit

Permalink
Quick fix for some self-referential table bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratstail91 committed Dec 24, 2024
1 parent b092b8c commit 9e2cbb1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/toy_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9e2cbb1

Please sign in to comment.