@amritk/nish-x86_64-linux 0.20.0 → 0.22.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 (74) hide show
  1. package/INSTALL.md +52 -10
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +2777 -0
  4. package/package.json +2 -1
  5. package/runtime/browser.d.ts +6 -0
  6. package/runtime/browser.mjs +77 -0
  7. package/runtime/core/arrays.d.ts +36 -0
  8. package/runtime/core/arrays.mjs +153 -0
  9. package/runtime/core/checks.mjs +20 -0
  10. package/runtime/core/host.d.ts +80 -0
  11. package/runtime/core/host.mjs +325 -0
  12. package/runtime/core/numbers.d.ts +66 -0
  13. package/runtime/core/numbers.mjs +343 -0
  14. package/runtime/core/result.d.ts +45 -0
  15. package/runtime/core/result.mjs +140 -0
  16. package/runtime/core/strings.d.ts +14 -0
  17. package/runtime/core/strings.mjs +169 -0
  18. package/runtime/core.d.ts +9 -0
  19. package/runtime/core.mjs +55 -0
  20. package/runtime/host.d.ts +6 -0
  21. package/runtime/nish.d.ts +46 -2
  22. package/runtime/nish.h +75 -2
  23. package/runtime/nish.mjs +23 -3
  24. package/runtime/node.mjs +386 -0
  25. package/runtime/runtime-bytes.c +401 -0
  26. package/runtime/runtime-cross.c +1 -1
  27. package/runtime/runtime-host.c +1 -1
  28. package/runtime/runtime-net.c +12 -1
  29. package/runtime/runtime-os.c +1 -1
  30. package/runtime/runtime-parallel.c +1 -1
  31. package/runtime/runtime-simd.c +231 -7
  32. package/runtime/runtime-term.c +504 -0
  33. package/runtime/runtime-wasm.c +0 -11
  34. package/runtime/runtime.c +190 -6
  35. package/runtime/shim.mjs +6 -985
  36. package/runtime/sqlite/LICENSE.md +85 -0
  37. package/runtime/sqlite/README.md +45 -0
  38. package/runtime/sqlite/nish-sqlite.c +359 -0
  39. package/runtime/sqlite/sqlite3.c +271131 -0
  40. package/runtime/sqlite/sqlite3.h +14447 -0
  41. package/scripts/build.sh +311 -59
  42. package/std/LICENSE-fast-float +23 -0
  43. package/std/LICENSE-fdlibm +8 -0
  44. package/std/README.md +32 -12
  45. package/std/base64.ts +116 -0
  46. package/std/bytes.ts +256 -0
  47. package/std/cli.ts +344 -0
  48. package/std/collections.ts +6 -5
  49. package/std/crypto/LICENSE-crypt_blowfish +26 -0
  50. package/std/crypto/base64url.ts +125 -0
  51. package/std/crypto/bcrypt.ts +1557 -0
  52. package/std/crypto/hmac.ts +138 -2
  53. package/std/crypto/x509.ts +11 -122
  54. package/std/json-tokenizer.ts +2998 -57
  55. package/std/json-value.ts +22 -3
  56. package/std/json.ts +87 -8
  57. package/std/math.ts +608 -0
  58. package/std/net/http1-server.ts +282 -40
  59. package/std/net/http1.ts +40 -21
  60. package/std/net/http3-server.ts +50 -12
  61. package/std/net/postgres.ts +2294 -0
  62. package/std/net/prefork.ts +23 -3
  63. package/std/net/quic-listener.ts +20 -4
  64. package/std/random.ts +66 -4
  65. package/std/regex.ts +4274 -0
  66. package/std/sqlite.ts +391 -0
  67. package/std/term-io.ts +978 -0
  68. package/std/term-pixels.ts +874 -0
  69. package/std/term-probe.ts +459 -0
  70. package/std/term-rate.ts +993 -0
  71. package/std/term.ts +2453 -0
  72. package/std/text.ts +90 -7
  73. package/std/yaml-lines.ts +141 -0
  74. package/std/yaml.ts +4675 -0
package/std/json-value.ts CHANGED
@@ -53,7 +53,8 @@
53
53
  *
54
54
  * **Numbers are lossless.** A number keeps its source text, and is read as
55
55
  * whatever the caller asks for when it asks: `i64` and `u64` when the text is
