@amritk/nish-aarch64-linux 0.42.0 → 0.45.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 (124) hide show
  1. package/bin/nish +0 -0
  2. package/docs/AI.md +287 -129
  3. package/package.json +1 -1
  4. package/runtime/core/numbers.mjs +3 -1
  5. package/runtime/core/strings.mjs +90 -38
  6. package/runtime/core.d.ts +24 -0
  7. package/runtime/core.mjs +21 -0
  8. package/runtime/nish.d.ts +167 -24
  9. package/runtime/nish.mjs +7 -1
  10. package/runtime/runtime-cross.c +9 -0
  11. package/runtime/runtime-net.c +51 -13
  12. package/runtime/runtime-region.c +13 -0
  13. package/runtime/runtime-text.c +11 -0
  14. package/runtime/runtime-uring.c +83 -25
  15. package/runtime/runtime-wasm.c +3 -0
  16. package/runtime/runtime.c +329 -6
  17. package/runtime/sqlite/README.md +16 -3
  18. package/runtime/sqlite/nish-sqlite.c +940 -29
  19. package/scripts/build.sh +111 -29
  20. package/std/README.md +6 -6
  21. package/std/array.ts +10 -2
  22. package/std/bytes.ts +239 -26
  23. package/std/cli-args.ts +1072 -606
  24. package/std/cli-flags.ts +180 -98
  25. package/std/cli.ts +21 -13
  26. package/std/collections.ts +245 -127
  27. package/std/compress/checksum.ts +32 -37
  28. package/std/compress/deflate.ts +1102 -542
  29. package/std/compress/gzip.ts +290 -145
  30. package/std/compress/zlib.ts +57 -21
  31. package/std/crypto/aes.ts +153 -75
  32. package/std/crypto/base64url.ts +163 -39
  33. package/std/crypto/bcrypt-batch.ts +164 -90
  34. package/std/crypto/bcrypt.ts +185 -107
  35. package/std/crypto/chacha20poly1305.ts +84 -68
  36. package/std/crypto/ct.ts +9 -7
  37. package/std/crypto/ed25519.ts +64 -27
  38. package/std/crypto/hkdf.ts +105 -63
  39. package/std/crypto/hmac.ts +95 -89
  40. package/std/crypto/jwt.ts +248 -126
  41. package/std/crypto/p256.ts +758 -444
  42. package/std/crypto/p384.ts +20 -13
  43. package/std/crypto/pki-roots.ts +95 -38
  44. package/std/crypto/pki.ts +164 -60
  45. package/std/crypto/rsa.ts +266 -223
  46. package/std/crypto/scram.ts +141 -0
  47. package/std/crypto/sha1.ts +157 -57
  48. package/std/crypto/sha256.ts +502 -422
  49. package/std/crypto/sha512.ts +204 -135
  50. package/std/crypto/x509-random.ts +9 -3
  51. package/std/crypto/x509.ts +331 -171
  52. package/std/host/ring.ts +1 -1
  53. package/std/host/text.ts +1 -1
  54. package/std/json-equal.ts +35 -19
  55. package/std/json-format.ts +215 -108
  56. package/std/json-number.ts +126 -72
  57. package/std/json-pointer.ts +42 -13
  58. package/std/json-tokenizer.ts +498 -307
  59. package/std/json-typed.ts +115 -36
  60. package/std/json-value.ts +341 -152
  61. package/std/json.ts +300 -158
  62. package/std/net/buffer-pool.ts +17 -7
  63. package/std/net/dns-config.ts +427 -236
  64. package/std/net/dns-message.ts +114 -47
  65. package/std/net/dns-resolver.ts +736 -237
  66. package/std/net/dns.ts +205 -52
  67. package/std/net/fetch.ts +320 -184
  68. package/std/net/grpc.ts +948 -0
  69. package/std/net/handler.ts +1276 -218
  70. package/std/net/hpack.ts +395 -180
  71. package/std/net/http-compress.ts +502 -65
  72. package/std/net/http-fields.ts +85 -49
  73. package/std/net/http-server.ts +1764 -603
  74. package/std/net/http1-client-codec.ts +372 -161
  75. package/std/net/http1-codec.ts +665 -331
  76. package/std/net/http1-server.ts +881 -269
  77. package/std/net/http2-cleartext.ts +165 -95
  78. package/std/net/http2-frame.ts +232 -89
  79. package/std/net/http2-tls.ts +42 -12
  80. package/std/net/http2.ts +327 -101
  81. package/std/net/http3-frame.ts +68 -33
  82. package/std/net/http3-server.ts +672 -206
  83. package/std/net/http3.ts +669 -191
  84. package/std/net/oidc.ts +63 -24
  85. package/std/net/outbound.ts +207 -142
  86. package/std/net/postgres-async.ts +1223 -470
  87. package/std/net/postgres-carrier.ts +575 -372
  88. package/std/net/postgres.ts +1521 -632
  89. package/std/net/prefork.ts +254 -98
  90. package/std/net/protobuf.ts +1017 -0
  91. package/std/net/qpack.ts +143 -92
  92. package/std/net/quic-conn-ack.ts +104 -22
  93. package/std/net/quic-conn-cid.ts +66 -26
  94. package/std/net/quic-conn-params.ts +13 -7
  95. package/std/net/quic-datagram.ts +90 -27
  96. package/std/net/quic-frame.ts +324 -121
  97. package/std/net/quic-listener.ts +206 -91
  98. package/std/net/quic-packet.ts +289 -163
  99. package/std/net/quic-recovery.ts +279 -128
  100. package/std/net/quic-stream.ts +466 -167
  101. package/std/net/quic.ts +584 -258
  102. package/std/net/router.ts +450 -99
  103. package/std/net/serve.ts +661 -240
  104. package/std/net/static.ts +1458 -0
  105. package/std/net/tls/client.ts +140 -45
  106. package/std/net/tls/codec.ts +510 -260
  107. package/std/net/tls/record-client.ts +268 -76
  108. package/std/net/tls/record-server.ts +236 -79
  109. package/std/net/tls/record.ts +173 -47
  110. package/std/net/tls/schedule.ts +58 -39
  111. package/std/net/tls/ticket.ts +295 -103
  112. package/std/net/tls/verify.ts +1 -1
  113. package/std/net/tls-tcp.ts +218 -75
  114. package/std/net/tls.ts +260 -152
  115. package/std/net/upstream.ts +283 -86
  116. package/std/net/url.ts +277 -102
  117. package/std/net/websocket.ts +532 -209
  118. package/std/net/webtransport.ts +755 -436
  119. package/std/regex.ts +1659 -829
  120. package/std/sqlite.ts +325 -0
  121. package/std/sync/ring.ts +320 -156
  122. package/std/sync/shm.ts +53 -6
  123. package/std/text.ts +285 -135
  124. package/std/threads.ts +22 -2
