@amritk/nish-aarch64-darwin 0.36.0 → 0.37.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.
Files changed (87) hide show
  1. package/INSTALL.md +67 -58
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +43 -4
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/nish.d.ts +736 -499
  8. package/runtime/nish.h +25 -0
  9. package/runtime/page.d.ts +53 -0
  10. package/runtime/page.mjs +146 -0
  11. package/runtime/runtime-async.c +557 -0
  12. package/runtime/runtime-wasm.c +63 -7
  13. package/scripts/build.sh +147 -5
  14. package/std/README.md +107 -82
  15. package/std/bytes.ts +23 -19
  16. package/std/compress/checksum.ts +1 -1
  17. package/std/crypto/aes.ts +48 -43
  18. package/std/crypto/base64url.ts +7 -5
  19. package/std/crypto/bcrypt-batch.ts +13 -13
  20. package/std/crypto/bcrypt.ts +33 -27
  21. package/std/crypto/chacha20poly1305.ts +16 -14
  22. package/std/crypto/ed25519.ts +19 -16
  23. package/std/crypto/hmac.ts +7 -6
  24. package/std/crypto/jwt.ts +23 -20
  25. package/std/crypto/p256.ts +63 -56
  26. package/std/crypto/p384.ts +23 -20
  27. package/std/crypto/pki.ts +18 -15
  28. package/std/crypto/rsa.ts +23 -19
  29. package/std/crypto/x25519.ts +11 -10
  30. package/std/crypto/x509.ts +69 -62
  31. package/std/host/ring.ts +124 -0
  32. package/std/json-equal.ts +12 -11
  33. package/std/json-number.ts +12 -12
  34. package/std/json-tokenizer.ts +26 -22
  35. package/std/json-typed.ts +92 -78
  36. package/std/json-value.ts +38 -33
  37. package/std/json.ts +32 -28
  38. package/std/net/fetch.ts +1117 -230
  39. package/std/net/handler.ts +18 -0
  40. package/std/net/hpack.ts +29 -26
  41. package/std/net/http-compress.ts +27 -21
  42. package/std/net/http1-client-codec.ts +29 -25
  43. package/std/net/http1-codec.ts +44 -87
  44. package/std/net/http1-server.ts +66 -54
  45. package/std/net/http2-frame.ts +17 -16
  46. package/std/net/http2-tls.ts +17 -15
  47. package/std/net/http2.ts +67 -54
  48. package/std/net/http3-frame.ts +11 -10
  49. package/std/net/http3-server.ts +36 -35
  50. package/std/net/http3.ts +70 -58
  51. package/std/net/postgres.ts +178 -160
  52. package/std/net/prefork.ts +38 -34
  53. package/std/net/qpack.ts +15 -14
  54. package/std/net/quic-conn-ack.ts +1 -0
  55. package/std/net/quic-conn-cid.ts +11 -0
  56. package/std/net/quic-conn-params.ts +41 -14
  57. package/std/net/quic-datagram.ts +7 -0
  58. package/std/net/quic-frame.ts +48 -12
  59. package/std/net/quic-listener.ts +61 -44
  60. package/std/net/quic-packet.ts +71 -52
  61. package/std/net/quic-recovery.ts +59 -21
  62. package/std/net/quic-stream.ts +83 -55
  63. package/std/net/quic.ts +204 -152
  64. package/std/net/tls/client.ts +1 -0
  65. package/std/net/tls/codec.ts +81 -12
  66. package/std/net/tls/record-client.ts +30 -18
  67. package/std/net/tls/record-server.ts +74 -46
  68. package/std/net/tls/record.ts +33 -24
  69. package/std/net/tls/ticket.ts +2 -0
  70. package/std/net/tls/verify.ts +8 -7
  71. package/std/net/tls-tcp.ts +58 -50
  72. package/std/net/tls.ts +55 -43
  73. package/std/net/url.ts +12 -9
  74. package/std/net/websocket.ts +23 -19
  75. package/std/net/webtransport.ts +24 -18
  76. package/std/random.ts +8 -6
  77. package/std/regex.ts +70 -59
  78. package/std/sync/ring.ts +24 -21
  79. package/std/sync/shm.ts +9 -7
  80. package/std/term-io.ts +17 -14
  81. package/std/term-probe.ts +11 -10
  82. package/std/term-rate.ts +71 -61
  83. package/std/term.ts +73 -59
  84. package/std/text.ts +11 -10
  85. package/std/threads.ts +19 -15
  86. package/std/yaml-json.ts +17 -15
  87. package/std/yaml-write.ts +21 -14
