diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-12-24 12:45:29 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-12-24 12:52:48 -0500 |
| commit | 649977aae7e5922f992cd69eb84da0a2db368580 (patch) | |
| tree | e61d35b74d2551901cc8f3f034aca7da1f375a8c /src/compile/functions.c | |
| parent | 88ccdab43c0a3ee53177e21a28724e496406a376 (diff) | |
Split out new()/gc logic from stdlib/util.h
Diffstat (limited to 'src/compile/functions.c')
| -rw-r--r-- | src/compile/functions.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/compile/functions.c b/src/compile/functions.c index a1b0a28c..9b8ba096 100644 --- a/src/compile/functions.c +++ b/src/compile/functions.c @@ -10,9 +10,9 @@ #include "../stdlib/optionals.h" #include "../stdlib/tables.h" #include "../stdlib/text.h" -#include "../util.h" #include "../typecheck.h" #include "../types.h" +#include "../util.h" #include "compilation.h" public @@ -683,8 +683,9 @@ Text_t compile_lambda(env_t *env, ast_t *ast) { code = Texts(code, "void *_)"); userdata = Text("NULL"); } else { - userdata = Texts("new(", name, "$userdata_t"); + userdata = Texts("heap(((", name, "$userdata_t){"); for (int64_t i = 0; i < (int64_t)closed_vars.entries.length; i++) { + if (i > 0) userdata = Text$concat(userdata, Text(", ")); struct { const char *name; binding_t *b; @@ -693,11 +694,11 @@ Text_t compile_lambda(env_t *env, ast_t *ast) { binding_t *b = get_binding(env, entry->name); assert(b); Text_t binding_code = b->code; - if (entry->b->type->tag == ListType) userdata = Texts(userdata, ", LIST_COPY(", binding_code, ")"); - else if (entry->b->type->tag == TableType) userdata = Texts(userdata, ", TABLE_COPY(", binding_code, ")"); - else userdata = Texts(userdata, ", ", binding_code); + if (entry->b->type->tag == ListType) userdata = Texts(userdata, "LIST_COPY(", binding_code, ")"); + else if (entry->b->type->tag == TableType) userdata = Texts(userdata, "TABLE_COPY(", binding_code, ")"); + else userdata = Texts(userdata, binding_code); } - userdata = Texts(userdata, ")"); + userdata = Texts(userdata, "}))"); code = Texts(code, name, "$userdata_t *userdata)"); } |
