nx_decl_base.nx
buildroot/runtime/nx_decl_base.nx
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
imports: nx_syscalls.nxnx_types.nxnx_tier.nx
imported by: nx_decl_base_test.nx
structs
| 58 | struct NxDeclBase |
consts
| 54 | const NX_MAGIC_2654435761: i64 = 2654435761 |
| 55 | const NX_MAGIC_374761393: i64 = 374761393 |
| 67 | const NX_DECL_MOD_REAL: nx_int = 0 |
| 68 | const NX_DECL_MOD_FANTASY: nx_int = 1 |
| 69 | const NX_DECL_MOD_SCI_FI: nx_int = 2 |
| 70 | const NX_DECL_MOD_N: nx_int = 3 |
functions
| 72 | func nx_decl_mod_is_valid(m: nx_int) -> nx_int |
| 79 | func nx_decl_mod_name(m: nx_int) -> *u8 called by 1: main |
| 91 | func nx_decl_base_init(base: *NxDeclBase, modifier: nx_int, seed: nx_int) -> nx_int |
| 103 | func nx_decl_base_alloc() -> *NxDeclBase |
| 113 | func nx_decl_hash_mod(seed: nx_int, salt: nx_int, modulus: nx_int) -> nx_int called by 1: main |