@amritk/nish-aarch64-linux 0.39.0 → 0.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/INSTALL.md +74 -129
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +112 -33
  4. package/package.json +1 -1
  5. package/runtime/nish.d.ts +21 -17
  6. package/runtime/nish.h +10 -0
  7. package/runtime/page-frame.d.ts +123 -0
  8. package/runtime/page-frame.mjs +736 -0
  9. package/runtime/page-game.d.ts +132 -0
  10. package/runtime/page-game.mjs +738 -0
  11. package/runtime/runtime-aes.c +85 -8
  12. package/runtime/runtime-bytes.c +88 -4
  13. package/runtime/runtime-net.c +32 -0
  14. package/runtime/runtime-sandbox.c +55 -28
  15. package/runtime/runtime-wasm.c +422 -0
  16. package/runtime/vite.mjs +1 -1
  17. package/scripts/build.sh +15 -0
  18. package/std/README.md +73 -87
  19. package/std/array.ts +36 -3
  20. package/std/collections.ts +51 -0
  21. package/std/crypto/hmac.ts +37 -10
  22. package/std/crypto/p256.ts +1388 -2664
  23. package/std/crypto/pki.ts +116 -4
  24. package/std/crypto/sha256.ts +34 -6
  25. package/std/crypto/x509.ts +7 -0
  26. package/std/host/game.ts +273 -0
  27. package/std/input.ts +56 -0
  28. package/std/json-tokenizer.ts +325 -112
  29. package/std/json-typed.ts +43 -8
  30. package/std/json-value.ts +144 -3
  31. package/std/json.ts +63 -8
  32. package/std/net/fetch.ts +22 -4
  33. package/std/net/http-server.ts +3382 -0
  34. package/std/net/http1-client-codec.ts +6 -2
  35. package/std/net/http1-codec.ts +137 -12
  36. package/std/net/http1-server.ts +83 -29
  37. package/std/net/http2.ts +47 -14
  38. package/std/net/http3-server.ts +29 -3
  39. package/std/net/http3.ts +180 -7
  40. package/std/net/quic-recovery.ts +240 -9
  41. package/std/net/quic-stream.ts +21 -1
  42. package/std/net/quic.ts +98 -4
  43. package/std/net/router.ts +378 -31
  44. package/std/net/serve.ts +873 -65
  45. package/std/net/tls/verify.ts +19 -1
  46. package/std/net/url.ts +83 -35
  47. package/std/net/websocket.ts +74 -1
  48. package/std/net/webtransport.ts +7 -1
  49. package/std/raster.ts +837 -0
  50. package/std/release.ts +593 -0
  51. package/std/synth.ts +143 -0
  52. package/std/threads.ts +298 -0
  53. package/std/yaml-json.ts +368 -28
  54. package/std/yaml.ts +122 -27
package/std/yaml.ts CHANGED
@@ -271,6 +271,12 @@ const YAML_CLIP: i32 = 0
271
271
  const YAML_STRIP: i32 = 1
272
272
  const YAML_KEEP: i32 = 2
273
273
 
274
+ /**
275
+ * A flow scalar's `extras` when its body is its source span, byte for byte.
276
+ * @internal Copied by std/yaml-json.ts with no search for a line break.
277
+ */
278
+ export const YAML_VERBATIM: i32 = 1
279
+
274
280
  // ---- Options -------------------------------------------------------------------
275
281
 
276
282
  /** How `parseYamlWith` reads a stream. Make one with `new YamlOptions()` and set what differs. */