@@ -195,11 +195,14 @@ export const httpFieldValueValid = (value: u8[]): boolean => {
195
195
  return false
196
196
  }
197
197
  }
198
- if (n === 0) {
198
+ // `n` is the length, so only an empty value, which has no edges to hold
199
+ // whitespace, takes this branch; the test is what proves the two indexes.
200
+ const lastAt: i32 = n - 1
201
+ if (lastAt < 0 || lastAt >= toI32(value.length) || toI32(value.length) < 1) {
199
202
  return true
200
203
  }
201
204
  const first: i32 = toI32(value[0])
202
- const last: i32 = toI32(value[n - 1])
205
+ const last: i32 = toI32(value[lastAt])
203
206
  return first !== 32 && first !== 9 && last !== 32 && last !== 9
204
207
  }
205
208
 
@@ -303,7 +306,7 @@ const httpFieldsSameHost = (bytes: u8[], other: u8[]): boolean => {
303
306
 
304
307
  /** The pseudo-header bit `name` is, 0 for a regular field, -1 for a name that starts with a colon and is none of them. */
305
308
  const httpFieldsPseudoOf = (name: u8[]): i32 => {
306
- if (toI32(name.length) === 0 || toI32(name[0]) !== 58) {
309
+ if (toI32(name.length) < 1 || toI32(name[0]) !== 58) {
307
310
  return 0
308
311
  }
309
312
  if (httpFieldIs(name, ":method")) {
@@ -352,7 +355,8 @@ const httpFieldsStatusOf = (value: u8[]): i32 => {
352
355
  if (digit < 0 || digit > 9) {
353
356
  return -1
354
357
  }
355
- code = code * 10 + digit
358
+ // Three digits are at most 999, so the unsigned sum cannot leave an `i32`.
359
+ code = toI32(toU32(code) * 10 + toU32(digit))
356
360
  }
357
361
  return code >= 100 && code <= 599 ? code : -1
358
362
  }
@@ -369,7 +373,9 @@ const httpFieldsLengthOf = (value: u8[]): i64 => {
369
373
  if (digit < 0 || digit > 9) {
370
374
  return toI64(-1)
371
375
  }
372
- length = length * toI64(10) + toI64(digit)
376
+ // At most eighteen digits stay below 10^18, so the unsigned sum cannot
377
+ // leave an `i64`.
378
+ length = toI64(toU64(length) * toU64(10) + toU64(digit))
373
379
  }
374
380
  return length
375
381
  }
@@ -704,19 +710,45 @@ export const HTTP_DATE_LAST_SECOND: i64 = 253402300799
704
710
  /** The day names from Sunday, then the month names from January, three letters each. */
705
711
  const HTTP_FIELDS_DATE_NAMES: string = "SunMonTueWedThuFriSatJanFebMarAprMayJunJulAugSepOctNovDec"
706
712
 
707
- /** Writes the three letters at `HTTP_FIELDS_DATE_NAMES[3 * index ..)` at `out[at ..)`. */
708
- const httpFieldsPutName = (out: u8[], at: i32, index: i32): void => {
709
- for (let k: i32 = 0; k < 3; k++) {
710
- out[at + k] = toU8(HTTP_FIELDS_DATE_NAMES.charCodeAt(3 * index + k))
713
+ /**
714
+ * Writes `b` at `out[at + k]`. Its one caller, `httpDateWrite`, has checked
715
+ * `0 <= at` and `at + HTTP_DATE_SIZE <= out.length` before the first write,
716
+ * and every `k` it passes is a constant from 0 to 28, under `HTTP_DATE_SIZE`:
717
+ * so `at + k` is inside `out`, the u32 sum does not wrap and the test always
718
+ * holds. The test is what proves the index; nothing is allocated, and a byte
719
+ * it skipped would show in the `httpDateWrite` round trips `tests/run.js`
720
+ * pins byte for byte (`tests/link/net_http_date`). The skip is unreachable by
721
+ * that room check in `httpDateWrite`, which the prover does not carry across
722
+ * the call, so the test stays.
723
+ */
724
+ const httpFieldsPut = (out: u8[], at: i32, k: i32, b: u32): void => {
725
+ const pos: i32 = toI32(toU32(at) + toU32(k))
726
+ if (pos >= 0 && pos < toI32(out.length)) {
727
+ out[pos] = toU8(b)
728
+ }
729
+ }
730
+
731
+ /**
732
+ * Writes the three letters at `HTTP_FIELDS_DATE_NAMES[3 * index ..)` at
733
+ * `out[at + k ..)`. `httpDateWrite` passes a weekday, `(days + 4) % 7`, so 0
734
+ * to 6, or `6 + month` with `month` 1 to 12 by the 153-day rule, so 7 to 18:
735
+ * `3 * index + 2` is at most 56, under the table's 57 letters, and the test
736
+ * always holds. It is what proves the index.
737
+ */
738
+ const httpFieldsPutName = (out: u8[], at: i32, k: i32, index: u32): void => {
739
+ const names: string = HTTP_FIELDS_DATE_NAMES
740
+ for (let d: u32 = 0; d < 3; d++) {
741
+ const pos: i32 = toI32(index * 3 + d)
742
+ if (pos >= 0 && pos < toI32(names.length)) {
743
+ httpFieldsPut(out, at, toI32(toU32(k) + d), toU32(names.charCodeAt(pos)))
744
+ }
711
745
  }
712
746
  }
713
747
 
714
- /** Writes `n`, 0 to 99, as two digits at `out[at ..)`. */
715
- const httpFieldsPutTwo = (out: u8[], at: i32, n: i32): void => {
716
- const tens: i32 = n / 10
717
- const ones: i32 = n % 10
718
- out[at] = toU8(48 + tens)
719
- out[at + 1] = toU8(48 + ones)
748
+ /** Writes `n`, 0 to 99, as two digits at `out[at + k ..)`. */
749
+ const httpFieldsPutTwo = (out: u8[], at: i32, k: i32, n: u32): void => {
750
+ httpFieldsPut(out, at, k, toU32(48) + n / 10)
751
+ httpFieldsPut(out, at, toI32(toU32(k) + toU32(1)), toU32(48) + (n % 10))
720
752
  }
721
753
 
722
754
  /**
@@ -732,8 +764,8 @@ const httpFieldsPutTwo = (out: u8[], at: i32, n: i32): void => {
732
764
  * its author donated to the public domain: days are counted from 0000-03-01,
733
765
  * so a leap day is the last day of its year and a 400-year era is always
734
766
  * 146,097 days long. Every step
735
- * is `i64` arithmetic on numbers that are not negative, so `--number-mode
736
- * f64` writes the same bytes.
767
+ * is `u64` arithmetic on numbers that never wrap, so `--number-mode f64`
768
+ * writes the same bytes.
737
769
  *
738
770
  * @param out the buffer to write into; its length is not changed
739
771
  * @param at the index in `out` where the date's first letter goes
@@ -750,39 +782,43 @@ export const httpDateWrite = (out: u8[], at: i32, seconds: i64): i32 => {
750
782
  ) {
751
783
  return -1
752
784
  }
753
- const days: i64 = seconds / 86400
754
- const inDay: i32 = toI32(seconds - days * 86400)
785
+ // The test above keeps `seconds` far below 2^63, so every step is `u64`
786
+ // arithmetic on numbers that neither wrap nor go below 0.
787
+ const total: u64 = toU64(seconds)
788
+ const days: u64 = total / 86400
789
+ const inDay: u32 = toU32(total % 86400)
755
790
  // 1970-01-01 was a Thursday, and 0 is Sunday.
756
- const weekday: i32 = toI32((days + 4) % 7)
791
+ const weekday: u32 = toU32((days + 4) % 7)
757
792
  // From 0000-03-01 to 1970-01-01 is 719,468 days.
758
- const z: i64 = days + 719468
759
- const era: i64 = z / 146097
760
- const dayOfEra: i64 = z - era * 146097
761
- const yearOfEra: i64 = (dayOfEra - dayOfEra / 1460 + dayOfEra / 36524 - dayOfEra / 146096) / 365
762
- const dayOfYear: i64 = dayOfEra - (365 * yearOfEra + yearOfEra / 4 - yearOfEra / 100)
793
+ const z: u64 = days + 719468
794
+ const era: u64 = z / 146097
795
+ const dayOfEra: u64 = z - era * 146097
796
+ const yearOfEra: u64 = (dayOfEra - dayOfEra / 1460 + dayOfEra / 36524 - dayOfEra / 146096) / 365
797
+ const dayOfYear: u64 = dayOfEra - (365 * yearOfEra + yearOfEra / 4 - yearOfEra / 100)
763
798
  // Months from March, each 30 or 31 days by the 153-day rule.
764
- const marchMonth: i64 = (5 * dayOfYear + 2) / 153
765
- const day: i32 = toI32(dayOfYear - (153 * marchMonth + 2) / 5 + 1)
766
- const month: i32 = toI32(marchMonth < 10 ? marchMonth + 3 : marchMonth - 9)
767
- const year: i32 = toI32(yearOfEra + era * 400) + (month <= 2 ? 1 : 0)
768
- httpFieldsPutName(out, at, weekday)
769
- out[at + 3] = 44
770
- out[at + 4] = 32
771
- httpFieldsPutTwo(out, at + 5, day)
772
- out[at + 7] = 32
773
- httpFieldsPutName(out, at + 8, 6 + month)
774
- out[at + 11] = 32
775
- httpFieldsPutTwo(out, at + 12, year / 100)
776
- httpFieldsPutTwo(out, at + 14, year % 100)
777
- out[at + 16] = 32
778
- httpFieldsPutTwo(out, at + 17, inDay / 3600)
779
- out[at + 19] = 58
780
- httpFieldsPutTwo(out, at + 20, (inDay / 60) % 60)
781
- out[at + 22] = 58
782
- httpFieldsPutTwo(out, at + 23, inDay % 60)
783
- out[at + 25] = 32
784
- out[at + 26] = 71
785
- out[at + 27] = 77
786
- out[at + 28] = 84
787
- return at + HTTP_DATE_SIZE
799
+ const marchMonth: u64 = (5 * dayOfYear + 2) / 153
800
+ const day: u32 = toU32(dayOfYear - (153 * marchMonth + 2) / 5 + 1)
801
+ const month: u32 = toU32(marchMonth < 10 ? marchMonth + 3 : marchMonth - 9)
802
+ const year: u32 = toU32(yearOfEra + era * 400) + (month <= 2 ? 1 : 0)
803
+ httpFieldsPutName(out, at, 0, weekday)
804
+ httpFieldsPut(out, at, 3, 44)
805
+ httpFieldsPut(out, at, 4, 32)
806
+ httpFieldsPutTwo(out, at, 5, day)
807
+ httpFieldsPut(out, at, 7, 32)
808
+ httpFieldsPutName(out, at, 8, 6 + month)
809
+ httpFieldsPut(out, at, 11, 32)
810
+ httpFieldsPutTwo(out, at, 12, year / 100)
811
+ httpFieldsPutTwo(out, at, 14, year % 100)
812
+ httpFieldsPut(out, at, 16, 32)
813
+ httpFieldsPutTwo(out, at, 17, inDay / 3600)
814
+ httpFieldsPut(out, at, 19, 58)
815
+ httpFieldsPutTwo(out, at, 20, (inDay / 60) % 60)
816
+ httpFieldsPut(out, at, 22, 58)
817
+ httpFieldsPutTwo(out, at, 23, inDay % 60)
818
+ httpFieldsPut(out, at, 25, 32)
819
+ httpFieldsPut(out, at, 26, 71)
820
+ httpFieldsPut(out, at, 27, 77)
821
+ httpFieldsPut(out, at, 28, 84)
822
+ // The date fits in `out` from `at`, so the end is at most its length.
823
+ return toI32(toU32(at) + toU32(HTTP_DATE_SIZE))
788
824
  }