From 22d5060439f58ecfe8148ad67819c179647e4751 Mon Sep 17 00:00:00 2001 From: agra Date: Fri, 26 Jun 2026 09:02:38 +0300 Subject: [PATCH] refactor: core.sx self-declares its libc #library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit core.sx owns the libc escape hatches (libc_write / libc_malloc / libc_free / memcpy / memset, all `extern libc "..."`) but never declared the `libc` #library constant — it free-rode on `#library` being program-global, satisfied by other std modules (socket/fs/cli) in a full std build. So core.sx — and list.sx, which imports it for Allocator/List — could not be imported without assembling the whole std prelude (`extern library 'libc' is not declared`). Declare `libc :: #library "c"` in core.sx itself. `#library` constants are program-global and dedup, so this is harmless alongside the other declarers, and it makes core.sx / list.sx self-contained — importable standalone. No snapshot drift (a #library decl adds no type/global), full suite green 817/0. --- library/modules/std/core.sx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/modules/std/core.sx b/library/modules/std/core.sx index ce6fa5d8..17eddf2e 100644 --- a/library/modules/std/core.sx +++ b/library/modules/std/core.sx @@ -4,6 +4,13 @@ // never import this file directly — std.sx re-exports every name here. Vector :: ($N: int, $T: Type) -> Type #builtin; +// The C library, declared HERE because core.sx owns the libc escape hatches +// (`libc_write`/`libc_malloc`/`libc_free`/`memcpy`/`memset` below). `#library` +// constants are program-global and dedup, so this is harmless when other std +// modules (socket/fs/cli) also declare it — and it makes core.sx (hence +// list.sx, which imports core for `Allocator`/`List`) self-contained, so they +// can be imported without assembling the whole std prelude. +libc :: #library "c"; // `out` writes a string straight to fd 1 via libc `write` — a plain sx function, // NOT a compiler builtin. At comptime it runs through the evaluator's host-FFI // escape (the VM's dlsym path / the interp's extern call); at runtime it's an