@amritk/nish-x86_64-linux 0.18.0 → 0.21.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.
Files changed (104) hide show
  1. package/INSTALL.md +58 -28
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +2759 -0
  4. package/package.json +3 -2
  5. package/runtime/browser.d.ts +14 -0
  6. package/runtime/browser.mjs +88 -0
  7. package/runtime/core/arrays.d.ts +18 -0
  8. package/runtime/core/arrays.mjs +125 -0
  9. package/runtime/core/checks.mjs +20 -0
  10. package/runtime/core/host.d.ts +70 -0
  11. package/runtime/core/host.mjs +311 -0
  12. package/runtime/core/numbers.d.ts +53 -0
  13. package/runtime/core/numbers.mjs +316 -0
  14. package/runtime/core/result.d.ts +41 -0
  15. package/runtime/core/result.mjs +127 -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 +99 -5
  22. package/runtime/nish.h +289 -19
  23. package/runtime/nish.mjs +39 -3
  24. package/runtime/node.mjs +383 -0
  25. package/runtime/runtime-aes.c +490 -0
  26. package/runtime/runtime-bytes.c +401 -0
  27. package/runtime/runtime-cross.c +366 -0
  28. package/runtime/runtime-host.c +8 -7
  29. package/runtime/runtime-net.c +93 -34
  30. package/runtime/runtime-os.c +214 -16
  31. package/runtime/runtime-parallel.c +590 -107
  32. package/runtime/runtime-simd.c +235 -11
  33. package/runtime/runtime-term.c +504 -0
  34. package/runtime/runtime-wasm.c +5 -14
  35. package/runtime/runtime.c +257 -17
  36. package/runtime/shim.mjs +6 -915
  37. package/runtime/sqlite/LICENSE.md +85 -0
  38. package/runtime/sqlite/README.md +45 -0
  39. package/runtime/sqlite/nish-sqlite.c +359 -0
  40. package/runtime/sqlite/sqlite3.c +271131 -0
  41. package/runtime/sqlite/sqlite3.h +14447 -0
  42. package/scripts/build.sh +437 -28
  43. package/std/LICENSE-fast-float +23 -0
  44. package/std/LICENSE-fdlibm +8 -0
  45. package/std/README.md +108 -58
  46. package/std/base64.ts +116 -0
  47. package/std/bytes.ts +419 -0
  48. package/std/cli.ts +328 -0
  49. package/std/collections.ts +6 -5
  50. package/std/crypto/LICENSE-crypt_blowfish +26 -0
  51. package/std/crypto/LICENSE-libsecp256k1 +19 -0
  52. package/std/crypto/aes.ts +238 -76
  53. package/std/crypto/base64url.ts +125 -0
  54. package/std/crypto/bcrypt.ts +760 -0
  55. package/std/crypto/chacha20poly1305.ts +43 -9
  56. package/std/crypto/ed25519.ts +840 -0
  57. package/std/crypto/hkdf.ts +304 -12
  58. package/std/crypto/hmac.ts +382 -54
  59. package/std/crypto/p256.ts +932 -61
  60. package/std/crypto/x25519.ts +55 -37
  61. package/std/crypto/x509-random.ts +71 -0
  62. package/std/crypto/x509.ts +20 -131
  63. package/std/json-tokenizer.ts +4237 -0
  64. package/std/json-typed.ts +1014 -0
  65. package/std/json-value.ts +1182 -0
  66. package/std/json.ts +1202 -34
  67. package/std/math.ts +608 -0
  68. package/std/net/buffer-pool.ts +151 -0
  69. package/std/net/hpack.ts +416 -112
  70. package/std/net/http-fields.ts +93 -0
  71. package/std/net/http1-server.ts +501 -62
  72. package/std/net/http1.ts +31 -6
  73. package/std/net/http2-tls.ts +112 -24
  74. package/std/net/http2.ts +333 -75
  75. package/std/net/http3-server.ts +261 -43
  76. package/std/net/http3.ts +187 -28
  77. package/std/net/postgres.ts +1875 -0
  78. package/std/net/prefork.ts +412 -0
  79. package/std/net/quic-listener.ts +108 -11
  80. package/std/net/quic-packet.ts +243 -82
  81. package/std/net/quic-recovery.ts +361 -30
  82. package/std/net/quic-stream.ts +424 -24
  83. package/std/net/quic.ts +519 -167
  84. package/std/net/router.ts +676 -0
  85. package/std/net/tls/codec.ts +426 -27
  86. package/std/net/tls/record-server.ts +478 -132
  87. package/std/net/tls/record.ts +133 -42
  88. package/std/net/tls/schedule.ts +464 -55
  89. package/std/net/tls/ticket.ts +610 -0
  90. package/std/net/tls-tcp.ts +196 -53
  91. package/std/net/tls.ts +1018 -260
  92. package/std/net/url.ts +571 -0
  93. package/std/random.ts +94 -0
  94. package/std/regex.ts +4274 -0
  95. package/std/sqlite.ts +391 -0
  96. package/std/term-io.ts +978 -0
  97. package/std/term-pixels.ts +874 -0
  98. package/std/term-probe.ts +459 -0
  99. package/std/term-rate.ts +993 -0
  100. package/std/term.ts +2453 -0
  101. package/std/text.ts +90 -7
  102. package/std/threads.ts +438 -14
  103. package/std/yaml-lines.ts +141 -0
  104. package/std/yaml.ts +4675 -0