package/INSTALL.md CHANGED
@@ -155,13 +155,15 @@ tarball's SHA-256 with the release's `SHA256SUMS` (or with the digest pinned
155
155
  for releases that predate it) and refuses a mismatch. For releases after
156
156
  0.21.0 it also checks the release's **build provenance attestation** when a
157
157
  signed-in GitHub CLI is present whose `gh attestation verify` takes the
158
- options below. The attestation
159
- is a Sigstore-signed statement, made by `actions/attest-build-provenance` in
160
- the release workflow, that every file in `SHA256SUMS` was built by
161
- `.github/workflows/release.yml` at the release's tag on a GitHub-hosted
162
- runner. A failed verification refuses the install; with no `gh`, a signed-out
163
- one or one too old for those options, the check is skipped with a note saying so, and the
164
- SHA-256 still applies. The same command by hand, on a tarball you downloaded:
158
+ options below.
159
+
160
+ The attestation is a Sigstore-signed statement, made by
161
+ `actions/attest-build-provenance` in the release workflow, that every file in
162
+ `SHA256SUMS` was built by `.github/workflows/release.yml` at the release's tag
163
+ on a GitHub-hosted runner. A failed verification refuses the install; with no
164
+ `gh`, a signed-out one or one too old for those options, the check is skipped
165
+ with a note saying so, and the SHA-256 still applies. The same command by hand,
166
+ on a tarball you downloaded:
165
167
 
