diff options
author | kartofen <mladenovnasko0@gmail.com> | 2024-08-25 12:30:48 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2024-08-25 12:30:48 +0300 |
commit | 54f071ac7d47ef515a3f6a4db9e83f2f9aca3c8c (patch) | |
tree | 63e9958c5961f32d191c580f6960b6f9eba02f20 /src/value.c | |
parent | df95e5bfca1c5e723b39f25f32401db8f9ebf6fe (diff) |
lambda nearly done
Diffstat (limited to 'src/value.c')
-rw-r--r-- | src/value.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/value.c b/src/value.c index 233b83c..3c06fa3 100644 --- a/src/value.c +++ b/src/value.c @@ -32,17 +32,17 @@ const char * const value_type_string[] = { X(VALUE_PROC_BUILTIN, \ FN(snprintf, "%p", *(void **)&VALUE(v).proc_builtin.proc)) -#define DR(value) (--(value)->refs == 0) -#define VALUE_DESTROY_TABLE(X, v) \ - X(VALUE_NIL, (void)DR(v)) \ - X(VALUE_ATOM, if(DR(v)) free(VALUE(v).atom)) \ - X(VALUE_STR, if(DR(v)) free(VALUE(v).str)) \ - X(VALUE_INT, (void)DR(v)) \ - X(VALUE_CONS, (void)DR(v); \ - value_destroy(VALUE(v).cons.left); \ - value_destroy(VALUE(v).cons.right)) \ - X(VALUE_PROC, if(DR(v)) proc_destroy(&VALUE(v).proc)) \ - X(VALUE_PROC_BUILTIN, (void)DR(v)) +#define NOREFS(value) (--(value)->refs == 0) +#define VALUE_DESTROY_TABLE(X, v) \ + X(VALUE_NIL, (void)NOREFS(v)) \ + X(VALUE_ATOM, if(NOREFS(v)) free(VALUE(v).atom)) \ + X(VALUE_STR, if(NOREFS(v)) free(VALUE(v).str)) \ + X(VALUE_INT, (void)NOREFS(v)) \ + X(VALUE_CONS, (void)NOREFS(v); \ + value_destroy(VALUE(v).cons.left); \ + value_destroy(VALUE(v).cons.right)) \ + X(VALUE_PROC, if(NOREFS(v)) proc_destroy(&VALUE(v).proc)) \ + X(VALUE_PROC_BUILTIN, (void)NOREFS(v)) #define CASE_RETURN_APPLY(vtype, apply) \ case vtype: return apply; @@ -147,6 +147,7 @@ static int cons_print(char *buf, size_t buf_sz, struct cons *cons) static int proc_print(char *buf, size_t buf_sz, struct proc *proc) { + return 0; (void)buf; (void)buf_sz; (void)proc; NOT_IMPLEMENTED(); @@ -154,6 +155,11 @@ static int proc_print(char *buf, size_t buf_sz, struct proc *proc) static void proc_destroy(struct proc *proc) { - (void)proc; - NOT_IMPLEMENTED(); + for(size_t i = 0; i < proc->argc; i++) value_destroy(proc->arg_keys[i]); + free(proc->arg_keys); + + for(size_t i = 0; i < proc->body_len; i++) token_dealloc(&proc->body[i]); + free(proc->body); + + env_destroy(proc->parent_env); } |