globals->symbols = naNewHash(c);
globals->save = naNewVector(c);
+ globals->save_hash = naNewHash(c);
+ globals->next_gc_key = 0;
// Cache pre-calculated "me", "arg" and "parents" scalars
globals->meRef = naInternSymbol(naStr_fromdata(naNewString(c), "me", 2));
naVec_append(globals->save, obj);
}
+int naGCSave(naRef obj)
+{
+ int key = globals->next_gc_key++;
+ naHash_set(globals->save_hash, naNum(key), obj);
+ return key;
+}
+
+void naGCRelease(int key)
+{
+ naHash_delete(globals->save_hash, naNum(key));
+}
+
void naClearSaved()
{
naContext c;
c = naNewContext();
globals->save = naNewVector(c);
- naFreeContext(c);
+ globals->save_hash = naNewHash(c);
+ naFreeContext(c);
}
int naStackDepth(naContext ctx)
// A hash of symbol names
naRef symbols;
+ // Vector/hash containing objects which should not be freed by the gc
+ // TODO do we need a separate vector and hash?
naRef save;
+ naRef save_hash;
+ int next_gc_key;
struct Context* freeContexts;
struct Context* allContexts;
// "Save" this object in the context, preventing it (and objects
// referenced by it) from being garbage collected.
+// TODO do we need a context? It is not used anyhow...
void naSave(naContext ctx, naRef obj);
+// "Save" this object and get a key which allows do mark the object as free
+// later on (with naGCFree).
+int naGCSave(naRef obj);
+
+// Release an object previously passed to naGCSave to allow it being cleaned up
+// by the garbage collector.
+void naGCRelease(int key);
+
// Drop all saved references
void naClearSaved();