-
-
Notifications
You must be signed in to change notification settings - Fork 5
N Language
N is the native systems language of NyxOS, in the spirit that HolyC was to TempleOS: a language designed for one operating system, whose compiler knows that OS from the inside — its syscall table, its ABI, its memory map — and which ultimately lives inside the OS itself, so a program can be written, compiled and run without ever leaving NyxOS.
N++ is its planned superset. The relationship is deliberately the C/C++ one: every valid N program is a valid N++ program, and N++ compiles down through the same pipeline. N++ adds the safety-and-ergonomics layer — ownership, sum types with match, Result/?, traits, capability checking — much of which already exists in the compiler as the N++ P1–P4 work.
The language lives in lang/ in the repository. It builds on the Toolchain: the same way cc (TinyCC) compiles C in-OS and xbm installs packages from source, ncc compiles N in-OS.
See also: Toolchain, Userspace, Syscalls, Shell, Version-History
Note
N is a working v0.15 language with a real compiler and a 16-program example suite that runs inside NyxOS; N++ is the same compiler's already-landed safety layer plus a design doc for the rest. This is a hobby language, honestly scoped — it lowers to C today, not native code, and self-hosting (M5) has only just begun.
| N | N++ | |
|---|---|---|
| Role | The metal: kernel modules, drivers, small userland tools | The ergonomics: applications, GUI programs, larger systems |
| File extension | .n |
.npp |
| Compiler |
ncc (exists — bootstrap) |
n++ (planned, builds on ncc) |
| Memory model | Manual, raw pointers | Ownership/borrowing opt-in, #[user] checked pointers |
| Error handling | Return codes |
Result<T, E> + ? propagation |
| Data types | Primitives, pointers, str
|
+ struct methods, enum sum types, match, generics, traits |
| Status | v0.15 — working |
P1–P4 complete (#[user] pointers, pageflags W^X, #[caps] capabilities); P5 next |
-
Syscalls are part of the language. An
extern syscallblock binds kernel entry points by number, and the compiler emits the raw x86-64syscallinstruction inline — no libc in between:extern syscall { fn write(fd: i32, buf: *u8, len: isize) -> i64 = 1 fn getpid() -> i64 = 6 } fn main() -> i64 { pid := getpid(); msg := "hello from N! pid={pid}\n"; write(1, msg.ptr as *u8, msg.len as isize); 0 }
-
The compiler knows NyxOS. Types like
addr, the canonical user-space boundary, the register ABI, the W^X page-flag rules — these are compiler knowledge, not header files. -
Readable surface, systems semantics.
:=inference,{...}string interpolation, expression blocks — but everything lowers to straightforward, dependency-free C (and to native code eventually) with zero hidden runtime.
ncc (lang/ncc/ncc.c) is a single-file, dependency-free C99 program (~2570 lines) that transpiles N to freestanding C targeting the NyxOS runtime. "Bootstrap" means it exists to get N off the ground and to be simple enough to port into NyxOS.
ncc input.n -o output.c # transpile
ncc input.n # ... or write the C to stdoutOn success it prints a one-line summary to stderr and exits 0; on the first error it prints file:line: message and exits 1. Since v0.2 the emitted C is strict C99 with no GNU extensions (checked with -std=c99 -pedantic-errors) — which matters because TinyCC is the in-OS compiler that builds N programs inside NyxOS, and tcc rejects extensions like __auto_type.
The runtime N links against lives with the rest of user space: user/nyxrt.h / nyxrt.c — freestanding string/format helpers plus the syscall primitive. (This is the same nyxrt the wiki previously called "Nyx C"; N is its matured, named, versioned form — see Userspace.)
Each ncc release adds one capability, versioned in lockstep with the spec. The N++ safety work (P1–P4) landed as part of this progression.
| Version | Feature | N++ phase |
|---|---|---|
v0.2 |
Type inference — typed := bindings (i64 default), typed interpolation, enforced mut; strict-C99 output |
— |
v0.3–v0.4
|
The expression-level static checker — undeclared names, unknown callees, arity, argument/operand/return/assignment types, all compile errors with file:line diagnostics |
P1 complete |
v0.5 |
struct declarations — checked literals, typed field access, mut-through-field |
P2 starts |
v0.6 |
defer — function-scoped LIFO cleanup on every exit path (Go semantics, static lowering) |
— |
v0.7 |
enum + match — tagged-union sum types with exhaustive dispatch (the Result foundation) |
— |
v0.8 |
impl methods — static dispatch on structs and enums, chained calls |
P2 complete |
v0.9 |
match as an expression — bind/assign/return positions, one result type |
P3 starts |
v0.10 |
? error propagation over Ok/Err result enums |
— |
| — | fs standard-bindings example — syscall→Result boundary, ? chains, deferred close |
P3 complete |
v0.11 |
Counted for loops over half-open ranges; reject C keywords as N names |
— |
v0.12 |
#[user] checked pointers — a distinct pointer flavor, explicit as crossings, syscall params markable |
P4 starts |
v0.13 |
pageflags — page permissions with a total compile-time W^X proof, PROT constants, a live mmap demo |
P4 2/3 |
v0.14 |
Capabilities — #[caps(syscall)] gates extern blocks; wrappers are the audited boundary |
P4 complete |
v0.15 |
Indexing — s[i]/p[i] byte and element reads (read-only); str.ptr is now truly *u8 (the self-hosting enabler) |
— |
N rides the same self-hosting ladder the C toolchain climbed (see Toolchain).
| Milestone | Description | Status |
|---|---|---|
| M0 | Bootstrap ncc compiles N v0.1 on the dev machine |
✅ done |
| M1 | Language home in-repo: compiler, spec, examples, docs | ✅ done |
| M2 |
ncc compiles inside NyxOS with the in-OS cc (tcc) |
✅ done |
| M3 |
ncc hello.n → running binary, entirely in-OS — the HolyC moment
|
✅ done |
| M4 | N++ front-end: type checker, structs/enums/match, Result/?
|
design ready (P1–P4 landed) |
| M5 |
Self-hosting — ncc rewritten in N |
started |
M2 and M3 were reached with zero changes to the compiler's design — ncc.c is plain C99 in one file, so the in-OS tcc builds it directly, and the same transpile-to-C pipeline works in-OS. The verified full loop inside a booted NyxOS:
cc /mnt/ncc.c -I/usr/src/nyx -o /mnt/bin/ncc # tcc compiles the N compiler
ncc /mnt/hello.n -o /mnt/hello_gen.c # ncc transpiles N source
cc /mnt/hello_gen.c /mnt/nyxrt.c -I/mnt -o /mnt/bin/nhello
nhello # → hello from N! pid=8On NyxOS itself the compiler is one command away — xbm install ncc builds it from source with the in-OS toolchain and installs it to /mnt/bin.
The first links of rewriting ncc in N are done — the classic "toy compiler triangle", each written in N and verified running in-OS:
| Link | Program | Does |
|---|---|---|
| 1 | ntokens.n | An N tokenizer written in N — tokenizes N source inside NyxOS |
| 2 | ncalc.n | A recursive-descent precedence parser + evaluator (functional state threading, mutual recursion) |
| 3 | nemit.n | A stack-code emitter (read → parse → emit) — the triangle closes |
Next for M5: writable buffers, then scaling the front-end up to the full compiler.
Three independent ways, so a regression shows up somewhere:
-
Real programs run on NyxOS. The in-OS TinyCC builds the current
nccfrom source, and that compiler transpiles, compiles and runs the entire 16-program example suite in a single boot, output identical to the host runs — the fs bindings exercise real kernelopen/read/close, thepageflagsdemo does a live anonymousmmapthrough the W^X-typed flags, and the M5 tokenizer tokenizes N source in-OS. -
Generated C is clean. It compiles warning-free with the OS freestanding flags and links with the standard
crt0+nyxrt. -
Host behavioral tests. The x86-64
syscallinstruction ABI is identical on Linux and NyxOS — only the numbers differ — solang/ncc/host/nyxrt.hmaps NyxOS syscall numbers to Linux ones, letting N programs run and be checked on the dev machine without booting.
Note
This workload doubles as a real OS stress test: running the whole suite in one boot uncovered a kernel VFS node-pool exhaustion (#66), which prompted the 512-node VFS pool and the vfsstat census (v6.4.197). See Filesystem.
lang/examples/ — one program per feature, each verified in-OS:
hello · countdown · inference · structs · defer · enums · methods · matchexpr · results · fsio (fs bindings) · forloop · userptr (#[user] pointers) · pageflags (W^X + live mmap) · caps (#[caps]) · bytes (indexing, FNV-1a in pure N) · plus the three M5 self-hosting programs above.
-
Toolchain — the in-OS C toolchain N rides on (
cc,xbm, the tcc self-host) -
Userspace — the
nyxrtruntime and the ELF a compiled N program becomes -
Syscalls — the kernel entry points an
extern syscallblock binds - Version-History — the N v0.x releases in context
-
N language home (
lang/) — README, spec, compiler, examples - N specification — the full language spec, versioned with the compiler
- N++ design — the superset plan
- HolyC — the TempleOS native language N takes its spirit from
NyxOS v6.4.363 · GPL v2 · GitHub · uselessalter on Discord · nyxos@inbox.lv
NyxOS Wiki
Getting started
Kernel
Storage & network
Graphics & apps
Userspace
HOWTO
- HOWTO-Add-a-system-call
- HOWTO-Write-a-userspace-program
- HOWTO-Add-a-shell-command
- HOWTO-Add-a-GUI-application
Reference
- Syscall-Reference
- Command-Reference
- Hardware-Reference
- Format-Reference
- Kernel-Data-Structures
- Source-Tree-Reference
Project