166
168
  ```bash
167
169
  gh attestation verify nish-<version>-<asset>.tar.gz \
@@ -405,11 +407,13 @@ header — and `runtime/sqlite/`, SQLite's vendored source),
405
407
  `docs/AI.md` (the rules card). The
406
408
  compiler itself is not in it: it arrives as one prebuilt
407
409
  `@amritk/nish-<asset>` package per platform, and `bin/nish` hands over to
408
- whichever one npm installed. That package carries its own copy of all of
409
- these, and its `docs/AI.md` is the one an agent's `nish --help` names. `nish` locates the runtime, the script and `std/`
410
- relative to its own install directory, so a global install works from any
411
- working directory — and the binary runs from inside its own platform package
412
- for exactly that reason.
410
+ whichever one npm installed.
411
+
412
+ That package carries its own copy of all of these, and its `docs/AI.md` is the
413
+ one an agent's `nish --help` names. `nish` locates the runtime, the script and
414
+ `std/` relative to its own install directory, so a global install works from
415
+ any working directory — and the binary runs from inside its own platform
416
+ package for exactly that reason.
413
417
 
414
418
  Building the IR yourself rather than through `--link` means naming the runtime
415
419
  on the `clang` line, and it is sixteen files:
@@ -425,26 +429,31 @@ clang app.ll runtime/runtime.c runtime/runtime-os.c runtime/runtime-parallel.c \
425
429
  `runtime.c` is the part every program touches — the arena, strings, arrays,
426
430
  number formatting, the panics — and `runtime-os.c` wraps the system calls:
427
431
  files, directories, subprocesses, `getenv`, the monotonic clock.
428
- `runtime-parallel.c` divides work across threads for `nish/threads` (a
429
- program built with `--threads`, as every importer of `nish/threads` is, also
430
- needs `-DNISH_THREADS=1 -pthread` on the line), `runtime-cross.c` copies
431
- the strings and arrays a task answers, a channel sends or a `Mutex` keeps out
432
- of the arena they were made in, `runtime-host.c` holds the wall clock,
433
- entropy, file times and signals, `runtime-net.c` the sockets of `nish:net`,
434
- `runtime-simd.c` and `runtime-aes.c` the vector text search and AES-GCM,
435
- `runtime-sha256.c` the SHA-256 block kernel `nish/crypto/sha256` hands its
436
- blocks to on a CPU with the SHA instructions (`NISH_SHA256=soft` keeps the
437
- portable path), `runtime-chacha20.c` the ChaCha20 keystream `nish/crypto/chacha20poly1305`
438
- hands a message of 256 bytes or more to on a CPU with AVX2 or NEON (`NISH_CHACHA20=soft`
439
- keeps the portable path), `runtime-term.c` the stdin reads and terminal calls of `nish:term`,
440
- `runtime-bytes.c` the byte-class runs of `nish/bytes`, which `nish/json` steps
441
- over, `runtime-checksum.c` the CRC-32 kernels of `nish/compress/checksum`,
442
- `runtime-sandbox.c` the confinement a `--sandbox` build applies, and
443
- `runtime-shm.c` the shared-memory regions of `nish/sync/shm`.
444
- They are separate so that each carries its own measured size ceiling
445
- ([docs/wp7-runtime.md](https://github.com/amritk/nish/blob/main/docs/wp7-runtime.md)); nothing in the core calls into the
446
- others, so a line that names only `runtime.c` and `runtime-os.c` still links a
447
- program that uses none of the other nine. `scripts/build.sh` compiles the other
432
+
433
+ `runtime-parallel.c` divides work across threads for `nish/threads` (a program
434
+ built with `--threads`, as every importer of `nish/threads` is, also needs
435
+ `-DNISH_THREADS=1 -pthread` on the line), `runtime-cross.c` copies the strings
436
+ and arrays a task answers, a channel sends or a `Mutex` keeps out of the arena
437
+ they were made in, `runtime-host.c` holds the wall clock, entropy, file times
438
+ and signals, `runtime-net.c` the sockets of `nish:net`, `runtime-simd.c` and
439
+ `runtime-aes.c` the vector text search and AES-GCM, `runtime-sha256.c` the
440
+ SHA-256 block kernel `nish/crypto/sha256` hands its blocks to on a CPU with the
441
+ SHA instructions (`NISH_SHA256=soft` keeps the portable path),
442
+ `runtime-chacha20.c` the ChaCha20 keystream `nish/crypto/chacha20poly1305`
443
+ hands a message of 256 bytes or more to on a CPU with AVX2 or NEON
444
+ (`NISH_CHACHA20=soft` keeps the portable path), `runtime-term.c` the stdin
445
+ reads and terminal calls of `nish:term`, `runtime-bytes.c` the byte-class runs
446
+ of `nish/bytes`, which `nish/json` steps over, `runtime-checksum.c` the CRC-32
447
+ kernels of `nish/compress/checksum`, `runtime-sandbox.c` the confinement a
448
+ `--sandbox` build applies, and `runtime-shm.c` the shared-memory regions of
449
+ `nish/sync/shm`. They are separate so that each carries its own measured size
450
+ ceiling
451
+ ([docs/wp7-runtime.md](https://github.com/amritk/nish/blob/main/docs/wp7-runtime.md));
452
+ nothing in the core calls into the others, so a line that names only
453
+ `runtime.c` and `runtime-os.c` still links a program that uses none of the
454
+ other nine.
455
+
456
+ `scripts/build.sh` compiles the other
448
457
  nine beside any
449
458
  `runtime.c` it is handed, so a build that goes through it — every `--link`,
450
459
  and every `--profile` recipe in these documents — needs to name only the one.
@@ -473,19 +482,19 @@ The seed builds stage1, stage1 builds stage2, and stage2 is installed as
473
482
  own IR is only reported beside them, because a codegen change since the
474
483
  release is expected to move it. `--stages 1` stops one link sooner.
475
484
 
476
- `build/nish` is then the compiler you run: it takes the same `-o`, `--link`
477
- and `--profile` spellings as an installed `nish`, because it is the same
478
- program, and makes every directory in the way of the IR, a sidecar or the
479
- binary itself. It looks for `scripts/build.sh` and the `runtime/*.c` files
480
- one level up from wherever it was invoked (and one level up from the file a
481
- symbolic link to it names), so it wants a checkout or an installed package
482
- around it the way `nish` does. It falls back to the working directory only
483
- when the compiler itself lies inside that directory, so a checkout you merely
484
- `cd` into cannot hand it a `scripts/build.sh` to run. Keep `bin/nish` beside
485
- `scripts/`, `runtime/` and `std/`, as every install above does, and keep that
486
- directory's parent writable only by you: the package root is the parent of
487
- the compiler's directory, so a compiler at `/tmp/x/nish` would trust
488
- `/tmp/scripts/build.sh` (CLI-9 in [docs/security/cli.md](security/cli.md)).
485
+ `build/nish` is then the compiler you run: it takes the same `-o`, `--link` and
486
+ `--profile` spellings as an installed `nish`, because it is the same program,
487
+ and makes every directory in the way of the IR, a sidecar or the binary itself.
488
+ It looks for `scripts/build.sh` and the `runtime/*.c` files one level up from
489
+ wherever it was invoked (and one level up from the file a symbolic link to it
490
+ names), so it wants a checkout or an installed package around it the way `nish`
491
+ does. It falls back to the working directory only when the compiler itself lies
492
+ inside that directory, so a checkout you merely `cd` into cannot hand it a
493
+ `scripts/build.sh` to run. Keep `bin/nish` beside `scripts/`, `runtime/` and
494
+ `std/`, as every install above does, and keep that directory's parent writable
495
+ only by you: the package root is the parent of the compiler's directory, so a
496
+ compiler at `/tmp/x/nish` would trust `/tmp/scripts/build.sh` (CLI-9 in
497
+ [docs/security/cli.md](security/cli.md)).
489
498
 
490
499
  Because the seed is the last release, `src/` may only *use* in its own
491
500
  source the constructs that release compiles. A new construct is implemented
@@ -537,24 +546,24 @@ nish run hello.ts
537
546
  `nish run [options] <file.ts> [args ...]` compiles the file, links it into
538
547
  `$XDG_CACHE_HOME/nish/run` (or `~/.cache/nish/run`) when that program has not
539
548
  been linked before, and starts it with the arguments after the file. The first
540
- run of a new edit pays for one link, and later runs start the cached binary.
541
- It needs clang only for that link. It needs `HOME` or `XDG_CACHE_HOME` set
542
- to an absolute path (a relative one is ignored, as if it were unset), and
543
- refuses the run without one rather than keep a binary in a shared directory.
544
- The first run that builds into the cache makes its root `0700`, so no other
545
- user can plant a binary in it ([docs/security/cli.md](security/cli.md)).
549
+ run of a new edit pays for one link, and later runs start the cached binary. It
550
+ needs clang only for that link. It needs `HOME` or `XDG_CACHE_HOME` set to an
551
+ absolute path (a relative one is ignored, as if it were unset), and refuses the
552
+ run without one rather than keep a binary in a shared directory. The first run
553
+ that builds into the cache makes its root `0700`, so no other user can plant a
554
+ binary in it ([docs/security/cli.md](security/cli.md)).
546
555
 
547
556
  Every link with the debug, speed or size profile, `nish run`'s and `--link`'s
548
557
  alike, keeps the compiled C runtime in `$XDG_CACHE_HOME/nish/runtime` (or
549
558
  `~/.cache/nish/runtime`), one entry per profile, `-g`, `--threads`, `CC` and
550
559
  the version that compiler reports, made `0700` the same way. The first link
551
- compiles the runtime's six files at once into it, and every later link
552
- compiles only the program's modules, also at once, and links against the
553
- entry: a `hello.ts` debug link goes from about half a second to about a
554
- tenth. `--link` with no absolute `HOME` or `XDG_CACHE_HOME`, or with a root
555
- it cannot make private, compiles the runtime itself as it always did; the
556
- wasi profile and `scripts/build.sh` called directly never use the cache.
557
- Removing the directory is always safe.
560
+ compiles the runtime's six files at once into it, and every later link compiles
561
+ only the program's modules, also at once, and links against the entry: a
562
+ `hello.ts` debug link goes from about half a second to about a tenth. `--link`
563
+ with no absolute `HOME` or `XDG_CACHE_HOME`, or with a root it cannot make
564
+ private, compiles the runtime itself as it always did; the wasi profile and
565
+ `scripts/build.sh` called directly never use the cache. Removing the directory
566
+ is always safe.
558
567
 
559
568
  <a id="4-exit-codes" style="scroll-margin-top: 65px"></a>
560
569
 
package/bin/nish CHANGED
Binary file
package/docs/AI.md CHANGED
@@ -1484,8 +1484,8 @@ export const main = (): i32 => {
1484
1484
  `--target`** (NL2666; `--target wasm32-wasi` keeps it): there a function the page
1485
1485
  supplies is imported from a host module, the page's own TypeScript file
1486
1486
  named by `--host`, and becomes a wasm import from module `host`. Only
1487
- scalars, enums and `HostHandle<"kind">` (a nominal `i32` for an object the
1488
- page keeps) cross; `import { Canvas, fill } from "./host.ts"`, no `type`
1487
+ scalars, enums, `HostHandle<"kind">` (a nominal `i32` for an object the
1488
+ page keeps) and buffer windows (an array, then `at: u32, n: u32`) cross; `import { Canvas, fill } from "./host.ts"`, no `type`
1489
1489
  modifier.
1490
1490
  - **A class with a `CPtr` field is a handle class: open one with `using`.**
1491
1491
  `using f = new File(p)` closes `f` once at every exit of its block (falling
@@ -1520,12 +1520,51 @@ emitted and no initialiser runs** — every use lowers to the value itself.
1520
1520
  array, class or interface constant would need an allocation, and there is no
1521
1521
  code to run it.
1522
1522
  - The initialiser is literals, other constants (declared anywhere, or
1523
- imported), and arithmetic over them. A call, a `new`, a local — anything else
1524
- — is rejected.
1523
+ imported), and arithmetic over them. A call, a local — anything else — is
1524
+ rejected. The one `new` allowed is module storage, below.
1525
1525
  - Folding uses the language's own arithmetic, so an overflowing fold is an
1526
1526
  error rather than a wrap, and `1 / 0` in a constant is refused at compile
1527
1527
  time.
1528
1528
 
1529
+ ### Module storage
1530
+
1531
+ ```ts nish:ok
1532
+ const SCORES = new Int32Array(4);
1533
+
1534
+ const sum = (xs: Int32Array): i32 => {
1535
+ let total: i32 = 0;
1536
+ for (let i = 0; i < xs.length; i++) {
1537
+ total += xs[i];
1538
+ }
1539
+ return total;
1540
+ };
1541
+
1542
+ export const main = (): i32 => {
1543
+ SCORES[0] = 30;
1544
+ SCORES[3] = 4;
1545
+ console.log(`${sum(SCORES)} ${SCORES[1]}`); // 34 0
1546
+ return 0;
1547
+ };
1548
+ ```
1549
+
1550
+ A top-level `const` holding `new Array<T>(n)` or a typed-array `new` of a
1551
+ constant length is **module storage**: a static, zero-filled array that keeps
1552
+ its values between calls, with no initialiser that runs. It is the only
1553
+ state a module keeps (there is no top-level `let`).
1554
+
1555
+ - The length is a constant from 1 to 16,777,216, at most 256 MiB in all. The element is pointer-free:
1556
+ a number, `boolean`, an enum or range whose zero is a member, a
1557
+ `HostHandle`, or an interface no class implements with fields of those.
1558
+ - **It never grows or moves**: no method call on it (`push`, `pop`, `sort`,
1559
+ NL2688) and no `length =`. Keep a count beside it.
1560
+ - **Its name is a place, not a value**: index it and read `length`; never bind,
1561
+ store or return it. Lend it only to a parameter spelled with a typed-array
1562
+ name (`xs: Int32Array`) or to a host function's buffer window. A record
1563
+ element is a place too: `bodies[i].x = 1` and `bodies[i] = bodies[j]` are
1564
+ fine, `const b = bodies[i]` is refused; pass the index.
1565
+ - Under `--profile wasm-host` the page reads and writes it through `layout`
1566
+ and `views()` in the `.d.ts`. The rules: `LANGUAGE.md` → "Module storage".
1567
+
1529
1568
  ### Classes and interfaces
1530
1569
 
1531
1570
  ```ts nish:ok
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/nish-aarch64-darwin",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "description": "The nish native compiler for macOS on ARM64",
5
5
  "license": "MIT",
6
6
  "os": [
@@ -45,5 +45,7 @@ export declare function awaitAll<A, B, C, D, E, F, G, H>(
45
45
  g: Promise<G>,
46
46
  h: Promise<H>,
47
47
  ): Promise<[A, B, C, D, E, F, G, H]>;
48
+ /** `true` once `ms` milliseconds have passed; `false` at once for a negative `ms`. */
49
+ export declare function sleep(ms: number): Promise<boolean>;
48
50
  /** Waits for every task `spawn` started, the tasks those tasks start included. */
49
51
  export declare function settleTasks(): Promise<void>;
package/runtime/async.mjs CHANGED
@@ -19,6 +19,13 @@ export const spawn = (task) => {
19
19
 
20
20
  export const awaitAll = (...tasks) => Promise.all(tasks);
21
21
 
22
+ // `sleep` is a timer: `true` once `ms` milliseconds have passed, `false` for a
23
+ // negative `ms`, as natively. `readable` and `writable` have no counterpart in
24
+ // Node, whose descriptors are not polled from JavaScript, so `--emit-ts`
25
+ // refuses them (NL4017) and this file does not export them.
26
+ export const sleep = (ms) =>
27
+ ms < 0 ? Promise.resolve(false) : new Promise((resolve) => setTimeout(() => resolve(true), ms));
28
+
22
29
  export const settleTasks = async () => {
23
30
  for (let i = 0; i < pending.length; i++) {
24
31
  await pending[i];