The compiler concept is declare/define (comptime type construction); the old "reify" framing is gone from the entire repo. - Rename: PLAN-REIFY → PLAN-METATYPE, CHECKPOINT-REIFY → CHECKPOINT-METATYPE, PLAN-POST-REIFY → PLAN-POST-METATYPE (both rewritten around declare/define); examples 0614/0615/0617 → comptime-metatype-* (+ their expected/ triplets), headers rewritten. - Scrub reify from design/execution-evolution-roadmap.md (§7 step 3 contracts, §8.1, §9 decisions, §10 gates) → declare/define / comptime type construction. - core.sx prelude pointer + parser.test.zig surface lock updated to the declare/define builtins (define(handle, info) -> Type; EnumInfo.name). No behavior change; renamed examples match their renamed snapshots. Full suite green (673), all unit tests pass. Zero `reify` tokens remain in src/docs/sx/examples.
75 lines
3.0 KiB
Plaintext
75 lines
3.0 KiB
Plaintext
// The compiler-coupled prelude primitives: #builtin declarations, the libc
|
|
// escape hatch, and the types the compiler resolves by NAME program-wide
|
|
// (`Context`, `Allocator`, `Into`, `Source_Location`, `string`). Consumers
|
|
// never import this file directly — std.sx re-exports every name here.
|
|
|
|
Vector :: ($N: int, $T: Type) -> Type #builtin;
|
|
out :: (str: string) -> void #builtin;
|
|
// sqrt :: (x: $T) -> T #builtin;
|
|
// sin :: (x: $T) -> T #builtin;
|
|
// cos :: (x: $T) -> T #builtin;
|
|
size_of :: ($T: Type) -> i64 #builtin;
|
|
align_of :: ($T: Type) -> i64 #builtin;
|
|
// Low-level libc bindings, used by allocator implementations to avoid
|
|
// recursing through `context.allocator`. The bare `malloc`/`free`
|
|
// spellings are NOT declared: the Allocator protocol + the std/mem.sx
|
|
// helpers are the allocation surface (`free` is the typed slice helper
|
|
// there). Raw libc escape hatch: `libc_malloc` / `libc_free`.
|
|
libc_malloc :: (size: i64) -> *void extern libc "malloc";
|
|
libc_free :: (ptr: *void) -> void extern libc "free";
|
|
|
|
memcpy :: (dst: *void, src: *void, size: i64) -> *void extern libc "memcpy";
|
|
memset :: (dst: *void, val: i64, size: i64) -> void extern libc "memset";
|
|
type_of :: (val: $T) -> Type #builtin;
|
|
type_name :: ($T: Type) -> string #builtin;
|
|
field_count :: ($T: Type) -> i64 #builtin;
|
|
field_name :: ($T: Type, idx: i64) -> string #builtin;
|
|
field_value :: (s: $T, idx: i64) -> Any #builtin;
|
|
is_flags :: ($T: Type) -> bool #builtin;
|
|
type_is_unsigned :: ($T: Type) -> bool #builtin;
|
|
field_value_int :: ($T: Type, idx: i64) -> i64 #builtin;
|
|
field_index :: ($T: Type, val: T) -> i64 #builtin;
|
|
error_tag_name :: (e: $T) -> string #builtin;
|
|
|
|
// Comptime type metaprogramming (`declare` / `define` / `type_info` /
|
|
// `field_type`) lives in the on-demand `modules/std/meta.sx`, NOT here —
|
|
// declaring its data types in the always-loaded prelude would intern them into
|
|
// every module's type table and shift every `.ir` snapshot. Import
|
|
// `modules/std/meta.sx` to construct or reflect types at comptime.
|
|
|
|
// Call-site location, synthesized by the `#caller_location` directive when it
|
|
// is a parameter's default value (ERR E4.1b). `process.exit` / `assert` use it
|
|
// to report where they were invoked.
|
|
Source_Location :: struct {
|
|
file: string;
|
|
line: i32;
|
|
col: i32;
|
|
func: string;
|
|
}
|
|
string :: []u8 #builtin;
|
|
|
|
// --- Allocator protocol (impls live in std/mem.sx) ---
|
|
|
|
// Bytes-level primitives carry the `_bytes` suffix so the typed
|
|
// helpers in std/mem.sx own the bare names (`alloc(T, n)`, `free(s)`).
|
|
Allocator :: protocol #inline {
|
|
alloc_bytes :: (size: i64) -> *void;
|
|
dealloc_bytes :: (ptr: *void);
|
|
}
|
|
|
|
// --- Context ---
|
|
|
|
Context :: struct {
|
|
allocator: Allocator;
|
|
data: *void;
|
|
}
|
|
|
|
// User-space `xx` extension. `xx val : T` where the built-in conversion
|
|
// ladder makes no progress falls through to an `impl Into(T) for Source`
|
|
// lookup; the compiler monomorphises `convert` for the (Source, T) pair
|
|
// and emits a direct call. Compile-time only — no vtable, no runtime
|
|
// dispatch.
|
|
Into :: protocol(Target: Type) {
|
|
convert :: () -> Target;
|
|
}
|