@@ -0,0 +1,141 @@
1
+ /**
2
+ * `nish/yaml-lines` — byte offsets turned into the `line:column` a person reads.
3
+ *
4
+ * Every range `nish/yaml` reports — a node's `start` and `end`, a diagnostic's
5
+ * — is a byte offset into the text it parsed, because a byte offset is what a
6
+ * program slices with and what costs nothing to keep. A message for a person
7
+ * wants a line and a column instead, and this module turns one into the other:
8
+ *
9
+ * import { YamlLineIndex } from "nish/yaml-lines"
10
+ *
11
+ * const lines = new YamlLineIndex(text)
12
+ * lines.line(offset) // 1-based
13
+ * lines.column(offset) // 1-based, in characters
14
+ *
15
+ * The index scans the text once, with `indexOf`, to record where each line
16
+ * starts; every lookup after that is a binary search. A line break is LF, CR
17
+ * LF or a lone CR (YAML 1.2 §5.4, `b-break`), and CR LF is one break, not two,
18
+ * so a Windows file has as many lines as a Unix one.
19
+ *
20
+ * An offset is clamped to `[0, text.length]` first, so a range's `end`, one
21
+ * past its last byte, has a position too, and a slip below zero reads as the
22
+ * start rather than panicking. `column` counts characters: every byte that is
23
+ * not a UTF-8 continuation byte, so `é` is one column natively. `byteColumn`
24
+ * counts bytes, which is what an editor that indexes lines by byte wants.
25
+ * Under Node a string is UTF-16 and each unit counts, which is the same answer
26
+ * for ASCII and the JavaScript answer otherwise.
27
+ */
28
+
29
+ const YAML_LINES_LF: i32 = 10
30
+ /** A UTF-8 continuation byte is `10xxxxxx`: at least this and below `0xC0`. */
31
+ const YAML_LINES_CONTINUATION: i32 = 128
32
+ const YAML_LINES_LEAD: i32 = 192
33
+
34
+ /**
35
+ * Where each line of one text starts, for turning byte offsets into lines and
36
+ * columns. Its fields and its "Internal" methods are reachable, as every member
37
+ * in Nish is; use the others, and do not change the fields.
38
+ */
39
+ export class YamlLineIndex {
40
+ /** The text the index was built from. */
41
+ text: string
42
+ /** Internal: `starts[n]` is the byte at which line `n + 1` begins; line 1 begins at 0. */
43
+ starts: i32[]
44
+
45
+ constructor(text: string) {
46
+ this.text = text
47
+ this.starts = [0]
48
+ const length: i32 = toI32(text.length)
49
+ let nl: i32 = toI32(text.indexOf("\n"))
50
+ let cr: i32 = toI32(text.indexOf("\r"))
51
+ while (nl >= 0 || cr >= 0) {
52
+ if (cr >= 0 && (nl < 0 || cr < nl)) {
53
+ // CR LF is one break: step over both, and move the LF search past it.
54
+ if (cr + 1 < length && toI32(text.charCodeAt(cr + 1)) === YAML_LINES_LF) {
55
+ this.starts.push(cr + 2)
56
+ nl = toI32(text.indexOf("\n", cr + 2))
57
+ } else {
58
+ this.starts.push(cr + 1)
59
+ }
60
+ cr = toI32(text.indexOf("\r", cr + 1))
61
+ } else {
62
+ this.starts.push(nl + 1)
63
+ nl = toI32(text.indexOf("\n", nl + 1))
64
+ }
65
+ }
66
+ }
67
+
68
+ /** How many lines the text has: one more than its breaks, so `""` has one. */
69
+ lineCount(): i32 {
70
+ return toI32(this.starts.length)
71
+ }
72
+
73
+ /** The byte at which 1-based `line` begins; a line outside the text clamps to the first or last. */
74
+ lineStart(line: i32): i32 {
75
+ const count: i32 = toI32(this.starts.length)
76
+ let index: i32 = line - 1
77
+ if (index >= count) {
78
+ index = count - 1
79
+ }
80
+ if (index < 0) {
81
+ index = 0
82
+ }
83
+ return index < count ? this.starts[index] : 0
84
+ }
85
+
86
+ /** The 1-based line `offset` is on, after clamping it to `[0, text.length]`. */
87
+ line(offset: i32): i32 {
88
+ return this.lineIndexOf(this.clamp(offset)) + 1
89
+ }
90
+
91
+ /** The 1-based column of `offset` on its line, counting characters. */
92
+ column(offset: i32): i32 {
93
+ const at: i32 = this.clamp(offset)
94
+ const index: i32 = this.lineIndexOf(at)
95
+ const starts: i32[] = this.starts
96
+ let i: i32 = index >= 0 && index < toI32(starts.length) ? starts[index] : 0
97
+ const text: string = this.text
98
+ const length: i32 = toI32(text.length)
99
+ let column: i32 = 1
100
+ while (i >= 0 && i < at && i < length) {
101
+ const code: i32 = toI32(text.charCodeAt(i))
102
+ if (code < YAML_LINES_CONTINUATION || code >= YAML_LINES_LEAD) {
103
+ column += 1
104
+ }
105
+ i += 1
106
+ }
107
+ return column
108
+ }
109
+
110
+ /** The 1-based column of `offset` on its line, counting bytes. */
111
+ byteColumn(offset: i32): i32 {
112
+ const at: i32 = this.clamp(offset)
113
+ return at - this.lineStart(this.lineIndexOf(at) + 1) + 1
114
+ }
115
+
116
+ /** Internal: `offset` clamped to `[0, text.length]`. */
117
+ clamp(offset: i32): i32 {
118
+ const length: i32 = toI32(this.text.length)
119
+ if (offset < 0) {
120
+ return 0
121
+ }
122
+ return offset > length ? length : offset
123
+ }
124
+
125
+ /** Internal: the 0-based line holding byte `at`, by binary search over `starts`. */
126
+ lineIndexOf(at: i32): i32 {
127
+ const starts: i32[] = this.starts
128
+ let low: i32 = 0
129
+ let high: i32 = toI32(starts.length) - 1
130
+ while (low < high) {
131
+ const mid: i32 = (low + high + 1) >> 1
132
+ const start: i32 = mid >= 0 && mid < toI32(starts.length) ? starts[mid] : 0
133
+ if (start <= at) {
134
+ low = mid
135
+ } else {
136
+ high = mid - 1
137
+ }
138
+ }
139
+ return low
140
+ }
141
+ }