@amritk/nish-aarch64-linux 0.46.0 → 0.48.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 (46) hide show
  1. package/bin/nish +0 -0
  2. package/docs/AI.md +29 -18
  3. package/package.json +1 -1
  4. package/runtime/gfx/README.md +55 -0
  5. package/runtime/gfx/nish-gfx.c +1063 -0
  6. package/runtime/gfx/nish-gfx.h +221 -0
  7. package/runtime/gfx/nish-gfx.overrides.json +14 -0
  8. package/runtime/nish.d.ts +22 -5
  9. package/runtime/nish.h +1 -0
  10. package/runtime/nish.mjs +1 -0
  11. package/runtime/runtime-bytes.c +167 -7
  12. package/runtime/runtime-net.c +122 -52
  13. package/runtime/runtime-uring.c +150 -69
  14. package/runtime/sqlite/nish-sqlite.c +166 -39
  15. package/scripts/build.sh +88 -3
  16. package/std/README.md +2 -2
  17. package/std/base64.ts +28 -30
  18. package/std/compress/deflate.ts +1371 -704
  19. package/std/crypto/aes.ts +81 -45
  20. package/std/crypto/bcrypt-batch.ts +23 -4
  21. package/std/crypto/bcrypt.ts +36 -11
  22. package/std/crypto/chacha20poly1305.ts +93 -52
  23. package/std/crypto/x25519.ts +7 -4
  24. package/std/host/game.ts +52 -20
  25. package/std/host/ring.ts +115 -31
  26. package/std/host/text.ts +9 -3
  27. package/std/json.ts +83 -0
  28. package/std/math.ts +161 -131
  29. package/std/net/handler.ts +24 -6
  30. package/std/net/http-server.ts +358 -141
  31. package/std/net/http1-server.ts +44 -13
  32. package/std/net/prefork.ts +1 -2
  33. package/std/net/static.ts +7 -2
  34. package/std/random.ts +34 -51
  35. package/std/raster.ts +377 -113
  36. package/std/regex.ts +46 -15
  37. package/std/release.ts +19 -13
  38. package/std/sqlite.ts +380 -16
  39. package/std/synth.ts +20 -3
  40. package/std/temporal.ts +740 -363
  41. package/std/term-io.ts +81 -33
  42. package/std/term-pixels.ts +287 -112
  43. package/std/term-probe.ts +7 -3
  44. package/std/term-rate.ts +142 -66
  45. package/std/term.ts +782 -406
  46. package/std/testing.ts +14 -7
package/bin/nish CHANGED
Binary file
package/docs/AI.md CHANGED
@@ -1601,11 +1601,12 @@ export const main = (): i32 => {
1601
1601
  };
1602
1602
  ```
1603
1603
 
1604
- - **A parameter is a scalar, a `CPtr`, a borrowed `string`, a `u8[]` buffer
1605
- with its count or a borrowed `declare class`; a return is a scalar, a `CPtr`
1606
- or a copied `string`.** The scalars are the integer and float widths,
1607
- `boolean` and `void`. Any other array, a Nish class or an interface is
1608
- rejected, in either position, and a `declare class` is never a return.
1604
+ - **A parameter is a scalar, a `CPtr`, a borrowed `string`, a buffer with its
1605
+ count or a borrowed `declare class`; a return is a scalar, a `CPtr` or a
1606
+ copied `string`.** The scalars are the integer and float widths, `boolean`
1607
+ and `void`. A buffer is a `u8[]`, `u16[]`, `u32[]`, `i32[]` or `f32[]`,
1608
+ readonly or not. Any other array, a Nish class or an interface is rejected,
1609
+ in either position, and a `declare class` is never a return.
1609
1610
  - **A `declare class` is a C struct, lent by pointer.** Its fields are laid out
1610
1611
  in declaration order at C's alignment, and `new Name()` zero-fills it. A
1611
1612
  field is `i32`, `i64`, `u8`, `u16`, `u32`, `u64`, `f32`, `f64`, `CPtr`,
@@ -1646,16 +1647,21 @@ export const main = (): i32 => {
1646
1647
  };
1647
1648
  ```
1648
1649
 
