Files
sx/examples/comptime/0626-comptime-weld-fn-intern-text-of.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

24 lines
819 B
Plaintext

// Comptime compiler API — welded compiler FUNCTIONS over the host-call bridge.
//
// `intern` / `text_of` are bound to the `compiler` library via
// `abi(.compiler)`. They have no real symbol — under the comptime
// interpreter the call dispatches to the compiler's registered Zig handler
// (the string pool), never dlsym. Comptime-only: here they run inside `#run`,
// folding to a plain string constant the runtime `main` prints.
//
// Round-trip: `text_of(intern(s)) == s` — interning a string yields a handle,
// and resolving the handle gives the text back.
#import "modules/std.sx";
StringId :: u32;
intern :: (s: string) -> StringId abi(.compiler);
text_of :: (id: StringId) -> string abi(.compiler);
greeting :: #run text_of(intern("hello, compiler"));
main :: () {
print("{}\n", greeting);
}