@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.
- package/INSTALL.md +67 -58
- package/bin/nish +0 -0
- package/docs/AI.md +43 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +736 -499
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/scripts/build.sh +147 -5
- package/std/README.md +107 -82
- package/std/bytes.ts +23 -19
- package/std/compress/checksum.ts +1 -1
- package/std/crypto/aes.ts +48 -43
- package/std/crypto/base64url.ts +7 -5
- package/std/crypto/bcrypt-batch.ts +13 -13
- package/std/crypto/bcrypt.ts +33 -27
- package/std/crypto/chacha20poly1305.ts +16 -14
- package/std/crypto/ed25519.ts +19 -16
- package/std/crypto/hmac.ts +7 -6
- package/std/crypto/jwt.ts +23 -20
- package/std/crypto/p256.ts +63 -56
- package/std/crypto/p384.ts +23 -20
- package/std/crypto/pki.ts +18 -15
- package/std/crypto/rsa.ts +23 -19
- package/std/crypto/x25519.ts +11 -10
- package/std/crypto/x509.ts +69 -62
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +12 -11
- package/std/json-number.ts +12 -12
- package/std/json-tokenizer.ts +26 -22
- package/std/json-typed.ts +92 -78
- package/std/json-value.ts +38 -33
- package/std/json.ts +32 -28
- package/std/net/fetch.ts +1117 -230
- package/std/net/handler.ts +18 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +27 -21
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +44 -87
- package/std/net/http1-server.ts +66 -54
- package/std/net/http2-frame.ts +17 -16
- package/std/net/http2-tls.ts +17 -15
- package/std/net/http2.ts +67 -54
- package/std/net/http3-frame.ts +11 -10
- package/std/net/http3-server.ts +36 -35
- package/std/net/http3.ts +70 -58
- package/std/net/postgres.ts +178 -160
- package/std/net/prefork.ts +38 -34
- package/std/net/qpack.ts +15 -14
- package/std/net/quic-conn-ack.ts +1 -0
- package/std/net/quic-conn-cid.ts +11 -0
- package/std/net/quic-conn-params.ts +41 -14
- package/std/net/quic-datagram.ts +7 -0
- package/std/net/quic-frame.ts +48 -12
- package/std/net/quic-listener.ts +61 -44
- package/std/net/quic-packet.ts +71 -52
- package/std/net/quic-recovery.ts +59 -21
- package/std/net/quic-stream.ts +83 -55
- package/std/net/quic.ts +204 -152
- package/std/net/tls/client.ts +1 -0
- package/std/net/tls/codec.ts +81 -12
- package/std/net/tls/record-client.ts +30 -18
- package/std/net/tls/record-server.ts +74 -46
- package/std/net/tls/record.ts +33 -24
- package/std/net/tls/ticket.ts +2 -0
- package/std/net/tls/verify.ts +8 -7
- package/std/net/tls-tcp.ts +58 -50
- package/std/net/tls.ts +55 -43
- package/std/net/url.ts +12 -9
- package/std/net/websocket.ts +23 -19
- package/std/net/webtransport.ts +24 -18
- package/std/random.ts +8 -6
- package/std/regex.ts +70 -59
- package/std/sync/ring.ts +24 -21
- package/std/sync/shm.ts +9 -7
- package/std/term-io.ts +17 -14
- package/std/term-probe.ts +11 -10
- package/std/term-rate.ts +71 -61
- package/std/term.ts +73 -59
- package/std/text.ts +11 -10
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- package/std/yaml-write.ts +21 -14
package/runtime/nish.d.ts
CHANGED
|
@@ -38,8 +38,9 @@
|
|
|
38
38
|
* only as the iterable of a `for...of`, and `get`'s `V | undefined` only as a
|
|
39
39
|
* `const`'s initialiser, the left of `??` or an operand of `=== undefined`,
|
|
40
40
|
* none of which `tsc` can know (docs/LANGUAGE.md -> `Map` and `Set`).
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
*
|
|
42
|
+
* `nish/map`'s `reserve` and `getOrInsert` are not declared here: they are
|
|
43
|
+
* ordinary source, `std/map.ts`, which `tsconfig.json` maps `nish/*` to.
|
|
43
44
|
*/
|
|
44
45
|
|
|
45
46
|
// ---- Numeric widths (docs/LANGUAGE.md -> Types) ------------------------------
|
|
@@ -131,9 +132,19 @@ type integer<Lo extends number, Hi extends number> = number;
|
|
|
131
132
|
// `nish`.
|
|
132
133
|
|
|
133
134
|
/** The success arm of a `Result`, as the discriminant proves it. */
|
|
134
|
-
type ResultOk<T> = {
|
|
135
|
+
type ResultOk<T> = {
|
|
136
|
+
/** `true` on this arm: the discriminant `if (r.ok)` tests. */
|
|
137
|
+
readonly ok: true;
|
|
138
|
+
/** The success payload, readable only where `r.ok` or `r.isOk()` holds. */
|
|
139
|
+
readonly value: T;
|
|
140
|
+
};
|
|
135
141
|
/** The failure arm. */
|
|
136
|
-
type ResultErr<E> = {
|
|
142
|
+
type ResultErr<E> = {
|
|
143
|
+
/** `false` on this arm: where `if (r.ok)` fails, `r` is this arm. */
|
|
144
|
+
readonly ok: false;
|
|
145
|
+
/** The failure payload, readable only where `!r.ok` or `r.isErr()` holds. */
|
|
146
|
+
readonly error: E;
|
|
147
|
+
};
|
|
137
148
|
|
|
138
149
|
/**
|
|
139
150
|
* The methods every `Result` carries. `r.ok` is the same bit as a plain
|
|
@@ -209,7 +220,11 @@ type Result<T, E> = (ResultOk<T> | ResultErr<E>) & ResultMethods<T, E>;
|
|
|
209
220
|
* @returns a `Result` on its success arm.
|
|
210
221
|
*/
|
|
211
222
|
declare function Ok<T, E>(value: T): Result<T, E>;
|
|
212
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* The success of a `Result<void, E>`, with no payload. Capability: none.
|
|
225
|
+
*
|
|
226
|
+
* @returns a `Result<void, E>` on its success arm.
|
|
227
|
+
*/
|
|
213
228
|
declare function Ok<E>(): Result<void, E>;
|
|
214
229
|
/**
|
|
215
230
|
* The failure value, likewise: its `Result` type comes from the context.
|
|
@@ -227,15 +242,18 @@ declare function Err<T, E>(error: E): Result<T, E>;
|
|
|
227
242
|
* `nish/threads`'s scope, a `Mutex`'s lock, `arena()` or a handle class needs
|
|
228
243
|
* no `"ESNext.Disposable"` in its `lib`. `nish` takes `using` only for a
|
|
229
244
|
* `scope()`, a `lock()`, an `arena()` or a `new` of a handle class, and any
|
|
230
|
-
* other `using` initialiser is refused.
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* `
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
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.
|
|
253
|
+
* `--deny ffi` refuses that `using`. Any other class that declares
|
|
254
|
+
* `[Symbol.dispose]` is refused.
|
|
255
|
+
*
|
|
256
|
+
* The compiler emits the join, the release, the unlock or the close itself, and
|
|
239
257
|
* `[Symbol.dispose]` is never called by name.
|
|
240
258
|
*/
|
|
241
259
|
interface SymbolConstructor {
|
|
@@ -263,16 +281,18 @@ interface StringConstructor {
|
|
|
263
281
|
/**
|
|
264
282
|
* The bytes of `bytes[start..end)` as one string, with one range check, one
|
|
265
283
|
* allocation and one copy. The range is `s.slice`'s, `0 <= start <= end <=
|
|
266
|
-
* bytes.length`, checked once after all three arguments are evaluated;
|
|
267
|
-
* else panics with `slice out of range: [start, end) of length len`
|
|
268
|
-
* `bytes` is a `u8[]` reached any way an array is, `readonly` or
|
|
269
|
-
* element or a `u8[] | null` is refused (NL2268). Both ends are
|
|
270
|
-
* and are numbers (NL2058).
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
284
|
+
* bytes.length`, checked once after all three arguments are evaluated;
|
|
285
|
+
* anything else panics with `slice out of range: [start, end) of length len`
|
|
286
|
+
* and exits 1. `bytes` is a `u8[]` reached any way an array is, `readonly` or
|
|
287
|
+
* not; a wider element or a `u8[] | null` is refused (NL2268). Both ends are
|
|
288
|
+
* required (NL2060) and are numbers (NL2058).
|
|
289
|
+
*
|
|
290
|
+
* Nothing validates the bytes as UTF-8: a multi-byte character copied whole
|
|
291
|
+
* is that character, and a range that cuts one is bytes that are not a valid
|
|
292
|
+
* string. Natively the string's bytes are the array's, so `write` or
|
|
293
|
+
* `writeFileSync` sends any bytes back out unchanged; bytes that are not text
|
|
294
|
+
* go out through `writeBytes` and `writeFileBytesSync`, which agree on every
|
|
295
|
+
* host. Capability: none.
|
|
276
296
|
*
|
|
277
297
|
* @param bytes the buffer to read.
|
|
278
298
|
* @param start the first byte taken.
|
|
@@ -375,12 +395,13 @@ declare var process: Process;
|
|
|
375
395
|
* integer of the same width and another signedness keeps its bits. The float
|
|
376
396
|
* rule is Rust's `as` cast, not JavaScript's modulo-2^32 `ToInt32`:
|
|
377
397
|
* `toI32(5e10)` is `2147483647`, while the integer rule gives
|
|
378
|
-
* `toI32(5000000000)` as `705032704`.
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
398
|
+
* `toI32(5000000000)` as `705032704`.
|
|
399
|
+
*
|
|
400
|
+
* The result of a `u8`, a `u16` or a ranged integer lies in the declared range
|
|
401
|
+
* of `x`, so `const r: integer<0, 255> = toI32(b)` costs no check for a `u8`
|
|
402
|
+
* `b`; under `--number-mode f64` this is how a `number` enters an `integer<Lo,
|
|
403
|
+
* Hi>`. An argument that is not a number is refused, as `` `toI32` expects a
|
|
404
|
+
* number (i32, i64, or f64), got string ``. Capability: none.
|
|
384
405
|
*
|
|
385
406
|
* @param x the value to convert.
|
|
386
407
|
* @returns `x` in 32 signed bits.
|
|
@@ -492,22 +513,25 @@ declare function f32ToBits(x: f32): i32;
|
|
|
492
513
|
* never turned into a branch: `a` for an all-ones mask, `b` for zero. Every
|
|
493
514
|
* operand is one type, `u32` or `u64`. Both are `number` here, so one generic
|
|
494
515
|
* declaration stands for the two. Any other type is refused, as `` `ctEq` takes
|
|
495
|
-
* u32 or u64 operands (convert with toU32 or toU64), got i64 `` (NL2399):
|
|
496
|
-
* `i64`, `u8`, `u16`, a ranged integer, `f32`, `f64` and `boolean`
|
|
497
|
-
* a boolean mask in particular.
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
516
|
+
* u32 or u64 operands (convert with toU32 or toU64), got i64 `` (NL2399):
|
|
517
|
+
* `i32`, `i64`, `u8`, `u16`, a ranged integer, `f32`, `f64` and `boolean`
|
|
518
|
+
* included, and a boolean mask in particular.
|
|
519
|
+
*
|
|
520
|
+
* Operands of two types are `` `ctSelect` needs every operand of one type, got
|
|
521
|
+
* u32 and u64 `` (NL2400). A bare numeric literal takes its type from the first
|
|
522
|
+
* operand that is not one, wherever it stands. The call takes exactly three
|
|
523
|
+
* arguments, and like every function it is not a value. The all-ones-or-zero
|
|
524
|
+
* convention for the mask is not checked, because the check would be a branch;
|
|
525
|
+
* any other mask is a defined bitwise blend, so `ctSelect(0xf0f0f0f0, a, b)`
|
|
526
|
+
* takes the high nibble of each byte from `a`.
|
|
527
|
+
*
|
|
528
|
+
* The promise is no branch and no secret-indexed load in the primitive itself
|
|
529
|
+
* and nothing about the caller's own code, which branches on a secret if it
|
|
530
|
+
* writes `if (ctEq(a, b) !== 0)`. On `wasm32` the same barrier is emitted, but
|
|
531
|
+
* the engine compiles the module again, so nothing is promised there. Under
|
|
532
|
+
* Node the runtime shim computes the same answer as a pure function (over
|
|
533
|
+
* `u32`, put back in range with `>>> 0`; over `u64`, on BigInts), and only the
|
|
534
|
+
* timing is not claimed. Capability: none.
|
|
511
535
|
*
|
|
512
536
|
* @param mask all ones to choose `a`, zero to choose `b`.
|
|
513
537
|
* @param a the value an all-ones mask selects.
|
|
@@ -521,11 +545,13 @@ declare function ctSelect<T extends u32 | u64>(mask: T, a: T, b: T): T;
|
|
|
521
545
|
* takes, so `ctSelect(ctEq(a, b), x, y)` never shows the optimiser a boolean.
|
|
522
546
|
* Both operands are one type, `u32` or `u64`; any other type, a boolean and a
|
|
523
547
|
* ranged integer included, is refused with NL2399, and operands of two types
|
|
524
|
-
* with NL2400, as for `ctSelect`.
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
548
|
+
* with NL2400, as for `ctSelect`.
|
|
549
|
+
*
|
|
550
|
+
* A bare numeric literal takes its type from the other operand, so `ctEq(0, x)`
|
|
551
|
+
* works, while `ctEq(1, 2)`, with no width to take, is an `i32` and refused.
|
|
552
|
+
* The call takes exactly two arguments, and like every function it is not a
|
|
553
|
+
* value. The no-branch promise and its limits are `ctSelect`'s, and so are the
|
|
554
|
+
* `wasm32` and Node readings. Capability: none.
|
|
529
555
|
*
|
|
530
556
|
* @param a one operand.
|
|
531
557
|
* @param b the other, of the same type.
|
|
@@ -536,42 +562,49 @@ declare function ctEq<T extends u32 | u64>(a: T, b: T): T;
|
|
|
536
562
|
* Every byte of `bytes` set to zero, in stores neither `-O2` nor `-flto` may
|
|
537
563
|
* drop as dead (#385): how a key, a secret scalar or another secret is cleared
|
|
538
564
|
* once it is used. A statement: used as a value it is `` `secureZero` returns
|
|
539
|
-
* void and can only be used as a statement `` (NL2105), and it takes exactly
|
|
540
|
-
* argument (NL2061). It fills a `u8[]` only; anything else is ``
|
|
541
|
-
* fills a `u8[]`, got i32[] `` (NL2402), a string included, which
|
|
565
|
+
* void and can only be used as a statement `` (NL2105), and it takes exactly
|
|
566
|
+
* one argument (NL2061). It fills a `u8[]` only; anything else is ``
|
|
567
|
+
* `secureZero` fills a `u8[]`, got i32[] `` (NL2402), a string included, which
|
|
568
|
+
* is immutable.
|
|
569
|
+
*
|
|
542
570
|
* The call writes its argument, so a `readonly u8[]` is `` Cannot `secureZero`
|
|
543
|
-
* through readonly u8[] (declare it u8[] to write through it) `` (NL2264), and
|
|
544
|
-
* function that wipes a parameter does not get `readonly` on it; in a scope's
|
|
571
|
+
* through readonly u8[] (declare it u8[] to write through it) `` (NL2264), and
|
|
572
|
+
* a function that wipes a parameter does not get `readonly` on it; in a scope's
|
|
545
573
|
* region it is refused where `fill` is (NL2394). An empty array is a call that
|
|
546
|
-
* clears nothing.
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
574
|
+
* clears nothing.
|
|
575
|
+
*
|
|
576
|
+
* It clears the bytes of the array it is handed and nothing else: a copy taken
|
|
577
|
+
* before (`slice`, a `push` into another array, an element read into a local, a
|
|
578
|
+
* register spilled to the stack) is the program's to clear, and nothing clears
|
|
579
|
+
* what the operating system swapped out. It works under the wasi profile; a
|
|
580
|
+
* freestanding wasm module has no wipe. Under Node it is a loop that sets every
|
|
581
|
+
* element to zero, and a collector that moved the array may have left the old
|
|
582
|
+
* bytes behind. Capability: none.
|
|
553
583
|
*
|
|
554
584
|
* @param bytes the buffer to clear.
|
|
555
585
|
*/
|
|
556
586
|
declare function secureZero(bytes: u8[]): void;
|
|
557
587
|
/**
|
|
558
588
|
* One `lstat` of `path`, so a symbolic link answers for itself and not for what
|
|
559
|
-
* it names: the owner's uid in the high 32 bits and `st_mode` (the file type
|
|
560
|
-
* the permission bits) in the low 32, or -1 when the path does not resolve
|
|
561
|
-
* holds a NUL (#386). Both come out of one `lstat`, so they describe the
|
|
562
|
-
* file however the path changes in between.
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
* `
|
|
574
|
-
*
|
|
589
|
+
* it names: the owner's uid in the high 32 bits and `st_mode` (the file type
|
|
590
|
+
* and the permission bits) in the low 32, or -1 when the path does not resolve
|
|
591
|
+
* or holds a NUL (#386). Both come out of one `lstat`, so they describe the
|
|
592
|
+
* same file however the path changes in between.
|
|
593
|
+
*
|
|
594
|
+
* Take them apart with `(om >> 32) & 0xffffffff` (the owner) and `om & 0xfff`
|
|
595
|
+
* (the permission bits) or `om & 0xf000` (the type: `0x8000` a regular file,
|
|
596
|
+
* `0x4000` a directory, `0xa000` a symbolic link). The mask on the owner is not
|
|
597
|
+
* optional: a uid of 2^31 or more fills bit 63, which `>>` on an `i64` copies
|
|
598
|
+
* down, so `om >> 32` alone answers a negative owner that never equals
|
|
599
|
+
* `geteuid()`.
|
|
600
|
+
*
|
|
601
|
+
* The answer is an `i64` in both number modes, and an `i32` variable is refused
|
|
602
|
+
* rather than truncated (`` Cannot initialize i32 variable `om` with i64 ``).
|
|
603
|
+
* It takes a `string` path and exactly one argument. A wasm32 build is refused,
|
|
604
|
+
* with `` `lstatOwnerModeSync` reaches the operating system, and a wasm32 build
|
|
605
|
+
* has none to reach ``. Under Node the runtime shim packs `fs.lstatSync`'s
|
|
606
|
+
* `uid` and `mode` the same way as a BigInt. It is a global, not a `nish:`
|
|
607
|
+
* export. Capability: fs.read.
|
|
575
608
|
*
|
|
576
609
|
* @param path the path to stat, not followed through a final link.
|
|
577
610
|
* @returns `(uid << 32) | st_mode`, or -1.
|
|
@@ -615,14 +648,16 @@ declare function isExecutableSync(path: string): boolean;
|
|
|
615
648
|
/**
|
|
616
649
|
* `xs[i]` with no bounds check: undefined behaviour when `i` is out of range,
|
|
617
650
|
* which is the whole of the trade. The array holds numbers (`i32`, `i64`, `u8`,
|
|
618
|
-
* `u16`, `u32`, `u64`, `f32` or `f64`) and nothing else, or it is ``
|
|
619
|
-
* takes an array of numbers (i32, i64, u8, u16, u32, u64, f32 or
|
|
620
|
-
* string[] `` (NL2455). The index is an `i32`, so an `f64` one is ``
|
|
621
|
-
* expects an argument of type i32, got f64 ``. A `readonly`
|
|
651
|
+
* `u16`, `u32`, `u64`, `f32` or `f64`) and nothing else, or it is ``
|
|
652
|
+
* `uncheckedGet` takes an array of numbers (i32, i64, u8, u16, u32, u64, f32 or
|
|
653
|
+
* f64), got string[] `` (NL2455). The index is an `i32`, so an `f64` one is ``
|
|
654
|
+
* `uncheckedGet` expects an argument of type i32, got f64 ``. A `readonly`
|
|
655
|
+
* array may be read.
|
|
656
|
+
*
|
|
622
657
|
* To the bounds proof it is the load `xs[i]` is, less the check: it moves no
|
|
623
658
|
* length, and it records no passed check, so a checked `xs[i]` after it keeps
|
|
624
|
-
* its check. Under `--deny-panics` it is an allowed `unchecked` site. Under
|
|
625
|
-
* the runtime shim reads `xs[i]`. Capability: unsafe.
|
|
659
|
+
* its check. Under `--deny-panics` it is an allowed `unchecked` site. Under
|
|
660
|
+
* Node the runtime shim reads `xs[i]`. Capability: unsafe.
|
|
626
661
|
*
|
|
627
662
|
* @param xs the array of numbers to read.
|
|
628
663
|
* @param i the index, trusted to be in range.
|
|
@@ -636,12 +671,13 @@ declare function uncheckedGet<T extends number>(xs: readonly T[], i: i32): T;
|
|
|
636
671
|
* array may not be written (`` Cannot `uncheckedSet` through readonly u8[] ``).
|
|
637
672
|
* A number is copied in and held by nothing, so the store needs none of the
|
|
638
673
|
* escape and inline-array reasoning `xs[i] = v` carries; an array field handed
|
|
639
|
-
* to it is a value and is not stored inline.
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
674
|
+
* to it is a value and is not stored inline.
|
|
675
|
+
*
|
|
676
|
+
* The store is a write of the array for every rule that asks, the rule for a
|
|
677
|
+
* parallel body included. To the bounds proof it is the store `xs[i] = v` is,
|
|
678
|
+
* less the check, and a resize in the value stored still takes the length away.
|
|
679
|
+
* Under `--deny-panics` it is an allowed `unchecked` site. Under Node the
|
|
680
|
+
* runtime shim stores `xs[i] = v`. Capability: unsafe.
|
|
645
681
|
*
|
|
646
682
|
* @param xs the array of numbers to write.
|
|
647
683
|
* @param i the index, trusted to be in range.
|
|
@@ -651,12 +687,14 @@ declare function uncheckedSet<T extends number>(xs: T[], i: i32, v: T): void;
|
|
|
651
687
|
/**
|
|
652
688
|
* `a + b` wrapped to the operands' width, `i32` or `i64`: defined for every
|
|
653
689
|
* pair, where the operator `+` panics on signed overflow. The two operands are
|
|
654
|
-
* one type, which is also the answer: `` `wrappingMul` takes i32 or i64
|
|
655
|
-
* (convert with toI32 or toI64), got u32 `` is NL2454 (the unsigned
|
|
656
|
-
* already wrap), and two widths are `` `wrappingAdd` needs every operand
|
|
657
|
-
* type, got i32 and i64 `` (NL2400). A bare literal takes the other
|
|
658
|
-
* type, wherever it stands. `wrappingAdd(2147483647, 1)` is
|
|
659
|
-
*
|
|
690
|
+
* one type, which is also the answer: `` `wrappingMul` takes i32 or i64
|
|
691
|
+
* operands (convert with toI32 or toI64), got u32 `` is NL2454 (the unsigned
|
|
692
|
+
* words already wrap), and two widths are `` `wrappingAdd` needs every operand
|
|
693
|
+
* of one type, got i32 and i64 `` (NL2400). A bare literal takes the other
|
|
694
|
+
* operand's type, wherever it stands. `wrappingAdd(2147483647, 1)` is
|
|
695
|
+
* `-2147483648`.
|
|
696
|
+
*
|
|
697
|
+
* In a module constant's initialiser the call folds, wrapping, where
|
|
660
698
|
* `2147483647 + 1` is refused; it is the one call such an initialiser may make.
|
|
661
699
|
* It is not a site under `--deny-panics`, as it cannot panic. Under Node the
|
|
662
700
|
* runtime shim computes `(a + b) | 0` on an `i32` and `BigInt.asIntN(64, ...)`
|
|
@@ -691,21 +729,24 @@ declare function wrappingMul<T extends i32 | i64>(a: T, b: T): T;
|
|
|
691
729
|
* The `NUL`-terminated bytes at `p`, copied into a new string of the program's
|
|
692
730
|
* own: undefined behaviour unless `p` is a live C string, since nothing proves
|
|
693
731
|
* the bytes end (a dangling or freed pointer, or a buffer with no `NUL`). It is
|
|
694
|
-
* the copy a `string` result of a `declare function` makes, for the pointers
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
* `
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
732
|
+
* the copy a `string` result of a `declare function` makes, for the pointers C
|
|
733
|
+
* allocated for the caller to free, and C's buffer is never held past the call,
|
|
734
|
+
* so `free(p)` straight after it is safe.
|
|
735
|
+
*
|
|
736
|
+
* The parameter is `CPtr`, so an unnarrowed `CPtr | null` is refused (``
|
|
737
|
+
* `readCString` expects an argument of type CPtr, got CPtr | null ``) and `if
|
|
738
|
+
* (p !== null)` comes first; a `declare function` whose result is declared
|
|
739
|
+
* `CPtr` gets no check, so declare a result that may be `NULL` as `CPtr |
|
|
740
|
+
* null`.
|
|
741
|
+
*
|
|
742
|
+
* The copy is new on every call and is the calling function's allocation, and
|
|
743
|
+
* it is refused inside a `using a = arena()` block that would release one held
|
|
744
|
+
* outside it (`` `readCString(p)` may be allocated inside the `using arena()`
|
|
745
|
+
* block ``). Under `--deny-panics` it is an allowed `unchecked` site, with the
|
|
746
|
+
* copy's `oom` beside it, and the pointer it reads is `ffi`. It lowers the same
|
|
747
|
+
* on wasm32, where whether the program links is the `declare function`'s
|
|
748
|
+
* question. It has no Node form, as a `CPtr` comes only from a `declare
|
|
749
|
+
* function`, which Node cannot call. Capability: unsafe.
|
|
709
750
|
*
|
|
710
751
|
* @param p the address a `declare function` handed back.
|
|
711
752
|
* @returns a copy of the bytes before the first `NUL`.
|
|
@@ -741,14 +782,15 @@ declare function writeError(s: string): void;
|
|
|
741
782
|
* — the one way to send bytes that are not text, a byte of 0x80 or above or a
|
|
742
783
|
* zero byte included. A loop of `write(2)` sends them all, retried on an
|
|
743
784
|
* interrupted call. A pipe whose reader has gone raises SIGPIPE natively, as it
|
|
744
|
-
* does for `write`, where Node answers `-32` EPIPE.
|
|
745
|
-
*
|
|
746
|
-
* `
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
785
|
+
* does for `write`, where Node answers `-32` EPIPE.
|
|
786
|
+
*
|
|
787
|
+
* `off` and `len` are `netWrite`'s buffer range, checked once after the
|
|
788
|
+
* arguments are evaluated: `0 <= off`, `0 <= len` and `off + len <=
|
|
789
|
+
* bytes.length`, and anything else panics, as `dst.set` does, with `slice out
|
|
790
|
+
* of range: [off, off+len) of length n` and exits 1. The shape is `netWrite`'s
|
|
791
|
+
* with the descriptor fixed at 1. Under Node the range is the same check and
|
|
792
|
+
* the bytes go to `fs.writeSync(1, ...)`. A `wasm32` build has no stdout to
|
|
793
|
+
* reach and refuses it. Also exported by `nish:io`. Capability: none.
|
|
752
794
|
*
|
|
753
795
|
* @param bytes the buffer to send.
|
|
754
796
|
* @param off the first byte sent; `0 <= off`.
|
|
@@ -873,21 +915,24 @@ declare function renameSync(from: string, to: string): i32;
|
|
|
873
915
|
*/
|
|
874
916
|
declare function unlinkSync(path: string): i32;
|
|
875
917
|
/**
|
|
876
|
-
* `writeFileSync` with an explicit `mode`: the file is exactly `mode`
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
*
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
918
|
+
* `writeFileSync` with an explicit `mode`: the file is exactly `mode` (`0o600`
|
|
919
|
+
* for a secret) before a byte of `data` is in it, whatever the umask or a file
|
|
920
|
+
* already there had. The open passes `mode` and an `fchmod(2)` sets it before
|
|
921
|
+
* the first byte is written, so the umask cannot widen it, a file that already
|
|
922
|
+
* existed at 0644 is narrowed before it holds the new contents, and no reader
|
|
923
|
+
* that opens it afterwards finds the secret under the old mode.
|
|
924
|
+
*
|
|
925
|
+
* A descriptor opened before, while the file was wider, is not revoked and
|
|
926
|
+
* still reads what is written. A symbolic link at the path is refused (-40),
|
|
927
|
+
* its target untouched. The file is truncated and written in place, so a crash
|
|
928
|
+
* or a failed write leaves it empty or partial, and a file this process may
|
|
929
|
+
* write but does not own is emptied before the mode change answers -1
|
|
930
|
+
* (`EPERM`).
|
|
931
|
+
*
|
|
932
|
+
* For a file that must be the old one or the new one, write a temporary name
|
|
933
|
+
* beside the target with this and move it over with `renameSync`. Never an exit
|
|
934
|
+
* and never a panic. A `wasm32` build refuses it, and a WASI build answers
|
|
935
|
+
* `-ENOSYS`, as WASI has no file modes to set. Capability: fs.write.
|
|
891
936
|
*
|
|
892
937
|
* @param path the file to write.
|
|
893
938
|
* @param data its new contents.
|
|
@@ -961,8 +1006,10 @@ declare function isDirectorySync(path: string): boolean;
|
|
|
961
1006
|
* like every string comparison here, so it agrees with Node's `.sort()` for
|
|
962
1007
|
* ASCII names and can differ for names that are not. `null` when the directory
|
|
963
1008
|
* cannot be read at all — a missing path, a plain file, a parent that cannot be
|
|
964
|
-
* searched.
|
|
965
|
-
*
|
|
1009
|
+
* searched.
|
|
1010
|
+
*
|
|
1011
|
+
* An empty directory is an empty array, so the null check is about the
|
|
1012
|
+
* directory and not about its contents. A WASI build always answers `null`:
|
|
966
1013
|
* `fd_readdir` lists a preopened directory rather than a path, which is a
|
|
967
1014
|
* different contract. Capability: fs.read.
|
|
968
1015
|
*
|
|
@@ -1019,17 +1066,18 @@ declare function spawnSyncTo(argv: string[], stdoutPath: string, stderrPath: str
|
|
|
1019
1066
|
* `stdin`'s bytes and then end of file, and whatever it prints is appended to
|
|
1020
1067
|
* `stdout` and `stderr`, which keep what they held. The runtime writes `stdin`
|
|
1021
1068
|
* and drains both outputs in one `poll` loop, so a child that fills one pipe
|
|
1022
|
-
* while the parent waits on another cannot deadlock it. When a stream passes
|
|
1023
|
-
*
|
|
1024
|
-
* keeps the first 16 MiB.
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
* the
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
*
|
|
1031
|
-
* (
|
|
1032
|
-
*
|
|
1069
|
+
* while the parent waits on another cannot deadlock it. When a stream passes 16
|
|
1070
|
+
* MiB (`NISH_PIPED_CAP`) the child is killed with `SIGKILL` and that array
|
|
1071
|
+
* keeps the first 16 MiB.
|
|
1072
|
+
*
|
|
1073
|
+
* A child that exits without reading its stdin is not a failure. The child
|
|
1074
|
+
* inherits the environment and working directory, and no descriptor of the
|
|
1075
|
+
* program but its three streams; it starts with SIGPIPE as the program had it,
|
|
1076
|
+
* and the program's own SIGPIPE from writing to a child that stopped reading is
|
|
1077
|
+
* absorbed. The two output arrays are grown by the runtime, so `readonly` is
|
|
1078
|
+
* refused for them, as is a typed-array spelling (`Int32Array`, ...), whose
|
|
1079
|
+
* length is fixed. A `wasm32` build refuses it (NL2404). Capability:
|
|
1080
|
+
* process.spawn.
|
|
1033
1081
|
*
|
|
1034
1082
|
* @param argv the program and its arguments.
|
|
1035
1083
|
* @param stdin the bytes the child reads.
|
|
@@ -1101,13 +1149,14 @@ declare function kill(pid: i32, sig: i32): i32;
|
|
|
1101
1149
|
* tuple). `pid` is a child's, or -1 for any child. After `signalFd()` a
|
|
1102
1150
|
* blocking wait never sees EINTR, because that handler is installed with
|
|
1103
1151
|
* `SA_RESTART` and the wait restarts, and it cannot be woken by SIGTERM either:
|
|
1104
|
-
* a supervisor that must answer a signal while its children run reaps with
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
* Capability:
|
|
1152
|
+
* a supervisor that must answer a signal while its children run reaps with flag
|
|
1153
|
+
* 1 (WNOHANG) on each tick of a `pollWait` loop that also watches the signal
|
|
1154
|
+
* descriptor, and stops its children with `kill` when `readSignal` answers.
|
|
1155
|
+
*
|
|
1156
|
+
* No reading under Node, which throws, naming itself. A `wasm32` build refuses
|
|
1157
|
+
* it (NL2404), and a scope's task or a parallel body that calls it is refused
|
|
1158
|
+
* as any shared write is. Also exported by `nish:process`. Capability:
|
|
1159
|
+
* process.spawn.
|
|
1111
1160
|
*
|
|
1112
1161
|
* @param pid the child to wait for, or -1.
|
|
1113
1162
|
* @param flags 0, or 1 for WNOHANG; any other bit is `[-22, 0]`, as is a pid
|
|
@@ -1151,11 +1200,12 @@ declare function totalMemory(): i64;
|
|
|
1151
1200
|
* calling thread's and every thread started after it, so it belongs at the top
|
|
1152
1201
|
* of `main`, before a `scope()` or a parallel loop starts the pool, and a task
|
|
1153
1202
|
* or a parallel body that calls it is refused as any shared write is. It never
|
|
1154
|
-
* crashes the program: a failure is only the answer.
|
|
1155
|
-
*
|
|
1156
|
-
* `
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
1203
|
+
* crashes the program: a failure is only the answer.
|
|
1204
|
+
*
|
|
1205
|
+
* A `wasm32` build refuses it (NL2404). Throws under Node. Also exported by
|
|
1206
|
+
* `nish:process`. The label is `kill`'s: neither reaches another process, but
|
|
1207
|
+
* the priority is the one the program's children inherit, and a step down
|
|
1208
|
+
* cannot always be taken back. Capability: process.spawn.
|
|
1159
1209
|
*
|
|
1160
1210
|
* @param n the nice value, 0..19.
|
|
1161
1211
|
* @returns 0, or a negative errno: `n` outside 0..19 is -22 (EINVAL), and `n`
|
|
@@ -1194,15 +1244,16 @@ declare function setIdlePriority(): i32;
|
|
|
1194
1244
|
declare function setCpuAffinity(cpu: i32): i32;
|
|
1195
1245
|
/**
|
|
1196
1246
|
* One environment variable, as the call runs. The value is what `getenv(3)`
|
|
1197
|
-
* answers, so it is bytes: a variable holding something that is not valid
|
|
1198
|
-
*
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1203
|
-
* is
|
|
1204
|
-
*
|
|
1205
|
-
*
|
|
1247
|
+
* answers, so it is bytes: a variable holding something that is not valid UTF-8
|
|
1248
|
+
* comes back as those bytes, as `readFileSync` does, and every offset into it
|
|
1249
|
+
* is a byte offset. The bytes are copied into the arena, so the result is an
|
|
1250
|
+
* ordinary string that outlives any later change to the environment, and it is
|
|
1251
|
+
* narrowed with `if (cc !== null)` like any other nullable.
|
|
1252
|
+
*
|
|
1253
|
+
* It is a call and not `process.env.CC`, because a member access on a key
|
|
1254
|
+
* chosen at runtime is forbidden. Two reads of one variable are two calls: a
|
|
1255
|
+
* `setenv` from linked C may change the answer between them. Also exported by
|
|
1256
|
+
* `nish:process`. Capability: env.
|
|
1206
1257
|
*
|
|
1207
1258
|
* @param name the variable's name.
|
|
1208
1259
|
* @returns its value, or `null` when it is unset (an empty value, as `CC=`, is a
|
|
@@ -1250,9 +1301,11 @@ declare function statMtimeSync(path: string): f64;
|
|
|
1250
1301
|
* A descriptor that becomes readable when SIGTERM or SIGINT arrives. It is the
|
|
1251
1302
|
* read end of a pipe that a `sigaction` handler in the runtime's C writes one
|
|
1252
1303
|
* byte to per signal, so the signals' default action (ending the process) never
|
|
1253
|
-
* runs. The handler runs in whichever thread the signal lands on, so a
|
|
1254
|
-
* task or a parallel worker running when it is called cannot take the
|
|
1255
|
-
* end the process, and nothing is blocked for a spawned child to
|
|
1304
|
+
* runs. The handler runs in whichever thread the signal lands on, so a
|
|
1305
|
+
* `scope()` task or a parallel worker running when it is called cannot take the
|
|
1306
|
+
* signal and end the process, and nothing is blocked for a spawned child to
|
|
1307
|
+
* inherit.
|
|
1308
|
+
*
|
|
1256
1309
|
* Installing the handler overrides a disposition the process started with, so a
|
|
1257
1310
|
* signal its parent ignored is heard, as `process.on("SIGTERM")` hears it under
|
|
1258
1311
|
* Node. Made once: every later call answers the same descriptor. A child that
|
|
@@ -1260,9 +1313,11 @@ declare function statMtimeSync(path: string): f64;
|
|
|
1260
1313
|
* signal, because `exec` resets a caught signal to its default. Signals other
|
|
1261
1314
|
* than SIGTERM and SIGINT are not in the language. A descriptor rather than a
|
|
1262
1315
|
* handler, so a server's loop can wait on it beside its sockets with
|
|
1263
|
-
* `pollWait`.
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1316
|
+
* `pollWait`.
|
|
1317
|
+
*
|
|
1318
|
+
* A `wasm32` build and the `wasi` profile refuse it (NL2404). No reading under
|
|
1319
|
+
* Node, which delivers a signal only to its event loop: it throws. Also
|
|
1320
|
+
* exported by `nish:process`. Capability: signal.
|
|
1266
1321
|
*
|
|
1267
1322
|
* @returns the descriptor, or -1 when it cannot be made.
|
|
1268
1323
|
*/
|
|
@@ -1335,20 +1390,27 @@ declare function netLocalPort(fd: i32): i32;
|
|
|
1335
1390
|
*/
|
|
1336
1391
|
declare function tcpListen(host: string, port: i32, backlog: i32): i32;
|
|
1337
1392
|
/**
|
|
1338
|
-
* `tcpListen`'s socket, with `SO_REUSEPORT` for flag 1 and `TCP_NODELAY` on
|
|
1339
|
-
* for flag 2. Flag 1 lets several listeners that all ask
|
|
1340
|
-
*
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
*
|
|
1349
|
-
*
|
|
1350
|
-
*
|
|
1351
|
-
*
|
|
1393
|
+
* `tcpListen`'s socket, with `SO_REUSEPORT` for flag 1 and `TCP_NODELAY` on
|
|
1394
|
+
* each accepted socket for flag 2. Flag 1 lets several listeners that all ask
|
|
1395
|
+
* for it share one port, each with its own accept queue, whether one process
|
|
1396
|
+
* holds them all or each of several processes holds one.
|
|
1397
|
+
*
|
|
1398
|
+
* On Linux the connections are spread by a hash of the connection's 4-tuple and
|
|
1399
|
+
* only listeners of the same user may share; on Darwin the listeners share the
|
|
1400
|
+
* port but one of them takes the connections, so the flag buys a restart
|
|
1401
|
+
* without a gap rather than a spread. Flag 2 sets `TCP_NODELAY` on every
|
|
1402
|
+
* connection `tcpAccept` takes from the listener, on every platform: the
|
|
1403
|
+
* runtime sets it on each accepted socket, and a connection on which it cannot
|
|
1404
|
+
* be set is closed and its failure answered.
|
|
1405
|
+
*
|
|
1406
|
+
* Flag 4, with flag 1, steers by CPU: a new connection goes to the group's
|
|
1407
|
+
* listener whose bind order is the index of the CPU that received it (Linux;
|
|
1408
|
+
* -95 elsewhere); a CPU past the group's size falls back to the hash. Flags
|
|
1409
|
+
* add: 3 is both, 5 and 7 steer. Flag 0 is `tcpListen` exactly. A port held by
|
|
1410
|
+
* a listener without flag 1 is -98 to a listener that asks for it, and the
|
|
1411
|
+
* other way round. Refused at compile time on wasm32 and the WASI profile
|
|
1412
|
+
* (NL2404). Not callable in a `scope()` task or a parallel body. Capability:
|
|
1413
|
+
* net.
|
|
1352
1414
|
*
|
|
1353
1415
|
* @param host the numeric address to bind.
|
|
1354
1416
|
* @param port the port, 0 for any.
|
|
@@ -1406,8 +1468,8 @@ declare function netRead(fd: i32, buf: u8[], off: i32, len: i32): i32;
|
|
|
1406
1468
|
declare function netWrite(fd: i32, buf: readonly u8[], off: i32, len: i32): i32;
|
|
1407
1469
|
/**
|
|
1408
1470
|
* `netWrite` of `a`'s range then `b`'s, in one system call (`sendmsg` with two buffers), so a
|
|
1409
|
-
* header and a body leave together with no copy into one buffer. The count may be fewer than
|
|
1410
|
-
* + bLen` and may end inside `a`; the program sends the rest, as after a short `netWrite`. A gone
|
|
1471
|
+
* header and a body leave together with no copy into one buffer. The count may be fewer than
|
|
1472
|
+
* `aLen + bLen` and may end inside `a`; the program sends the rest, as after a short `netWrite`. A gone
|
|
1411
1473
|
* peer is -32, never SIGPIPE. Both ranges are checked as `netRead`'s is, `a`'s first, and either
|
|
1412
1474
|
* may be empty. Not callable in a `scope()` task or a parallel body. Refused at compile time on
|
|
1413
1475
|
* wasm32 and the WASI profile (NL2404). Capability: net.
|
|
@@ -1534,18 +1596,24 @@ declare function udpSendTo(
|
|
|
1534
1596
|
ecn: i32
|
|
1535
1597
|
): i32;
|
|
1536
1598
|
/**
|
|
1537
|
-
* The next datagram, or several GRO coalesced, into `buf[off, off + len)` in
|
|
1538
|
-
* `len` if it is longer. An empty datagram is a datagram:
|
|
1539
|
-
*
|
|
1540
|
-
* `
|
|
1541
|
-
*
|
|
1542
|
-
*
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1546
|
-
*
|
|
1547
|
-
*
|
|
1548
|
-
*
|
|
1599
|
+
* The next datagram, or several GRO coalesced, into `buf[off, off + len)` in
|
|
1600
|
+
* one `recvmsg`, cut to `len` if it is longer. An empty datagram is a datagram:
|
|
1601
|
+
* the answer is 0 for it. Not `willreturn`, as `udpSendTo`. The range is
|
|
1602
|
+
* checked as `netRead`'s is, with the same panic. `meta` must be an `i32[]`
|
|
1603
|
+
* (NL2406), and none of the written arrays may be `readonly`.
|
|
1604
|
+
*
|
|
1605
|
+
* On a socket bound with `udpBind` flag 2, one GSO send arrives as one datagram
|
|
1606
|
+
* of up to 64 KB with `meta[0]` its segment size, so walk the buffer in steps
|
|
1607
|
+
* of that size, the last datagram possibly shorter; without it the datagrams
|
|
1608
|
+
* arrive apart with `meta[0]` 0. The kernel coalesces only datagrams of one
|
|
1609
|
+
* flow that arrive after the option is set. On Darwin `meta` is always `0, 0`,
|
|
1610
|
+
* and a `meta[1]` of 0 is also what a datagram that is not ECN-capable reads
|
|
1611
|
+
* as.
|
|
1612
|
+
*
|
|
1613
|
+
* Not callable in a `scope()` task or a parallel body. A call that writes
|
|
1614
|
+
* `buf`, `from` or `meta` is refused in a scope's region on an array a task may
|
|
1615
|
+
* read, as `fill` is. Refused at compile time on wasm32 and the WASI profile
|
|
1616
|
+
* (NL2404). Capability: net.
|
|
1549
1617
|
*
|
|
1550
1618
|
* @param fd the UDP socket.
|
|
1551
1619
|
* @param buf the buffer filled.
|
|
@@ -1624,18 +1692,23 @@ declare function pollModify(loop: i32, fd: i32, events: i32, token: i32): i32;
|
|
|
1624
1692
|
*/
|
|
1625
1693
|
declare function pollRemove(loop: i32, fd: i32): i32;
|
|
1626
1694
|
/**
|
|
1627
|
-
* Wait for readiness, filling pairs: `ready[2k]` token, `ready[2k + 1]` events
|
|
1628
|
-
* writable, with 4 added for a hang-up or an error). Not
|
|
1629
|
-
*
|
|
1630
|
-
* `
|
|
1631
|
-
*
|
|
1632
|
-
*
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
1635
|
-
*
|
|
1636
|
-
*
|
|
1637
|
-
*
|
|
1638
|
-
*
|
|
1695
|
+
* Wait for readiness, filling pairs: `ready[2k]` token, `ready[2k + 1]` events
|
|
1696
|
+
* (1 readable, 2 writable, with 4 added for a hang-up or an error). Not
|
|
1697
|
+
* `willreturn`, because it can wait forever. It never writes past
|
|
1698
|
+
* `ready.length`. `ready` must be an `i32[]` (the tokens are the program's own
|
|
1699
|
+
* `i32`s) and not `readonly`. A signal that interrupts the wait makes it answer
|
|
1700
|
+
* 0, as a timeout does, rather than wait past the deadline; the descriptor
|
|
1701
|
+
* `signalFd()` answers can be added to the loop, and is readable when SIGTERM
|
|
1702
|
+
* or SIGINT arrives.
|
|
1703
|
+
*
|
|
1704
|
+
* A UDP socket is always writable, and on Linux one whose both sides are shut
|
|
1705
|
+
* is readable, writable and hung up, 7. On Darwin a descriptor both readable
|
|
1706
|
+
* and writable is one pair, 3; a descriptor watching nothing is never reported
|
|
1707
|
+
* (epoll still reports its hang-up or error as 4); and a peer's half-close is 5
|
|
1708
|
+
* (`1|4`) where Linux reports 1. Not callable in a `scope()` task or a parallel
|
|
1709
|
+
* body. A call that writes `ready` is refused in a scope's region on an array a
|
|
1710
|
+
* task may read, as `fill` is. Refused at compile time on wasm32 and the WASI
|
|
1711
|
+
* profile (NL2404). Capability: net.
|
|
1639
1712
|
*
|
|
1640
1713
|
* @param loop the loop from `pollCreate`.
|
|
1641
1714
|
* @param ready receives the pairs; shorter than 2 is -22.
|
|
@@ -1720,22 +1793,29 @@ declare const NET_SO_SNDBUF: i32;
|
|
|
1720
1793
|
*/
|
|
1721
1794
|
declare const NET_SO_RCVBUF: i32;
|
|
1722
1795
|
/**
|
|
1723
|
-
* A listening Unix stream socket at `path` (`@name`: Linux's abstract
|
|
1724
|
-
* 0600, so only its owner may connect. A Unix socket
|
|
1725
|
-
*
|
|
1726
|
-
*
|
|
1727
|
-
*
|
|
1728
|
-
*
|
|
1729
|
-
*
|
|
1730
|
-
*
|
|
1731
|
-
*
|
|
1732
|
-
*
|
|
1733
|
-
*
|
|
1734
|
-
*
|
|
1735
|
-
*
|
|
1736
|
-
*
|
|
1737
|
-
*
|
|
1738
|
-
*
|
|
1796
|
+
* A listening Unix stream socket at `path` (`@name`: Linux's abstract
|
|
1797
|
+
* namespace), its file mode 0600, so only its owner may connect. A Unix socket
|
|
1798
|
+
* is a descriptor like any other: `netRead`, `netWrite`, `netShutdown`,
|
|
1799
|
+
* `netClose` and the readiness loop take it, and a gone peer is -32. The path
|
|
1800
|
+
* is bytes up to the first NUL, so a NUL inside it is -22, as an empty path is.
|
|
1801
|
+
*
|
|
1802
|
+
* It must fit `sun_path` with its NUL: 107 bytes on Linux, 103 on Darwin,
|
|
1803
|
+
* measured on the string as written; a longer one is -36 before a socket
|
|
1804
|
+
* exists. An abstract name leaves no file; its name is at most 107 bytes, a
|
|
1805
|
+
* bare `@` is -22, and on Darwin every `@` path is -95. A file whose name
|
|
1806
|
+
* starts with `@` is spelled `./@name`. A bind never replaces a file. Closing a
|
|
1807
|
+
* listener does not unlink its file: `unlinkSync` it when the server stops, or
|
|
1808
|
+
* let the next start's `NET_UNIX_UNLINK_STALE` clear it.
|
|
1809
|
+
*
|
|
1810
|
+
* A failure after the bind closes the socket and unlinks the file it made. A
|
|
1811
|
+
* connect needs write permission on the file and search permission on every
|
|
1812
|
+
* directory above it, which is the real boundary: put the socket in a directory
|
|
1813
|
+
* only the users who may connect can reach. With `NET_UNIX_UNLINK_STALE`, the
|
|
1814
|
+
* runtime connects to an existing socket file and unlinks it only on a refusal;
|
|
1815
|
+
* between the probe and the unlink another process can bind the path, so the
|
|
1816
|
+
* directory must be the program's own. Refused at compile time on wasm32 and
|
|
1817
|
+
* the WASI profile (NL2404). Not callable in a `scope()` task or a parallel
|
|
1818
|
+
* body. Capability: net.
|
|
1739
1819
|
*
|
|
1740
1820
|
* @param path the socket file, or `@name`; it must be a `string`.
|
|
1741
1821
|
* @param backlog the kernel's queue of unaccepted connections.
|
|
@@ -1795,14 +1875,17 @@ declare function unixAccept(fd: i32): i32;
|
|
|
1795
1875
|
*/
|
|
1796
1876
|
declare function unixSocketPair(kind: i32, fds: i32[]): i32;
|
|
1797
1877
|
/**
|
|
1798
|
-
* Send `buf[off..off+len)` over the Unix socket `sock` with a copy of the
|
|
1799
|
-
* (`SCM_RIGHTS`). The receiver's `recvFd` gets a new descriptor
|
|
1800
|
-
* offset and status flags shared, as `dup`
|
|
1801
|
-
*
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1804
|
-
*
|
|
1805
|
-
*
|
|
1878
|
+
* Send `buf[off..off+len)` over the Unix socket `sock` with a copy of the
|
|
1879
|
+
* descriptor `fd` (`SCM_RIGHTS`). The receiver's `recvFd` gets a new descriptor
|
|
1880
|
+
* for the same open file, with its offset and status flags shared, as `dup`
|
|
1881
|
+
* gives; `fd` stays open here. The descriptor rides on at least one byte of
|
|
1882
|
+
* data, so the receiver's read is what tells it a descriptor came. A stream
|
|
1883
|
+
* socket can send short: the descriptor travels with the first bytes, so send
|
|
1884
|
+
* the rest with `netWrite`, not `sendFd`, or the receiver gets a second copy.
|
|
1885
|
+
*
|
|
1886
|
+
* The range is checked as `netRead`'s is, with the same panic; `buf` may be
|
|
1887
|
+
* `readonly`. Not callable in a `scope()` task or a parallel body. Refused at
|
|
1888
|
+
* compile time on wasm32 and the WASI profile (NL2404). Capability: net.
|
|
1806
1889
|
*
|
|
1807
1890
|
* @param sock the Unix socket.
|
|
1808
1891
|
* @param fd the descriptor sent.
|
|
@@ -1815,19 +1898,25 @@ declare function unixSocketPair(kind: i32, fds: i32[]): i32;
|
|
|
1815
1898
|
*/
|
|
1816
1899
|
declare function sendFd(sock: i32, fd: i32, buf: readonly u8[], off: i32, len: i32): i32;
|
|
1817
1900
|
/**
|
|
1818
|
-
* Read at most `len` bytes into `buf[off..]` from the Unix socket `sock`, and
|
|
1819
|
-
* that came with them into `fd[0]`, or -1 when the message
|
|
1820
|
-
* the message is closed before the
|
|
1821
|
-
*
|
|
1822
|
-
*
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1826
|
-
*
|
|
1827
|
-
*
|
|
1828
|
-
*
|
|
1829
|
-
*
|
|
1830
|
-
*
|
|
1901
|
+
* Read at most `len` bytes into `buf[off..]` from the Unix socket `sock`, and
|
|
1902
|
+
* the first descriptor that came with them into `fd[0]`, or -1 when the message
|
|
1903
|
+
* carried none. Every other descriptor in the message is closed before the
|
|
1904
|
+
* answer, so a peer cannot leave this process holding descriptors it never
|
|
1905
|
+
* asked for; room is made for 8, so the kernel drops the rest of a message that
|
|
1906
|
+
* carries more and the bytes are still answered.
|
|
1907
|
+
*
|
|
1908
|
+
* The one kept is close-on-exec, so a later `spawn` does not hand it on, and
|
|
1909
|
+
* keeps the sender's blocking mode (it is not made non-blocking, so `netRead`
|
|
1910
|
+
* on a blocking one waits: set what the program needs on it before it joins a
|
|
1911
|
+
* loop). The range is checked as `netRead`'s is, with the same panic. `buf` and
|
|
1912
|
+
* `fd` must not be `readonly`, and `fd` must be an `i32[]`. On Darwin the
|
|
1913
|
+
* descriptor is made close-on-exec by a later `fcntl`, so a child another
|
|
1914
|
+
* thread spawns between the two inherits it.
|
|
1915
|
+
*
|
|
1916
|
+
* Not callable in a `scope()` task or a parallel body. A call that writes `buf`
|
|
1917
|
+
* or `fd` is refused in a scope's region on an array a task may read, as `fill`
|
|
1918
|
+
* is. Refused at compile time on wasm32 and the WASI profile (NL2404).
|
|
1919
|
+
* Capability: net.
|
|
1831
1920
|
*
|
|
1832
1921
|
* @param sock the Unix socket.
|
|
1833
1922
|
* @param buf the buffer filled.
|
|
@@ -1840,14 +1929,17 @@ declare function sendFd(sock: i32, fd: i32, buf: readonly u8[], off: i32, len: i
|
|
|
1840
1929
|
*/
|
|
1841
1930
|
declare function recvFd(sock: i32, buf: u8[], off: i32, len: i32, fd: i32[]): i32;
|
|
1842
1931
|
/**
|
|
1843
|
-
* The peer of the Unix socket `fd` as the kernel recorded it when the
|
|
1844
|
-
* `connect`, or the `socketpair`): `out` gets its pid,
|
|
1845
|
-
*
|
|
1846
|
-
*
|
|
1847
|
-
*
|
|
1848
|
-
*
|
|
1849
|
-
*
|
|
1850
|
-
*
|
|
1932
|
+
* The peer of the Unix socket `fd` as the kernel recorded it when the
|
|
1933
|
+
* connection was made (the `connect`, or the `socketpair`): `out` gets its pid,
|
|
1934
|
+
* uid and gid. A peer that has since changed its uid, passed the socket on or
|
|
1935
|
+
* closed still reads as it was then. The pid is -1 where Darwin has no
|
|
1936
|
+
* `LOCAL_PEERPID` or the kernel refuses it. A uid or gid of 2^31 or above wraps
|
|
1937
|
+
* (-2 is uid 4294967294). `out` must be an `i32[]` and not `readonly`. Not
|
|
1938
|
+
* callable in a `scope()` task or a parallel body.
|
|
1939
|
+
*
|
|
1940
|
+
* A call that writes `out` is refused in a scope's region on an array a task
|
|
1941
|
+
* may read, as `fill` is. Refused at compile time on wasm32 and the WASI
|
|
1942
|
+
* profile (NL2404). Capability: net.
|
|
1851
1943
|
*
|
|
1852
1944
|
* @param fd the connected Unix socket.
|
|
1853
1945
|
* @param out at least 3 slots, receiving pid, uid and gid.
|
|
@@ -1923,15 +2015,18 @@ declare const NET_UNIX_SEQPACKET: i32;
|
|
|
1923
2015
|
*/
|
|
1924
2016
|
declare function readStdin(buf: u8[], off: i32, len: i32): i32;
|
|
1925
2017
|
/**
|
|
1926
|
-
* Wait for stdin to be readable, or `timeoutMs` milliseconds to pass: the frame
|
|
1927
|
-
* terminal program, which costs nothing when a key arrives early.
|
|
1928
|
-
* as readable, so the read after it answers at once,
|
|
1929
|
-
* -11, which a loop treats as the end.
|
|
1930
|
-
*
|
|
1931
|
-
*
|
|
1932
|
-
*
|
|
1933
|
-
*
|
|
1934
|
-
*
|
|
2018
|
+
* Wait for stdin to be readable, or `timeoutMs` milliseconds to pass: the frame
|
|
2019
|
+
* clock of a terminal program, which costs nothing when a key arrives early.
|
|
2020
|
+
* Its end and an error count as readable, so the read after it answers at once,
|
|
2021
|
+
* with 0 or a negative errno that is not -11, which a loop treats as the end.
|
|
2022
|
+
*
|
|
2023
|
+
* A signal that ends the wait early gives `false`, except a Ctrl-Z and `fg`
|
|
2024
|
+
* once `setRawMode(true)` has caught SIGTSTP, after which the wait goes on for
|
|
2025
|
+
* what is left of the timeout; before raw mode the system's default stop
|
|
2026
|
+
* decides (Linux goes on with what is left, Darwin ends the wait). Not
|
|
2027
|
+
* `willreturn`. Under `--profile wasi` it waits at least 10 ms; under Node it
|
|
2028
|
+
* throws; refused at compile time on a freestanding wasm32 target. Capability:
|
|
2029
|
+
* tty.
|
|
1935
2030
|
*
|
|
1936
2031
|
* @param timeoutMs the most milliseconds to wait; negative: forever.
|
|
1937
2032
|
* @returns `true` when it is readable, `false` when the time passed or a signal ended the wait.
|
|
@@ -1958,32 +2053,45 @@ declare function isTerminal(fd: i32): boolean;
|
|
|
1958
2053
|
declare function terminalSize(): i32[];
|
|
1959
2054
|
/**
|
|
1960
2055
|
* Raw mode on stdin's terminal, or the mode it had back. No echo, no line
|
|
1961
|
-
* editing, no CR-to-NL translation, no flow control (Ctrl-S, Ctrl-Q) and no
|
|
1962
|
-
* bytes are 8 bits wide, and a read answers as soon as one
|
|
1963
|
-
* its bytes (an arrow as the three of `ESC [
|
|
1964
|
-
*
|
|
1965
|
-
*
|
|
1966
|
-
* `
|
|
1967
|
-
*
|
|
1968
|
-
*
|
|
1969
|
-
*
|
|
1970
|
-
*
|
|
1971
|
-
*
|
|
1972
|
-
*
|
|
1973
|
-
*
|
|
1974
|
-
*
|
|
1975
|
-
*
|
|
1976
|
-
*
|
|
1977
|
-
*
|
|
1978
|
-
*
|
|
1979
|
-
*
|
|
1980
|
-
*
|
|
1981
|
-
*
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
*
|
|
2056
|
+
* editing, no CR-to-NL translation, no flow control (Ctrl-S, Ctrl-Q) and no
|
|
2057
|
+
* parity stripping; bytes are 8 bits wide, and a read answers as soon as one
|
|
2058
|
+
* byte is there, so a key arrives as its bytes (an arrow as the three of `ESC [
|
|
2059
|
+
* A`).
|
|
2060
|
+
*
|
|
2061
|
+
* `ISIG` stays on: Ctrl-C is still SIGINT and ends the program, Ctrl-\ is still
|
|
2062
|
+
* SIGQUIT and Ctrl-Z still stops it, so none of them arrives as a byte (3, 28,
|
|
2063
|
+
* 26); a program that wants Ctrl-C as a key asks for SIGINT through `signalFd`
|
|
2064
|
+
* and handles it in its loop. `OPOST` stays on, so "\n" still moves to the
|
|
2065
|
+
* start of the next line and output needs no "\r\n".
|
|
2066
|
+
*
|
|
2067
|
+
* Each `setRawMode(true)` that enters raw mode saves the termios that was
|
|
2068
|
+
* there; it comes back on `setRawMode(false)`, when `main` returns or
|
|
2069
|
+
* `process.exit` is called, on every panic, and on every signal whose default
|
|
2070
|
+
* action ends the program, SIGKILL aside (SIGINT, SIGTERM, SIGQUIT, SIGHUP,
|
|
2071
|
+
* SIGPIPE, SIGALRM, SIGUSR1, SIGUSR2, SIGPROF, SIGVTALRM, SIGXCPU, SIGXFSZ,
|
|
2072
|
+
* SIGSYS, and the faults SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS and SIGSEGV).
|
|
2073
|
+
*
|
|
2074
|
+
* For each, a handler is installed only when the program left it at its default
|
|
2075
|
+
* action: it restores the terminal, puts the default back and raises the signal
|
|
2076
|
+
* again, so the program still dies of it and its parent sees that (exit status
|
|
2077
|
+
* 143 for SIGTERM). A program that took SIGTERM or SIGINT through `signalFd`
|
|
2078
|
+
* keeps it and puts the terminal back itself, or by returning.
|
|
2079
|
+
*
|
|
2080
|
+
* SIGKILL leaves raw mode behind, and so does a stack overflow on a thread
|
|
2081
|
+
* other than the one that called `setRawMode(true)`; `stty sane` undoes either,
|
|
2082
|
+
* as it does a stop by SIGSTOP. Ctrl-Z (SIGTSTP) restores the terminal, stops
|
|
2083
|
+
* the program, and once `fg` or `bg` continues it enters raw mode again; a
|
|
2084
|
+
* program continued in the background stops again, by SIGTTOU, until `fg`. A
|
|
2085
|
+
* program started in the background (`app &`) that calls `setRawMode(true)` is
|
|
2086
|
+
* stopped by SIGTTOU, as any program that sets the terminal is, and enters raw
|
|
2087
|
+
* mode on `fg`.
|
|
2088
|
+
*
|
|
2089
|
+
* Two threads that call it at once take turns, so the termios saved is the one
|
|
2090
|
+
* from before either. Asking for the mode it is already in changes nothing and
|
|
2091
|
+
* answers 0, so `setRawMode(false)` is always safe. Under `--profile wasi`, on
|
|
2092
|
+
* a pipe or a file, `true` is -25 and `false` is 0; under Node and in a browser
|
|
2093
|
+
* it throws; refused at compile time on a freestanding wasm32 target.
|
|
2094
|
+
* Capability: tty.
|
|
1987
2095
|
*
|
|
1988
2096
|
* @param on `true` for raw mode, `false` for the mode before.
|
|
1989
2097
|
* @returns 0, -25 when stdin is not a terminal, or the host's `-errno` when the terminal
|
|
@@ -1991,18 +2099,21 @@ declare function terminalSize(): i32[];
|
|
|
1991
2099
|
*/
|
|
1992
2100
|
declare function setRawMode(on: boolean): i32;
|
|
1993
2101
|
/**
|
|
1994
|
-
* Bytes the runtime writes to the terminal on stdout at exit, on a panic and
|
|
1995
|
-
*
|
|
1996
|
-
* restored; raw mode or not, and setting them installs the same handlers.
|
|
1997
|
-
* the escapes that leave an alternate screen, show the cursor
|
|
1998
|
-
* Replaces the previous string; "" clears it. The
|
|
1999
|
-
*
|
|
2000
|
-
*
|
|
2001
|
-
*
|
|
2002
|
-
*
|
|
2003
|
-
*
|
|
2004
|
-
*
|
|
2005
|
-
*
|
|
2102
|
+
* Bytes the runtime writes to the terminal on stdout at exit, on a panic and on
|
|
2103
|
+
* every signal that ends the program (SIGKILL aside), before termios is
|
|
2104
|
+
* restored; raw mode or not, and setting them installs the same handlers.
|
|
2105
|
+
* Typical bytes are the escapes that leave an alternate screen, show the cursor
|
|
2106
|
+
* or turn mouse reporting off. Replaces the previous string; "" clears it. The
|
|
2107
|
+
* cap is 4096 bytes.
|
|
2108
|
+
*
|
|
2109
|
+
* They are written to stdout once, with `write` alone, at most once however
|
|
2110
|
+
* many of those paths race, and after all the program printed (output is not
|
|
2111
|
+
* buffered). Ctrl-Z and `setRawMode(false)` do not end the program, so they
|
|
2112
|
+
* write nothing. A signal that lands while the string is replaced writes the
|
|
2113
|
+
* old one or the new one, whole. A program sets them once it has switched the
|
|
2114
|
+
* terminal and again with each change, last the set that undoes them all. Under
|
|
2115
|
+
* `--profile wasi` it keeps nothing; under Node and in a browser it throws;
|
|
2116
|
+
* refused at compile time on a freestanding wasm32 target. Capability: tty.
|
|
2006
2117
|
*
|
|
2007
2118
|
* @param bytes the bytes written at the end.
|
|
2008
2119
|
* @returns 0, -25 when stdout is not a terminal (`""` is still 0 there), -7 (E2BIG) past
|
|
@@ -2020,19 +2131,23 @@ declare function setTerminalRestore(bytes: string): i32;
|
|
|
2020
2131
|
/** The system's random source, with its one member. */
|
|
2021
2132
|
declare var crypto: {
|
|
2022
2133
|
/**
|
|
2023
|
-
* Every byte of `bytes` from the kernel's CSPRNG (`getrandom(2)` on Linux,
|
|
2024
|
-
* `EINTR` and short reads; `getentropy(3)` in 256-byte chunks on
|
|
2025
|
-
* bytes a call. A `u8[]` only, where the Web API takes
|
|
2026
|
-
* the unit a key or a nonce is written
|
|
2027
|
-
*
|
|
2028
|
-
*
|
|
2029
|
-
*
|
|
2030
|
-
*
|
|
2031
|
-
*
|
|
2032
|
-
*
|
|
2033
|
-
*
|
|
2034
|
-
*
|
|
2035
|
-
*
|
|
2134
|
+
* Every byte of `bytes` from the kernel's CSPRNG (`getrandom(2)` on Linux,
|
|
2135
|
+
* looping over `EINTR` and short reads; `getentropy(3)` in 256-byte chunks on
|
|
2136
|
+
* macOS); at most 65,536 bytes a call. A `u8[]` only, where the Web API takes
|
|
2137
|
+
* any integer typed array: the byte is the unit a key or a nonce is written
|
|
2138
|
+
* in, and anything else is refused at compile time (NL2402). A statement,
|
|
2139
|
+
* where the Web API also answers its argument, which the caller already
|
|
2140
|
+
* holds. An empty array is filled with nothing.
|
|
2141
|
+
*
|
|
2142
|
+
* The array is written, so a `readonly u8[]` is refused (and, inside a
|
|
2143
|
+
* `scope()` region, an array a task may read). More than 65,536 bytes is a
|
|
2144
|
+
* panic, `crypto.getRandomValues: <n> bytes asked for, and one call fills at
|
|
2145
|
+
* most 65536`, exit 1. A source that fails is a panic too; nothing weaker is
|
|
2146
|
+
* ever substituted. It is the source for a key. `crypto` has no other member
|
|
2147
|
+
* (NL2403, for example `crypto.randomUUID`). Refused at compile time on
|
|
2148
|
+
* wasm32 and the WASI profile (NL2404). Under Node the prelude fills a plain
|
|
2149
|
+
* `u8[]` too and panics past 65,536 with the same words; without the prelude
|
|
2150
|
+
* it takes only a typed array. Capability: entropy.
|
|
2036
2151
|
*
|
|
2037
2152
|
* @param bytes the buffer filled.
|
|
2038
2153
|
*/
|
|
@@ -2388,14 +2503,16 @@ declare module "nish:process" {
|
|
|
2388
2503
|
/**
|
|
2389
2504
|
* The same run as `spawnSync`, with every stream a pipe: the child reads
|
|
2390
2505
|
* `stdin`'s bytes and then end of file, and whatever it writes to its stdout
|
|
2391
|
-
* and stderr is appended to `stdout` and `stderr`, which keep what they
|
|
2392
|
-
*
|
|
2393
|
-
*
|
|
2394
|
-
*
|
|
2395
|
-
*
|
|
2396
|
-
*
|
|
2397
|
-
*
|
|
2398
|
-
*
|
|
2506
|
+
* and stderr is appended to `stdout` and `stderr`, which keep what they held.
|
|
2507
|
+
* It is the run for a child that takes a secret on stdin, which `ps` and
|
|
2508
|
+
* `/proc` do not show. A child that exits without reading its stdin is not a
|
|
2509
|
+
* failure.
|
|
2510
|
+
*
|
|
2511
|
+
* The child inherits the environment and working directory, and no descriptor
|
|
2512
|
+
* of the program but its three streams; it starts with SIGPIPE as the program
|
|
2513
|
+
* had it, and the program's own SIGPIPE from writing to a child that stopped
|
|
2514
|
+
* reading is absorbed. One `poll` loop writes and drains, so a child that
|
|
2515
|
+
* fills one pipe cannot deadlock the parent.
|
|
2399
2516
|
*
|
|
2400
2517
|
* @param argv The program and its arguments.
|
|
2401
2518
|
* @param stdin The bytes the child reads.
|
|
@@ -3374,6 +3491,21 @@ declare module "nish:simd" {
|
|
|
3374
3491
|
* folds to a constant vector when every lane is one.
|
|
3375
3492
|
*
|
|
3376
3493
|
* @param a0 Lane 0, a `u8`; `a1` to `a15` are lanes 1 to 15 in order.
|
|
3494
|
+
* @param a1 Lane 1.
|
|
3495
|
+
* @param a2 Lane 2.
|
|
3496
|
+
* @param a3 Lane 3.
|
|
3497
|
+
* @param a4 Lane 4.
|
|
3498
|
+
* @param a5 Lane 5.
|
|
3499
|
+
* @param a6 Lane 6.
|
|
3500
|
+
* @param a7 Lane 7.
|
|
3501
|
+
* @param a8 Lane 8.
|
|
3502
|
+
* @param a9 Lane 9.
|
|
3503
|
+
* @param a10 Lane 10.
|
|
3504
|
+
* @param a11 Lane 11.
|
|
3505
|
+
* @param a12 Lane 12.
|
|
3506
|
+
* @param a13 Lane 13.
|
|
3507
|
+
* @param a14 Lane 14.
|
|
3508
|
+
* @param a15 Lane 15.
|
|
3377
3509
|
* @returns The vector.
|
|
3378
3510
|
*/
|
|
3379
3511
|
export function u8x16(
|
|
@@ -3384,6 +3516,13 @@ declare module "nish:simd" {
|
|
|
3384
3516
|
* A `u16x8` of 8 lanes, one argument per lane, lane 0 first.
|
|
3385
3517
|
*
|
|
3386
3518
|
* @param a0 Lane 0, a `u16`; `a1` to `a7` are lanes 1 to 7 in order.
|
|
3519
|
+
* @param a1 Lane 1.
|
|
3520
|
+
* @param a2 Lane 2.
|
|
3521
|
+
* @param a3 Lane 3.
|
|
3522
|
+
* @param a4 Lane 4.
|
|
3523
|
+
* @param a5 Lane 5.
|
|
3524
|
+
* @param a6 Lane 6.
|
|
3525
|
+
* @param a7 Lane 7.
|
|
3387
3526
|
* @returns The vector.
|
|
3388
3527
|
*/
|
|
3389
3528
|
export function u16x8(a0: u16, a1: u16, a2: u16, a3: u16, a4: u16, a5: u16, a6: u16, a7: u16): u16x8;
|
|
@@ -3391,6 +3530,9 @@ declare module "nish:simd" {
|
|
|
3391
3530
|
* An `i32x4` of 4 lanes, one argument per lane, lane 0 first.
|
|
3392
3531
|
*
|
|
3393
3532
|
* @param a0 Lane 0, an `i32`; `a1` to `a3` are lanes 1 to 3 in order.
|
|
3533
|
+
* @param a1 Lane 1.
|
|
3534
|
+
* @param a2 Lane 2.
|
|
3535
|
+
* @param a3 Lane 3.
|
|
3394
3536
|
* @returns The vector.
|
|
3395
3537
|
*/
|
|
3396
3538
|
export function i32x4(a0: i32, a1: i32, a2: i32, a3: i32): i32x4;
|
|
@@ -3398,6 +3540,9 @@ declare module "nish:simd" {
|
|
|
3398
3540
|
* A `u32x4` of 4 lanes, one argument per lane, lane 0 first.
|
|
3399
3541
|
*
|
|
3400
3542
|
* @param a0 Lane 0, a `u32`; `a1` to `a3` are lanes 1 to 3 in order.
|
|
3543
|
+
* @param a1 Lane 1.
|
|
3544
|
+
* @param a2 Lane 2.
|
|
3545
|
+
* @param a3 Lane 3.
|
|
3401
3546
|
* @returns The vector.
|
|
3402
3547
|
*/
|
|
3403
3548
|
export function u32x4(a0: u32, a1: u32, a2: u32, a3: u32): u32x4;
|
|
@@ -3405,6 +3550,9 @@ declare module "nish:simd" {
|
|
|
3405
3550
|
* An `f32x4` of 4 lanes, one argument per lane, lane 0 first.
|
|
3406
3551
|
*
|
|
3407
3552
|
* @param a0 Lane 0, an `f32`; `a1` to `a3` are lanes 1 to 3 in order.
|
|
3553
|
+
* @param a1 Lane 1.
|
|
3554
|
+
* @param a2 Lane 2.
|
|
3555
|
+
* @param a3 Lane 3.
|
|
3408
3556
|
* @returns The vector.
|
|
3409
3557
|
*/
|
|
3410
3558
|
export function f32x4(a0: f32, a1: f32, a2: f32, a3: f32): f32x4;
|
|
@@ -3412,6 +3560,7 @@ declare module "nish:simd" {
|
|
|
3412
3560
|
* An `f64x2` of 2 lanes, one argument per lane, lane 0 first.
|
|
3413
3561
|
*
|
|
3414
3562
|
* @param a0 Lane 0, an `f64`; `a1` is lane 1.
|
|
3563
|
+
* @param a1 Lane 1.
|
|
3415
3564
|
* @returns The vector.
|
|
3416
3565
|
*/
|
|
3417
3566
|
export function f64x2(a0: f64, a1: f64): f64x2;
|
|
@@ -4413,9 +4562,22 @@ declare module "nish:region" {
|
|
|
4413
4562
|
* spawn(log(c + d));
|
|
4414
4563
|
* }
|
|
4415
4564
|
*
|
|
4416
|
-
*
|
|
4417
|
-
* to an `async` function, written where it is
|
|
4418
|
-
* it to (`src/async-check.ts`); `tsc` sees ordinary promises.
|
|
4565
|
+
* All five are reached only through the import. Each argument to `awaitAll`
|
|
4566
|
+
* or `spawn` is a direct call to an `async` function, written where it is
|
|
4567
|
+
* made, which the checker holds it to (`src/async-check.ts`); `tsc` sees ordinary promises. A spawned
|
|
4568
|
+
* call's arguments are numbers, `boolean`s, enums or `string`s (NL2673): the
|
|
4569
|
+
* task outlives the function that spawned it.
|
|
4570
|
+
*
|
|
4571
|
+
* `sleep(ms)`, `readable(fd)` and `writable(fd)` are the waits a task makes
|
|
4572
|
+
* on the executor, an epoll (kqueue on Darwin) loop that resumes ready tasks
|
|
4573
|
+
* in the kernel's order and then expired timers by deadline:
|
|
4574
|
+
*
|
|
4575
|
+
* import { readable, sleep } from "nish:async";
|
|
4576
|
+
*
|
|
4577
|
+
* async function tick(): Promise<void> {
|
|
4578
|
+
* await sleep(10);
|
|
4579
|
+
* console.log("tick");
|
|
4580
|
+
* }
|
|
4419
4581
|
*
|
|
4420
4582
|
* There is no `async` in a wasm build: under a `wasm32` target or
|
|
4421
4583
|
* `--profile wasi` an `async` function is NL2652.
|
|
@@ -4564,6 +4726,37 @@ declare module "nish:async" {
|
|
|
4564
4726
|
g: Promise<G>,
|
|
4565
4727
|
h: Promise<H>,
|
|
4566
4728
|
): Promise<[A, B, C, D, E, F, G, H]>;
|
|
4729
|
+
/**
|
|
4730
|
+
* Suspend the task for `ms` milliseconds while the executor runs the
|
|
4731
|
+
* others. Written only as `await sleep(ms)` inside an `async` function
|
|
4732
|
+
* (NL2671).
|
|
4733
|
+
*
|
|
4734
|
+
* @param ms The milliseconds to wait, an `i32`.
|
|
4735
|
+
* @returns `true` once the time has passed; `false` at once for a negative
|
|
4736
|
+
* `ms`, which makes no wait.
|
|
4737
|
+
*/
|
|
4738
|
+
export function sleep(ms: i32): Promise<boolean>;
|
|
4739
|
+
/**
|
|
4740
|
+
* Suspend the task until `fd` has bytes to read, or its peer has hung up,
|
|
4741
|
+
* while the executor runs the others. Written only as
|
|
4742
|
+
* `await readable(fd)` inside an `async` function (NL2671). Refused under
|
|
4743
|
+
* `--emit-ts` (NL4017).
|
|
4744
|
+
*
|
|
4745
|
+
* @param fd An open descriptor: a socket, a pipe or a terminal.
|
|
4746
|
+
* @returns `true` once `fd` is ready; `false` when the wait could not be
|
|
4747
|
+
* made (an `fd` that is not open). A regular file is always ready.
|
|
4748
|
+
*/
|
|
4749
|
+
export function readable(fd: i32): Promise<boolean>;
|
|
4750
|
+
/**
|
|
4751
|
+
* Suspend the task until `fd` takes bytes without blocking, while the
|
|
4752
|
+
* executor runs the others. Written only as `await writable(fd)` inside an
|
|
4753
|
+
* `async` function (NL2671). Refused under `--emit-ts` (NL4017).
|
|
4754
|
+
*
|
|
4755
|
+
* @param fd An open descriptor: a socket, a pipe or a terminal.
|
|
4756
|
+
* @returns `true` once `fd` is ready; `false` when the wait could not be
|
|
4757
|
+
* made (an `fd` that is not open). A regular file is always ready.
|
|
4758
|
+
*/
|
|
4759
|
+
export function writable(fd: i32): Promise<boolean>;
|
|
4567
4760
|
}
|
|
4568
4761
|
|
|
4569
4762
|
// ---- Arena (docs/LANGUAGE.md -> Arena) ---------------------------------------
|
|
@@ -4605,25 +4798,30 @@ declare const Arena: {
|
|
|
4605
4798
|
* initialiser, and the binding is never read; under Node there is no arena and
|
|
4606
4799
|
* the disposal does nothing.
|
|
4607
4800
|
*
|
|
4608
|
-
* `arena()` anywhere but the initialiser of a `using` is NL2416, and reading
|
|
4609
|
-
* binding is NL2417. A number, a `boolean` or an `enum` leaves the block
|
|
4610
|
-
* as does a value older than it.
|
|
4611
|
-
*
|
|
4612
|
-
*
|
|
4613
|
-
*
|
|
4614
|
-
*
|
|
4615
|
-
*
|
|
4616
|
-
*
|
|
4617
|
-
*
|
|
4618
|
-
*
|
|
4619
|
-
*
|
|
4620
|
-
*
|
|
4621
|
-
*
|
|
4622
|
-
*
|
|
4623
|
-
*
|
|
4624
|
-
*
|
|
4625
|
-
*
|
|
4626
|
-
*
|
|
4801
|
+
* `arena()` anywhere but the initialiser of a `using` is NL2416, and reading
|
|
4802
|
+
* the binding is NL2417. A number, a `boolean` or an `enum` leaves the block
|
|
4803
|
+
* freely, as does a value older than it.
|
|
4804
|
+
*
|
|
4805
|
+
* These routes are refused for anything else allocated inside:
|
|
4806
|
+
* - assigning it to a local declared outside the block (NL2418),
|
|
4807
|
+
* - storing it into a field (NL2419) or an element (NL2420),
|
|
4808
|
+
* - storing it any other way (NL2421),
|
|
4809
|
+
* - a `push` onto an array the block does not bind to a fresh array (NL2422),
|
|
4810
|
+
* - a `return` or `orReturn()` (NL2423),
|
|
4811
|
+
* - a call to a function that stores an allocation (NL2424)
|
|
4812
|
+
* - and a `spawn` on a scope declared outside the block (NL2427), on a scope
|
|
4813
|
+
* the same `using` declares ahead of `arena()` (`using s = scope(), a =
|
|
4814
|
+
* arena()`, NL2427, since `s` joins after the release) or on one ahead of the
|
|
4815
|
+
* statement's last `arena()` (`using a = arena(), s = scope(), b = arena()`,
|
|
4816
|
+
* NL2427, since `b` releases before `s` joins).
|
|
4817
|
+
*
|
|
4818
|
+
* The rule is the escape analysis's, so it is conservative. A parallel body or
|
|
4819
|
+
* a task may not open one (NL2351). A map that answers numbers or strings may
|
|
4820
|
+
* run inside one, and a task filed on a scope the block declares may read what
|
|
4821
|
+
* it allocated. It nests with `scope()` and `lock()` on the same stack,
|
|
4822
|
+
* innermost first. A `return g(n)` whose arguments are all numbers is a tail
|
|
4823
|
+
* call with the release moved ahead of it, unless `g` reads the arena. A panic
|
|
4824
|
+
* ends the process. Capability: none.
|
|
4627
4825
|
*
|
|
4628
4826
|
* @returns the scope the `using` declaration disposes.
|
|
4629
4827
|
*/
|
|
@@ -4631,18 +4829,20 @@ declare function arena(): Disposable;
|
|
|
4631
4829
|
|
|
4632
4830
|
/**
|
|
4633
4831
|
* `CPtr`: the address a `declare function` hands back, opaque and eight bytes
|
|
4634
|
-
* wide (`i8*` in the IR). It is C's, not arena memory, and its lifetime is the
|
|
4635
|
-
* library's business. `docs/LANGUAGE.md` has the rules — it may be written in
|
|
4636
|
-
* `declare function` signature and on a local that holds one, compared with
|
|
4637
|
-
* `null` or with another `CPtr`, assigned, and passed back to C, and that is
|
|
4638
|
-
*
|
|
4639
|
-
*
|
|
4640
|
-
*
|
|
4641
|
-
*
|
|
4642
|
-
*
|
|
4643
|
-
*
|
|
4644
|
-
*
|
|
4645
|
-
*
|
|
4832
|
+
* wide (`i8*` in the IR). It is C's, not arena memory, and its lifetime is the
|
|
4833
|
+
* C library's business. `docs/LANGUAGE.md` has the rules — it may be written in
|
|
4834
|
+
* a `declare function` signature and on a local that holds one, compared with
|
|
4835
|
+
* `null` or with another `CPtr`, assigned, and passed back to C, and that is
|
|
4836
|
+
* all.
|
|
4837
|
+
*
|
|
4838
|
+
* A field, an array element, a `Result` arm, a type argument, and the
|
|
4839
|
+
* parameters or return type of a function the program defines are each refused
|
|
4840
|
+
* (`` `CPtr` cannot be ...: a foreign pointer may only appear in a `declare
|
|
4841
|
+
* function` signature or on a local bound to one ``). There is no arithmetic
|
|
4842
|
+
* (`p + 1`), no index (`` Cannot index a value of type CPtr ``), no dereference
|
|
4843
|
+
* and no member. A `CPtr | null` reaches C only as the literal `null` or a
|
|
4844
|
+
* pointer narrowed with `!== null` (NL2539). `readCString` from `nish:unsafe`
|
|
4845
|
+
* copies the string at one.
|
|
4646
4846
|
*
|
|
4647
4847
|
* An empty interface with a private brand rather than `unknown` or a type
|
|
4648
4848
|
* alias: `tsc` has to refuse the arithmetic and the dereference `nish` refuses,
|
|
@@ -4651,6 +4851,7 @@ declare function arena(): Disposable;
|
|
|
4651
4851
|
* declaration costs a reader nothing.
|
|
4652
4852
|
*/
|
|
4653
4853
|
declare interface CPtr {
|
|
4854
|
+
/** The private brand that makes `CPtr` nominal. Not a field: nothing reads or writes it. */
|
|
4654
4855
|
readonly __nishForeignPointer: unique symbol;
|
|
4655
4856
|
}
|
|
4656
4857
|
|
|
@@ -4685,16 +4886,25 @@ type HostHandle<K extends string> = (number & { readonly __nishHostKind: K }) |
|
|
|
4685
4886
|
* an `i64` or `u64` crosses as a `bigint`, every other width as a `number`.
|
|
4686
4887
|
*/
|
|
4687
4888
|
declare module "nish" {
|
|
4889
|
+
/** A 32-bit signed integer, a `number` on the page. */
|
|
4688
4890
|
export type i32 = number;
|
|
4891
|
+
/** A 64-bit signed integer, a `bigint` on the page. */
|
|
4689
4892
|
export type i64 = bigint;
|
|
4893
|
+
/** An 8-bit unsigned integer, a `number` on the page. */
|
|
4690
4894
|
export type u8 = number;
|
|
4895
|
+
/** A 16-bit unsigned integer, a `number` on the page. */
|
|
4691
4896
|
export type u16 = number;
|
|
4897
|
+
/** A 32-bit unsigned integer, a `number` on the page. */
|
|
4692
4898
|
export type u32 = number;
|
|
4899
|
+
/** A 64-bit unsigned integer, a `bigint` on the page. */
|
|
4693
4900
|
export type u64 = bigint;
|
|
4901
|
+
/** A 32-bit float, a `number` on the page. */
|
|
4694
4902
|
export type f32 = number;
|
|
4903
|
+
/** A 64-bit float, a `number` on the page. */
|
|
4695
4904
|
export type f64 = number;
|
|
4696
4905
|
/** A ranged integer, which the loader checks on the way in. */
|
|
4697
4906
|
export type integer<Lo extends number, Hi extends number> = number;
|
|
4907
|
+
/** A host object's handle, the global `HostHandle`'s twin, spelled alike so the two are one type. */
|
|
4698
4908
|
export type HostHandle<K extends string> = (number & { readonly __nishHostKind: K }) | 0;
|
|
4699
4909
|
}
|
|
4700
4910
|
|
|
@@ -4919,26 +5129,28 @@ interface Math {
|
|
|
4919
5129
|
/**
|
|
4920
5130
|
* An array. `Int32Array`, `Float32Array`, `Float64Array` and `BigInt64Array`
|
|
4921
5131
|
* name `i32[]`, `f32[]`, `f64[]` and `i64[]`, the same type with no second
|
|
4922
|
-
* layout, but a receiver spelled with one of the four refuses `push` and
|
|
4923
|
-
*
|
|
4924
|
-
*
|
|
4925
|
-
*
|
|
4926
|
-
*
|
|
4927
|
-
*
|
|
4928
|
-
*
|
|
4929
|
-
*
|
|
4930
|
-
*
|
|
4931
|
-
*
|
|
4932
|
-
*
|
|
4933
|
-
*
|
|
4934
|
-
*
|
|
4935
|
-
*
|
|
4936
|
-
*
|
|
4937
|
-
*
|
|
4938
|
-
*
|
|
4939
|
-
*
|
|
4940
|
-
*
|
|
4941
|
-
*
|
|
5132
|
+
* layout, but a receiver spelled with one of the four refuses `push` and `pop`
|
|
5133
|
+
* (NL2415), because a typed array in TypeScript has a fixed length and a call
|
|
5134
|
+
* to either is a `TypeError` there: "`push` is not a method of `Float64Array`,
|
|
5135
|
+
* whose length is fixed: declare it `f64[]` to push and pop". Every other array
|
|
5136
|
+
* operation is unchanged, and a `Float64Array` is an `f64[]` wherever one is
|
|
5137
|
+
* expected.
|
|
5138
|
+
*
|
|
5139
|
+
* The refusal follows the spelling the program wrote, carried by: `new X(n)`;
|
|
5140
|
+
* an identifier annotated with the name (directly, as the one member of `X |
|
|
5141
|
+
* null`, or through a `type` alias) or unannotated and initialised with such a
|
|
5142
|
+
* receiver; a field declared with the name; a call whose callee declares it as
|
|
5143
|
+
* its return type; a call of a generic function whose return type is a type
|
|
5144
|
+
* parameter that an argument binds to such a receiver; a value read out of a
|
|
5145
|
+
* `Map` whose value type is spelled with a name; an element of an array spelled
|
|
5146
|
+
* with a name; and a ternary or `??` either of whose operands carries it.
|
|
5147
|
+
*
|
|
5148
|
+
* A member of a generic class instantiated at one of the names does not carry
|
|
5149
|
+
* it, and a typed array that flows into a binding spelled `T[]` may be pushed
|
|
5150
|
+
* there. A numeric literal argument to `push`, `indexOf` or `fill` takes the
|
|
5151
|
+
* element type, so `wide.push(3)` on an `i64[]` pushes an `i64` three. An
|
|
5152
|
+
* unknown method is refused with the supported list: "Unknown method `shift` on
|
|
5153
|
+
* i32[]"; there is no `map`, `shift`, `slice` or `toString` on an array.
|
|
4942
5154
|
*/
|
|
4943
5155
|
interface Array<T> {
|
|
4944
5156
|
/** The element count, read-only: assigning to it is refused. */
|
|
@@ -4973,6 +5185,7 @@ interface Array<T> {
|
|
|
4973
5185
|
* argument of another type than the element is refused. Capability: none.
|
|
4974
5186
|
*
|
|
4975
5187
|
* @param searchElement the element looked for.
|
|
5188
|
+
* @param fromIndex declared to match TypeScript's `lib`; `nish` refuses a second argument.
|
|
4976
5189
|
* @returns its index, or `-1`.
|
|
4977
5190
|
*/
|
|
4978
5191
|
indexOf(searchElement: T, fromIndex?: number): number;
|
|
@@ -4990,24 +5203,28 @@ interface Array<T> {
|
|
|
4990
5203
|
join(separator?: string): string;
|
|
4991
5204
|
/**
|
|
4992
5205
|
* Store `value` into every slot of `[start, end)`, each end relative (a
|
|
4993
|
-
* negative one counts back from the length) and then clamped into
|
|
4994
|
-
*
|
|
4995
|
-
*
|
|
4996
|
-
*
|
|
4997
|
-
*
|
|
4998
|
-
*
|
|
4999
|
-
*
|
|
5000
|
-
*
|
|
5001
|
-
*
|
|
5206
|
+
* negative one counts back from the length) and then clamped into `[0,
|
|
5207
|
+
* a.length]`, as `TypedArray.prototype.fill`'s are, so no range is out of
|
|
5208
|
+
* range, a reversed range fills nothing, and `fill` never panics. Arrays of
|
|
5209
|
+
* numbers only, of any width and ranged integers included (a ranged element
|
|
5210
|
+
* checks `value` once, before the fill); on any other array it is refused:
|
|
5211
|
+
* "`set` copies bytes, so it needs an array whose elements are numbers
|
|
5212
|
+
* (`u8[]`, `i32[]`, `f64[]`, ...), got string[]" (NL2395).
|
|
5213
|
+
*
|
|
5214
|
+
* `value` is the element type ("`fill` expects u8 (the element type of u8[]),
|
|
5215
|
+
* got string"), one to three arguments are taken (NL2398), and each end is a
|
|
5002
5216
|
* number. It is a statement: its answer cannot be used as a value, and
|
|
5003
|
-
* JavaScript's answer is the array the program already holds.
|
|
5004
|
-
*
|
|
5005
|
-
*
|
|
5217
|
+
* JavaScript's answer is the array the program already holds.
|
|
5218
|
+
*
|
|
5219
|
+
* A float end converts as JavaScript's `ToIntegerOrInfinity` does: `NaN` is
|
|
5220
|
+
* `0`, a fraction truncates toward zero (`2.7` is `2`, `-0.5` is `0`), and an
|
|
5006
5221
|
* infinity or a value past the `i64` range saturates, then clamps, so in f64
|
|
5007
5222
|
* mode `a.fill(v, 0, 1 / 0)` fills all of it. An unsigned end is never
|
|
5008
5223
|
* negative, whatever its width: a `u64` of 2^63 or more as a start fills
|
|
5009
5224
|
* nothing and as an end fills to the length. Natively a `u8[]` fill is one
|
|
5010
|
-
* `memset`.
|
|
5225
|
+
* `memset`.
|
|
5226
|
+
*
|
|
5227
|
+
* Under Node it is `Array.prototype.fill`, which has
|
|
5011
5228
|
* `TypedArray.prototype.fill`'s meaning for every argument Nish admits,
|
|
5012
5229
|
* except that an `i64` or `u64` end is a `bigint` there and throws a
|
|
5013
5230
|
* `TypeError`, as all 64-bit arithmetic does. A `readonly T[]` refuses it:
|
|
@@ -5017,6 +5234,7 @@ interface Array<T> {
|
|
|
5017
5234
|
* @param value the value stored.
|
|
5018
5235
|
* @param start the first slot, `0` by default.
|
|
5019
5236
|
* @param end the slot after the last, `a.length` by default.
|
|
5237
|
+
* @returns the array, to `tsc` only: `nish` refuses the call as a value.
|
|
5020
5238
|
*/
|
|
5021
5239
|
fill(value: T, start?: number, end?: number): this;
|
|
5022
5240
|
/**
|
|
@@ -5026,17 +5244,19 @@ interface Array<T> {
|
|
|
5026
5244
|
* "`sort` needs a comparator: write `xs.sort((a, b) => a - b)`") and is the
|
|
5027
5245
|
* one argument (NL2619: "`sort` takes one comparator"); only "positive or
|
|
5028
5246
|
* not" is read of its answer, so `-0` and `NaN` count as zero. A `readonly
|
|
5029
|
-
* T[]` ("Cannot `sort` through readonly") and `process.argv`
|
|
5030
|
-
*
|
|
5031
|
-
*
|
|
5032
|
-
*
|
|
5033
|
-
* an arrow reading
|
|
5034
|
-
*
|
|
5035
|
-
*
|
|
5036
|
-
*
|
|
5037
|
-
* `
|
|
5038
|
-
*
|
|
5039
|
-
*
|
|
5247
|
+
* T[]` ("Cannot `sort` through readonly") and `process.argv` ("`process.argv`
|
|
5248
|
+
* is read-only") are refused.
|
|
5249
|
+
*
|
|
5250
|
+
* The comparator is a compile-time function argument: a top-level function,
|
|
5251
|
+
* or an arrow reading only the `const` locals and parameters of the function
|
|
5252
|
+
* it is written in; an arrow reading a `let` is refused. The sort costs one
|
|
5253
|
+
* scratch array of `n` elements, released before it returns. `(a, b) => a -
|
|
5254
|
+
* b` is checked arithmetic on `i32` elements: two a full range apart
|
|
5255
|
+
* (`[2147483647, -1]`) panic with `attempt to subtract with overflow`, where
|
|
5256
|
+
* `(a, b) => (a > b ? 1 : a < b ? -1 : 0)` cannot overflow.
|
|
5257
|
+
*
|
|
5258
|
+
* Where JavaScript leaves the order to the implementation, so does Nish: an
|
|
5259
|
+
* array holding `NaN` under `(a, b) => a - b`, or a comparator that is not a
|
|
5040
5260
|
* consistent order, comes out a permutation of its elements but not
|
|
5041
5261
|
* necessarily Node's permutation; give `NaN` a place of its own in the
|
|
5042
5262
|
* comparator to agree. Under Node and `--emit-ts` the call is the platform's
|
|
@@ -5051,31 +5271,34 @@ interface Array<T> {
|
|
|
5051
5271
|
/**
|
|
5052
5272
|
* Copy every element of `source` into this array from `offset` on, with
|
|
5053
5273
|
* `TypedArray.prototype.set`'s meaning. Arrays of numbers only, of any width
|
|
5054
|
-
* and ranged integers included, and `source` has this array's element type
|
|
5055
|
-
*
|
|
5056
|
-
*
|
|
5057
|
-
*
|
|
5058
|
-
*
|
|
5059
|
-
*
|
|
5060
|
-
*
|
|
5061
|
-
* `offset + source.length <=
|
|
5062
|
-
* `slice out of range: [offset,
|
|
5063
|
-
* a.length` and exits 1, the message `s.slice` gives;
|
|
5064
|
-
* exactly at `a.length`, and an empty `source` at
|
|
5065
|
-
* where JavaScript throws a `RangeError` for
|
|
5066
|
-
* overlapping `source` (`a.set(a)`, or two headers
|
|
5067
|
-
* host) is copied as if it were read first.
|
|
5068
|
-
*
|
|
5069
|
-
*
|
|
5070
|
-
*
|
|
5071
|
-
*
|
|
5072
|
-
*
|
|
5073
|
-
*
|
|
5074
|
-
*
|
|
5075
|
-
* it
|
|
5076
|
-
*
|
|
5077
|
-
*
|
|
5078
|
-
* `
|
|
5274
|
+
* and ranged integers included, and `source` has this array's element type (a
|
|
5275
|
+
* `readonly` array may be the source, since it is only read); another element
|
|
5276
|
+
* type is refused: "`set` copies from an array of the receiver's element
|
|
5277
|
+
* type, so it expects u8[], got i32[]" (NL2396), and a non-number receiver as
|
|
5278
|
+
* for `fill` (NL2395). One or two arguments (NL2397). It is a statement:
|
|
5279
|
+
* "`set` returns void and can only be used as a statement".
|
|
5280
|
+
*
|
|
5281
|
+
* The range written is checked: `0 <= offset` and `offset + source.length <=
|
|
5282
|
+
* a.length`, or the program panics with `slice out of range: [offset,
|
|
5283
|
+
* offset + src.length) of length a.length` and exits 1, the message `s.slice` gives;
|
|
5284
|
+
* a range that ends exactly at `a.length`, and an empty `source` at
|
|
5285
|
+
* `a.length`, are in range, where JavaScript throws a `RangeError` for
|
|
5286
|
+
* exactly these offsets. An overlapping `source` (`a.set(a)`, or two headers
|
|
5287
|
+
* over one buffer from a C host) is copied as if it were read first.
|
|
5288
|
+
*
|
|
5289
|
+
* A float offset converts as for `fill`'s ends (`NaN` is `0`, a fraction
|
|
5290
|
+
* truncates, an infinity or a value past the `i64` range saturates), and a
|
|
5291
|
+
* saturated offset fails the range check with the saturated value in the
|
|
5292
|
+
* message, for example `slice out of range: [9223372036854775807,
|
|
5293
|
+
* -9223372036854775808) of length 4` for `1e300`. An unsigned offset is never
|
|
5294
|
+
* negative: a `u64` of 2^63 or more panics, printed signed. A `readonly T[]`
|
|
5295
|
+
* refuses it: "Cannot `set` through readonly u8[] (declare it u8[] to write
|
|
5296
|
+
* through it)".
|
|
5297
|
+
*
|
|
5298
|
+
* Under Node, `runtime/nish.mjs` adds `set` to `Array.prototype` with the
|
|
5299
|
+
* copy-first semantics and the native panic; a TypeScript host without it has
|
|
5300
|
+
* no `set` on a plain array, and an `i64` or `u64` offset is a `bigint` there
|
|
5301
|
+
* and throws a `TypeError`. Capability: none.
|
|
5079
5302
|
*
|
|
5080
5303
|
* @param source the elements copied.
|
|
5081
5304
|
* @param offset the first slot written, `0` by default.
|
|
@@ -5086,20 +5309,22 @@ interface Array<T> {
|
|
|
5086
5309
|
/**
|
|
5087
5310
|
* `readonly T[]`, or `ReadonlyArray<T>` under the other spelling: the same
|
|
5088
5311
|
* array, which may not be written through. It is the same header, the same
|
|
5089
|
-
* pointer and the same layout as `T[]`; the annotation is a promise the
|
|
5090
|
-
*
|
|
5091
|
-
*
|
|
5092
|
-
*
|
|
5093
|
-
*
|
|
5094
|
-
*
|
|
5095
|
-
*
|
|
5096
|
-
*
|
|
5097
|
-
*
|
|
5098
|
-
*
|
|
5099
|
-
*
|
|
5100
|
-
*
|
|
5101
|
-
* type
|
|
5102
|
-
*
|
|
5312
|
+
* pointer and the same layout as `T[]`; the annotation is a promise the checker
|
|
5313
|
+
* keeps, and a `--emit-header` prototype spells such a parameter `const
|
|
5314
|
+
* nish_array *`.
|
|
5315
|
+
*
|
|
5316
|
+
* Everything that reads works (`length`, `a[i]`, `for...of`, `indexOf`, `join`,
|
|
5317
|
+
* passing it on to another `readonly T[]`); every write is refused under its
|
|
5318
|
+
* own name, an element store ("Cannot assign to an element of readonly i32[]
|
|
5319
|
+
* (declare it i32[] to write through it)"), `push`, `pop`, `set`, `fill` and
|
|
5320
|
+
* `sort` included. A `T[]` widens into a `readonly T[]`, and never back:
|
|
5321
|
+
* "Argument 1 of `fill`: expected i32[], got readonly i32[]". It is shallow, as
|
|
5322
|
+
* TypeScript's is: the element of a `readonly T[][]` is a mutable `T[]`.
|
|
5323
|
+
*
|
|
5324
|
+
* It is a type, not a parameter modifier, so it is legal wherever an array type
|
|
5325
|
+
* is (a class field, a return type, a `const`'s annotation). `readonly` goes on
|
|
5326
|
+
* an array type and nothing else: "`readonly` is only permitted on an array
|
|
5327
|
+
* type, got i32". `process.argv` is read-only under a rule of its own.
|
|
5103
5328
|
*/
|
|
5104
5329
|
interface ReadonlyArray<T> {
|
|
5105
5330
|
/** The element count. */
|
|
@@ -5110,6 +5335,7 @@ interface ReadonlyArray<T> {
|
|
|
5110
5335
|
* and a `NaN` element is never found. Capability: none.
|
|
5111
5336
|
*
|
|
5112
5337
|
* @param searchElement the element looked for.
|
|
5338
|
+
* @param fromIndex declared to match TypeScript's `lib`; `nish` refuses a second argument.
|
|
5113
5339
|
* @returns its index, or `-1`.
|
|
5114
5340
|
*/
|
|
5115
5341
|
indexOf(searchElement: T, fromIndex?: number): number;
|
|
@@ -5180,15 +5406,16 @@ interface String {
|
|
|
5180
5406
|
slice(start?: number, end?: number): string;
|
|
5181
5407
|
/**
|
|
5182
5408
|
* The first byte offset at or after `position` at which `searchString`
|
|
5183
|
-
* occurs. `position` is clamped into `[0, s.length]` first, as in
|
|
5184
|
-
*
|
|
5185
|
-
*
|
|
5186
|
-
* `s.indexOf(""
|
|
5187
|
-
*
|
|
5188
|
-
*
|
|
5189
|
-
*
|
|
5190
|
-
*
|
|
5191
|
-
*
|
|
5409
|
+
* occurs. `position` is clamped into `[0, s.length]` first, as in JavaScript:
|
|
5410
|
+
* a negative start searches from `0`, a start past the end finds nothing, and
|
|
5411
|
+
* the empty needle answers the clamped start, so `s.indexOf("")` is `0`,
|
|
5412
|
+
* `s.indexOf("", 3)` is `3` and `s.indexOf("", 99)` is `s.length`. A float
|
|
5413
|
+
* start converts as JavaScript's `ToIntegerOrInfinity` does (a fraction
|
|
5414
|
+
* truncates and `NaN` is `0`), and an unsigned one is clamped from above
|
|
5415
|
+
* only, so a `u64` past 2^63 is past the end.
|
|
5416
|
+
*
|
|
5417
|
+
* The search allocates nothing, so a loop `at = s.indexOf(sub, at +
|
|
5418
|
+
* sub.length)` copies nothing. Under Node it is the same call to
|
|
5192
5419
|
* `String.prototype.indexOf`, whose answers differ only where every offset
|
|
5193
5420
|
* does, on text that is not ASCII (NL8001). Capability: none.
|
|
5194
5421
|
*
|
|
@@ -5202,6 +5429,7 @@ interface String {
|
|
|
5202
5429
|
* Capability: none.
|
|
5203
5430
|
*
|
|
5204
5431
|
* @param searchString the prefix.
|
|
5432
|
+
* @param position declared to match TypeScript's `lib`; `nish` refuses a second argument.
|
|
5205
5433
|
* @returns whether it is one.
|
|
5206
5434
|
*/
|
|
5207
5435
|
startsWith(searchString: string, position?: number): boolean;
|
|
@@ -5210,6 +5438,7 @@ interface String {
|
|
|
5210
5438
|
* `false`. One argument. Capability: none.
|
|
5211
5439
|
*
|
|
5212
5440
|
* @param searchString the suffix.
|
|
5441
|
+
* @param endPosition declared to match TypeScript's `lib`; `nish` refuses a second argument.
|
|
5213
5442
|
* @returns whether it is one.
|
|
5214
5443
|
*/
|
|
5215
5444
|
endsWith(searchString: string, endPosition?: number): boolean;
|
|
@@ -5230,42 +5459,49 @@ interface StringConstructor {
|
|
|
5230
5459
|
|
|
5231
5460
|
/**
|
|
5232
5461
|
* An insertion-ordered map with SameValueZero keys (`-0` is `+0` and `NaN` is
|
|
5233
|
-
* `NaN`), a builtin with no import. A key is a `string`, a number of any
|
|
5234
|
-
*
|
|
5235
|
-
*
|
|
5236
|
-
*
|
|
5237
|
-
*
|
|
5238
|
-
*
|
|
5239
|
-
*
|
|
5240
|
-
*
|
|
5241
|
-
*
|
|
5242
|
-
* Map<string,
|
|
5243
|
-
*
|
|
5244
|
-
*
|
|
5245
|
-
*
|
|
5246
|
-
*
|
|
5247
|
-
* a
|
|
5248
|
-
*
|
|
5249
|
-
*
|
|
5250
|
-
*
|
|
5251
|
-
*
|
|
5252
|
-
*
|
|
5253
|
-
*
|
|
5254
|
-
*
|
|
5255
|
-
* (
|
|
5462
|
+
* `NaN`), a builtin with no import. A key is a `string`, a number of any width
|
|
5463
|
+
* in either mode (`f32` and `f64` included), a `boolean`, an `enum` or a class
|
|
5464
|
+
* instance (by identity); not an interface, an array, a nullable or a `Result`:
|
|
5465
|
+
* "`Point` cannot be the key type of `Map<Point, i32>`: a key is hashed and
|
|
5466
|
+
* compared by value, or by identity for a class instance".
|
|
5467
|
+
*
|
|
5468
|
+
* A `-0` key is stored as `+0` by every insert path, so a walk over `keys()`
|
|
5469
|
+
* yields `+0`. A value is anything but `void` and an interface, whose record
|
|
5470
|
+
* would be copied into the table rather than shared: "`Point` cannot be the
|
|
5471
|
+
* value type of `Map<string, Point>`".
|
|
5472
|
+
*
|
|
5473
|
+
* `new Map<K, V>()` takes no arguments ("`new Map<string, i32>` takes no
|
|
5474
|
+
* arguments in this version"); the type arguments are written out, except that
|
|
5475
|
+
* a `const` or `let` annotated with the type takes them from the annotation,
|
|
5476
|
+
* and a bare `new Map()` is refused: "`Map` is generic: it must be written with
|
|
5477
|
+
* its type arguments". The members are JavaScript's, less `entries` and
|
|
5478
|
+
* `forEach` (there is no destructuring, and a method cannot take a function);
|
|
5479
|
+
* anything else is refused as if it did not exist. `set` answers the receiver,
|
|
5480
|
+
* so calls chain.
|
|
5481
|
+
*
|
|
5482
|
+
* `keys()` and `values()` are iterators, admitted only as the iterable of a
|
|
5483
|
+
* `for...of`: stored, passed, returned or dropped, they are refused (NL2372,
|
|
5484
|
+
* NL2373, NL2374, NL2358), and `for (const e of m)` needs `entries()` (NL2375).
|
|
5485
|
+
* The walk visits entries in insertion order, skips a deleted key not yet
|
|
5486
|
+
* reached, visits a key set during the walk later in the same walk, and keeps a
|
|
5487
|
+
* re-set key in its place, as JavaScript's does.
|
|
5488
|
+
*
|
|
5489
|
+
* At most 2^24 − 1 entries (one fewer than Node's 2^24); one more panics with
|
|
5256
5490
|
* `Map maximum size exceeded`, after first compacting away dead entries (not
|
|
5257
|
-
* while a loop walks the table). String keys are hashed with SipHash-1-3
|
|
5258
|
-
*
|
|
5259
|
-
*
|
|
5260
|
-
*
|
|
5261
|
-
*
|
|
5262
|
-
*
|
|
5263
|
-
*
|
|
5264
|
-
*
|
|
5265
|
-
*
|
|
5266
|
-
*
|
|
5267
|
-
*
|
|
5268
|
-
*
|
|
5491
|
+
* while a loop walks the table). String keys are hashed with SipHash-1-3 under
|
|
5492
|
+
* a per-process random key drawn from the system's entropy source before
|
|
5493
|
+
* `main`, and an integer, `boolean` or enum key under a per-process random
|
|
5494
|
+
* multiply-add-shift; if the entropy source fails the program panics before
|
|
5495
|
+
* `main`: "Map: the system's entropy source failed".
|
|
5496
|
+
*
|
|
5497
|
+
* A float key and a class instance key are not keyed, so a program keying a
|
|
5498
|
+
* table by floats a peer chose converts them to a string or a scaled integer
|
|
5499
|
+
* first. On wasm32 the key comes from WASI's `random_get`, and a reactor module
|
|
5500
|
+
* is keyed only once its host calls `_initialize`. A pair of `i32`s is one
|
|
5501
|
+
* `i64` key: `(toI64(hi) << toI64(32)) | toI64(toU32(lo))`. `nish/map` adds
|
|
5502
|
+
* `reserve(m, n)` and `getOrInsert(m, k, v)`, which JavaScript's `Map` has no
|
|
5503
|
+
* call for. A module that declares or imports its own `Map` gets no implicit
|
|
5504
|
+
* import.
|
|
5269
5505
|
*/
|
|
5270
5506
|
interface Map<K, V> {
|
|
5271
5507
|
/** The entry count, read-only: assigning to it is refused. */
|
|
@@ -5273,16 +5509,17 @@ interface Map<K, V> {
|
|
|
5273
5509
|
/**
|
|
5274
5510
|
* The value under `key`, one probe. The `V | undefined` is a maybe, admitted
|
|
5275
5511
|
* only as the initialiser of a `const` (unannotated, or annotated with the
|
|
5276
|
-
* maybe type), the left of `??`, or an operand of `=== undefined` or
|
|
5277
|
-
*
|
|
5278
|
-
*
|
|
5279
|
-
*
|
|
5280
|
-
*
|
|
5281
|
-
*
|
|
5282
|
-
*
|
|
5283
|
-
*
|
|
5284
|
-
*
|
|
5285
|
-
* value. Capability:
|
|
5512
|
+
* maybe type), the left of `??`, or an operand of `=== undefined` or `!==
|
|
5513
|
+
* undefined`. A `const` so bound reads as `V` in the region a test proves it
|
|
5514
|
+
* present (`if (a === undefined) return` included), and nowhere else.
|
|
5515
|
+
*
|
|
5516
|
+
* Any other place is refused with a message naming it: a `let` (NL2361), an
|
|
5517
|
+
* argument (NL2362), a `return` (NL2363), a field (NL2364), an array element
|
|
5518
|
+
* (NL2365), a template literal hole (NL2366), an operand of another operator
|
|
5519
|
+
* (NL2367), the default of another `??` (NL2371), a `const` annotated `V`
|
|
5520
|
+
* (NL2368), or anywhere else (NL2369). When `V` is nullable, `??` replaces a
|
|
5521
|
+
* stored `null` as well. `get` is called, never read as a value. Capability:
|
|
5522
|
+
* none.
|
|
5286
5523
|
*
|
|
5287
5524
|
* @param key the key looked up.
|
|
5288
5525
|
* @returns the value, or `undefined`.
|