Files
sx/library/modules/std.sx
agra 1d17b0abcf lang: introduce cstring — the C-boundary string (Odin model)
cstring is ONE pointer to a null-terminated u8 buffer, C's char*: thin
(8 bytes, no length; cstring_len walks to the terminator), crossing
#foreign boundaries verbatim in both directions, with ?cstring as the
nullable case lowering to the same bare pointer (null = absent).

Conversion discipline mirrors Odin: a string LITERAL coerces implicitly
(its bytes are terminated constants); any other string is rejected with
a diagnostic naming to_cstring (it may be an unterminated view); and
cstring never coerces to string implicitly — from_cstring(c) is the
explicit zero-copy view, pricing the strlen.

Plumbing: TypeId/TypeInfo builtin slot 18 (first_user 19), name
classifiers, size/align/name tables, LLVM ptr lowering, the ?T pointer
niche, the xx pointer ladder, the literal-gated coercion plan
(isConstString + data_ptr), and the reserved-spelling set. std gains
cstring_len/from_cstring/to_cstring (fmt.sx, re-exported); the old
cstring(size) allocator helper is renamed alloc_string everywhere;
getenv migrates to (name: cstring) -> ?cstring as the canonical user
and env() drops its manual strlen/memcpy.

Pinned: examples/1222 (FFI both directions, literal coercion,
?cstring null paths, round trip) and examples/1173 (both coercion
diagnostics); FAIL pre-feature. The alloc_string rename + getenv
signature shift the .ir snapshots — regenerated. zig build test
426/426; run_examples 604/604.

Spec: reserved spelling + cstring section + C-interop rows.
2026-06-12 14:50:53 +03:00

100 lines
3.4 KiB
Plaintext

// The prelude facade: every name here is a RE-EXPORT. The implementations
// live in the part-files (std/core.sx — compiler-coupled primitives,
// std/fmt.sx — formatting + string helpers, std/list.sx — List); each
// alias below is an ordinary OWN declaration of this file, so a flat
// `#import "modules/std.sx"` sees the whole prelude bare, one hop —
// visibility never chains, aliases are the re-export mechanism. The
// part-file namespaces (`core` / `fmt` / `list`) and the namespace tail at
// the bottom are carried to flat importers the same one level.
core :: #import "modules/std/core.sx";
fmt :: #import "modules/std/fmt.sx";
list :: #import "modules/std/list.sx";
// --- Compiler-resolved types ---
// (`string` has no alias here: it is a reserved type name — its #builtin
// declaration in core.sx resolves program-wide and cannot be re-bound.)
Context :: core.Context;
Allocator :: core.Allocator;
Into :: core.Into;
Source_Location :: core.Source_Location;
// --- Type system & reflection builtins ---
Vector :: core.Vector;
size_of :: core.size_of;
align_of :: core.align_of;
type_of :: core.type_of;
type_name :: core.type_name;
type_is_unsigned :: core.type_is_unsigned;
field_count :: core.field_count;
field_name :: core.field_name;
field_value :: core.field_value;
field_value_int :: core.field_value_int;
field_index :: core.field_index;
is_flags :: core.is_flags;
error_tag_name :: core.error_tag_name;
// --- Output & libc escape hatch ---
out :: core.out;
libc_malloc :: core.libc_malloc;
libc_free :: core.libc_free;
memcpy :: core.memcpy;
memset :: core.memset;
// --- Formatting ---
print :: fmt.print;
format :: fmt.format;
any_to_string :: fmt.any_to_string;
int_to_string :: fmt.int_to_string;
uint_to_string :: fmt.uint_to_string;
int_to_hex_string :: fmt.int_to_hex_string;
float_to_string :: fmt.float_to_string;
bool_to_string :: fmt.bool_to_string;
struct_to_string :: fmt.struct_to_string;
enum_to_string :: fmt.enum_to_string;
flags_to_string :: fmt.flags_to_string;
vector_to_string :: fmt.vector_to_string;
array_to_string :: fmt.array_to_string;
slice_to_string :: fmt.slice_to_string;
pointer_to_string :: fmt.pointer_to_string;
optional_to_string :: fmt.optional_to_string;
// --- String ops & allocation helpers ---
concat :: fmt.concat;
substr :: fmt.substr;
path_join :: fmt.path_join;
alloc_string :: fmt.alloc_string;
cstring_len :: fmt.cstring_len;
from_cstring :: fmt.from_cstring;
to_cstring :: fmt.to_cstring;
alloc_slice :: fmt.alloc_slice;
// fmt internals, re-exported only because they were always part of the
// flat prelude surface.
build_format :: fmt.build_format;
hex_group :: fmt.hex_group;
decompose_u16x4 :: fmt.decompose_u16x4;
// --- Containers ---
List :: list.List;
// --- The stdlib namespace tail: flat-importing std.sx carries these ---
mem :: #import "modules/std/mem.sx";
fs :: #import "modules/std/fs.sx";
process :: #import "modules/std/process.sx";
socket :: #import "modules/std/socket.sx";
json :: #import "modules/std/json.sx";
xml :: #import "modules/std/xml.sx";
cli :: #import "modules/std/cli.sx";
hash :: #import "modules/std/hash.sx";
log :: #import "modules/std/log.sx";
test :: #import "modules/std/test.sx";