From 3074ba5babaf39e4a177444a8ffb5f81b991440f Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 20 Aug 2025 21:12:46 +0100 Subject: Constructors and context -> sys We can register memory we've allocated onto the heap into a ~sys_t~ instance for examination (read: garbage collection) later. We can also add items to the symbol table it has internally. --- base.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'base.h') diff --git a/base.h b/base.h index a114ce0..6d1f034 100644 --- a/base.h +++ b/base.h @@ -102,22 +102,26 @@ typedef struct { lisp_t *memory; sym_table_t symtable; -} context_t; +} sys_t; -void context_init(context_t *); -void context_cleanup(context_t *); +void sys_init(sys_t *); +void sys_register(sys_t *sys, lisp_t *ptr); +void sys_cleanup(sys_t *); /// Constructors and destructors lisp_t *make_int(i64 i); -lisp_t *intern(context_t *context, char *str); -lisp_t *cons(context_t *context, lisp_t *car, lisp_t *cdr); -lisp_t *make_vec(context_t *context, u64 capacity); +lisp_t *make_vec(sys_t *sys, u64 capacity); +lisp_t *intern(sys_t *sys, sv_t sv); +lisp_t *cons(sys_t *sys, lisp_t *car, lisp_t *cdr); i64 as_int(lisp_t *); char *as_sym(lisp_t *); cons_t *as_cons(lisp_t *); void *as_vec(lisp_t *); +#define CAR(L) (as_cons(L)->car) +#define CDR(L) (as_cons(L)->cdr) + /// Pointer tagging scheme for lisps typedef enum Tag @@ -153,6 +157,8 @@ enum Mask #define INT_MAX ((1L << 62) - 1) #define INT_MIN (-(1L << 62)) +tag_t get_tag(lisp_t *lisp); + lisp_t *tag_int(i64 i); lisp_t *tag_sym(char *str); lisp_t *tag_cons(cons_t *cons); -- cgit v1.2.3-13-gbd6f