summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/v1/nock.c
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-06 01:01:41 +0700
committerpolwex <polwex@sortug.com>2025-10-06 01:01:41 +0700
commitc4b392a179048f936c062f5ffccc2bc25627e500 (patch)
tree09be0904be8ec4d7ea52992ef7580d42ed0c28c1 /vere/pkg/noun/v1/nock.c
working
Diffstat (limited to 'vere/pkg/noun/v1/nock.c')
-rw-r--r--vere/pkg/noun/v1/nock.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/vere/pkg/noun/v1/nock.c b/vere/pkg/noun/v1/nock.c
new file mode 100644
index 0000000..aa1dc9c
--- /dev/null
+++ b/vere/pkg/noun/v1/nock.c
@@ -0,0 +1,69 @@
+/// @file
+
+#include "../nock.h"
+#include "v1/nock.h"
+
+#include "v1/allocate.h"
+#include "v1/hashtable.h"
+#include "../jets.h"
+#include "v1/jets.h"
+
+/* u3n_v1_reclaim(): clear ad-hoc persistent caches to reclaim memory.
+*/
+void
+u3n_v1_reclaim(void)
+{
+ // clear the bytecode cache
+ //
+ // We can't just u3h_v1_free() -- the value is a post to a u3n_v1_prog.
+ // Note that the hank cache *must* also be freed (in u3j_v1_reclaim())
+ //
+ u3n_v1_free();
+}
+
+/* _cn_v1_prog_free(): free memory retained by program pog_u
+*/
+static void
+_cn_v1_prog_free(u3n_v1_prog* pog_u)
+{
+ // fix up pointers for loom portability
+ pog_u->byc_u.ops_y = (c3_y*) ((void*) pog_u) + sizeof(u3n_v1_prog);
+ pog_u->lit_u.non = (u3_noun*) (pog_u->byc_u.ops_y + pog_u->byc_u.len_w);
+ pog_u->mem_u.sot_u = (u3n_v1_memo*) (pog_u->lit_u.non + pog_u->lit_u.len_w);
+ pog_u->cal_u.sit_u = (u3j_v1_site*) (pog_u->mem_u.sot_u + pog_u->mem_u.len_w);
+ pog_u->reg_u.rit_u = (u3j_v1_rite*) (pog_u->cal_u.sit_u + pog_u->cal_u.len_w);
+
+ c3_w dex_w;
+ for (dex_w = 0; dex_w < pog_u->lit_u.len_w; ++dex_w) {
+ u3a_v1_lose(pog_u->lit_u.non[dex_w]);
+ }
+ for (dex_w = 0; dex_w < pog_u->mem_u.len_w; ++dex_w) {
+ u3a_v1_lose(pog_u->mem_u.sot_u[dex_w].key);
+ }
+ for (dex_w = 0; dex_w < pog_u->cal_u.len_w; ++dex_w) {
+ u3j_v1_site_lose(&(pog_u->cal_u.sit_u[dex_w]));
+ }
+ for (dex_w = 0; dex_w < pog_u->reg_u.len_w; ++dex_w) {
+ u3j_v1_rite_lose(&(pog_u->reg_u.rit_u[dex_w]));
+ }
+ u3a_v1_free(pog_u);
+}
+
+/* _n_v1_feb(): u3h_v1_walk helper for u3n_v1_free
+ */
+static void
+_n_v1_feb(u3_noun kev)
+{
+ u3a_v1_cell *cel_u = (u3a_v1_cell*) u3a_v1_to_ptr(kev);
+ _cn_v1_prog_free(u3to(u3n_v1_prog, cel_u->tel));
+}
+
+/* u3n_v1_free(): free bytecode cache
+ */
+void
+u3n_v1_free(void)
+{
+ u3p(u3h_v1_root) har_p = u3R_v1->byc.har_p;
+ u3h_v1_walk(har_p, _n_v1_feb);
+ u3h_v1_free_nodes(har_p);
+}