code wiki / (root) / nx_decl_base.nx

nx_decl_base.nx

buildroot/runtime/nx_decl_base.nx

4249 B118 linesdepth 2pulls 3 transitivereach 1 importersview sourcekind librarytopic decl
docsdependenciesstructsconstsfunctions

about

nx_decl_base.nx -- shared base struct for the #tag declarator family. license_tier: ORIGINAL Object-oriented composition discipline: every `nx_decl_*` primitive shares a HEADER struct (seed, modifier, is_valid) that's validated + initialized centrally. Derived types compose by EMBEDDING (as the first pointer field) and delegating the header validate to this module. Today's `nx_decl_*` family duplicates the same validation 5 times (random_environment, simple_scene, combat_arena, dungeon_floor, townscape). This file centralizes that into ONE base. Migration is additive: existing declarators keep their current shape; new declarators can compose via `NxDeclBase` and `nx_decl_base_init`. Pattern (OO in substrate-procedural style): struct NxFooDecl { base: *NxDeclBase, // pointer to shared header foo_specific_a: nx_int, foo_specific_b: nx_int, } func nx_decl_foo(out: *NxFooDecl, modifier: nx_int, seed: nx_int) -> nx_int { let base: *NxDeclBase = nx_decl_base_alloc() let ok: nx_int = nx_decl_base_init(base, modifier, seed) if ok == 0 { return 0 } out.base = base // ... fill foo-specific fields ... return 1 } Then `out.base.is_valid`, `out.base.modifier`, `out.base.seed` are uniform across the family. Inheritance discipline: substrate- procedural has no method dispatch, but composition + a shared init/validate is the practical equivalent. Per cardinals: - DRY-through-shared-libraries: 5 copies of the same validate

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_types.nx nx_tier.nx nx_decl_base.nx nx_decl_base_test.nx

imports: nx_syscalls.nxnx_types.nxnx_tier.nx

imported by: nx_decl_base_test.nx

structs

58struct NxDeclBase

consts

54const NX_MAGIC_2654435761: i64 = 2654435761
55const NX_MAGIC_374761393: i64 = 374761393
67const NX_DECL_MOD_REAL: nx_int = 0
68const NX_DECL_MOD_FANTASY: nx_int = 1
69const NX_DECL_MOD_SCI_FI: nx_int = 2
70const NX_DECL_MOD_N: nx_int = 3

functions

72func nx_decl_mod_is_valid(m: nx_int) -> nx_int
79func nx_decl_mod_name(m: nx_int) -> *u8
called by 1: main
91func nx_decl_base_init(base: *NxDeclBase, modifier: nx_int, seed: nx_int) -> nx_int
called by 1: main calls 1: nx_decl_mod_is_valid
103func nx_decl_base_alloc() -> *NxDeclBase
called by 1: main calls 1: sys_mmap
113func nx_decl_hash_mod(seed: nx_int, salt: nx_int, modulus: nx_int) -> nx_int
called by 1: main