Minor table refactor, added cosmoV_compileString and loadstring() to baselib

cosmoV_compileString is recommended since it'll push the result (<error> or <closure>) onto the stack.

also, fixed some GC-related bugs, so yay!
This commit is contained in:
2021-01-10 14:38:53 -06:00
parent 8dc8cef7dc
commit c510c9aebf
9 changed files with 122 additions and 59 deletions

View File

@@ -55,7 +55,8 @@ void markTable(CState *state, CTable *tbl) {
if (tbl->table == NULL) // table is still being initialized
return;
for (int i = 0; i < tbl->capacity; i++) {
int cap = tbl->capacityMask + 1;
for (int i = 0; i < cap; i++) {
CTableEntry *entry = &tbl->table[i];
markValue(state, entry->key);
markValue(state, entry->val);
@@ -67,7 +68,8 @@ void tableRemoveWhite(CState *state, CTable *tbl) {
if (tbl->table == NULL) // table is still being initialized
return;
for (int i = 0; i < tbl->capacity; i++) {
int cap = tbl->capacityMask + 1;
for (int i = 0; i < cap; i++) {
CTableEntry *entry = &tbl->table[i];
if (IS_OBJ(entry->key) && !(cosmoV_readObj(entry->key))->isMarked) { // if the key is a object and it's white (unmarked), remove it from the table
cosmoT_remove(state, tbl, entry->key);