nish 0.49.0 → 0.50.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 (92) hide show
  1. package/README.md +27 -21
  2. package/docs/AI.md +233 -159
  3. package/docs/INSTALL.md +1 -1
  4. package/package.json +12 -12
  5. package/runtime/gfx/nish-gfx.h +373 -61
  6. package/runtime/nish.d.ts +12 -9
  7. package/std/README.md +8 -5
  8. package/std/base64.ts +74 -1
  9. package/std/bytes.ts +201 -93
  10. package/std/compress/deflate.ts +20 -15
  11. package/std/crypto/base64url.ts +93 -66
  12. package/std/crypto/bcrypt.ts +25 -21
  13. package/std/crypto/hmac.ts +1 -1
  14. package/std/crypto/jwt.ts +32 -19
  15. package/std/crypto/p256.ts +9 -12
  16. package/std/crypto/pki-roots.ts +7 -4
  17. package/std/crypto/pki.ts +43 -55
  18. package/std/crypto/rsa-sign.ts +1632 -0
  19. package/std/crypto/rsa.ts +26 -4
  20. package/std/crypto/sha256.ts +135 -68
  21. package/std/crypto/x25519.ts +12 -11
  22. package/std/crypto/x509.ts +164 -40
  23. package/std/gpu/sys.ts +490 -0
  24. package/std/json-equal.ts +33 -18
  25. package/std/json-format.ts +39 -8
  26. package/std/json-number.ts +15 -3
  27. package/std/json-tokenizer.ts +4 -3
  28. package/std/json-typed.ts +29 -12
  29. package/std/json-value.ts +222 -104
  30. package/std/json.ts +81 -46
  31. package/std/net/dns-config.ts +18 -5
  32. package/std/net/dns-message.ts +60 -27
  33. package/std/net/dns-resolver.ts +35 -16
  34. package/std/net/dns.ts +3 -2
  35. package/std/net/fetch.ts +120 -38
  36. package/std/net/handler.ts +178 -66
  37. package/std/net/hpack.ts +192 -98
  38. package/std/net/http-compress.ts +83 -30
  39. package/std/net/http-fields.ts +327 -31
  40. package/std/net/http-server.ts +317 -20
  41. package/std/net/http1-client-codec.ts +137 -40
  42. package/std/net/http1-codec.ts +391 -202
  43. package/std/net/http1-server.ts +220 -38
  44. package/std/net/http2-cleartext.ts +10 -4
  45. package/std/net/http2-frame.ts +2 -2
  46. package/std/net/http2-tls.ts +3 -3
  47. package/std/net/http2.ts +69 -15
  48. package/std/net/http3-frame.ts +11 -14
  49. package/std/net/http3-server.ts +12 -15
  50. package/std/net/http3.ts +41 -29
  51. package/std/net/multipart.ts +592 -0
  52. package/std/net/outbound.ts +24 -8
  53. package/std/net/postgres-async.ts +92 -54
  54. package/std/net/postgres-carrier.ts +28 -4
  55. package/std/net/postgres.ts +166 -65
  56. package/std/net/prefork.ts +86 -5
  57. package/std/net/protobuf.ts +6 -2
  58. package/std/net/qpack.ts +66 -25
  59. package/std/net/quic-conn-ack.ts +27 -7
  60. package/std/net/quic-conn-cid.ts +13 -7
  61. package/std/net/quic-datagram.ts +6 -5
  62. package/std/net/quic-frame.ts +67 -23
  63. package/std/net/quic-listener.ts +19 -12
  64. package/std/net/quic-recovery.ts +11 -9
  65. package/std/net/quic-stream.ts +7 -5
  66. package/std/net/quic.ts +36 -31
  67. package/std/net/router.ts +136 -24
  68. package/std/net/serve.ts +59 -5
  69. package/std/net/static.ts +81 -33
  70. package/std/net/tls/record.ts +26 -13
  71. package/std/net/tls/ticket.ts +6 -5
  72. package/std/net/tls-tcp.ts +69 -30
  73. package/std/net/tls.ts +152 -38
  74. package/std/net/upstream.ts +65 -19
  75. package/std/net/url.ts +97 -78
  76. package/std/net/websocket.ts +33 -15
  77. package/std/net/webtransport.ts +28 -12
  78. package/std/regex.ts +600 -388
  79. package/std/sqlite.ts +37 -19
  80. package/std/sync/ring.ts +232 -115
  81. package/std/sync/shm.ts +11 -4
  82. package/std/temporal.ts +232 -133
  83. package/std/term-io.ts +12 -6
  84. package/std/term-pixels.ts +158 -22
  85. package/std/term-rate.ts +8 -3
  86. package/std/term.ts +4 -4
  87. package/std/text.ts +33 -11
  88. package/std/threads.ts +52 -8
  89. package/std/yaml-json.ts +238 -106
  90. package/std/yaml-lines.ts +47 -27
  91. package/std/yaml-write.ts +58 -24
  92. package/std/yaml.ts +808 -395