1649
- - **A run of `u8[]` / `readonly u8[]` parameters is followed by exactly one
1650
- `u64`**, the byte count C may touch in each (`memcpy(dst: u8[], src:
1651
- readonly u8[], n: u64)`). `readonly` is C's `const`. A run without its count
1652
- is NL2549, a count that is not `u64` NL2550, `i32[]` NL2551, `u8[] | null`
1653
- NL2552. Declare `fwrite` as `(buf: readonly u8[], n: u64, one: u64, f: CPtr)`
1654
- and pass `1` for `one`. A call passes the data pointer and first checks the
1655
- count against every buffer of the run: a larger count is an `ffi-length`
1656
- panic, and only `toU64(buf.length)` of the buffer itself is proved. C
1657
- borrows the bytes for the call and may write a `u8[]`; a spawned task may
1658
- not make the call.
1650
+ - **A run of buffer parameters is followed by exactly one `u64`**, the
1651
+ count of elements C may touch in each (`memcpy(dst: u8[], src: readonly
1652
+ u8[], n: u64)`, `scale(xs: f32[], n: u64, k: f32)`). The five element types
1653
+ are `u8`, `u16`, `u32`, `i32` and `f32` (C's `uint8_t`, `uint16_t`,
1654
+ `uint32_t`, `int32_t`, `float`); the count is in elements, so 4 for an
1655
+ `f32[]` of 4 is 16 bytes. `readonly` is C's `const`. A run without its count
1656
+ is NL2549, a count that is not `u64` NL2550, any other element (`f64[]`,
1657
+ `i64[]`) NL2551, `u8[] | null` NL2552, and a run that mixes element types
1658
+ (`f32[]` then `readonly u8[]`) NL2824: give each its own count. Declare
1659
+ `fwrite` as `(buf: readonly u8[], n: u64, one: u64, f: CPtr)` and pass `1`
1660
+ for `one`. A call passes the data pointer and first checks the count against
1661
+ every buffer of the run: a larger count is an `ffi-length` panic, and only
1662
+ `toU64(buf.length)` of the buffer itself is proved. C borrows the elements
1663
+ for the call and may write a buffer that is not `readonly`; a spawned task
1664
+ may not make the call.
1659
1665
 
1660
1666
  <!-- nish:err NL2549 -->
1661
1667
  ```ts
@@ -3073,8 +3079,7 @@ tag under one key (NL2721) as a different string (NL2720). A `tag` on a class
3073
3079
  no union holds does nothing, and a JSON call on that class refuses its
3074
3080
  enum-member field.
3075
3081
 
3076
- <!-- allow-panics: builds an array whose length it does not bound; indexes an array without a guard the checker reads; calls `std/json-typed.ts` code that keeps panic sites no proof removes yet -->
3077
- <!-- nish:ok --allow-panics -->
3082
+ <!-- nish:ok -->
3078
3083
  ```ts
3079
3084
  import { JsonWriter } from "nish/json";
3080
3085
  import { JsonLimits } from "nish/json-tokenizer";
@@ -3546,7 +3551,13 @@ its fix, and there are five:
3546
3551
  `--number-mode f64` — has no guard, so index with an `i32` or a `u32`),
3547
3552
  `if (d !== 0 && d !== -1)` before `a / d` (a
3548
3553
  constant divisor needs nothing), `if (xs.length > 0)` before `xs.pop()`,
3549
- `if (n >= 0 && n <= 9)` before `n` enters `integer<0, 9>`.
3554
+ `if (n >= 0 && n <= 9)` before `n` enters `integer<0, 9>`, `if (n >= 0)`
3555
+ before `new Array<T>(n)` of an `i32` (a local of `integer<0, N>` needs
3556
+ nothing), `if (start >= 0 && start <= end && end <= bytes.length)` before
3557
+ `s.slice(start, end)`, `xs.slice(start, end)` or
3558
+ `String.fromBytes(bytes, start, end)`, `if (src.length <= dst.length)`
3559
+ before `dst.set(src, 0)`, and `if (n >= 0 && n <= buf.length)` before
3560
+ `writeBytes(buf, 0, n)` or `netRead(fd, buf, 0, n)`.
3550
3561
  - **Bound a signed `+ - *`, or say it wraps**: an `i32`/`i64` operation the
