Skip to content

Commit 4167ff6

Browse files
leifericfclaude
andcommitted
Factoring: Move make_fn constructor from collections/map.c to values/val.c
make_fn allocates and initialises a MINO_FN value cell -- a values-domain constructor that belongs in values/val.c alongside the other value constructors. It was in collections/map.c because of co-location with other fn-related utilities, but that placed a values-domain function outside its owning module. Move the implementation to val.c (which already includes runtime/internal.h for mino_current_ctx, giving access to alloc_val and S->ns_vars.*), remove it from map.c, and update the implementation listing in values/internal.h. All callers reach the declaration through collections/internal.h, which includes values/internal.h -- no caller changes needed. Fixes factoring-values-r3-002 (make_fn placement). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> (cherry picked from commit d1b643a14e996f7418a6745feba7a75cf4543121)
1 parent a90c429 commit 4167ff6

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

src/collections/map.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -916,32 +916,4 @@ void mino_atom_reset(mino_state *S, mino_val *a, mino_val *val)
916916
}
917917
}
918918

919-
mino_val *make_fn(mino_state *S, mino_val *params, mino_val *body,
920-
mino_env *env)
921-
{
922-
mino_val *v = alloc_val(S, MINO_FN);
923-
v->as.fn.params = params;
924-
v->as.fn.body = body;
925-
v->as.fn.env = env;
926-
v->as.fn.shape = 0;
927-
v->as.fn.wraps_prim = NULL;
928-
v->as.fn.template_fn = NULL;
929-
/* Inside a macro body, current_ns is still the caller's ns (only
930-
* fn_ambient_ns is the macro's defining ns). Closures created here
931-
* are artifacts of the macro expansion -- they should resolve free
932-
* vars and qualify syntax-quoted symbols against the macro's ns,
933-
* not the caller's. Without this, `(fn [...] `(sym ...))` inside
934-
* a macro body emits bare `sym` instead of `defining-ns/sym` once
935-
* the closure runs, since invoking the closure overwrites
936-
* fn_ambient_ns with its (caller-derived) defining_ns. */
937-
if (S->ns_vars.fn_ambient_ns != NULL
938-
&& S->ns_vars.fn_ambient_ns != S->ns_vars.current_ns
939-
&& (S->ns_vars.current_ns == NULL
940-
|| strcmp(S->ns_vars.fn_ambient_ns, S->ns_vars.current_ns) != 0)) {
941-
v->as.fn.defining_ns = S->ns_vars.fn_ambient_ns;
942-
} else {
943-
v->as.fn.defining_ns = S->ns_vars.current_ns;
944-
}
945-
return v;
946-
}
947919

src/values/val.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,42 @@ mino_val *mino_mk_var(mino_state *S, const char *ns, const char *name,
473473
return v;
474474
}
475475

476+
/* Fn-value constructor (MINO_FN). Lives here rather than in
477+
* collections/map.c (where the other fn-related utilities used to
478+
* co-locate) because this is a values-domain object constructor and
479+
* values/ is the natural owner of value-type allocation. The only
480+
* runtime-internal state it reads is S->ns_vars.{fn_ambient_ns,
481+
* current_ns}, which is available via runtime/internal.h that val.c
482+
* already includes. */
483+
mino_val *make_fn(mino_state *S, mino_val *params, mino_val *body,
484+
mino_env *env)
485+
{
486+
mino_val *v = alloc_val(S, MINO_FN);
487+
v->as.fn.params = params;
488+
v->as.fn.body = body;
489+
v->as.fn.env = env;
490+
v->as.fn.shape = 0;
491+
v->as.fn.wraps_prim = NULL;
492+
v->as.fn.template_fn = NULL;
493+
/* Inside a macro body, current_ns is still the caller's ns (only
494+
* fn_ambient_ns is the macro's defining ns). Closures created here
495+
* are artifacts of the macro expansion -- they should resolve free
496+
* vars and qualify syntax-quoted symbols against the macro's ns,
497+
* not the caller's. Without this, `(fn [...] `(sym ...))` inside
498+
* a macro body emits bare `sym` instead of `defining-ns/sym` once
499+
* the closure runs, since invoking the closure overwrites
500+
* fn_ambient_ns with its (caller-derived) defining_ns. */
501+
if (S->ns_vars.fn_ambient_ns != NULL
502+
&& S->ns_vars.fn_ambient_ns != S->ns_vars.current_ns
503+
&& (S->ns_vars.current_ns == NULL
504+
|| strcmp(S->ns_vars.fn_ambient_ns, S->ns_vars.current_ns) != 0)) {
505+
v->as.fn.defining_ns = S->ns_vars.fn_ambient_ns;
506+
} else {
507+
v->as.fn.defining_ns = S->ns_vars.current_ns;
508+
}
509+
return v;
510+
}
511+
476512
mino_val *mino_cons(mino_state *S, mino_val *car, mino_val *cdr)
477513
{
478514
mino_val *v = alloc_val(S, MINO_CONS);

0 commit comments

Comments
 (0)