nish 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -555
- package/docs/AI.md +112 -33
- package/docs/INSTALL.md +79 -133
- package/llms.txt +2 -9
- package/package.json +17 -19
- package/runtime/nish.d.ts +21 -17
- package/runtime/nish.h +10 -0
- package/runtime/page-frame.d.ts +123 -0
- package/runtime/page-frame.mjs +736 -0
- package/runtime/page-game.d.ts +132 -0
- package/runtime/page-game.mjs +738 -0
- package/runtime/runtime-aes.c +85 -8
- package/runtime/runtime-bytes.c +88 -4
- package/runtime/runtime-net.c +32 -0
- package/runtime/runtime-sandbox.c +55 -28
- package/runtime/runtime-uring.c +1194 -0
- package/runtime/runtime-wasm.c +422 -0
- package/runtime/vite.mjs +1 -1
- package/scripts/build.sh +22 -6
- package/std/README.md +74 -87
- package/std/array.ts +36 -3
- package/std/collections.ts +51 -0
- package/std/crypto/hmac.ts +37 -10
- package/std/crypto/p256.ts +1388 -2664
- package/std/crypto/pki.ts +116 -4
- package/std/crypto/sha256.ts +34 -6
- package/std/crypto/x509.ts +7 -0
- package/std/host/game.ts +273 -0
- package/std/input.ts +56 -0
- package/std/json-tokenizer.ts +325 -112
- package/std/json-typed.ts +43 -8
- package/std/json-value.ts +144 -3
- package/std/json.ts +63 -8
- package/std/net/fetch.ts +22 -4
- package/std/net/http-server.ts +3382 -0
- package/std/net/http1-client-codec.ts +6 -2
- package/std/net/http1-codec.ts +137 -12
- package/std/net/http1-server.ts +83 -29
- package/std/net/http2.ts +47 -14
- package/std/net/http3-server.ts +29 -3
- package/std/net/http3.ts +180 -7
- package/std/net/prefork.ts +49 -13
- package/std/net/quic-recovery.ts +240 -9
- package/std/net/quic-stream.ts +21 -1
- package/std/net/quic.ts +98 -4
- package/std/net/router.ts +378 -31
- package/std/net/serve.ts +873 -65
- package/std/net/tls/verify.ts +19 -1
- package/std/net/url.ts +83 -35
- package/std/net/websocket.ts +74 -1
- package/std/net/webtransport.ts +7 -1
- package/std/raster.ts +837 -0
- package/std/release.ts +593 -0
- package/std/synth.ts +143 -0
- package/std/temporal.ts +3091 -0
- package/std/threads.ts +298 -0
- package/std/yaml-json.ts +368 -28
- package/std/yaml.ts +122 -27
- package/scripts/bootstrap.sh +0 -375
- package/scripts/build-id-smoke.sh +0 -28
- package/scripts/changelog-gen.mjs +0 -649
- package/scripts/changelog-section.sh +0 -28
- package/scripts/check-hardening.mjs +0 -202
- package/scripts/ci-profile.mjs +0 -200
- package/scripts/codes-registry.js +0 -85
- package/scripts/fuzz.sh +0 -280
- package/scripts/gen-diagnostic-codes.mjs +0 -243
- package/scripts/gen-json-pow5.mjs +0 -130
- package/scripts/gen-p256-table.mjs +0 -177
- package/scripts/gen-pow10-table.py +0 -80
- package/scripts/gen-regex-unicode.mjs +0 -822
- package/scripts/gen-union-scale.mjs +0 -294
- package/scripts/nish-compiler.sh +0 -19
- package/scripts/platform-package.mjs +0 -93
- package/scripts/security-scope.mjs +0 -139
- package/scripts/shard-costs.mjs +0 -429
- package/scripts/size-report.sh +0 -84
- package/scripts/smoke.sh +0 -105
- package/scripts/std-module-paths.mjs +0 -25
- package/scripts/undocumented.txt +0 -14
- package/scripts/verify-binaries.sh +0 -214
package/README.md
CHANGED
|
@@ -17,105 +17,61 @@
|
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
runtime dependency.
|
|
20
|
+
You write `.ts` files with the syntax you already know. Nish checks that every
|
|
21
|
+
value has one fixed type and memory layout, refuses everything dynamic
|
|
22
|
+
(`any`, prototypes, `eval`, exceptions), and emits LLVM IR that `clang` turns
|
|
23
|
+
into a small native binary for x86_64, ARM64 or WebAssembly. The compiler is
|
|
24
|
+
itself written in Nish.
|
|
26
25
|
|
|
27
26
|
```
|
|
28
|
-
TypeScript source ──▶
|
|
29
|
-
(src/parser.ts) (src/checker.ts) (src/emit*.ts) + runtime/runtime.c + runtime-os.c
|
|
27
|
+
TypeScript source ──▶ lexer + parser ──▶ validator + checker ──▶ LLVM IR (.ll) ──▶ clang ──▶ native binary
|
|
30
28
|
```
|
|
31
29
|
|
|
32
|
-
If it compiles, every value has one fixed, known memory layout; binaries are
|
|
33
|
-
a few kilobytes; there is no interpreter and no GC anywhere in the pipeline.
|
|
34
|
-
|
|
35
30
|
> [!CAUTION]
|
|
36
|
-
> **Do not use
|
|
37
|
-
>
|
|
38
|
-
>
|
|
39
|
-
>
|
|
40
|
-
>
|
|
41
|
-
>
|
|
42
|
-
> ([docs/security/](docs/security/README.md)), which fixed what it found and
|
|
43
|
-
> left findings open. No one independent has reviewed them. Nothing it
|
|
44
|
-
> produces should handle data, money or systems you care about. To report a
|
|
45
|
-
> vulnerability, see [SECURITY.md](SECURITY.md).
|
|
46
|
-
|
|
47
|
-
> [!WARNING]
|
|
48
|
-
> **Everything still changes.** Until 1.0, the language, the CLI flags and the
|
|
49
|
-
> IR the compiler emits all change without notice, often from one minor
|
|
50
|
-
> release to the next. Every commit compiles, tests and bootstraps itself (see
|
|
51
|
-
> [Project status](#project-status) for what is done and what is next), but
|
|
52
|
-
> nothing here is frozen. If you try it anyway, pin an exact version rather
|
|
53
|
-
> than a range, expect to fix your source when you move to a newer one, and
|
|
54
|
-
> read [CHANGELOG.md](CHANGELOG.md) before you upgrade.
|
|
55
|
-
|
|
56
|
-
---
|
|
31
|
+
> **Nish is pre-alpha. Do not use it in production.** Expect
|
|
32
|
+
> miscompilations, crashes, missing features and confusing diagnostics. Until
|
|
33
|
+
> 1.0 the language, the flags and the output change without notice, often
|
|
34
|
+
> between minor releases: pin an exact version and read the
|
|
35
|
+
> [changelog](CHANGELOG.md) before you upgrade. The code, cryptography
|
|
36
|
+
> included, has had no independent review ([security records](docs/security/README.md)).
|
|
57
37
|
|
|
58
|
-
##
|
|
59
|
-
|
|
60
|
-
Requirements: clang (LLVM 18) + lld, to produce binaries; per-OS install
|
|
61
|
-
commands are in [docs/INSTALL.md](docs/INSTALL.md).
|
|
38
|
+
## A taste
|
|
62
39
|
|
|
63
40
|
```bash
|
|
64
41
|
curl -fsSL https://raw.githubusercontent.com/amritk/nish/main/install.sh | sh
|
|
65
42
|
```
|
|
66
43
|
|
|
67
|
-
The script needs only `sh`, `curl` and `tar`. It installs the prebuilt
|
|
68
|
-
compiler into `~/.nish` and ends by printing the `export PATH=…` line to add
|
|
69
|
-
to your shell profile.
|
|
70
|
-
|
|
71
|
-
**Or with npm**, which needs Node.js 22.18+:
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
npm install -g nish # or per project: npm i -D nish
|
|
75
|
-
npx nish --version # or run it without installing
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
npm fetches the prebuilt native compiler for your machine alongside it.
|
|
79
|
-
|
|
80
|
-
> [!NOTE]
|
|
81
|
-
> **From a release tarball rather than the registry, install the pair.** The
|
|
82
|
-
> main package is a launcher and carries no compiler: installed on its own it
|
|
83
|
-
> has nothing to hand over to and says so, exiting 3.
|
|
84
|
-
> The same is true on a platform this project publishes no binary for — musl,
|
|
85
|
-
> FreeBSD, 32-bit anything — which since 0.6.0 gets a diagnostic naming the four
|
|
86
|
-
> that do rather than the TypeScript compiler under Node that used to ship
|
|
87
|
-
> beside it. [docs/INSTALL.md](docs/INSTALL.md) §2 has the table of what is
|
|
88
|
-
> built for what, and what is left for a platform outside it.
|
|
89
|
-
|
|
90
|
-
> [!TIP]
|
|
91
|
-
> Building from source works just as well: `git clone`, `npm ci`,
|
|
92
|
-
> `bash scripts/fetch-seed.sh`, `npm run build`, then `build/nish ...` wherever this README says `nish`.
|
|
93
|
-
> The build is a bootstrap: the previous release's `nish` (the seed, fetched
|
|
94
|
-
> by `scripts/fetch-seed.sh`, or named with `NISH_BOOTSTRAP=<path>`) compiles
|
|
95
|
-
> `src/`, and that compiler compiles `src/` again into `build/nish`.
|
|
96
|
-
|
|
97
44
|
`hello.ts`:
|
|
98
45
|
|
|
99
46
|
```ts
|
|
100
|
-
export const main = ():
|
|
47
|
+
export const main = (): i32 => {
|
|
101
48
|
console.log("hello from Nish");
|
|
102
|
-
return 0;
|
|
49
|
+
return 0; // the process exit code
|
|
103
50
|
};
|
|
104
51
|
```
|
|
105
52
|
|
|
106
53
|
```bash
|
|
107
|
-
nish hello.ts
|
|
108
|
-
|
|
109
|
-
nish hello.ts -o hello.ll
|
|
110
|
-
nish run hello.ts # build into a cache and run it: a script, still native
|
|
54
|
+
nish run hello.ts # build into a cache and run it
|
|
55
|
+
nish hello.ts --link hello # a native binary, about 4.7 KB
|
|
56
|
+
nish hello.ts -o hello.ll # just the LLVM IR
|
|
111
57
|
```
|
|
112
58
|
|
|
113
|
-
|
|
59
|
+
A short program can skip `main` and read like a script:
|
|
114
60
|
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #2
|
|
61
|
+
```ts
|
|
62
|
+
const square = (n: i32): i32 => n * n
|
|
118
63
|
|
|
64
|
+
const sides = [3, 4, 5]
|
|
65
|
+
for (const side of sides) {
|
|
66
|
+
console.log(square(side))
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The IR is readable. `examples/add.ts`, `a + b` on two `number`s (32-bit
|
|
71
|
+
integers by default), compiles to a checked add: an overflow panics instead
|
|
72
|
+
of wrapping, and a sum the compiler proves fits is a plain `add nsw`.
|
|
73
|
+
|
|
74
|
+
```llvm
|
|
119
75
|
define noundef i32 @add(i32 noundef %a, i32 noundef %b) #0 {
|
|
120
76
|
entry:
|
|
121
77
|
%0 = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
|
|
@@ -130,519 +86,198 @@ ovf.fail:
|
|
|
130
86
|
call void @nish_panic_overflow(i32 0)
|
|
131
87
|
unreachable
|
|
132
88
|
}
|
|
133
|
-
|
|
134
|
-
attributes #0 = { nounwind }
|
|
135
|
-
attributes #1 = { nounwind noreturn cold }
|
|
136
|
-
attributes #2 = { nounwind willreturn readnone }
|
|
137
89
|
```
|
|
138
90
|
|
|
139
|
-
|
|
140
|
-
`attempt to add with overflow` rather than wrapping or being undefined, and a
|
|
141
|
-
sum the compiler proves fits is a plain `add nsw` instead
|
|
142
|
-
([Semantics decisions](docs/LANGUAGE.md#semantics-decisions)).
|
|
91
|
+
Next step: [Your first program](docs/guide/getting-started/first-program.md).
|
|
143
92
|
|
|
144
|
-
|
|
145
|
-
`define i32 @add(i32 %a, i32 %b)` with the same body. Every construct's IR
|
|
146
|
-
is in [docs/IR_COOKBOOK.md](docs/IR_COOKBOOK.md).
|
|
93
|
+
## Contents
|
|
147
94
|
|
|
148
|
-
|
|
95
|
+
- [Install](#install)
|
|
96
|
+
- [The language](#the-language)
|
|
97
|
+
- [Memory without a garbage collector](#memory-without-a-garbage-collector)
|
|
98
|
+
- [The standard library](#the-standard-library)
|
|
99
|
+
- [Threads and async](#threads-and-async)
|
|
100
|
+
- [The command line](#the-command-line)
|
|
101
|
+
- [Performance and binary size](#performance-and-binary-size)
|
|
102
|
+
- [Interop](#interop)
|
|
103
|
+
- [The compiler in a browser](#the-compiler-in-a-browser)
|
|
104
|
+
- [Documentation](#documentation)
|
|
105
|
+
- [Project status](#project-status)
|
|
106
|
+
- [Contributing, security and license](#contributing-security-and-license)
|
|
107
|
+
|
|
108
|
+
## Install
|
|
109
|
+
|
|
110
|
+
The install script needs only `sh`, `curl` and `tar`, and puts the prebuilt
|
|
111
|
+
compiler in `~/.nish`. With Node.js 22.18+ there is also npm:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm install -g nish
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Linking binaries needs clang (LLVM 18) and lld. Per-OS commands, the supported
|
|
118
|
+
platforms and building from source are in
|
|
119
|
+
[Installation](docs/guide/getting-started/installation.md).
|
|
149
120
|
|
|
150
121
|
## The language
|
|
151
122
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
[`std/text`](std/text.ts) (`trim`, `splitLines`, `splitWhitespace`,
|
|
207
|
-
`replaceAll`) and [`std/regex`](std/regex.ts), regular expressions in
|
|
208
|
-
JavaScript syntax whose search time is linear in the input. For data there is
|
|
209
|
-
`std/json` (plus a tokenizer, typed decoding and a value tree), `std/yaml`,
|
|
210
|
-
`std/base64` and `std/bytes`. Programs also get `std/cli` for arguments,
|
|
211
|
-
`std/random` (a seeded `Rng`), `std/map`, `std/collections`, `std/threads`,
|
|
212
|
-
`std/sqlite` (SQLite, the database in a file) and `std/term` (raw-mode
|
|
213
|
-
terminal I/O and styling, with pixel graphics in `std/term-pixels`).
|
|
214
|
-
`nish/crypto/*` holds the primitives: SHA-1/2, HMAC, PBKDF2, HKDF,
|
|
215
|
-
ChaCha20-Poly1305, AES-GCM, X25519, Ed25519, P-256 ECDSA, bcrypt and X.509,
|
|
216
|
-
with secret material held as a wiped `Secret<T>`. `nish/net/*` holds the
|
|
217
|
-
protocols built on them: TLS 1.3, QUIC, HTTP/1.1, HTTP/2 (HPACK), HTTP/3
|
|
218
|
-
(QPACK), WebSocket (server and client), WebTransport, a URL parser, an HTTP router, a prefork
|
|
219
|
-
server and a sans-IO PostgreSQL client. The [standard
|
|
220
|
-
library](docs/guide/using-nish/standard-library.md) guide page walks through
|
|
221
|
-
them, and the [`std/` README](std/README.md) lists every module.
|
|
123
|
+
The TypeScript you know, held to one rule: every value's type and layout is
|
|
124
|
+
known at compile time.
|
|
125
|
+
|
|
126
|
+
- **Types:** `number`, fixed-width integers (`i32`, `u8`, `i64`, ...), ranged
|
|
127
|
+
`integer<Lo, Hi>`, `f64`, `boolean`, `string`, arrays, `Map` and `Set`,
|
|
128
|
+
classes, interfaces, enums, discriminated unions and `T | null`.
|
|
129
|
+
- **Code:** arrow functions, generics by monomorphisation, modules and
|
|
130
|
+
packages, `for...of`, exhaustive `switch`, `async`/`await`.
|
|
131
|
+
- **Errors:** `Result<T, E>` with `orReturn()` (Rust's `?`), and `panic` for
|
|
132
|
+
what a caller should not handle. No `throw`, no unwinding.
|
|
133
|
+
- **Refused, with the idiom to use instead:** `any`, `unknown`, `var`, `==`,
|
|
134
|
+
`try`, `typeof`, `instanceof`, prototypes, closures stored as values.
|
|
135
|
+
|
|
136
|
+
Some answers differ from JavaScript on purpose: signed overflow and integer
|
|
137
|
+
division by zero panic, and `.length` counts UTF-8 bytes.
|
|
138
|
+
|
|
139
|
+
Start with [Coming from TypeScript](docs/guide/getting-started/from-typescript.md),
|
|
140
|
+
then the language pages: [types](docs/guide/language/types.md),
|
|
141
|
+
[functions](docs/guide/language/functions.md),
|
|
142
|
+
[classes and interfaces](docs/guide/language/classes-and-interfaces.md),
|
|
143
|
+
[unions](docs/guide/language/unions.md),
|
|
144
|
+
[generics](docs/guide/language/generics.md),
|
|
145
|
+
[errors](docs/guide/language/errors.md) and
|
|
146
|
+
[modules](docs/guide/language/modules.md). The normative rules are in the
|
|
147
|
+
[language reference](docs/LANGUAGE.md); writing Nish with an AI, start from
|
|
148
|
+
[docs/AI.md](docs/AI.md) and [llms.txt](llms.txt).
|
|
149
|
+
|
|
150
|
+
## Memory without a garbage collector
|
|
151
|
+
|
|
152
|
+
There is no GC and no `free`, so use-after-free and double free cannot be
|
|
153
|
+
written. The compiler places each value: on the stack when it provably dies
|
|
154
|
+
with its function, in an arena scope the compiler opens and releases for you,
|
|
155
|
+
or in a region you free in a long-running program. Array indexes are
|
|
156
|
+
bounds-checked unless a proof shows they are in range, `null` is a separate
|
|
157
|
+
type that must be narrowed, and the only ways around a check are imports you
|
|
158
|
+
ask for by name (`nish:unsafe`).
|
|
159
|
+
|
|
160
|
+
Read [Memory](docs/guide/language/memory.md) and
|
|
161
|
+
[Regions](docs/guide/language/regions.md).
|
|
162
|
+
|
|
163
|
+
## The standard library
|
|
164
|
+
|
|
165
|
+
[`std/`](std/README.md) is Nish written in Nish, compiled with your program,
|
|
166
|
+
so what you never call is dropped at the link:
|
|
167
|
+
|
|
168
|
+
- **Data and text:** JSON, YAML, regular expressions with linear-time search,
|
|
169
|
+
base64, bytes, text helpers, sorting and collections.
|
|
170
|
+
- **Programs:** a test runner, argument parsing, terminal I/O, SQLite, a
|
|
171
|
+
seeded random generator.
|
|
172
|
+
- **Crypto:** SHA-1/2, HMAC, HKDF, PBKDF2, ChaCha20-Poly1305, AES-GCM, X25519,
|
|
173
|
+
Ed25519, P-256 and P-384 ECDSA, RSA, bcrypt and X.509, with keys held as a
|
|
174
|
+
wiped `Secret<T>`.
|
|
175
|
+
- **Network:** TLS 1.3, HTTP/1.1, HTTP/2, HTTP/3 and QUIC, WebSocket,
|
|
176
|
+
WebTransport, an HTTP router and client, DNS and PostgreSQL.
|
|
222
177
|
|
|
223
178
|
```ts
|
|
224
179
|
import { Suite } from "nish/testing";
|
|
225
180
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
181
|
+
const sumOf = (xs: i32[]): i32 => {
|
|
182
|
+
let total = 0;
|
|
183
|
+
for (const x of xs) {
|
|
184
|
+
total = total + x;
|
|
185
|
+
}
|
|
186
|
+
return total;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const main = (): i32 => {
|
|
190
|
+
const t = new Suite("sums");
|
|
191
|
+
t.eqI32("four numbers", sumOf([3, 9, 4, 9]), 25);
|
|
229
192
|
return t.done(); // prints the report; 0 when nothing failed
|
|
230
193
|
};
|
|
231
194
|
```
|
|
232
195
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
`test("name", () => ...)` closures.
|
|
241
|
-
|
|
242
|
-
The suite's own golden cases are run by [`tests/nish/run.ts`](tests/nish/run.ts),
|
|
243
|
-
which is this repository's test harness written in the language it tests:
|
|
244
|
-
`readdirSync` finds the cases, `spawnSyncTo` captures each compile and each run,
|
|
245
|
-
and the IR is diffed against the golden line by line. `npm run test:nish` runs it
|
|
246
|
-
over the whole corpus.
|
|
247
|
-
|
|
248
|
-
[`tests/nish/cli.ts`](tests/nish/cli.ts) is the other half of that idea, pointed
|
|
249
|
-
at the compiler's own promises rather than at its output: `--help` on stdout with
|
|
250
|
-
exit 0 against the same text on stderr with exit 2, one flat `--json` object per
|
|
251
|
-
diagnostic with a stable code, and each documented exit-code band. It reads those
|
|
252
|
-
objects with `std/json` and takes the version it expects out of `package.json`, so
|
|
253
|
-
a release cannot leave the expectation behind (`npm run test:cli` runs it
|
|
254
|
-
against `build/nish`).
|
|
196
|
+
Tour it in [The standard library](docs/guide/using-nish/standard-library.md);
|
|
197
|
+
there are guide pages for an [API server](docs/guide/using-nish/api-server.md),
|
|
198
|
+
an [HTTP client](docs/guide/using-nish/http-client.md),
|
|
199
|
+
[PostgreSQL](docs/guide/using-nish/postgres.md),
|
|
200
|
+
[SQLite](docs/guide/using-nish/sqlite.md),
|
|
201
|
+
[password hashing](docs/guide/using-nish/password-hashing.md) and
|
|
202
|
+
[more](docs/guide/index.md).
|
|
255
203
|
|
|
256
|
-
|
|
204
|
+
## Threads and async
|
|
257
205
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
checked, and every way to give a check up is a flag you pass or a builtin you
|
|
263
|
-
call on purpose.
|
|
264
|
-
|
|
265
|
-
| Bug class | What Nish does | Reference |
|
|
266
|
-
|:---|:---|:---|
|
|
267
|
-
| Use-after-free, double free | Not expressible: nothing is freed individually. Four compile-time mechanisms decide where a value lives — a stack `alloca` when escape analysis proves it dies with the frame, an automatic arena scope when a function's temporaries do, a `nish_arena_keep` reclaim at the call site for a returned string, the bump arena otherwise — and the arena goes back when `main` returns | [Memory model](docs/LANGUAGE.md#memory-model), [wp6-memory.md](docs/wp6-memory.md) |
|
|
268
|
-
| Out-of-bounds read or write | Every `a[i]`, `a[i] op= v`, `s.charCodeAt(i)`, `s.slice(a, b)` and `a.pop()` is bounds-checked, with an unsigned compare, so a negative index fails too; the failure prints `index out of range: <i> >= <len>` (or, for `slice`, `slice out of range: [<a>, <b>) of length <len>`) and exits 1. Where a flow-sensitive proof shows the index is already in range — a loop condition, a length guard, a hoisted `const n = a.length`, an unsigned index — **no check is emitted at all**, and the checks that survive inside a loop say so as a `performance` warning naming the guard that would remove them | [Element access](docs/LANGUAGE.md#element-access), `tests/cases/arr_bounds_panic`, `arr_bounds_proven` |
|
|
269
|
-
| Null dereference | `T \| null` is a separate type, for pointers only; member access needs a narrowing the checker accepts, and `?.` appears only in a chain that ends in a `??` default — which is what lets the emitter put `nonnull dereferenceable` on every pointer that is not one | [Nullable types](docs/LANGUAGE.md#nullable-types) |
|
|
270
|
-
| Uninitialised memory | `new Array<T>(n)` zero-fills and rejects pointer element types, because a zeroed pointer would be a null nobody declared; class fields are definitely assigned | [Classes](docs/LANGUAGE.md#classes), `tests/cases/arr_new_zeroed` |
|
|
271
|
-
| Unwinding past a release | There is none. Every function is `nounwind`; a failure a caller should handle is a `Result<T, E>` and one it should not is `panic(message)` — stderr, exit 1 | [Result](docs/LANGUAGE.md#result-and-error-handling) |
|
|
272
|
-
|
|
273
|
-
### What happens when the proof fails
|
|
274
|
-
|
|
275
|
-
This is where designs actually differ. Asked to place a value it cannot show
|
|
276
|
-
dies with its frame, Rust refuses to compile it, Go falls back to the garbage
|
|
277
|
-
collector, and Zig hands the question back to you and an allocator. Nish
|
|
278
|
-
leaves the value in the arena, where it stays until `main` returns.
|
|
279
|
-
|
|
280
|
-
So [`src/escape.ts`](src/escape.ts) and the whole-program fact
|
|
281
|
-
fixpoint are optimisations and nothing else: a refusal costs memory and never
|
|
282
|
-
correctness, and no program is rejected for a lifetime reason. The compiler
|
|
283
|
-
says so out loud where the cost is real: assigning an allocation to a local
|
|
284
|
-
that already holds one drops the old value where nothing can free it *and*
|
|
285
|
-
costs the whole function its arena scope, and that is a `performance`
|
|
286
|
-
diagnostic naming both rewrites ([Diagnostics](docs/LANGUAGE.md#diagnostics-and-debugging-flags), on by
|
|
287
|
-
default, never fatal). That is the
|
|
288
|
-
trade the whole memory design rests on — the arena discipline a compiler pass
|
|
289
|
-
or a frame loop would otherwise be written around by hand, moved into the
|
|
290
|
-
compiler. `tests/cases/mem_*` pin the placements, and `Arena.used()` either
|
|
291
|
-
side of a 100000-iteration loop is how the suite checks that a scope really
|
|
292
|
-
does recycle.
|
|
293
|
-
|
|
294
|
-
### Which language is this like
|
|
295
|
-
|
|
296
|
-
Not any one of them; it is more useful to say which piece came from where.
|
|
297
|
-
|
|
298
|
-
| Concern | Closest to | Not |
|
|
299
|
-
|:---|:---|:---|
|
|
300
|
-
| Lifetimes | Go's escape analysis, over a Zig-style arena discipline the compiler writes for you | Rust: no ownership, no borrow checker, no lifetime annotations |
|
|
301
|
-
| Bounds and panics | Rust with `panic=abort` | C |
|
|
302
|
-
| Null | Kotlin and C# nullable reference types: flow narrowing, not a wrapper type | Rust's `Option<T>` |
|
|
303
|
-
| Errors | Rust: `Result<T, E>`, and `orReturn()` is `?` | exceptions, or Go's second return value |
|
|
304
|
-
| Signed overflow | Rust's debug profile: a checked panic, in every build, unless the compiler proves the operation fits; Rust's `wrapping_add` as an imported call to opt out at one site | C, where it is undefined |
|
|
305
|
-
| Syntax | TypeScript | |
|
|
306
|
-
|
|
307
|
-
The older relative is region inference as in Cyclone and MLKit: regions the
|
|
308
|
-
compiler infers, bracketed by a mark and a release, which is exactly what the
|
|
309
|
-
arena scopes and the call-site reclaim are. This version is deliberately
|
|
310
|
-
weaker: one global arena, per-function granularity, no region polymorphism.
|
|
311
|
-
|
|
312
|
-
### Where it is not safe
|
|
206
|
+
`nish/threads` gives parallel maps and reduces, scoped tasks, a `Mutex` that
|
|
207
|
+
owns its data, atomics and channels, with data races and deadlocks refused at
|
|
208
|
+
compile time. `async` functions compile to a frame and a resume switch, with
|
|
209
|
+
no promise ever a value.
|
|
313
210
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
- **`uncheckedGet` and `uncheckedSet`** from `nish:unsafe` read and write an
|
|
318
|
-
element with no bounds check, after which an out-of-range index at that site
|
|
319
|
-
is undefined behaviour. A module reaches them only through the import, so
|
|
320
|
-
every module that gives up a check says so at its top and every site is a
|
|
321
|
-
call (`tests/cases/unsafe_get_set`). That is a different thing from the
|
|
322
|
-
proof above: the proof removes a check the compiler showed was never going
|
|
323
|
-
to fire, and changes nothing about what the program means
|
|
324
|
-
([`nish:unsafe`](docs/LANGUAGE.md#nishunsafe-unchecked-access-and-defined-wrapping)).
|
|
325
|
-
No flag turns the checks off for a whole program.
|
|
326
|
-
- **Interop** hands a pointer to a C, wasm or N-API host, and what happens to
|
|
327
|
-
it there is the host's business
|
|
328
|
-
([wp8-interop.md](docs/wp8-interop.md)).
|
|
329
|
-
|
|
330
|
-
Memory-safe like Go, allocated like Zig, errors like Rust, nulls like Kotlin,
|
|
331
|
-
overflow checked like Rust's debug builds — with two C-shaped holes you have to ask for by name. What it
|
|
332
|
-
buys is the output: no GC, no runtime, and the sizes under
|
|
333
|
-
[Performance and binary size](#performance-and-binary-size).
|
|
211
|
+
Read [Threads](docs/guide/using-nish/threads.md),
|
|
212
|
+
[Async](docs/guide/language/async.md) and
|
|
213
|
+
[An async server](docs/guide/using-nish/async-server.md).
|
|
334
214
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
## Command line
|
|
215
|
+
## The command line
|
|
338
216
|
|
|
339
217
|
```
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
218
|
+
nish <file.ts> [more.ts ...] [flags] compile to LLVM IR (--link for a binary)
|
|
219
|
+
nish run [flags] <file.ts> [args ...] build, cache and run it
|
|
220
|
+
nish --help every flag, the exit codes, examples
|
|
343
221
|
```
|
|
344
222
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
line that points at `--help`. [The CLI](docs/guide/using-nish/cli.md) walks
|
|
350
|
-
through the flags you will reach for. Among them: `--link` builds a native
|
|
351
|
-
binary, and `--fix` applies the compiler's safe fixes in place.
|
|
352
|
-
`--allow`/`--deny` refuse a program that reaches more than a capability
|
|
353
|
-
policy grants, and `--update-capability-lock` records what each dependency
|
|
354
|
-
reaches. `--deny-panics` refuses any panic the compiler cannot prove away.
|
|
355
|
-
`--emit-ts` writes the program out as plain TypeScript instead of IR.
|
|
356
|
-
|
|
357
|
-
Exit codes: `0` success, `1` compile error (`file:line:col: error: ...` plus
|
|
358
|
-
a caret excerpt), `2` usage error, `3` toolchain error, `70` internal
|
|
359
|
-
compiler error (please
|
|
360
|
-
[report it](https://github.com/amritk/nish/issues/new/choose) with the input and
|
|
361
|
-
the command line).
|
|
362
|
-
A compile that fails reports every error it found (statement by statement,
|
|
363
|
-
declaration by declaration), in source order, up to 20 before `...and N more
|
|
364
|
-
errors`; `--json` gives editors and tools the same list as
|
|
365
|
-
`{"file","line","column","endLine","endColumn","severity","code","message"}`
|
|
366
|
-
objects, one per line, where `code` is a stable identifier for the rule
|
|
367
|
-
(`NL1013`, `NL2231`) and is what to match on rather than the prose. Failures
|
|
368
|
-
with no source position — an unusable C toolchain, an internal error — are JSON
|
|
369
|
-
objects too, so `--json` never leaves a caller with an empty stdout.
|
|
370
|
-
`--help` prints on stdout and exits `0`; only a usage *error* goes to stderr
|
|
371
|
-
with `2`. `-g` adds a DWARF line table and variables to the IR so
|
|
372
|
-
`gdb`/`lldb` step through the `.ts` source of a `--link`ed binary
|
|
373
|
-
([docs/wp10-ci.md](docs/wp10-ci.md)).
|
|
374
|
-
Multi-file programs: `nish examples/multi/main.ts --link build/multi && ./build/multi; echo $?`
|
|
375
|
-
prints `49`.
|
|
376
|
-
|
|
377
|
-
**`nish run` is the scripting shape.** `nish run tool.ts a b` compiles
|
|
378
|
-
`tool.ts`, links it into a cache, and starts it with `a b` as its arguments.
|
|
379
|
-
Its stdin, stdout and stderr are the program's, and its exit status is the
|
|
380
|
-
program's once it starts (`128 + n` for a signal). The options before the file
|
|
381
|
-
are the compiler's (`--number-mode f64`, `--profile speed`, `-g`), and
|
|
382
|
-
everything after it is the program's, `--help` included. Nothing is
|
|
383
|
-
interpreted: every run compiles, which takes milliseconds, and links only when
|
|
384
|
-
the IR, the recipe or the runtime is new, so the first run of an edit pays for
|
|
385
|
-
one `--profile debug` link (the default here, and the fast one) and every run
|
|
386
|
-
after that starts the cached binary. The cache is `$XDG_CACHE_HOME/nish/run`,
|
|
387
|
-
or `~/.cache/nish/run`. Each entry is one program, so `rm -rf` of it is always
|
|
388
|
-
safe. Beside it, `nish/runtime` keeps the C runtime compiled once per profile,
|
|
389
|
-
`-g`, `--threads` and C compiler, so a link (a run's or `--link`'s) compiles
|
|
390
|
-
only the program's own modules, each in parallel; removing it costs one
|
|
391
|
-
recompile of the runtime. `-o`, `--link`, `--target`, the `--emit-*` sidecars and
|
|
392
|
-
`--profile wasi` write something a run keeps to itself, so they are usage
|
|
393
|
-
errors there, and performance warnings are not printed, because stderr belongs
|
|
394
|
-
to the program.
|
|
395
|
-
|
|
396
|
-
Without `--link`, build the IR yourself: `clang add.ll examples/main.c runtime/runtime.c runtime/runtime-text.c runtime/runtime-os.c -ffp-contract=off -o app`
|
|
397
|
-
(a program that uses threads, the host calls or `nish:net` also names
|
|
398
|
-
`runtime/runtime-parallel.c`, `runtime-host.c` or `runtime-net.c`; the
|
|
399
|
-
`overriding the module target triple` warning is harmless: the IR is
|
|
400
|
-
target-neutral unless you pass `--target`; `-Wno-override-module` silences
|
|
401
|
-
it), or step by step with `llvm-as`, `llc -O2 -filetype=obj`, and
|
|
402
|
-
`opt -S -O2` to watch `mem2reg` turn the `alloca` locals into registers.
|
|
403
|
-
`opt` and `llc` only vectorise when the module carries a data layout, so
|
|
404
|
-
pass `--target host` (or a triple) when you inspect optimised IR by hand;
|
|
405
|
-
`--link` never needs it because clang supplies the layout. Cross-compile
|
|
406
|
-
with `--target aarch64-unknown-linux-gnu` / `wasm32-wasi` plus
|
|
407
|
-
`clang --target=...`, or with `llc -mtriple=...`.
|
|
223
|
+
Errors arrive all at once as `file:line:col` with a caret, or as JSON with a
|
|
224
|
+
stable code for editors. `--fix` applies safe fixes, `--allow`/`--deny` refuse
|
|
225
|
+
a program that reaches more capabilities (files, network, processes) than you
|
|
226
|
+
grant, and `--emit-ts` writes the program back out as plain TypeScript.
|
|
408
227
|
|
|
409
|
-
|
|
228
|
+
Read [The CLI](docs/guide/using-nish/cli.md) and
|
|
229
|
+
[Sandboxing](docs/guide/using-nish/sandbox.md).
|
|
410
230
|
|
|
411
231
|
## Performance and binary size
|
|
412
232
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
| Profile | Bytes | What it does |
|
|
420
|
-
|:---|---:|:---|
|
|
421
|
-
| `debug` | 15,072 | `clang` defaults: no optimisation, symbols kept. |
|
|
422
|
-
| `speed` | 4,528 | `-O3 -flto`, section GC, unwind tables off, stripped. Rust `--release`. |
|
|
423
|
-
| `size` | 4,512 | `-Oz -flto`, plus hidden visibility and no stack protector. Rust `opt-level="z"`. |
|
|
424
|
-
| `wasm` | 279 | Freestanding `wasm32` module, every function exported, stripped. |
|
|
425
|
-
| `wasi` | 42,228 (`argv.ts`) | `wasm32-wasi` command module: the runtime linked against wasi-libc, `_start` runs `main`; needs a WASI sysroot ([INSTALL.md](docs/INSTALL.md#wasi-optional-for---profile-wasi)). |
|
|
426
|
-
|
|
427
|
-
`hello.ts` with `--link` is 4,712 bytes. The runtime is seventeen translation units
|
|
428
|
-
with a measured ceiling each, so that the core does not grow every time the
|
|
429
|
-
language reaches further into the operating system, and section GC drops
|
|
430
|
-
whatever a program does not call: `runtime.c` is the 1,723 bytes every program
|
|
431
|
-
touches (one chunked bump arena with O(1) reset and mark/release, string
|
|
432
|
-
parsing, `Math.random`, `process.argv`, array growth, the panic paths),
|
|
433
|
-
`runtime-text.c` the 1,787 bytes of strings and JavaScript-exact number
|
|
434
|
-
formatting, which a wasm module links too, `runtime-os.c` the 1,530 bytes
|
|
435
|
-
that wrap a system call (exit, files, directories, subprocesses, the
|
|
436
|
-
environment, the clock), and `runtime-parallel.c`, `runtime-cross.c`,
|
|
437
|
-
`runtime-host.c`, `runtime-net.c`, `runtime-simd.c`, `runtime-aes.c`,
|
|
438
|
-
`runtime-sha256.c`, `runtime-chacha20.c`, `runtime-term.c`, `runtime-bytes.c`, `runtime-checksum.c`, `runtime-sandbox.c`, `runtime-shm.c` and `runtime-region.c` hold threads, the copies that cross between
|
|
439
|
-
their arenas, the host calls (wall clock, entropy, signals), `nish:net`'s sockets,
|
|
440
|
-
the vector text search, AES-GCM, SHA-256's block, ChaCha20's keystream, `nish:term`'s stdin and terminal, the
|
|
441
|
-
byte-class runs JSON steps over, the CRC-32 kernels, `--sandbox`'s confinement, the shared-memory regions of `nish/sync/shm` and the regions a program frees one at a time — see
|
|
442
|
-
[docs/wp7-runtime.md](docs/wp7-runtime.md#runtime-additions-and-budget) for the
|
|
443
|
-
budgets and the reasoning. `Math.*` calls are LLVM intrinsics, so pure functions
|
|
444
|
-
stay `readnone`.
|
|
445
|
-
|
|
446
|
-
Memory is the part that usually costs a compiled-JavaScript design its
|
|
447
|
-
speed, so it is done statically ([docs/wp6-memory.md](docs/wp6-memory.md)):
|
|
448
|
-
a `new`, object literal or array literal that provably never outlives its
|
|
449
|
-
function is an `alloca` (LLVM's SROA then turns its fields into registers);
|
|
450
|
-
what does reach the arena is bumped inline (a load, an add, a compare and a
|
|
451
|
-
store); a function whose arena temporaries all die with it brackets its body
|
|
452
|
-
with `nish_arena_mark` / `nish_arena_release`, so hot loops keep the arena
|
|
453
|
-
flat. Every LLVM attribute the compiler emits (`nounwind`, `willreturn`,
|
|
454
|
-
`readnone`/`readonly`, `noundef`, `zeroext`, `nonnull`, `noalias`,
|
|
455
|
-
`nocapture`, `dereferenceable`) is a proved guarantee, never a hint; the
|
|
456
|
-
rules are in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md#attribute-soundness-rules).
|
|
457
|
-
|
|
458
|
-
The benchmark suite (`bench/`: fib, n-body, spectral norm, sieve, string
|
|
459
|
-
building, a `Vec3` method loop, each in Nish, C and Rust with identical
|
|
460
|
-
algorithms and a shared checksum) is run by `node bench/run.mjs`, which
|
|
461
|
-
writes [docs/BENCHMARKS.md](docs/BENCHMARKS.md): wall time, binary size and
|
|
462
|
-
peak memory per column, plus the exact build commands. The analysis of every
|
|
463
|
-
gap, and what `nsw` and PGO (`scripts/build.sh --pgo-generate` /
|
|
464
|
-
`--pgo-use`) bought when overflow was still undefined, is in [docs/wp9-optimisation.md](docs/wp9-optimisation.md);
|
|
465
|
-
the rules of the game are in [bench/README.md](bench/README.md).
|
|
233
|
+
No GC, no embedded engine, and every LLVM attribute the compiler emits is a
|
|
234
|
+
proved guarantee. `hello.ts` links to about 4.7 KB; a freestanding wasm
|
|
235
|
+
module can be a few hundred bytes. The benchmark suite runs the same
|
|
236
|
+
algorithms in Nish, C and Rust and records wall time, size and memory in
|
|
237
|
+
[docs/BENCHMARKS.md](docs/BENCHMARKS.md).
|
|
466
238
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
## Interop: export, do not embed
|
|
239
|
+
## Interop
|
|
470
240
|
|
|
471
|
-
Nish never embeds a JavaScript engine
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
[
|
|
476
|
-
I/O, HTTP, npm packages math, parsing, data transforms, hot loops
|
|
477
|
-
cross the boundary once per batch, not once per element
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
- `scripts/build.sh --profile wasm` produces a module `WebAssembly.instantiate`
|
|
481
|
-
loads directly (`examples/node-host.mjs`); exports use the plain C ABI.
|
|
482
|
-
Add `runtime/runtime-wasm.c` (arena + arrays, no libc) when a function
|
|
483
|
-
takes or returns an array.
|
|
484
|
-
- `--emit-napi` + `scripts/build.sh --profile napi` build a `.node` addon
|
|
485
|
-
with argument type checks (`examples/node-addon.mjs`).
|
|
486
|
-
- Buffers cross as typed arrays: an Nish `Int32Array` / `Float64Array` /
|
|
487
|
-
`BigInt64Array` parameter (the spellings of `i32[]` / `f64[]` / `i64[]`,
|
|
488
|
-
one layout) is a JS typed array on both paths. The addon borrows it
|
|
489
|
-
(zero-copy; writes are visible in JS), the wasm loader that `--emit-dts`
|
|
490
|
-
writes next to the `.d.ts` copies it into the module's memory and results
|
|
491
|
-
back out; strings cross the addon as copies (`examples/arrays.ts`).
|
|
492
|
-
- `--emit-header` writes C prototypes (`int32_t add(int32_t a, int32_t b);`,
|
|
493
|
-
`double sumF64(const nish_array *xs);`) next to `runtime/nish.h`, the
|
|
494
|
-
public runtime ABI (arena, strings, arrays, `nish_reset_arena`,
|
|
495
|
-
`nish_arena_mark` / `nish_arena_release` for a host that manages batches).
|
|
496
|
-
- `--emit-ts <dir>` writes the program back out as TypeScript that Node 22.18+
|
|
497
|
-
runs with type stripping, one file per module plus an `entry.ts`, importing
|
|
498
|
-
its builtins from `nish/runtime`; overflow and bounds checks stay, as
|
|
499
|
-
helpers (`docs/guide/using-nish/to-typescript.md`).
|
|
500
|
-
- An N-API call costs about 30 ns and a wasm call about 2 ns before any work
|
|
501
|
-
is done; one call with a 1M-element `Float64Array` runs at 0.5 ns/element
|
|
502
|
-
(`node bench/ffi.mjs`), so pass whole buffers, not elements.
|
|
503
|
-
|
|
504
|
-
Details: [docs/wp8-interop.md](docs/wp8-interop.md).
|
|
505
|
-
|
|
506
|
-
---
|
|
241
|
+
Nish never embeds a JavaScript engine; JavaScript calls Nish. A program
|
|
242
|
+
builds to a wasm module or a Node addon with generated `.d.ts` types, the
|
|
243
|
+
addon borrows typed arrays without a copy, and `--emit-header` writes C
|
|
244
|
+
prototypes for a C host. Read [Calling Nish from other languages](docs/guide/using-nish/interop.md)
|
|
245
|
+
and [Browser games](docs/guide/using-nish/browser-games.md).
|
|
507
246
|
|
|
508
247
|
## The compiler in a browser
|
|
509
248
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
```bash
|
|
514
|
-
nish src/compile.ts --link web/nish.wasm --profile wasi
|
|
515
|
-
node web/compile.mjs web/nish.wasm examples/add.ts # the IR, from a Web Worker
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
That module is about 480 KB (140 KB gzipped) and lexes, checks and emits IR
|
|
519
|
-
with no server in the loop; `web/index.html` is a playground built on it and
|
|
520
|
-
`web/wasi.mjs` is the in-memory filesystem it runs against. It stops at the
|
|
521
|
-
IR — `clang` and `wasm-ld` are not in a page — so `--link` and `--profile` are
|
|
522
|
-
refused there. [web/README.md](web/README.md) has the rest.
|
|
523
|
-
|
|
524
|
-
---
|
|
525
|
-
|
|
526
|
-
## Self-hosting
|
|
527
|
-
|
|
528
|
-
`src/` is the compiler, and the only one: lexer, parser, checker and emitter,
|
|
529
|
-
written in Nish, with no `typescript` package underneath. It compiles its own
|
|
530
|
-
source to a fixed point:
|
|
249
|
+
The compiler compiles itself to WebAssembly, about 140 KB gzipped, and checks
|
|
250
|
+
and emits IR in a Web Worker with no server. [web/README.md](web/README.md)
|
|
251
|
+
has the playground.
|
|
531
252
|
|
|
532
|
-
|
|
533
|
-
IR(stage1, src/) == IR(stage2, src/) byte for byte, and stage3 == stage2
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
The chain starts from a seed, the previous release's `nish` binary, the way
|
|
537
|
-
Rust and Go build themselves: stage1 is `src/` built by the seed, stage2 is
|
|
538
|
-
`src/` built by stage1 and is what gets installed, and stage3, built by
|
|
539
|
-
stage2, has to reproduce stage2 file for file. `scripts/bootstrap.sh --verify`
|
|
540
|
-
asserts both equalities, and `npm test` re-proves them on every run. Compiling
|
|
541
|
-
the whole compiler costs it **91 ms and 86 MB**; the TypeScript compiler it
|
|
542
|
-
replaced took 786 ms and 178 MB for the same input.
|
|
543
|
-
|
|
544
|
-
```bash
|
|
545
|
-
bash scripts/fetch-seed.sh # the last release, into build/seed/
|
|
546
|
-
npm run build # seed -> stage1 -> stage2 = build/nish
|
|
547
|
-
build/nish hello.ts --link hello # -o, --link, --profile, its own directories
|
|
548
|
-
```
|
|
253
|
+
## Documentation
|
|
549
254
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
[
|
|
560
|
-
|
|
561
|
-
---
|
|
255
|
+
| Read | For |
|
|
256
|
+
|:---|:---|
|
|
257
|
+
| [The user guide](docs/guide/index.md) | Learning Nish page by page, every example compiled by the test suite |
|
|
258
|
+
| [Installation](docs/guide/getting-started/installation.md) | Platforms, LLVM, WASI, building from source |
|
|
259
|
+
| [Language reference](docs/LANGUAGE.md) | Every rule, each citing the test that proves it |
|
|
260
|
+
| [docs/AI.md](docs/AI.md), [llms.txt](llms.txt) | The whole language in one pass, for people and models writing it |
|
|
261
|
+
| [`std/` README](std/README.md) | Every standard library module |
|
|
262
|
+
| [FAQ](docs/FAQ.md) | Why the design is the way it is |
|
|
263
|
+
| [IR cookbook](docs/IR_COOKBOOK.md) | The exact IR of every construct |
|
|
264
|
+
| [Roadmap](docs/roadmap/index.md) | What is built and what is next |
|
|
265
|
+
| [Changelog](CHANGELOG.md) | What changed in each release |
|
|
562
266
|
|
|
563
267
|
## Project status
|
|
564
268
|
|
|
565
|
-
Pre-alpha
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
| M6 "One compiler" | the TypeScript twin deleted; `src/` built by the last release, the seed | done |
|
|
581
|
-
|
|
582
|
-
Not in the language yet, in the order they are likely to land: optional
|
|
583
|
-
reference counting for objects that must outlive an arena reset, and dynamic
|
|
584
|
-
dispatch — which would be a trait object over an interface, since inheritance
|
|
585
|
-
was removed ([docs/wp25-inheritance.md](docs/wp25-inheritance.md)) and every
|
|
586
|
-
method call names one symbol today.
|
|
587
|
-
Generic functions, classes, interfaces and methods compile — each
|
|
588
|
-
instantiation becomes its own specialised function or struct
|
|
589
|
-
([docs/wp18-generics.md](docs/wp18-generics.md)) — while generic type aliases,
|
|
590
|
-
closures as values (an arrow written as a call's argument may read the
|
|
591
|
-
caller's `const` locals and parameters, but is never stored) and `try`/`catch` are refusals
|
|
592
|
-
rather than gaps, each with the message and the idiom to use instead
|
|
593
|
-
([docs/LANGUAGE.md](docs/LANGUAGE.md#forbidden-constructs-phase-0-validator)).
|
|
594
|
-
Release engineering (`--version`, exit codes, npm packaging, tag-driven
|
|
595
|
-
releases) landed with WP12; see [CHANGELOG.md](CHANGELOG.md) and
|
|
596
|
-
[docs/wp12-release.md](docs/wp12-release.md). The plan itself is
|
|
597
|
-
[docs/MASTER_PLAN.md](docs/MASTER_PLAN.md), and what is built and what is next is
|
|
598
|
-
the [roadmap](docs/roadmap/index.md).
|
|
599
|
-
|
|
600
|
-
---
|
|
601
|
-
|
|
602
|
-
## Contributing
|
|
603
|
-
|
|
604
|
-
```bash
|
|
605
|
-
npm ci
|
|
606
|
-
bash scripts/fetch-seed.sh # the last release into build/seed/, once
|
|
607
|
-
npm run build # seeded bootstrap into build/nish (NISH_BOOTSTRAP=<nish> names the seed)
|
|
608
|
-
npm test # build + goldens, llvm-as, native round trips, runtime, layout, memory, interop, bench checksums, differential
|
|
609
|
-
node tests/run.js locals # only cases whose name contains "locals"
|
|
610
|
-
npm run test:update # write missing .ll goldens for new cases
|
|
611
|
-
npm run test:diff # every whole program natively and under Node (runtime/shim.mjs), compared byte for byte
|
|
612
|
-
node tests/differential/fuzz.js --stage1 --count 200 # random integer programs, the released seed's IR against HEAD's; prints the seed
|
|
613
|
-
npm run check # tsc --noEmit: an ambient type-check of src/, std/ and tests/nish/
|
|
614
|
-
npm run lint # Biome style lint (advisory, never a compile gate)
|
|
615
|
-
npm run smoke # build and run every example with a main
|
|
616
|
-
scripts/bootstrap.sh --verify # the whole chain, with IR(stage1) == IR(stage2) and stage3 == stage2 asserted
|
|
617
|
-
node bench/run.mjs # the benchmark suite; rewrites docs/BENCHMARKS.md (about 3 minutes)
|
|
618
|
-
docs/cookbook/regen.sh # refresh docs/IR_COOKBOOK.md; node docs/check-links.mjs checks the links
|
|
619
|
-
```
|
|
620
|
-
|
|
621
|
-
Read [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) (the pipeline, side tables,
|
|
622
|
-
the add-a-construct checklist, ABI guard tests) and the conventions in
|
|
623
|
-
[docs/MASTER_PLAN.md §7](docs/MASTER_PLAN.md#7-conventions-for-every-agent):
|
|
624
|
-
every construct ships with a golden `.ll`, an `llvm-as` pass, a native round
|
|
625
|
-
trip, a negative test, and its LANGUAGE.md and cookbook entries; no attribute
|
|
626
|
-
without a proof; layout changes touch `src/runtime.ts` and `runtime/runtime.c` together.
|
|
627
|
-
CI runs the suite on Ubuntu with LLVM 18, and the bootstrap and the CLI
|
|
628
|
-
contract on every platform a release ships a compiler for, macOS and ARM Linux
|
|
629
|
-
included ([docs/wp10-ci.md](docs/wp10-ci.md)). The documentation index is
|
|
630
|
-
[docs/README.md](docs/README.md). Coding guidelines for contributors and
|
|
631
|
-
coding agents are in [AGENTS.md](AGENTS.md) and [`.claude/`](.claude/).
|
|
632
|
-
|
|
633
|
-
---
|
|
634
|
-
|
|
635
|
-
## Security
|
|
636
|
-
|
|
637
|
-
Report a vulnerability privately, through GitHub's **Security → Report a
|
|
638
|
-
vulnerability**, never in a public issue. [SECURITY.md](SECURITY.md) has the
|
|
639
|
-
reporting channel, the supported versions and the threat model.
|
|
640
|
-
[docs/security/](docs/security/README.md) holds the audit record of every area
|
|
641
|
-
and the list of findings still open.
|
|
642
|
-
|
|
643
|
-
---
|
|
644
|
-
|
|
645
|
-
## License
|
|
646
|
-
|
|
647
|
-
MIT, see [LICENSE](LICENSE). Third-party code in the repository keeps its own
|
|
648
|
-
licence; see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
269
|
+
Pre-alpha and on 0.x, with no compatibility promise: a construct's spelling,
|
|
270
|
+
a flag's name and the IR either lowers to can change between minor releases.
|
|
271
|
+
Every commit compiles, tests and rebuilds the compiler with itself. The
|
|
272
|
+
[roadmap](docs/roadmap/index.md) has what is built and what is next.
|
|
273
|
+
|
|
274
|
+
## Contributing, security and license
|
|
275
|
+
|
|
276
|
+
- **Contributing:** building the compiler, the tests and the conventions are in
|
|
277
|
+
[CONTRIBUTING.md](CONTRIBUTING.md).
|
|
278
|
+
- **Security:** report a vulnerability privately through GitHub's **Security →
|
|
279
|
+
Report a vulnerability**, never in a public issue; see
|
|
280
|
+
[SECURITY.md](SECURITY.md). The audit records are in
|
|
281
|
+
[docs/security/](docs/security/README.md).
|
|
282
|
+
- **License:** MIT, see [LICENSE](LICENSE). Third-party code keeps its own
|
|
283
|
+
licence; see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|