3551
3562
  checker cannot prove fits is an `overflow` site; bound its operands (a loop
3552
3563
  below a length, a guard on the value), compute in `u32`/`u64`, or write
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/nish-aarch64-linux",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "description": "The nish native compiler for Linux on ARM64",
5
5
  "license": "MIT",
6
6
  "os": [
@@ -0,0 +1,55 @@
1
+ # runtime/gfx/
2
+
3
+ The C shim a Nish program draws through: `nish-gfx.h` and `nish-gfx.c`, a thin
4
+ synchronous layer over [wgpu-native](https://github.com/gfx-rs/wgpu-native)
5
+ (WebGPU) and [SDL3](https://libsdl.org/) (windows and input). Neither library
6
+ is vendored: `scripts/fetch-gfx.sh` downloads and pins them into
7
+ `build/gfx/<platform>/`, or `NISH_GFX_PREFIX` names an install made another
8
+ way.
9
+
10
+ | | wgpu-native | SDL |
11
+ | --- | --- | --- |
12
+ | Version | v29.0.1.1 | 3.4.20 |
13
+ | From | `wgpu-<platform>-release.zip` from <https://github.com/gfx-rs/wgpu-native/releases/tag/v29.0.1.1> | `SDL3-3.4.20.tar.gz` from <https://github.com/libsdl-org/SDL/releases/tag/release-3.4.20>, built by `fetch-gfx.sh` as a static library |
14
+ | SHA-256 | one per platform, in `scripts/fetch-gfx.sh` | `f3bb06f55bed9557227a700af2ea62e49497ebdf58037732a731a5fb3ef8581f` |
15
+ | Licence | MIT or Apache-2.0, at the user's choice; its `webgpu.h` is BSD-3-Clause (Copyright 2019-2023 WebGPU-Native developers) | zlib (Copyright (C) 1997-2026 Sam Lantinga) |
16
+
17
+ A binary that links the shim carries both libraries, statically, so whoever
18
+ ships it ships their notices too: SDL's zlib licence asks that its notice not
19
+ be removed from source distributions, and wgpu-native's MIT and Apache-2.0
20
+ terms ask that the notice travel with copies. Neither library's code is in
21
+ this repository, so neither is listed in `THIRD_PARTY_NOTICES.md`.
22
+
23
+ ## The shim's rules
24
+
25
+ - `nish-gfx.h` is what `nish c-import` reads, with
26
+ `nish-gfx.overrides.json` naming its buffers and nullable parameters. Every
27
+ parameter is a scalar, an opaque handle or a struct by pointer: no unions,
28
+ structs by value, callbacks or variadics. It does not include `webgpu.h`.
29
+ - Every WebGPU request that answers through a callback is made synchronous
30
+ with a bounded `wgpuInstanceProcessEvents` loop, never `wgpuInstanceWaitAny`
31
+ or a timed wait.
32
+ - Errors are queued, never called back into Nish: each device and instance
33
+ keeps a ring of 16 reports of at most 255 bytes, and counts the ones that
34
+ found it full.
35
+ - Offscreen targets read back through rows padded to 256 bytes and copy only
36
+ the unpadded rows into a buffer whose length is checked first.
37
+
38
+ The security record is [`docs/security/gfx.md`](../../docs/security/gfx.md).
39
+
40
+ ## How it is linked
41
+
42
+ `scripts/build.sh` compiles every `*.c` here for a link whose IR declares a
43
+ `nishgfx_*` function, and for no other link, and adds `-lSDL3 -lwgpu_native`
44
+ with the platform's system libraries. A link that needs the libraries and
45
+ finds none fails with a message naming `scripts/fetch-gfx.sh`. `wasm`,
46
+ `wasm-host` and `wasi` builds refuse the shim. `tests/gfx.js` ("gfx") draws
47
+ `tests/gfx/triangle.c` offscreen and checks its pixels.
48
+
49
+ ## Updating
50
+
51
+ 1. Change the versions and SHA-256 pins in `scripts/fetch-gfx.sh` and the
52
+ table above, then run `scripts/fetch-gfx.sh --force`.
53
+ 2. Rebuild against the new `webgpu.h`; its structs are filled through its
54
+ `WGPU_*_INIT` macros, so a field added upstream needs no change here.
55
+ 3. Run `node tests/run.js gfx`.