From 8b2fe97fc2895270f59b224386875dc900fbb395 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 11 Feb 2026 07:56:57 +0000 Subject: [PATCH] lisp: sys_cost for memory footprint --- include/alisp/lisp.h | 3 +++ src/lisp.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/alisp/lisp.h b/include/alisp/lisp.h index 52b29a1..d4aae26 100644 --- a/include/alisp/lisp.h +++ b/include/alisp/lisp.h @@ -34,6 +34,9 @@ void sys_init(sys_t *); void sys_register(sys_t *, lisp_t *); void sys_free(sys_t *); +// Debugging function: provides total memory usage from system. +u64 sys_cost(sys_t *); + /// Constructors and destructors lisp_t *make_int(i64); lisp_t *make_vec(sys_t *, u64); diff --git a/src/lisp.c b/src/lisp.c index 42395fb..8cf35cf 100644 --- a/src/lisp.c +++ b/src/lisp.c @@ -22,6 +22,11 @@ void sys_register(sys_t *sys, lisp_t *ptr) vec_append(&sys->memory, &ptr, sizeof(&ptr)); } +u64 sys_cost(sys_t *sys) +{ + return sym_table_cost(&sys->symtable) + sys->memory.capacity; +} + void sys_free(sys_t *sys) { static_assert(NUM_TAGS == 5);