@@ -319,7 +325,8 @@ export class YamlStream {
319
325
  counts: i32[]
320
326
  /**
321
327
  * Per node: a block scalar's content indent, whether it was written, and its
322
- * chomping, as `(indent + 1) * 8 + explicit * 4 + chomp`.
328
+ * chomping, as `(indent + 1) * 8 + explicit * 4 + chomp`; a flow scalar's
329
+ * `YAML_VERBATIM` when its source span is its body.
323
330
  * @internal Used by `yamlDecode` and `YamlParser`.
324
331
  */
325
332
  extras: i32[]
@@ -328,8 +335,12 @@ export class YamlStream {
328
335
  * @internal Used by `YamlParser`.
329
336
  */
330
337
  props: i32[]
331
- /** Every collection's children, one collection after another. */
332
- private kids: i32[]
338
+ /**
339
+ * Every collection's children, one collection after another.
340
+ * @internal Used by `YamlParser`, and read by std/yaml-json.ts, which walks
341
+ * each collection's children in turn.
342
+ */
343
+ kids: i32[]
333
344
  /**
334
345
  * Per property slot: the anchor's name (after `&`), the tag as written, and the anchor table entry.
335
346
  * @internal Used by `YamlParser`.
@@ -413,10 +424,23 @@ export class YamlStream {
413
424
  * @internal Used by `YamlPathWalker`.
414
425
  */
415
426
  mergeStep: i32 = 0
427
+ /**
428
+ * How many sequence items the parser's merge checks have read, so a test
429
+ * can see that a shared merge sequence is read once, not once per use.
430
+ * @internal Used by `YamlParser`.
431
+ */
432
+ mergeItemsChecked: i32 = 0
416
433
  /**
417
434
  * Whether a plain `<<` key is a merge key, as `YamlOptions.merge` said; paths follow merge keys while it is.
418
435
  */
419
436
  merge: boolean = true
437
+ /**
438
+ * @internal Set by `YamlParser`, and read by std/yaml-json.ts. Whether the
439
+ * parser reported every map that repeats a key, as `YamlOptions.uniqueKeys`
440
+ * said; `false` for a stream built by hand, so a reader that relies on it
441
+ * checks for itself.
442
+ */
443
+ uniqueKeys: boolean = false
420
444
 
421
445
  /**
422
446
  * An empty stream over `text`, for the parser to fill; get a parsed one from
@@ -1530,8 +1554,12 @@ const yamlDecodeBlock = (text: string, from: i32, to: i32, extras: i32, folded:
1530
1554
 
1531
1555
  /** Internal: scalar `n`'s core-schema type, from its text and its tag. */
1532
1556
  const yamlResolve = (stream: YamlStream, n: i32): i32 => {
1533
- const tag: string = stream.tag(n)
1534
1557
  const plain: boolean = stream.style(n) === YAML_PLAIN
1558
+ // A node with no properties has no tag, which spares reading its text.
1559
+ if (n < 0 || n >= stream.top || yamlAt(stream.props, n) < 0) {
1560
+ return plain ? yamlPlainType(stream.source, stream.start(n), stream.end(n)) : YAML_STRING
1561
+ }
1562
+ const tag: string = stream.tag(n)
1535
1563
  if (tag === "") {
1536
1564
  return plain ? yamlPlainType(stream.source, stream.start(n), stream.end(n)) : YAML_STRING
1537
1565
  }
@@ -1567,26 +1595,12 @@ const yamlPlainType = (text: string, from: i32, to: i32): i32 => {
1567
1595
  if (!letter && !yamlIsDigit(c) && c !== YAML_DOT && c !== YAML_DASH && c !== YAML_PLUS && c !== 126) {
1568
1596
  return YAML_STRING
1569
1597
  }
1570
- if (
1571
- yamlIsWord(text, from, to, "~") ||
1572
- yamlIsWord(text, from, to, "null") ||
1573
- yamlIsWord(text, from, to, "Null") ||
1574
- yamlIsWord(text, from, to, "NULL")
1575
- ) {
1598
+ // Each word is told by its first byte, so a text is compared with its own three at most.
1599
+ if (c === 126 && to - from === 1) {
1576
1600
  return YAML_NULL
1577
1601
  }
1578
- if (
1579
- yamlIsWord(text, from, to, "true") ||
1580
- yamlIsWord(text, from, to, "True") ||
1581
- yamlIsWord(text, from, to, "TRUE") ||
1582
- yamlIsWord(text, from, to, "false") ||
1583
- yamlIsWord(text, from, to, "False") ||
1584
- yamlIsWord(text, from, to, "FALSE")
1585
- ) {
1586
- return YAML_BOOL
1587
- }
1588
1602
  if (letter) {
1589
- return YAML_STRING
1603
+ return yamlWordType(text, from, to, c)
1590
1604
  }
1591
1605
  if (yamlIntBase(text, from, to) > 0) {
1592
1606
  return YAML_INT
@@ -1597,6 +1611,33 @@ const yamlPlainType = (text: string, from: i32, to: i32): i32 => {
1597
1611
  return YAML_STRING
1598
1612
  }
1599
1613
 
1614
+ /**
1615
+ * The type of the plain scalar `text[from, to)`, whose first byte `c` is one
1616
+ * of `nNtTfF`: `YAML_NULL` for a `null`, `YAML_BOOL` for a `true` or `false`,
1617
+ * in the core schema's three spellings each, and `YAML_STRING` otherwise.
1618
+ */
1619
+ const yamlWordType = (text: string, from: i32, to: i32, c: i32): i32 => {
1620
+ if (c === 110 || c === 78) {
1621
+ const isNull: boolean =
1622
+ yamlIsWord(text, from, to, "null") ||
1623
+ yamlIsWord(text, from, to, "Null") ||
1624
+ yamlIsWord(text, from, to, "NULL")
1625
+ return isNull ? YAML_NULL : YAML_STRING
1626
+ }
1627
+ if (c === 116 || c === 84) {
1628
+ const isTrue: boolean =
1629
+ yamlIsWord(text, from, to, "true") ||
1630
+ yamlIsWord(text, from, to, "True") ||
1631
+ yamlIsWord(text, from, to, "TRUE")
1632
+ return isTrue ? YAML_BOOL : YAML_STRING
1633
+ }
1634
+ const isFalse: boolean =
1635
+ yamlIsWord(text, from, to, "false") ||
1636
+ yamlIsWord(text, from, to, "False") ||
1637
+ yamlIsWord(text, from, to, "FALSE")
1638
+ return isFalse ? YAML_BOOL : YAML_STRING
1639
+ }
1640
+
1600
1641
  /** The base of the core-schema integer `text[from, to)`, signed, decimal, `0x` or `0o`; `0` for none. */
1601
1642
  const yamlIntBase = (text: string, from: i32, to: i32): i32 => {
1602
1643
  let i: i32 = from
@@ -1811,6 +1852,11 @@ class YamlParser {
1811
1852
  private scratch: i32[]
1812
1853
  /** Hash sets for the duplicate check of maps past YAML_PAIRWISE_KEYS pairs, reused as maps nest and end. */
1813
1854
  private keySets: YamlKeySet[]
1855
+ /**
1856
+ * Per sequence node an alias merge has named: `0` not yet checked, `1`
1857
+ * every item merges a map, `2` one does not, so a shared sequence is read once.
1858
+ */
1859
+ private mergeVerdicts: u8[]
1814
1860
  private pos: i32 = 0
1815
1861
  private len: i32 = 0
1816
1862
  private depth: i32 = 0
@@ -1857,10 +1903,12 @@ class YamlParser {
1857
1903
  this.handlePrefixes = []
1858
1904
  this.scratch = []
1859
1905
  this.keySets = []
1906
+ this.mergeVerdicts = []
1860
1907
  this.len = toI32(text.length)
1861
1908
  this.maxDepth = options.maxDepth
1862
1909
  this.uniqueKeys = options.uniqueKeys
1863
1910
  this.stream.merge = options.merge
1911
+ this.stream.uniqueKeys = options.uniqueKeys
1864
1912
  this.keepComments = options.keepComments
1865
1913
  this.firstOnly = options.firstDocumentOnly
1866
1914
  }
@@ -2489,6 +2537,8 @@ class YamlParser {
2489
2537
  let indentReported: boolean = parentIndent < 0
2490
2538
  let closed: boolean = false
2491
2539
  let contentEnd: i32 = this.len
2540
+ // No break, escape or doubled quote met: the span is the body.
2541
+ let verbatim: boolean = true
2492
2542
  while (i < this.len) {
2493
2543
  const at: i32 = toI32(indexOfAny(this.text, single ? YAML_SINGLE_STOPS : YAML_DOUBLE_STOPS, i))
2494
2544
  if (at < 0) {
@@ -2499,6 +2549,7 @@ class YamlParser {
2499
2549
  const c: i32 = this.at(i)
2500
2550
  if (c === YAML_SQUOTE) {
2501
2551
  if (this.at(i + 1) === YAML_SQUOTE) {
2552
+ verbatim = false
2502
2553
  i += 2
2503
2554
  continue
2504
2555
  }
@@ -2514,6 +2565,7 @@ class YamlParser {
2514
2565
  break
2515
2566
  }
2516
2567
  if (c === YAML_BACKSLASH) {
2568
+ verbatim = false
2517
2569
  const e: i32 = this.at(i + 1)
2518
2570
  if (e < 0) {
2519
2571
  i = this.len
@@ -2530,6 +2582,7 @@ class YamlParser {
2530
2582
  continue
2531
2583
  }
2532
2584
  // A line break.
2585
+ verbatim = false
2533
2586
  const after: i32 = yamlAfterBreak(this.text, i)
2534
2587
  if (this.isDocMarker(after)) {
2535
2588
  contentEnd = i
@@ -2552,6 +2605,9 @@ class YamlParser {
2552
2605
  )
2553
2606
  yamlPut(this.stream.firsts, node, start + 1)
2554
2607
  yamlPut(this.stream.counts, node, contentEnd)
2608
+ if (verbatim && closed) {
2609
+ yamlPut(this.stream.extras, node, YAML_VERBATIM)
2610
+ }
2555
2611
  this.pos = i
2556
2612
  return node
2557
2613
  }
@@ -2720,6 +2776,8 @@ class YamlParser {
2720
2776
  private scanPlainScalar(parentIndent: i32): i32 {
2721
2777
  const start: i32 = this.pos
2722
2778
  let valueEnd: i32 = this.plainLineEnd(start)
2779
+ // The first line's end: a scalar that stops there has no break in its span.
2780
+ const firstEnd: i32 = valueEnd
2723
2781
  let colonReported: boolean = false
2724
2782
  const firstColon: i32 = this.plainColonAt(start, valueEnd)
2725
2783
  if (firstColon >= 0) {
@@ -2770,6 +2828,9 @@ class YamlParser {
2770
2828
  const node: i32 = this.stream.newNode(YAML_SCALAR, YAML_PLAIN, start, valueEnd)
2771
2829
  yamlPut(this.stream.firsts, node, start)
2772
2830
  yamlPut(this.stream.counts, node, valueEnd)
2831
+ if (valueEnd === firstEnd) {
2832
+ yamlPut(this.stream.extras, node, YAML_VERBATIM)
2833
+ }
2773
2834
  return node
2774
2835
  }
2775
2836
 
@@ -3199,7 +3260,9 @@ class YamlParser {
3199
3260
  let valueEnd: i32 = this.trimEnd(start, i)
3200
3261
  if (!yamlIsBreak(this.at(i))) {
3201
3262
  this.pos = i
3202
- return this.plainNode(start, valueEnd)
3263
+ const one: i32 = this.plainNode(start, valueEnd)
3264
+ yamlPut(this.stream.extras, one, YAML_VERBATIM)
3265
+ return one
3203
3266
  }
3204
3267
  let scan: i32 = yamlAfterBreak(this.text, i)
3205
3268
  while (true) {
@@ -3542,7 +3605,8 @@ class YamlParser {
3542
3605
  * Reports the value of merge key `key` unless it is a map, an alias
3543
3606
  * to one or a sequence of those; an empty value is reported on the key, a
3544
3607
  * sequence on each item that is not, and an alias to a sequence on the alias.
3545
- * An alias with no target is already reported.
3608
+ * An alias with no target is already reported. An aliased sequence's
3609
+ * verdict is kept, so a sequence many merges name is read once (YJ-5).
3546
3610
  */
3547
3611
  private checkMerge(key: i32, value: i32): void {
3548
3612
  const stream: YamlStream = this.stream
@@ -3553,15 +3617,18 @@ class YamlParser {
3553
3617
  const onAlias: boolean = stream.kind(value) === YAML_ALIAS
3554
3618
  const seq: i32 = onAlias ? stream.target(value) : value
3555
3619
  if (seq >= 0 && stream.kind(seq) === YAML_SEQ) {
3620
+ if (onAlias) {
3621
+ if (!this.aliasedSeqMerges(seq)) {
3622
+ this.badMerge(stream.start(value), stream.end(value))
3623
+ }
3624
+ return
3625
+ }
3556
3626
  const count: i32 = stream.count(seq)
3557
3627
  let i: i32 = 0
3558
3628
  while (i < count) {
3559
3629
  const item: i32 = stream.child(seq, i)
3630
+ stream.mergeItemsChecked += 1
3560
3631
  if (!this.mergesMap(item)) {
3561
- if (onAlias) {
3562
- this.badMerge(stream.start(value), stream.end(value))
3563
- return
3564
- }
3565
3632
  this.badMerge(stream.start(item), stream.end(item))
3566
3633
  }
3567
3634
  i += 1
@@ -3571,6 +3638,34 @@ class YamlParser {
3571
3638
  }
3572
3639
  }
3573
3640
 
3641
+ /**
3642
+ * Whether every item of sequence `seq`, which an alias merge names, merges
3643
+ * a map: read up to its first item that does not the first time, then
3644
+ * answered from the verdict kept for it.
3645
+ */
3646
+ private aliasedSeqMerges(seq: i32): boolean {
3647
+ const stream: YamlStream = this.stream
3648
+ this.mergeVerdicts = yamlRoomU8(this.mergeVerdicts, seq + 1)
3649
+ const verdicts: u8[] = this.mergeVerdicts
3650
+ if (seq < 0 || seq >= toI32(verdicts.length)) {
3651
+ return false
3652
+ }
3653
+ const kept: i32 = toI32(verdicts[seq])
3654
+ if (kept !== 0) {
3655
+ return kept === 1
3656
+ }
3657
+ const count: i32 = stream.count(seq)
3658
+ let good: boolean = true
3659
+ let i: i32 = 0
3660
+ while (good && i < count) {
3661
+ stream.mergeItemsChecked += 1
3662
+ good = this.mergesMap(stream.child(seq, i))
3663
+ i += 1
3664
+ }
3665
+ verdicts[seq] = good ? toU8(1) : toU8(2)
3666
+ return good
3667
+ }
3668
+
3574
3669
  /** Whether `n` is a map, an alias to one or an alias with no target, which merges nothing and is reported as such. */
3575
3670
  private mergesMap(n: i32): boolean {
3576
3671
  const stream: YamlStream = this.stream