package/docs/INSTALL.md CHANGED
@@ -57,7 +57,7 @@ the Homebrew LLVM is needed for the `wasm`, `wasm-host` and `wasi` profiles (`wa
57
57
  `wasm-opt` (binaryen: `apt-get install binaryen`, `brew install binaryen`) is
58
58
  optional. When it is on `PATH`, `scripts/build.sh --profile wasm-host` runs
59
59
  `wasm-opt -Oz --strip-target-features` on the module, and the build line says
60
- whether it ran: `add.wasm` goes from 102 bytes to 74. Without it the module
60
+ whether it ran: `add.wasm` goes from 122 bytes to 106. Without it the module
61
61
  is complete and works the same. clang 18 also runs a `wasm-opt` it finds,
62
62
  after any optimising wasm link, and keeps a `target_features` section for it
63
63
  that build.sh's pass then drops. `NISH_WASM_OPT=0` links with neither pass,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nish",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "Nish: an ahead-of-time compiler from a static subset of TypeScript to LLVM IR",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -64,9 +64,9 @@
64
64
  "postinstall": "node scripts/postinstall.mjs",
65
65
  "bootstrap": "bash scripts/bootstrap.sh",
66
66
  "compile": "build/nish",
67
- "example": "build/nish examples/add.ts --allow-panics -o build/add.ll && cat build/add.ll",
67
+ "example": "build/nish examples/add.ts -o build/add.ll && cat build/add.ll",
68
68
  "test": "node tests/run.js",
69
- "size-report": "build/nish examples/add.ts --allow-panics -o build/add.ll && bash scripts/size-report.sh build/add.ll examples/main.c",
69
+ "size-report": "build/nish examples/add.ts -o build/add.ll && bash scripts/size-report.sh build/add.ll examples/main.c",
70
70
  "smoke": "bash scripts/smoke.sh",
71
71
  "check": "tsc -p tsconfig.json",
72
72
  "test:update": "UPDATE_GOLDENS=1 node tests/run.js",
@@ -74,7 +74,7 @@
74
74
  "test:nish": "bash scripts/nish-harness.sh tests/nish/run.ts build/nish-runner",
75
75
  "test:cli": "bash scripts/nish-harness.sh tests/nish/cli.ts build/nish-cli",
76
76
  "test:node": "node tests/differential/unmodified.js",
77
- "lint": "node scripts/check-filenames.mjs && node scripts/check-install-scripts.mjs && biome check .",
77
+ "lint": "node scripts/check-filenames.mjs && node scripts/check-install-scripts.mjs && node scripts/rfc-specs.mjs && node scripts/wrap-casts.mjs && biome check .",
78
78
  "lint:fix": "biome check --write .",
79
79
  "lint:dead": "knip --no-progress",
80
80
  "format": "biome format --write .",
@@ -107,16 +107,16 @@
107
107
  ],
108
108
  "devDependencies": {
109
109
  "@amritk/generate-markdown": "0.12.0",
110
- "@biomejs/biome": "2.5.12",
111
- "@types/node": "^22.0.0",
112
- "knip": "6.38.0",
110
+ "@biomejs/biome": "2.6.8",
111
+ "@types/node": "^26.6.11",
112
+ "knip": "6.48.0",
113
113
  "typedoc": "0.28.20",
114
- "typescript": "^5.6.0"
114
+ "typescript": "^6.0.3"
115
115
  },
116
116
  "optionalDependencies": {
117
- "@amritk/nish-aarch64-darwin": "0.49.0",
118
- "@amritk/nish-aarch64-linux": "0.49.0",
119
- "@amritk/nish-x86_64-darwin": "0.49.0",
120
- "@amritk/nish-x86_64-linux": "0.49.0"
117
+ "@amritk/nish-aarch64-darwin": "0.50.0",
118
+ "@amritk/nish-aarch64-linux": "0.50.0",
119
+ "@amritk/nish-x86_64-darwin": "0.50.0",
120
+ "@amritk/nish-x86_64-linux": "0.50.0"
121
121
  }
122
122
  }
@@ -14,6 +14,10 @@
14
14
  * nishgfx_error_next(); a report that finds the ring full is counted by
15
15
  * nishgfx_errors_dropped(). Failures before a device exists (no adapter, a
16
16
  * refused device) are queued on the instance the same way.
17
+ *
18
+ * Every declaration below carries a doc comment, which `nish c-import` copies
19
+ * onto the binding it writes in std/gpu/sys.ts, and which the library
20
+ * reference shows.
17
21
  */
18
22
  #ifndef NISH_GFX_H
19
23
  #define NISH_GFX_H
@@ -25,49 +29,78 @@
25
29
  extern "C" {
26
30
  #endif
27
31
 
32
+ /** A WebGPU instance: the root every surface, adapter and device is made from. */
28
33
  typedef struct NishGfxInstance NishGfxInstance;
34
+ /** An SDL3 window, with the ring its input and window events queue in. */
29
35
  typedef struct NishGfxWindow NishGfxWindow;
36
+ /** A WebGPU surface that presents frames into a window. */
30
37
  typedef struct NishGfxSurface NishGfxSurface;
38
+ /** A WebGPU adapter: one GPU, or a software rasteriser, that devices are requested from. */
31
39
  typedef struct NishGfxAdapter NishGfxAdapter;
40
+ /** A WebGPU device and its queue, with the ring its errors queue in. */
32
41
  typedef struct NishGfxDevice NishGfxDevice;
42
+ /** A WebGPU buffer on a device. */
33
43
  typedef struct NishGfxBuffer NishGfxBuffer;
44
+ /** A WebGPU shader module compiled from WGSL. */
34
45
  typedef struct NishGfxShader NishGfxShader;
46
+ /** A render pipeline builder, freed by nishgfx_pipeline_create(). */
35
47
  typedef struct NishGfxPipelineDesc NishGfxPipelineDesc;
48
+ /** A render pipeline: a shader's two stages, its vertex layout and one color target. */
36
49
  typedef struct NishGfxPipeline NishGfxPipeline;
50
+ /** A bind group builder, freed by nishgfx_bind_group_create(). */
37
51
  typedef struct NishGfxBindGroupDesc NishGfxBindGroupDesc;
52
+ /** A bind group: the buffers a pipeline's group of bindings reads. */
38
53
  typedef struct NishGfxBindGroup NishGfxBindGroup;
54
+ /** A command encoder, freed when it is submitted. */
39
55
  typedef struct NishGfxEncoder NishGfxEncoder;
56
+ /** A render pass on one color view, freed when it ends. */
40
57
  typedef struct NishGfxPass NishGfxPass;
58
+ /** A texture view a render pass draws into: a surface's frame or an offscreen target. */
41
59
  typedef struct NishGfxView NishGfxView;
60
+ /** A render target with no window, whose pixels can be read back. */
42
61
  typedef struct NishGfxOffscreen NishGfxOffscreen;
43
62
 
44
63
  /* Error kinds nishgfx_error_next() answers. */
64
+ /** No error was queued. */
45
65
  #define NISHGFX_ERROR_NONE 0
66
+ /** A WebGPU validation error. */
46
67
  #define NISHGFX_ERROR_VALIDATION 1
68
+ /** A WebGPU out-of-memory error. */
47
69
  #define NISHGFX_ERROR_OUT_OF_MEMORY 2
70
+ /** A WebGPU internal error, or a failure of the shim's own. */
48
71
  #define NISHGFX_ERROR_INTERNAL 3
72
+ /** The device was lost. */
49
73
  #define NISHGFX_ERROR_DEVICE_LOST 4
50
74
 
51
- /* The error ring's size, per instance and per device. */
75
+ /** The error ring's size, per instance and per device. */
52
76
  #define NISHGFX_ERROR_RING 16
53
- /* The longest message an entry keeps, without its NUL. */
77
+ /** The longest message an entry keeps, without its NUL. */
54
78
  #define NISHGFX_ERROR_MESSAGE_MAX 255
55
79
 
56
80
  /* Event kinds nishgfx_event_next() answers. */
81
+ /** No event was queued. */
57
82
  #define NISHGFX_EVENT_NONE 0
83
+ /** The window was asked to close. */
58
84
  #define NISHGFX_EVENT_QUIT 1
85
+ /** A key went down. */
59
86
  #define NISHGFX_EVENT_KEY_DOWN 2
87
+ /** A key came up. */
60
88
  #define NISHGFX_EVENT_KEY_UP 3
89
+ /** The pointer moved. */
61
90
  #define NISHGFX_EVENT_MOUSE_MOVE 4
91
+ /** A mouse button went down. */
62
92
  #define NISHGFX_EVENT_MOUSE_DOWN 5
93
+ /** A mouse button came up. */
63
94
  #define NISHGFX_EVENT_MOUSE_UP 6
95
+ /** The wheel turned. */
64
96
  #define NISHGFX_EVENT_WHEEL 7
97
+ /** The window's pixel size changed. */
65
98
  #define NISHGFX_EVENT_RESIZED 8
66
99
 
67
- /* The event ring's size, per window. */
100
+ /** The event ring's size, per window. */
68
101
  #define NISHGFX_EVENT_RING 64
69
102
 
70
- /* One input or window event. Fields a kind does not use are zero. */
103
+ /** One input or window event. Fields a kind does not use are zero. */
71
104
  typedef struct NishGfxEvent {
72
105
  uint32_t kind; /* NISHGFX_EVENT_* */
73
106
  uint32_t key; /* SDL keycode, for KEY_DOWN and KEY_UP */
@@ -78,7 +111,7 @@ typedef struct NishGfxEvent {
78
111
  uint32_t width, height; /* new size in pixels, for RESIZED */
79
112
  } NishGfxEvent;
80
113
 
81
- /* A buffer to create. `usage` is WGPUBufferUsage bits. */
114
+ /** A buffer to create. `usage` is WGPUBufferUsage bits. */
82
115
  typedef struct NishGfxBufferDesc {
83
116
  uint64_t size;
84
117
  uint32_t usage;
@@ -87,131 +120,410 @@ typedef struct NishGfxBufferDesc {
87
120
 
88
121
  /* ---- instance, window, surface ---------------------------------------- */
89
122
 
90
- /* A WebGPU instance. Answers null if wgpu-native refuses one. */
123
+ /**
124
+ * A WebGPU instance.
125
+ *
126
+ * @returns the instance, or null if wgpu-native refuses one
127
+ */
91
128
  NishGfxInstance *nishgfx_instance_create(void);
92
- /* Release it last: every surface, adapter and device made from it keeps it,
93
- * and a device's readback drives events through it. */
129
+ /**
130
+ * Release an instance. Release it last: every surface, adapter and device
131
+ * made from it keeps it, and a device's readback drives events through it.
132
+ *
133
+ * @param instance the instance to release
134
+ */
94
135
  void nishgfx_instance_release(NishGfxInstance *instance);
95
- /* Drain one queued instance error (adapter or device refusal) into msg,
96
- * NUL-terminated and cut to cap - 1 bytes; answers its kind, 0 when empty. */
136
+ /**
137
+ * Drain one queued instance error (an adapter or device refusal) into msg,
138
+ * NUL-terminated and cut to cap - 1 bytes.
139
+ *
140
+ * @param instance the instance whose ring is drained
141
+ * @param msg the buffer the message is copied into
142
+ * @param cap the bytes msg holds
143
+ * @returns the error's kind, a NISHGFX_ERROR_* value, or 0 when the ring is empty
144
+ */
97
145
  int32_t nishgfx_instance_error_next(NishGfxInstance *instance, void *msg, size_t cap);
98
146
 
99
- /* An SDL3 window of width x height pixels; `title` is NUL-terminated UTF-8.
100
- * Answers null for a 0 side or one past INT32_MAX, when SDL has no video
101
- * driver, when memory or SDL's window properties run out, and when SDL
102
- * refuses the window; SDL_GetError() says why for the SDL failures. */
147
+ /**
148
+ * An SDL3 window of width x height pixels.
149
+ *
150
+ * @param title the window's title, NUL-terminated UTF-8
151
+ * @param width the width in pixels
152
+ * @param height the height in pixels
153
+ * @returns the window, or null for a 0 side or one past INT32_MAX, when SDL
154
+ * has no video driver, when memory or SDL's window properties run out, and
155
+ * when SDL refuses the window; SDL_GetError() says why for the SDL failures
156
+ */
103
157
  NishGfxWindow *nishgfx_window_create(const char *title, uint32_t width, uint32_t height);
104
- /* Release a surface made on the window first: it reads the window's size. */
158
+ /**
159
+ * Release a window. Release a surface made on the window first: it reads the
160
+ * window's size.
161
+ *
162
+ * @param window the window to release
163
+ */
105
164
  void nishgfx_window_release(NishGfxWindow *window);
106
- /* Move every pending SDL event into the window's ring; answers how many were
107
- * queued. Events past the ring's size are dropped and counted. */
165
+ /**
166
+ * Move every pending SDL event into the window's ring. Events past the ring's
167
+ * size are dropped and counted.
168
+ *
169
+ * @param window the window whose ring is filled
170
+ * @returns how many events were queued
171
+ */
108
172
  uint32_t nishgfx_events_poll(NishGfxWindow *window);
109
- /* Take the oldest queued event into *out; answers its kind, 0 when empty. */
173
+ /**
174
+ * Take the oldest queued event.
175
+ *
176
+ * @param window the window whose ring is drained
177
+ * @param out where the event is written
178
+ * @returns the event's kind, a NISHGFX_EVENT_* value, or 0 when the ring is empty
179
+ */
110
180
  uint32_t nishgfx_event_next(NishGfxWindow *window, NishGfxEvent *out);
181
+ /**
182
+ * How many events found the window's ring full and were dropped.
183
+ *
184
+ * @param window the window to ask
185
+ * @returns the count since the window was made, or 0 for a null window
186
+ */
111
187
  uint32_t nishgfx_events_dropped(NishGfxWindow *window);
112
188
 
113
- /* A surface on the window, through Metal, Wayland or X11 as SDL's current
114
- * video driver says. Answers null (and queues an instance error) otherwise. */
189
+ /**
190
+ * A surface on the window, through Metal, Wayland or X11 as SDL's current
191
+ * video driver says.
192
+ *
193
+ * @param instance the instance the surface is made from
194
+ * @param window the window it presents into
195
+ * @returns the surface, or null (and an instance error is queued) on any
196
+ * other video driver or failure
197
+ */
115
198
  NishGfxSurface *nishgfx_surface_create(NishGfxInstance *instance, NishGfxWindow *window);
199
+ /**
200
+ * Release a surface.
201
+ *
202
+ * @param surface the surface to release
203
+ */
116
204
  void nishgfx_surface_release(NishGfxSurface *surface);
117
- /* Configure for width x height. vsync != 0 is Fifo; otherwise Mailbox, then
118
- * Immediate, then Fifo, whichever the surface offers first. Answers 0, or -1
119
- * (and queues a device error) for a 0 side or a surface with no format. */
205
+ /**
206
+ * Configure a surface for width x height. vsync != 0 is Fifo; otherwise
207
+ * Mailbox, then Immediate, then Fifo, whichever the surface offers first.
208
+ *
209
+ * @param surface the surface to configure
210
+ * @param adapter the adapter the device came from
211
+ * @param device the device that draws into the surface
212
+ * @param width the width in pixels
213
+ * @param height the height in pixels
214
+ * @param vsync nonzero to wait for the display
215
+ * @returns 0, or -1 (and a device error is queued) for a 0 side or a surface
216
+ * with no format
217
+ */
120
218
  int32_t nishgfx_surface_configure(NishGfxSurface *surface, NishGfxAdapter *adapter, NishGfxDevice *device,
121
219
  uint32_t width, uint32_t height, uint32_t vsync);
122
- /* The WGPUTextureFormat configure picked. */
220
+ /**
221
+ * The texture format nishgfx_surface_configure() picked.
222
+ *
223
+ * @param surface the surface to ask
224
+ * @returns a WGPUTextureFormat, or 0 for a null surface
225
+ */
123
226
  uint32_t nishgfx_surface_format(NishGfxSurface *surface);
124
- /* The next frame's view, or null to skip this frame (an outdated, lost or
125
- * timed-out surface is reconfigured at the window's pixel size, or left until
126
- * a frame where that size is above 0; any other failure queues a device
127
- * error). The view lives until nishgfx_surface_present(). */
227
+ /**
228
+ * The next frame's view, which lives until nishgfx_surface_present().
229
+ *
230
+ * @param surface the configured surface
231
+ * @returns the view, or null to skip this frame: an outdated, lost or
232
+ * timed-out surface is reconfigured at the window's pixel size, or left
233
+ * until a frame where that size is above 0; any other failure queues a
234
+ * device error
235
+ */
128
236
  NishGfxView *nishgfx_surface_acquire(NishGfxSurface *surface);
237
+ /**
238
+ * Present the frame nishgfx_surface_acquire() answered.
239
+ *
240
+ * @param surface the surface to present
241
+ */
129
242
  void nishgfx_surface_present(NishGfxSurface *surface);
130
243
 
131
244
  /* ---- adapter, device, errors ------------------------------------------- */
132
245
 
133
- /* An adapter, compatible with `surface` when it is not null. power is a
134
- * WGPUPowerPreference. Answers null and queues an instance error on failure. */
246
+ /**
247
+ * Request an adapter.
248
+ *
249
+ * @param instance the instance to request it from
250
+ * @param surface a surface the adapter must be able to present to, or null
251
+ * @param power a WGPUPowerPreference
252
+ * @returns the adapter, or null (and an instance error is queued) on failure
253
+ */
135
254
  NishGfxAdapter *nishgfx_adapter_request(NishGfxInstance *instance, NishGfxSurface *surface, uint32_t power);
255
+ /**
256
+ * Release an adapter.
257
+ *
258
+ * @param adapter the adapter to release
259
+ */
136
260
  void nishgfx_adapter_release(NishGfxAdapter *adapter);
137
- /* A device with default limits. Answers null and queues an instance error on
138
- * failure. Its device-lost and uncaptured-error reports go to its ring. */
261
+ /**
262
+ * Request a device with default limits. Its device-lost and uncaptured-error
263
+ * reports go to its ring.
264
+ *
265
+ * @param instance the instance the adapter came from
266
+ * @param adapter the adapter to request it from
267
+ * @returns the device, or null (and an instance error is queued) on failure
268
+ */
139
269
  NishGfxDevice *nishgfx_device_request(NishGfxInstance *instance, NishGfxAdapter *adapter);
140
- /* Release every buffer, shader, pipeline, bind group, offscreen target and
141
- * surface made from the device first: one used after this can report an
142
- * error into the freed device. */
270
+ /**
271
+ * Release a device. Release every buffer, shader, pipeline, bind group,
272
+ * offscreen target and surface made from the device first: one used after
273
+ * this can report an error into the freed device.
274
+ *
275
+ * @param device the device to release
276
+ */
143
277
  void nishgfx_device_release(NishGfxDevice *device);
144
- /* Drain one queued device error into msg (as nishgfx_instance_error_next). */
278
+ /**
279
+ * Drain one queued device error into msg, NUL-terminated and cut to cap - 1
280
+ * bytes.
281
+ *
282
+ * @param device the device whose ring is drained
283
+ * @param msg the buffer the message is copied into
284
+ * @param cap the bytes msg holds
285
+ * @returns the error's kind, a NISHGFX_ERROR_* value, or 0 when the ring is empty
286
+ */
145
287
  int32_t nishgfx_error_next(NishGfxDevice *device, void *msg, size_t cap);
146
- /* How many reports found the ring full, since the device was made. */
288
+ /**
289
+ * How many reports found the device's ring full.
290
+ *
291
+ * @param device the device to ask
292
+ * @returns the count since the device was made
293
+ */
147
294
  uint32_t nishgfx_errors_dropped(NishGfxDevice *device);
148
295
 
149
296
  /* ---- resources --------------------------------------------------------- */
150
297
 
151
- /* `label` may be null. Answers null when wgpu-native does. */
298
+ /**
299
+ * Create a buffer.
300
+ *
301
+ * @param device the device it lives on
302
+ * @param desc its size, usage and whether it starts mapped
303
+ * @param label a debug label, or null
304
+ * @returns the buffer, or null when wgpu-native answers none
305
+ */
152
306
  NishGfxBuffer *nishgfx_buffer_create(NishGfxDevice *device, const NishGfxBufferDesc *desc, const char *label);
307
+ /**
308
+ * Release a buffer.
309
+ *
310
+ * @param buffer the buffer to release
311
+ */
153
312
  void nishgfx_buffer_release(NishGfxBuffer *buffer);
154
- /* Copy len bytes of data into buffer at offset, on the device's queue. */
313
+ /**
314
+ * Copy len bytes of data into buffer at offset, on the device's queue.
315
+ *
316
+ * @param device the device whose queue writes
317
+ * @param buffer the buffer written
318
+ * @param offset the byte offset into buffer
319
+ * @param data the bytes to copy
320
+ * @param len how many bytes of data to copy
321
+ */
155
322
  void nishgfx_queue_write(NishGfxDevice *device, NishGfxBuffer *buffer, uint64_t offset,
156
323
  const void *data, size_t len);
157
- /* A shader module from NUL-terminated WGSL. A compile error is queued on the
158
- * device; the module answered is then invalid but safe to pass on. */
324
+ /**
325
+ * A shader module from WGSL. A compile error is queued on the device; the
326
+ * module answered is then invalid but safe to pass on.
327
+ *
328
+ * @param device the device it lives on
329
+ * @param wgsl the shader's source, NUL-terminated
330
+ * @returns the module, or null when wgpu-native answers none
331
+ */
159
332
  NishGfxShader *nishgfx_shader_create(NishGfxDevice *device, const char *wgsl);
333
+ /**
334
+ * Release a shader module.
335
+ *
336
+ * @param shader the module to release
337
+ */
160
338
  void nishgfx_shader_release(NishGfxShader *shader);
161
339
 
162
- /* A render pipeline builder: one vertex buffer of `stride` bytes (0 for no
163
- * vertex buffer), one color target of `color_format`, triangle list. */
340
+ /**
341
+ * A render pipeline builder: one vertex buffer of `stride` bytes (0 for no
342
+ * vertex buffer), one color target of `color_format`, triangle list.
343
+ *
344
+ * @param shader the module both stages come from
345
+ * @param vs_entry the vertex stage's entry point, NUL-terminated
346
+ * @param fs_entry the fragment stage's entry point, NUL-terminated
347
+ * @param color_format the color target's WGPUTextureFormat
348
+ * @param stride the vertex buffer's stride in bytes, or 0 for none
349
+ * @returns the builder, or null when memory runs out
350
+ */
164
351
  NishGfxPipelineDesc *nishgfx_pipeline_desc_new(NishGfxShader *shader, const char *vs_entry, const char *fs_entry,
165
352
  uint32_t color_format, uint64_t stride);
166
- /* Add a vertex attribute (a WGPUVertexFormat at offset, shader location).
167
- * Answers 0, or -1 once the builder holds 16. */
353
+ /**
354
+ * Add a vertex attribute to a pipeline builder.
355
+ *
356
+ * @param desc the builder
357
+ * @param format the attribute's WGPUVertexFormat
358
+ * @param offset its byte offset in a vertex
359
+ * @param location its shader location
360
+ * @returns 0, or -1 once the builder holds 16
361
+ */
168
362
  int32_t nishgfx_pipeline_desc_attribute(NishGfxPipelineDesc *desc, uint32_t format, uint64_t offset,
169
363
  uint32_t location);
170
- /* Build the pipeline and free the builder, either way. */
364
+ /**
365
+ * Build the pipeline and free the builder, either way.
366
+ *
367
+ * @param device the device it lives on
368
+ * @param desc the builder, freed by this call
369
+ * @returns the pipeline, or null when it cannot be built
370
+ */
171
371
  NishGfxPipeline *nishgfx_pipeline_create(NishGfxDevice *device, NishGfxPipelineDesc *desc);
372
+ /**
373
+ * Release a pipeline.
374
+ *
375
+ * @param pipeline the pipeline to release
376
+ */
172
377
  void nishgfx_pipeline_release(NishGfxPipeline *pipeline);
173
378
 
174
- /* A bind group builder for group `index` of the pipeline's layout. */
379
+ /**
380
+ * A bind group builder for group `index` of the pipeline's layout.
381
+ *
382
+ * @param pipeline the pipeline whose layout the group follows
383
+ * @param index the group's index in that layout
384
+ * @returns the builder, or null when memory runs out
385
+ */
175
386
  NishGfxBindGroupDesc *nishgfx_bind_group_desc_new(NishGfxPipeline *pipeline, uint32_t index);
176
- /* Bind size bytes of buffer at offset to `binding`; size 0 binds the rest of
177
- * the buffer from offset. Answers 0, or -1 once the builder holds 16. */
387
+ /**
388
+ * Bind size bytes of buffer at offset to `binding`; size 0 binds the rest of
389
+ * the buffer from offset.
390
+ *
391
+ * @param desc the builder
392
+ * @param binding the binding number
393
+ * @param buffer the buffer bound
394
+ * @param offset the byte offset into buffer
395
+ * @param size the bytes bound, or 0 for the rest of the buffer
396
+ * @returns 0, or -1 once the builder holds 16
397
+ */
178
398
  int32_t nishgfx_bind_group_desc_buffer(NishGfxBindGroupDesc *desc, uint32_t binding, NishGfxBuffer *buffer,
179
399
  uint64_t offset, uint64_t size);
180
- /* Build the bind group and free the builder, either way. */
400
+ /**
401
+ * Build the bind group and free the builder, either way.
402
+ *
403
+ * @param device the device it lives on
404
+ * @param desc the builder, freed by this call
405
+ * @returns the bind group, or null when it cannot be built
406
+ */
181
407
  NishGfxBindGroup *nishgfx_bind_group_create(NishGfxDevice *device, NishGfxBindGroupDesc *desc);
408
+ /**
409
+ * Release a bind group.
410
+ *
411
+ * @param group the bind group to release
412
+ */
182
413
  void nishgfx_bind_group_release(NishGfxBindGroup *group);
183
414
 
184
415
  /* ---- encoding ---------------------------------------------------------- */
185
416
 
417
+ /**
418
+ * A command encoder on the device.
419
+ *
420
+ * @param device the device whose commands it records
421
+ * @returns the encoder, or null when wgpu-native or memory answers none
422
+ */
186
423
  NishGfxEncoder *nishgfx_encoder_create(NishGfxDevice *device);
187
- /* Finish the encoder, submit it on the device's queue, and free it. */
424
+ /**
425
+ * Finish the encoder, submit it on the device's queue, and free it.
426
+ *
427
+ * @param device the device whose queue runs it
428
+ * @param encoder the encoder, freed by this call
429
+ */
188
430
  void nishgfx_encoder_submit(NishGfxDevice *device, NishGfxEncoder *encoder);
189
431
 
190
- /* A render pass on one color view. load != 0 keeps the view's contents;
191
- * otherwise it is cleared to (r, g, b, a). */
432
+ /**
433
+ * A render pass on one color view. load != 0 keeps the view's contents;
434
+ * otherwise it is cleared to (r, g, b, a).
435
+ *
436
+ * @param encoder the encoder that records it
437
+ * @param view the color view it draws into
438
+ * @param load nonzero to keep the view's contents
439
+ * @param r the clear color's red, 0 to 1
440
+ * @param g the clear color's green, 0 to 1
441
+ * @param b the clear color's blue, 0 to 1
442
+ * @param a the clear color's alpha, 0 to 1
443
+ * @returns the pass, or null for a null encoder or view or when it cannot begin
444
+ */
192
445
  NishGfxPass *nishgfx_pass_begin(NishGfxEncoder *encoder, NishGfxView *view, uint32_t load,
193
446
  double r, double g, double b, double a);
447
+ /**
448
+ * Set the pass's pipeline.
449
+ *
450
+ * @param pass the pass
451
+ * @param pipeline the pipeline the next draws use
452
+ */
194
453
  void nishgfx_pass_set_pipeline(NishGfxPass *pass, NishGfxPipeline *pipeline);
454
+ /**
455
+ * Set a bind group of the pass.
456
+ *
457
+ * @param pass the pass
458
+ * @param index the group's index in the pipeline's layout
459
+ * @param group the bind group, or null
460
+ */
195
461
  void nishgfx_pass_set_bind_group(NishGfxPass *pass, uint32_t index, NishGfxBindGroup *group);
196
- /* size 0 binds the rest of the buffer from offset. */
462
+ /**
463
+ * Set a vertex buffer of the pass. size 0 binds the rest of the buffer from
464
+ * offset.
465
+ *
466
+ * @param pass the pass
467
+ * @param slot the vertex buffer slot
468
+ * @param buffer the buffer, or null
469
+ * @param offset the byte offset into buffer
470
+ * @param size the bytes bound, or 0 for the rest of the buffer
471
+ */
197
472
  void nishgfx_pass_set_vertex_buffer(NishGfxPass *pass, uint32_t slot, NishGfxBuffer *buffer, uint64_t offset,
198
473
  uint64_t size);
474
+ /**
475
+ * Draw vertices with the pass's pipeline.
476
+ *
477
+ * @param pass the pass
478
+ * @param vertices how many vertices to draw
479
+ * @param instances how many instances to draw
480
+ * @param first_vertex the first vertex's index
481
+ * @param first_instance the first instance's index
482
+ */
199
483
  void nishgfx_pass_draw(NishGfxPass *pass, uint32_t vertices, uint32_t instances, uint32_t first_vertex,
200
484
  uint32_t first_instance);
201
- /* End the pass and free it. */
485
+ /**
486
+ * End the pass and free it.
487
+ *
488
+ * @param pass the pass, freed by this call
489
+ */
202
490
  void nishgfx_pass_end(NishGfxPass *pass);
203
491
 
204
492
  /* ---- offscreen --------------------------------------------------------- */
205
493
 
206
- /* A width x height RGBA8Unorm render target with readback; needs no window
207
- * and initialises no SDL video. */
494
+ /**
495
+ * A width x height RGBA8Unorm render target with readback; needs no window
496
+ * and initialises no SDL video.
497
+ *
498
+ * @param device the device it lives on
499
+ * @param width the width in pixels, 1 to 16384
500
+ * @param height the height in pixels, 1 to 16384
501
+ * @returns the target, or null for a side outside 1 to 16384 or when the
502
+ * device answers none
503
+ */
208
504
  NishGfxOffscreen *nishgfx_offscreen_create(NishGfxDevice *device, uint32_t width, uint32_t height);
505
+ /**
506
+ * Release an offscreen target.
507
+ *
508
+ * @param offscreen the target to release
509
+ */
209
510
  void nishgfx_offscreen_release(NishGfxOffscreen *offscreen);
210
- /* The target's view, valid until the offscreen is released. */
511
+ /**
512
+ * The target's view, valid until the offscreen is released.
513
+ *
514
+ * @param offscreen the target
515
+ * @returns the view, or null for a null target
516
+ */
211
517
  NishGfxView *nishgfx_offscreen_view(NishGfxOffscreen *offscreen);
212
- /* Copy the target's pixels, width * 4 bytes per row, top row first, into dst.
213
- * Answers 0; -1 when cap < width * height * 4 (dst untouched); -2 when the
214
- * map fails (an error is queued on the device). */
518
+ /**
519
+ * Copy the target's pixels, width * 4 bytes per row, top row first, into dst.
520
+ *
521
+ * @param offscreen the target to read
522
+ * @param dst the buffer the pixels are copied into
523
+ * @param cap the bytes dst holds
524
+ * @returns 0; -1 when cap < width * height * 4 (dst untouched); -2 when the
525
+ * map fails (an error is queued on the device)
526
+ */
215
527
  int32_t nishgfx_offscreen_read(NishGfxOffscreen *offscreen, void *dst, size_t cap);
216
528
 
217
529
  #ifdef __cplusplus
package/runtime/nish.d.ts CHANGED
@@ -241,15 +241,18 @@ declare function Err<T, E>(error: E): Result<T, E>;
241
241
  * The disposable protocol `using` reads: declared here so that a program using
242
242
  * `nish/threads`'s scope, a `Mutex`'s lock, `arena()` or a handle class needs
243
243
  * no `"ESNext.Disposable"` in its `lib`. `nish` takes `using` only for a
244
- * `scope()`, a `lock()`, an `arena()` or a `new` of a handle class, and any
245
- * other `using` initialiser is refused.
246
- *
247
- * A handle class is a class with exactly one `readonly` `CPtr` or `CPtr | null`
248
- * field: it owns the C resource the pointer names, and its `[Symbol.dispose]():
249
- * void` is `close(this.file);` or `const p = this.file; if (p !== null) {
250
- * close(p); }` for a `declare function` `close` of one parameter. `using` of a
251
- * handle class closes it at every exit of its block, once, in the reverse of
252
- * the order the declarators opened; a panic and `process.exit` do not close.
244
+ * `scope()`, a `lock()`, an `arena()`, or a handle class's `new` or factory
245
+ * call, and any other `using` initialiser is refused.
246
+ *
247
+ * A handle class is a class that owns one or more `readonly` fields, each a
248
+ * `CPtr`, an opaque `declare class`, a `HostHandle` or another handle class
249
+ * (each but a `HostHandle` perhaps `| null`). Its `[Symbol.dispose](): void`
250
+ * closes each native field, the last declared first, as `close(this.file);`
251
+ * or `const p = this.file; if (p !== null) { close(p); }` for a `declare
252
+ * function` `close` of one parameter.
253
+ * `using` of a handle class closes it at every exit of its block, once, in the
254
+ * reverse of the order the declarators opened; a panic and `process.exit` do
255
+ * not close.
253
256
  * `--deny ffi` refuses that `using`. Any other class that declares
254
257
  * `[Symbol.dispose]` is refused.
255
258
  *