56
- * an integer that fits (`isI64`, `isU64`), the nearest `f64` (`f64`, correctly
56
+ * an integer that fits (`isI64`, `isU64`), whether its value is whole at all
57
+ * (`isIntegral`, so `1.0` and `1e2` are), the nearest `f64` (`f64`, correctly
57
58
  * rounded, the tokenizer's `numberF64`), or the text itself (`numberText`).
58
59
  * Writing it back copies the text. So `18446744073709551616`, wider than any
59
60
  * integer type, and `0.1000000000000000055511151231257827`, more digits than an
@@ -748,7 +749,11 @@ export class JsonDocument {
748
749
  return this.textOf(jsonValueGet(this.first, x), jsonValueGet(this.count, x))
749
750
  }
750
751
 
751
- /** Whether `v` is a number written without a fraction or an exponent whose value fits an `i64`. */
752
+ /**
753
+ * Whether `v` is a number written without a fraction or an exponent whose
754
+ * value fits an `i64`: the spelling, so `1.0` is not one. `isIntegral(v)`
755
+ * asks whether the value is whole.
756
+ */
752
757
  isI64(v: JsonValue): boolean {
753
758
  return this.readNumber(this.index(v)) && this.numbers.isInteger()
754
759
  }
@@ -759,7 +764,10 @@ export class JsonDocument {
759
764
  return this.readNumber(this.index(v)) ? this.numbers.numberI64() : toI64(0)
760
765
  }
761
766
 
762
- /** Whether `v` is a number written without a sign, a fraction or an exponent whose value fits a `u64`. */
767
+ /**
768
+ * Whether `v` is a number written without a sign, a fraction or an exponent
769
+ * whose value fits a `u64`: the spelling, as `isI64(v)` is.
770
+ */
763
771
  isU64(v: JsonValue): boolean {
764
772
  this.unsigned(this.index(v))
765
773
  return this.unsignedFits
@@ -804,6 +812,17 @@ export class JsonDocument {
804
812
  return acc
805
813
  }
806
814
 
815
+ /**
816
+ * Whether `v` is a number whose value is whole, however it is written:
817
+ * JSON Schema 2020-12's "integer", the tokenizer's `isIntegral`. `1.0`,
818
+ * `1e2` and `1e400` are, where `isI64(v)` and `isU64(v)` go by spelling and
819
+ * by range and answer `false` for all three. `false` for any other kind and
820
+ * for a handle from an earlier parse.
821
+ */
822
+ isIntegral(v: JsonValue): boolean {
823
+ return this.readNumber(this.index(v)) && this.numbers.isIntegral()
824
+ }
825
+
807
826
  /** A number's nearest `f64`, ties to even, as `JSON.parse` reads it; `0` for any other value. */
808
827
  f64(v: JsonValue): f64 {
809
828
  if (!this.readNumber(this.index(v))) {
package/std/json.ts CHANGED
@@ -109,6 +109,8 @@
109
109
  * (`docs/wp26-stdlib.md` §4).
110
110
  */
111
111
 
112
+ import { copyBytes, skipJsonPlain } from "nish/bytes"
113
+
112
114
  const JSON_BACKSPACE: i32 = 8
113
115
  const JSON_TAB: i32 = 9
114
116
  const JSON_NEWLINE: i32 = 10
@@ -1218,8 +1220,9 @@ export class JsonWriter {
1218
1220
  * `bytes[off .. off + len)`, copied as it is and counted as one value: a
1219
1221
  * fragment the caller encoded already, such as a cached object. Nothing in
1220
1222
  * it is checked, so a fragment that is not one whole JSON value makes a
1221
- * text that is not JSON either. The bytes are copied front to back, so
1222
- * `bytes` is not the writer's own buffer at a window the copy overtakes.
1223
+ * text that is not JSON either. The bytes are copied in one move
1224
+ * (`copyBytes`), as if all were read before any was written, so a window
1225
+ * of the writer's own buffer comes out as it was.
1223
1226
  * In an indented text the fragment goes in where a value would, after its
1224
1227
  * line break and indent, but its own bytes are not re-indented: an object
1225
1228
  * fragment stays on one line, where `JSON.stringify` would spread it out.
@@ -1241,11 +1244,7 @@ export class JsonWriter {
1241
1244
  this.failed = JSON_WRITE_FULL
1242
1245
  return
1243
1246
  }
1244
- for (let k: i32 = 0; k < len && off + k < toI32(bytes.length) && at + k < toI32(buf.length); k += 1) {
1245
- if (off + k >= 0 && at + k >= 0) {
1246
- buf[at + k] = bytes[off + k]
1247
- }
1248
- }
1247
+ copyBytes(buf, at, bytes, off, len)
1249
1248
  this.end = at + len
1250
1249
  jsonWriterValueDone(this)
1251
1250
  }
@@ -1576,14 +1575,26 @@ const jsonWriterPutString = (w: JsonWriter, s: string): boolean => {
1576
1575
  return true
1577
1576
  }
1578
1577
 
1578
+ /**
1579
+ * The shortest window `jsonWriterPutBytes` hands to `skipJsonPlain` and
1580
+ * `copyBytes`; a shorter one keeps the byte loop, where the two calls cost
1581
+ * more than the bytes they would save (docs/wp38-simd.md, "JsonWriter's byte
1582
+ * writers").
1583
+ */
1584
+ const JSON_PLAIN_RUN_MIN: i32 = 16
1585
+
1579
1586
  /**
1580
1587
  * `jsonWriterPutString` over `bytes[off .. off + len)`, a window the caller
1581
1588
  * has checked: the same quotes and escapes, from the same three helpers, so
1582
1589
  * the two write the same bytes for the same text. The loop is its own rather
1583
1590
  * than shared with the string one, so that `string` and `key` keep the code
1584
- * they had.
1591
+ * they had. A window of `JSON_PLAIN_RUN_MIN` bytes or more goes to
1592
+ * `jsonWriterPutRuns` instead.
1585
1593
  */
1586
1594
  const jsonWriterPutBytes = (w: JsonWriter, bytes: u8[], off: i32, len: i32): boolean => {
1595
+ if (len >= JSON_PLAIN_RUN_MIN) {
1596
+ return jsonWriterPutRuns(w, bytes, off, len)
1597
+ }
1587
1598
  const buf: u8[] = w.buf
1588
1599
  const cap: i32 = toI32(buf.length)
1589
1600
  let at: i32 = w.end
@@ -1637,6 +1648,74 @@ const jsonWriterPutBytes = (w: JsonWriter, bytes: u8[], off: i32, len: i32): boo
1637
1648
  return true
1638
1649
  }
1639
1650
 
1651
+ /**
1652
+ * `jsonWriterPutBytes` a run at a time: `skipJsonPlain` finds where the bytes
1653
+ * that need no escape end, `copyBytes` moves them in one copy, and only the
1654
+ * byte the walk stopped at is escaped. The same bytes as the byte loop, the
1655
+ * same all-or-nothing on a full buffer. Variable-time, as the loop is: this
1656
+ * writes text, never key material.
1657
+ */
1658
+ const jsonWriterPutRuns = (w: JsonWriter, bytes: u8[], off: i32, len: i32): boolean => {
1659
+ const buf: u8[] = w.buf
1660
+ const cap: i32 = toI32(buf.length)
1661
+ let at: i32 = w.end
1662
+ if (at < 0 || at >= cap) {
1663
+ w.failed = JSON_WRITE_FULL
1664
+ return false
1665
+ }
1666
+ buf[at] = toU8(JSON_QUOTE)
1667
+ at += 1
1668
+ const stop: i32 = off + len
1669
+ let i: i32 = off
1670
+ while (i >= 0 && i < stop && i < toI32(bytes.length)) {
1671
+ const run: i32 = skipJsonPlain(bytes, i, stop)
1672
+ const count: i32 = run - i
1673
+ if (count > 0) {
1674
+ if (at > cap - count) {
1675
+ w.failed = JSON_WRITE_FULL
1676
+ return false
1677
+ }
1678
+ copyBytes(buf, at, bytes, i, count)
1679
+ at += count
1680
+ i = run
1681
+ }
1682
+ if (i < 0 || i >= stop || i >= toI32(bytes.length)) {
1683
+ break
1684
+ }
1685
+ const code: i32 = toI32(bytes[i])
1686
+ i += 1
1687
+ const letter: i32 = jsonShortEscape(code)
1688
+ if (letter !== 0) {
1689
+ if (at < 0 || at + 1 >= cap) {
1690
+ w.failed = JSON_WRITE_FULL
1691
+ return false
1692
+ }
1693
+ buf[at] = toU8(JSON_BACKSLASH)
1694
+ buf[at + 1] = toU8(letter)
1695
+ at += 2
1696
+ continue
1697
+ }
1698
+ if (at < 0 || at + 5 >= cap) {
1699
+ w.failed = JSON_WRITE_FULL
1700
+ return false
1701
+ }
1702
+ buf[at] = toU8(JSON_BACKSLASH)
1703
+ buf[at + 1] = toU8(JSON_LETTER_U)
1704
+ buf[at + 2] = toU8(JSON_DIGIT_ZERO)
1705
+ buf[at + 3] = toU8(JSON_DIGIT_ZERO)
1706
+ buf[at + 4] = toU8(jsonHexByte(code >> 4))
1707
+ buf[at + 5] = toU8(jsonHexByte(code & 15))
1708
+ at += 6
1709
+ }
1710
+ if (at >= cap) {
1711
+ w.failed = JSON_WRITE_FULL
1712
+ return false
1713
+ }
1714
+ buf[at] = toU8(JSON_QUOTE)
1715
+ w.end = at + 1
1716
+ return true
1717
+ }
1718
+
1640
1719
  /**
1641
1720
  * The decimal digits of `v`, then `suffix` as one more digit when it is not
1642
1721
  * negative, at the cursor; all of them or, with `JSON_WRITE_FULL`, none.