@amritk/nish-aarch64-linux 0.37.0 → 0.38.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/runtime/nish.d.ts CHANGED
@@ -382,11 +382,81 @@ interface Process {
382
382
  declare var process: Process;
383
383
 
384
384
  // ---- Numeric conversions (there is no cast in Nish) ----------------------
385
- // `Number`, `parseInt` and `parseFloat` are `lib.es2022`'s and are not
386
- // declared here; docs/LANGUAGE.md -> Numeric conversions has their rules.
387
385
  // Nothing converts implicitly: a mixed operation, an initializer of another
388
386
  // numeric type and a call with the wrong numeric type are each refused until
389
- // one of the functions below is written.
387
+ // one of the functions below is written. `Number`, `parseInt` and
388
+ // `parseFloat` are `lib.es2022`'s too. `Number`'s call repeats lib's signature;
389
+ // `parseInt` and `parseFloat` add Nish's own as an overload beside lib's, as
390
+ // `runtime/core/numbers.d.ts` declares them. An `i32` and an `f64` are both
391
+ // `number` to `tsc`, so what it accepts does not change; `nish` refuses lib's
392
+ // radix.
393
+
394
+ /**
395
+ * `Number(value)`: `value` as an `f64`, in both number modes. Nish has no
396
+ * `new Number` and no member of `Number`; the call is the conversion, merged
397
+ * into the `NumberConstructor` `lib.es2022` declares.
398
+ *
399
+ * A string is parsed with JavaScript's `Number(s)` rules: ASCII whitespace
400
+ * (` \t\n\v\f\r`, not the Unicode spaces JavaScript also trims) is trimmed
401
+ * on both sides, then the whole string must be one literal, so `Number("")`
402
+ * and `Number(" ")` are `0`, `Number(" 7.5 ")` is `7.5`, and
403
+ * `Number("12px")`, `Number("1e")` and `Number("nan")` are `NaN`.
404
+ * `Number("0x1A")` is `26`, as in JavaScript, and a hex float such as `0x1p3`
405
+ * is also accepted, which JavaScript rejects; the `0b` and `0o` prefixes are
406
+ * `NaN`, which JavaScript reads. Under `--deterministic` a `0x` string reads
407
+ * as `--emit-ts` reads it on every target: a hex float is `NaN`, and a hex
408
+ * integer is correctly rounded whatever the C library.
409
+ *
410
+ * An `i32` or an `i64` converts as `toF64` does, a `boolean` is `1` or `0`,
411
+ * and an `f64` is itself. A numeric literal argument is typed `f64`
412
+ * (`Number(2.5)` works in i32 mode). Exactly one argument; anything other than
413
+ * a string, a number or a boolean is refused: "`Number` expects a string,
414
+ * number, or boolean, got i32[]". Capability: none.
415
+ */
416
+ interface NumberConstructor {
417
+ /**
418
+ * `value` as an `f64`, by the rules on `NumberConstructor` above.
419
+ * Capability: none.
420
+ *
421
+ * @param value a string, an `i32`, an `i64`, an `f64` or a `boolean`;
422
+ * `nish` requires it, though `lib`'s signature marks it optional.
423
+ * @returns an `f64`, in both number modes.
424
+ */
425
+ (value?: any): number;
426
+ }
427
+
428
+ /**
429
+ * The base-10 integer at the start of `s`, as an `i32`: ASCII whitespace,
430
+ * an optional sign, then digits, stopping at the first other character
431
+ * (`parseInt("42px")` is `42`). Three deviations from JavaScript: there is no
432
+ * `NaN` in an `i32`, so no digits give `0` (`parseInt("abc")`,
433
+ * `parseInt("")`); a value beyond the `i32` range saturates as `toI32` does
434
+ * (`parseInt("99999999999")` is `2147483647`); and a `0x` prefix is not
435
+ * hexadecimal (`parseInt("0x10")` is `0`). Always an `i32`, under
436
+ * `--number-mode f64` too, where `Number` reads a wider value. Exactly one
437
+ * argument: there is no radix, since base 10 is the only one. A non-string is
438
+ * refused: "`parseInt` expects a string, got i32". Capability: none.
439
+ *
440
+ * @param s the text read.
441
+ * @returns the integer, or `0` when there are no digits.
442
+ */
443
+ declare function parseInt(s: string): i32;
444
+ /**
445
+ * The decimal number at the start of `s`, as an `f64`: ASCII whitespace,
446
+ * then the longest decimal literal (`[sign] digits [. digits] [e [sign]
447
+ * digits]`, `. digits`, or `[sign] Infinity`), correctly rounded.
448
+ * `parseFloat("3.14xyz")` is `3.14` and `parseFloat("1e")` is `1`. One
449
+ * deviation from JavaScript: a `0x` prefix is read as hexadecimal
450
+ * (`parseFloat("0x1A")` is `26`, where JavaScript stops at the `x` and gives
451
+ * `0`). Under `--deterministic` a `0x` string reads as `--emit-ts` reads it
452
+ * on every target: the hex integer, correctly rounded, stopping at a hex
453
+ * float's `.` or `p` (`0x1p3` is `1`). Exactly one argument. Capability: none.
454
+ *
455
+ * @param s the text read.
456
+ * @returns the number, or `NaN` when there is none (`parseFloat("abc")`,
457
+ * `parseFloat("")`, `parseFloat(".")`).
458
+ */
459
+ declare function parseFloat(s: string): f64;
390
460
 
391
461
  /**
392
462
  * `x` as an `i32`. An integer of 32 bits or more wraps to its low 32 bits, a
@@ -2123,10 +2193,34 @@ declare function setTerminalRestore(bytes: string): i32;
2123
2193
 
2124
2194
  // ---- `Date` and `crypto` (WP34 N3) -----------------------------------------------
2125
2195
  //
2126
- // `lib.es2022` already declares `Date`, whose `now()` is Nish's one member of it,
2127
- // so nothing is added: `tsc` accepting `new Date()` is `tsc` not being Nish's
2128
- // checker. `crypto` is a Web API that `lib.es2022` leaves out, so it is
2129
- // declared with its one member, typed as Nish types it.
2196
+ // `lib.es2022` already declares `Date`, whose `now()` is Nish's one member of it;
2197
+ // `DateConstructor` below repeats lib's signature of it to document it, and adds
2198
+ // nothing: `tsc` accepting `new Date()` is `tsc` not being Nish's checker.
2199
+ // `crypto` is a Web API that `lib.es2022` leaves out, so it is declared with its
2200
+ // one member, typed as Nish types it.
2201
+
2202
+ /**
2203
+ * `Date`, merged into the `DateConstructor` `lib.es2022` declares. Nish has no
2204
+ * `Date` object: `Date.now()` is its one member, and `new Date()`, `Date()`,
2205
+ * `Date.parse`, `Date.UTC`, any other member, and `Date` or `Date.now` used as
2206
+ * a value are each refused: "`new Date()` is refused: Nish has no `Date`
2207
+ * object; the one `Date` member is `Date.now()`, the wall clock in
2208
+ * milliseconds" (NL2401).
2209
+ */
2210
+ interface DateConstructor {
2211
+ /**
2212
+ * The wall clock, `CLOCK_REALTIME`, in whole milliseconds since 1970-01-01
2213
+ * UTC, as JavaScript answers it: the milliseconds are counted as integers and
2214
+ * then converted, so the value is exact and a time before 1970 floors. An
2215
+ * `f64` in both number modes, because an `i32` of milliseconds overflowed in
2216
+ * January 1970. It can go backwards when the clock is corrected, so an
2217
+ * interval is `monotonicNanos`'s job, not this one's. A wasm32 build has no
2218
+ * operating system to ask, and refuses it. Capability: clock.
2219
+ *
2220
+ * @returns the milliseconds, an `f64`.
2221
+ */
2222
+ now(): number;
2223
+ }
2130
2224
 
2131
2225
  /** The system's random source, with its one member. */
2132
2226
  declare var crypto: {
@@ -3490,22 +3584,22 @@ declare module "nish:simd" {
3490
3584
  * A `u8x16` of sixteen lanes: one `insertelement` per lane, which `opt`
3491
3585
  * folds to a constant vector when every lane is one.
3492
3586
  *
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.
3587
+ * @param a0 Lane 0, a `u8`.
3588
+ * @param a1 Lane 1, a `u8`.
3589
+ * @param a2 Lane 2, a `u8`.
3590
+ * @param a3 Lane 3, a `u8`.
3591
+ * @param a4 Lane 4, a `u8`.
3592
+ * @param a5 Lane 5, a `u8`.
3593
+ * @param a6 Lane 6, a `u8`.
3594
+ * @param a7 Lane 7, a `u8`.
3595
+ * @param a8 Lane 8, a `u8`.
3596
+ * @param a9 Lane 9, a `u8`.
3597
+ * @param a10 Lane 10, a `u8`.
3598
+ * @param a11 Lane 11, a `u8`.
3599
+ * @param a12 Lane 12, a `u8`.
3600
+ * @param a13 Lane 13, a `u8`.
3601
+ * @param a14 Lane 14, a `u8`.
3602
+ * @param a15 Lane 15, a `u8`.
3509
3603
  * @returns The vector.
3510
3604
  */
3511
3605
  export function u8x16(
@@ -3515,52 +3609,52 @@ declare module "nish:simd" {
3515
3609
  /**
3516
3610
  * A `u16x8` of 8 lanes, one argument per lane, lane 0 first.
3517
3611
  *
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.
3612
+ * @param a0 Lane 0, a `u16`.
3613
+ * @param a1 Lane 1, a `u16`.
3614
+ * @param a2 Lane 2, a `u16`.
3615
+ * @param a3 Lane 3, a `u16`.
3616
+ * @param a4 Lane 4, a `u16`.
3617
+ * @param a5 Lane 5, a `u16`.
3618
+ * @param a6 Lane 6, a `u16`.
3619
+ * @param a7 Lane 7, a `u16`.
3526
3620
  * @returns The vector.
3527
3621
  */
3528
3622
  export function u16x8(a0: u16, a1: u16, a2: u16, a3: u16, a4: u16, a5: u16, a6: u16, a7: u16): u16x8;
3529
3623
  /**
3530
3624
  * An `i32x4` of 4 lanes, one argument per lane, lane 0 first.
3531
3625
  *
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.
3626
+ * @param a0 Lane 0, an `i32`.
3627
+ * @param a1 Lane 1, an `i32`.
3628
+ * @param a2 Lane 2, an `i32`.
3629
+ * @param a3 Lane 3, an `i32`.
3536
3630
  * @returns The vector.
3537
3631
  */
3538
3632
  export function i32x4(a0: i32, a1: i32, a2: i32, a3: i32): i32x4;
3539
3633
  /**
3540
3634
  * A `u32x4` of 4 lanes, one argument per lane, lane 0 first.
3541
3635
  *
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.
3636
+ * @param a0 Lane 0, a `u32`.
3637
+ * @param a1 Lane 1, a `u32`.
3638
+ * @param a2 Lane 2, a `u32`.
3639
+ * @param a3 Lane 3, a `u32`.
3546
3640
  * @returns The vector.
3547
3641
  */
3548
3642
  export function u32x4(a0: u32, a1: u32, a2: u32, a3: u32): u32x4;
3549
3643
  /**
3550
3644
  * An `f32x4` of 4 lanes, one argument per lane, lane 0 first.
3551
3645
  *
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.
3646
+ * @param a0 Lane 0, an `f32`.
3647
+ * @param a1 Lane 1, an `f32`.
3648
+ * @param a2 Lane 2, an `f32`.
3649
+ * @param a3 Lane 3, an `f32`.
3556
3650
  * @returns The vector.
3557
3651
  */
3558
3652
  export function f32x4(a0: f32, a1: f32, a2: f32, a3: f32): f32x4;
3559
3653
  /**
3560
3654
  * An `f64x2` of 2 lanes, one argument per lane, lane 0 first.
3561
3655
  *
3562
- * @param a0 Lane 0, an `f64`; `a1` is lane 1.
3563
- * @param a1 Lane 1.
3656
+ * @param a0 Lane 0, an `f64`.
3657
+ * @param a1 Lane 1, an `f64`.
3564
3658
  * @returns The vector.
3565
3659
  */
3566
3660
  export function f64x2(a0: f64, a1: f64): f64x2;
@@ -4757,6 +4851,71 @@ declare module "nish:async" {
4757
4851
  * made (an `fd` that is not open). A regular file is always ready.
4758
4852
  */
4759
4853
  export function writable(fd: i32): Promise<boolean>;
4854
+ /**
4855
+ * Suspend the task until `fd` has bytes to read, or its peer has hung up,
4856
+ * or `ms` milliseconds pass, whichever comes first. Written only as
4857
+ * `await readableWithin(fd, ms)` inside an `async` function (NL2671).
4858
+ * Refused under `--emit-ts` (NL4018).
4859
+ *
4860
+ * @param fd An open descriptor: a socket, a pipe or a terminal.
4861
+ * @param ms The most milliseconds to wait; a negative `ms` waits without a
4862
+ * limit, as `readable` does.
4863
+ * @returns `true` once `fd` is ready; `false` when `ms` passed first, when
4864
+ * the wait could not be made, or when the task is cancelled.
4865
+ */
4866
+ export function readableWithin(fd: i32, ms: i32): Promise<boolean>;
4867
+ /**
4868
+ * Suspend the task until `fd` takes bytes without blocking, or `ms`
4869
+ * milliseconds pass, whichever comes first. Written only as
4870
+ * `await writableWithin(fd, ms)` inside an `async` function (NL2671).
4871
+ * Refused under `--emit-ts` (NL4018).
4872
+ *
4873
+ * @param fd An open descriptor: a socket, a pipe or a terminal.
4874
+ * @param ms The most milliseconds to wait; a negative `ms` waits without a
4875
+ * limit, as `writable` does.
4876
+ * @returns `true` once `fd` is ready; `false` when `ms` passed first, when
4877
+ * the wait could not be made, or when the task is cancelled.
4878
+ */
4879
+ export function writableWithin(fd: i32, ms: i32): Promise<boolean>;
4880
+ /**
4881
+ * The running task's handle, to hand to `cancel` or `cancelAfter`. `main`'s
4882
+ * handle is 0, which no call cancels. Refused under `--emit-ts` (NL4018).
4883
+ *
4884
+ * @returns The handle, an `i64` that names this task and no later one.
4885
+ */
4886
+ export function taskId(): i64;
4887
+ /**
4888
+ * Cancel a task: every `sleep`, `readable` or `writable` it is waiting on
4889
+ * answers `false` at once, and so does every one it makes later, so it runs
4890
+ * on to its end, its `using` bindings dispose and its region is freed. A
4891
+ * task is never stopped in the middle of its code. Refused under
4892
+ * `--emit-ts` (NL4018).
4893
+ *
4894
+ * @param task A handle `taskId()` answered.
4895
+ * @returns `true` while the task is still running, so it is now cancelled
4896
+ * (a second `cancel` of it answers `true` too); `false` for a task that
4897
+ * has finished, or for `main`.
4898
+ */
4899
+ export function cancel(task: i64): boolean;
4900
+ /**
4901
+ * Whether the running task has been cancelled. Refused under `--emit-ts`
4902
+ * (NL4018).
4903
+ *
4904
+ * @returns `true` once `cancel` was called on it, or its `cancelAfter`
4905
+ * deadline passed.
4906
+ */
4907
+ export function cancelled(): boolean;
4908
+ /**
4909
+ * Cancel a task `ms` milliseconds from now, unless it finishes first. A
4910
+ * later call replaces the deadline; a negative `ms` removes it. Refused
4911
+ * under `--emit-ts` (NL4018).
4912
+ *
4913
+ * @param task A handle `taskId()` answered.
4914
+ * @param ms The milliseconds until the task is cancelled.
4915
+ * @returns `true` when the task is still running and the deadline is set
4916
+ * (or removed); `false` for a task that has finished or is `main`.
4917
+ */
4918
+ export function cancelAfter(task: i64, ms: i32): boolean;
4760
4919
  }
4761
4920
 
4762
4921
  // ---- Arena (docs/LANGUAGE.md -> Arena) ---------------------------------------
@@ -5150,7 +5309,7 @@ interface Math {
5150
5309
  * there. A numeric literal argument to `push`, `indexOf` or `fill` takes the
5151
5310
  * element type, so `wide.push(3)` on an `i64[]` pushes an `i64` three. An
5152
5311
  * 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.
5312
+ * i32[]"; there is no `shift`, `find` or `toString` on an array.
5154
5313
  */
5155
5314
  interface Array<T> {
5156
5315
  /** The element count, read-only: assigning to it is refused. */
@@ -5304,6 +5463,72 @@ interface Array<T> {
5304
5463
  * @param offset the first slot written, `0` by default.
5305
5464
  */
5306
5465
  set(source: readonly T[], offset?: number): void;
5466
+ /**
5467
+ * A new array of `callbackfn(element)` for each element, in order, as
5468
+ * `Array.prototype.map` gives. The callback takes the element, or the
5469
+ * element and its index; a third parameter (JavaScript's array argument) is
5470
+ * refused (NL2698), as is a second argument to `map` itself. It is a
5471
+ * top-level function or an arrow reading only `const` locals and parameters,
5472
+ * and the call compiles to a loop that calls it directly (`std/array`'s
5473
+ * `map`). Capability: none.
5474
+ *
5475
+ * @param callbackfn called once per element, with the element and its index.
5476
+ * @returns a new array of the callback's answers, of the receiver's length.
5477
+ */
5478
+ map<U>(callbackfn: (value: T, index: number) => U): U[];
5479
+ /**
5480
+ * A new array of the elements for which `predicate` answers `true`, in
5481
+ * order, as `Array.prototype.filter` gives. The predicate answers a
5482
+ * `boolean` and takes the element, or the element and its index, under the
5483
+ * callback rules of `map`. Capability: none.
5484
+ *
5485
+ * @param predicate called once per element, with the element and its index.
5486
+ * @returns a new array of the elements kept.
5487
+ */
5488
+ filter(predicate: (value: T, index: number) => boolean): T[];
5489
+ /**
5490
+ * Whether `predicate` answers `true` for some element, stopping at the first
5491
+ * that does, as `Array.prototype.some` does; an empty array answers `false`.
5492
+ * The callback rules are `map`'s. Capability: none.
5493
+ *
5494
+ * @param predicate called in order, with the element and its index, until it answers `true`.
5495
+ * @returns `true` when some element satisfies `predicate`.
5496
+ */
5497
+ some(predicate: (value: T, index: number) => boolean): boolean;
5498
+ /**
5499
+ * Whether `predicate` answers `true` for every element, stopping at the
5500
+ * first that does not, as `Array.prototype.every` does; an empty array
5501
+ * answers `true`. The callback rules are `map`'s. Capability: none.
5502
+ *
5503
+ * @param predicate called in order, with the element and its index, until it answers `false`.
5504
+ * @returns `true` when no element fails `predicate`.
5505
+ */
5506
+ every(predicate: (value: T, index: number) => boolean): boolean;
5507
+ /**
5508
+ * The index of the first element for which `predicate` answers `true`, or
5509
+ * `-1`, as `Array.prototype.findIndex` gives. The callback rules are
5510
+ * `map`'s. There is no `find`: TypeScript types its answer `T | undefined`
5511
+ * and Nish has no `undefined`, so `xs.find(...)` is refused (NL2697) and
5512
+ * points here. Capability: none.
5513
+ *
5514
+ * @param predicate called in order, with the element and its index, until it answers `true`.
5515
+ * @returns the first such index, or `-1`.
5516
+ */
5517
+ findIndex(predicate: (value: T, index: number) => boolean): number;
5518
+ /**
5519
+ * A copy of the elements from `start` up to `end`, in a new array, with
5520
+ * string `slice`'s rule: the range must satisfy `0 <= start <= end <=
5521
+ * length`, and anything else panics with `slice out of range: [start, end)
5522
+ * of length n` and exits 1, where JavaScript counts a negative index back
5523
+ * from the length and clamps the rest. `start` is `0` and `end` the length
5524
+ * by default; a third argument is refused (NL2699). Under Node the prelude's
5525
+ * `sliceArray` applies the same check. Capability: none.
5526
+ *
5527
+ * @param start the first index copied, `0` by default.
5528
+ * @param end the index after the last copied, the length by default.
5529
+ * @returns a new array of `end - start` elements.
5530
+ */
5531
+ slice(start?: number, end?: number): T[];
5307
5532
  }
5308
5533
 
5309
5534
  /**
@@ -5314,8 +5539,9 @@ interface Array<T> {
5314
5539
  * nish_array *`.
5315
5540
  *
5316
5541
  * 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[]
5542
+ * `map`, `filter`, `some`, `every`, `findIndex`, `slice`, passing it on to
5543
+ * another `readonly T[]`); every write is refused under its own name, an
5544
+ * element store ("Cannot assign to an element of readonly i32[]
5319
5545
  * (declare it i32[] to write through it)"), `push`, `pop`, `set`, `fill` and
5320
5546
  * `sort` included. A `T[]` widens into a `readonly T[]`, and never back:
5321
5547
  * "Argument 1 of `fill`: expected i32[], got readonly i32[]". It is shallow, as
@@ -5347,6 +5573,72 @@ interface ReadonlyArray<T> {
5347
5573
  * @returns the joined string.
5348
5574
  */
5349
5575
  join(separator?: string): string;
5576
+ /**
5577
+ * A new array of `callbackfn(element)` for each element, in order, as
5578
+ * `Array.prototype.map` gives. The callback takes the element, or the
5579
+ * element and its index; a third parameter (JavaScript's array argument) is
5580
+ * refused (NL2698), as is a second argument to `map` itself. It is a
5581
+ * top-level function or an arrow reading only `const` locals and parameters,
5582
+ * and the call compiles to a loop that calls it directly (`std/array`'s
5583
+ * `map`). Capability: none.
5584
+ *
5585
+ * @param callbackfn called once per element, with the element and its index.
5586
+ * @returns a new array of the callback's answers, of the receiver's length.
5587
+ */
5588
+ map<U>(callbackfn: (value: T, index: number) => U): U[];
5589
+ /**
5590
+ * A new array of the elements for which `predicate` answers `true`, in
5591
+ * order, as `Array.prototype.filter` gives. The predicate answers a
5592
+ * `boolean` and takes the element, or the element and its index, under the
5593
+ * callback rules of `map`. Capability: none.
5594
+ *
5595
+ * @param predicate called once per element, with the element and its index.
5596
+ * @returns a new array of the elements kept.
5597
+ */
5598
+ filter(predicate: (value: T, index: number) => boolean): T[];
5599
+ /**
5600
+ * Whether `predicate` answers `true` for some element, stopping at the first
5601
+ * that does, as `Array.prototype.some` does; an empty array answers `false`.
5602
+ * The callback rules are `map`'s. Capability: none.
5603
+ *
5604
+ * @param predicate called in order, with the element and its index, until it answers `true`.
5605
+ * @returns `true` when some element satisfies `predicate`.
5606
+ */
5607
+ some(predicate: (value: T, index: number) => boolean): boolean;
5608
+ /**
5609
+ * Whether `predicate` answers `true` for every element, stopping at the
5610
+ * first that does not, as `Array.prototype.every` does; an empty array
5611
+ * answers `true`. The callback rules are `map`'s. Capability: none.
5612
+ *
5613
+ * @param predicate called in order, with the element and its index, until it answers `false`.
5614
+ * @returns `true` when no element fails `predicate`.
5615
+ */
5616
+ every(predicate: (value: T, index: number) => boolean): boolean;
5617
+ /**
5618
+ * The index of the first element for which `predicate` answers `true`, or
5619
+ * `-1`, as `Array.prototype.findIndex` gives. The callback rules are
5620
+ * `map`'s. There is no `find`: TypeScript types its answer `T | undefined`
5621
+ * and Nish has no `undefined`, so `xs.find(...)` is refused (NL2697) and
5622
+ * points here. Capability: none.
5623
+ *
5624
+ * @param predicate called in order, with the element and its index, until it answers `true`.
5625
+ * @returns the first such index, or `-1`.
5626
+ */
5627
+ findIndex(predicate: (value: T, index: number) => boolean): number;
5628
+ /**
5629
+ * A copy of the elements from `start` up to `end`, in a new array, with
5630
+ * string `slice`'s rule: the range must satisfy `0 <= start <= end <=
5631
+ * length`, and anything else panics with `slice out of range: [start, end)
5632
+ * of length n` and exits 1, where JavaScript counts a negative index back
5633
+ * from the length and clamps the rest. `start` is `0` and `end` the length
5634
+ * by default; a third argument is refused (NL2699). Under Node the prelude's
5635
+ * `sliceArray` applies the same check. Capability: none.
5636
+ *
5637
+ * @param start the first index copied, `0` by default.
5638
+ * @param end the index after the last copied, the length by default.
5639
+ * @returns a new array of `end - start` elements.
5640
+ */
5641
+ slice(start?: number, end?: number): T[];
5350
5642
  }
5351
5643
 
5352
5644
  /**
@@ -5444,6 +5736,10 @@ interface String {
5444
5736
  endsWith(searchString: string, endPosition?: number): boolean;
5445
5737
  }
5446
5738
 
5739
+ /**
5740
+ * `String.fromCharCode`, `lib.es2022`'s own member of `StringConstructor`,
5741
+ * repeated so that its byte meaning in Nish is documented.
5742
+ */
5447
5743
  interface StringConstructor {
5448
5744
  /**
5449
5745
  * The one-byte string of `c & 0xFF`, the inverse of `charCodeAt`. One
package/runtime/nish.h CHANGED
@@ -4,7 +4,8 @@
4
4
  * runtime next to compiled Nish modules. Everything here is a contract shared
5
5
  * with `src/runtime.ts` (the IR side) and the implementation, which is
6
6
  * several translation units: `runtime/runtime.c` holds the core every program
7
- * touches — the arena, strings, arrays, number formatting, the panics —
7
+ * touches — the arena, arrays, the panics — `runtime/runtime-text.c` holds
8
+ * strings and number formatting (freestanding, so a wasm module links it too),
8
9
  * `runtime/runtime-os.c` holds everything that wraps a system call: the file
9
10
  * functions, the directory and subprocess calls, `nish_getenv`, the monotonic
10
11
  * clock, `nish_platform` / `nish_arch` — and runtime-parallel.c, runtime-host.c,
@@ -51,7 +52,8 @@ extern "C" {
51
52
  * ELF refuses to link that against a non-TLS definition. `scripts/build.sh
52
53
  * --threads` passes the macro to every input, which is how `nish --threads
53
54
  * --link` keeps the two halves in step. The same definition is in
54
- * runtime/runtime.c and runtime/runtime-wasm.c. */
55
+ * runtime/runtime.c and runtime/runtime-wasm.c, and runtime/runtime-text.c
56
+ * repeats it for its inlined allocation fast path. */
55
57
  #ifdef NISH_THREADS
56
58
  #define NISH_TLS _Thread_local
57
59
  #else
@@ -94,7 +96,8 @@ static inline __attribute__((unused)) const char *nish_cpath(const nish_str *s)
94
96
  * `off` and `cap` are `uint64_t` and not `size_t` because that `i64` is what
95
97
  * the inlined fast path bumps and compares on every target: under wasm32 a
96
98
  * `size_t` pair would put them at bytes 4 and 8 while compiled code reads 8
97
- * and 16. runtime.c and runtime-wasm.c static-assert these offsets. */
99
+ * and 16. runtime.c and runtime-wasm.c static-assert these offsets, and
100
+ * runtime-text.c, which keeps its own copy of the struct, asserts all four. */
98
101
  struct nish_arena {
99
102
  char *buf;
100
103
  uint64_t off;
@@ -146,12 +149,17 @@ uint64_t nish_arena_used(void);
146
149
  * already entered panics. `nish_region_leave` must name the region entered
147
150
  * last on this thread, puts back the arena its enter displaced and records
148
151
  * `root`. `nish_region_free` frees every chunk of a region that is not
149
- * entered and makes its handle stale. The wasm profile has none of these
150
- * (scripts/build.sh refuses IR that names them); wasi has. */
152
+ * entered and makes its handle stale. `nish_region_adopt` instead moves the
153
+ * chunks of a region that is not entered onto the thread's current arena, so
154
+ * they live on until that arena releases below them, and makes its handle
155
+ * stale: an `awaitAll` lane's region, once the lane has answered. The wasm
156
+ * profile has none of these (scripts/build.sh refuses IR that names them);
157
+ * wasi has. */
151
158
  uint64_t nish_region_new(void);
152
159
  void *nish_region_enter(uint64_t r);
153
160
  void nish_region_leave(uint64_t r, void *root);
154
161
  void nish_region_free(uint64_t r);
162
+ void nish_region_adopt(uint64_t r);
155
163
 
156
164
  /* ---- The async executor (runtime-async.c) --------------------------------
157
165
  * Linked only into a program whose IR names `@nish_async_`
@@ -166,7 +174,16 @@ void nish_region_free(uint64_t r);
166
174
  * resume, blocking in the kernel until one is ready, or null when nothing is
167
175
  * ready and nothing waits. `nish_async_stat` answers 0: nodes allocated, 1:
168
176
  * completions dropped because their task had finished, 2: spawned tasks not yet
169
- * finished. */
177
+ * finished.
178
+ *
179
+ * Cancellation is cooperative. A task's handle (`nish_async_task_id`) is its
180
+ * slot and generation, and `main`'s is 0. `nish_async_cancel` flags a task and
181
+ * fires the waits it is parked on, which then read 0, as does every later wait
182
+ * it makes; it answers 1 when it flagged a live task other than `main`.
183
+ * `nish_async_cancelled` answers 1 inside a flagged task, and
184
+ * `nish_async_cancel_after` arms a timer that cancels the task in `ms`.
185
+ * `nish_async_wait_fd_within` is `nish_async_wait_fd` that reads 0 when `ms`
186
+ * pass first. */
170
187
  void *nish_async_spawn(int32_t kind, uint64_t bytes);
171
188
  void *nish_async_enter(void *node);
172
189
  void nish_async_leave(void *node, void *prev);
@@ -177,6 +194,11 @@ int32_t nish_async_poll(uint64_t token);
177
194
  void *nish_async_next(void);
178
195
  void *nish_async_copy_str(const void *s);
179
196
  int32_t nish_async_stat(int32_t which);
197
+ uint64_t nish_async_wait_fd_within(int32_t fd, int32_t dir, int32_t ms);
198
+ int64_t nish_async_task_id(void);
199
+ int32_t nish_async_cancel(int64_t handle);
200
+ int32_t nish_async_cancelled(void);
201
+ int32_t nish_async_cancel_after(int64_t handle, int32_t ms);
180
202
 
181
203
  /* ---- String operations ------------------------------------------------- */
182
204
  /* Copy `len` bytes into a new arena string (`bytes` need not be terminated). */
@@ -248,7 +270,7 @@ nish_str *nish_str_from_i32(int32_t v);
248
270
  nish_str *nish_str_from_f64(double v);
249
271
  /* The bytes `nish_str_from_f64` would hold, written into `out` with no NUL;
250
272
  returns the length. 32 bytes is room to spare: the longest spelling,
251
- -0.0000012345678901234567, is 25 (runtime.c says why, and runtime-test.c
273
+ -0.0000012345678901234567, is 25 (runtime-text.c says why, and runtime-test.c
252
274
  pins it). For a caller that writes numbers into its own buffer. */
253
275
  #define NISH_F64_MAX 32
254
276
  int nish_f64_format(double v, char out[NISH_F64_MAX]);