@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.
- package/INSTALL.md +52 -10
- package/bin/nish +0 -0
- package/docs/AI.md +2777 -0
- package/package.json +2 -1
- package/runtime/browser.d.ts +6 -0
- package/runtime/browser.mjs +77 -0
- package/runtime/core/arrays.d.ts +36 -0
- package/runtime/core/arrays.mjs +153 -0
- package/runtime/core/checks.mjs +20 -0
- package/runtime/core/host.d.ts +80 -0
- package/runtime/core/host.mjs +325 -0
- package/runtime/core/numbers.d.ts +66 -0
- package/runtime/core/numbers.mjs +343 -0
- package/runtime/core/result.d.ts +45 -0
- package/runtime/core/result.mjs +140 -0
- package/runtime/core/strings.d.ts +14 -0
- package/runtime/core/strings.mjs +169 -0
- package/runtime/core.d.ts +9 -0
- package/runtime/core.mjs +55 -0
- package/runtime/host.d.ts +6 -0
- package/runtime/nish.d.ts +46 -2
- package/runtime/nish.h +75 -2
- package/runtime/nish.mjs +23 -3
- package/runtime/node.mjs +386 -0
- package/runtime/runtime-bytes.c +401 -0
- package/runtime/runtime-cross.c +1 -1
- package/runtime/runtime-host.c +1 -1
- package/runtime/runtime-net.c +12 -1
- package/runtime/runtime-os.c +1 -1
- package/runtime/runtime-parallel.c +1 -1
- package/runtime/runtime-simd.c +231 -7
- package/runtime/runtime-term.c +504 -0
- package/runtime/runtime-wasm.c +0 -11
- package/runtime/runtime.c +190 -6
- package/runtime/shim.mjs +6 -985
- package/runtime/sqlite/LICENSE.md +85 -0
- package/runtime/sqlite/README.md +45 -0
- package/runtime/sqlite/nish-sqlite.c +359 -0
- package/runtime/sqlite/sqlite3.c +271131 -0
- package/runtime/sqlite/sqlite3.h +14447 -0
- package/scripts/build.sh +311 -59
- package/std/LICENSE-fast-float +23 -0
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +32 -12
- package/std/base64.ts +116 -0
- package/std/bytes.ts +256 -0
- package/std/cli.ts +344 -0
- package/std/collections.ts +6 -5
- package/std/crypto/LICENSE-crypt_blowfish +26 -0
- package/std/crypto/base64url.ts +125 -0
- package/std/crypto/bcrypt.ts +1557 -0
- package/std/crypto/hmac.ts +138 -2
- package/std/crypto/x509.ts +11 -122
- package/std/json-tokenizer.ts +2998 -57
- package/std/json-value.ts +22 -3
- package/std/json.ts +87 -8
- package/std/math.ts +608 -0
- package/std/net/http1-server.ts +282 -40
- package/std/net/http1.ts +40 -21
- package/std/net/http3-server.ts +50 -12
- package/std/net/postgres.ts +2294 -0
- package/std/net/prefork.ts +23 -3
- package/std/net/quic-listener.ts +20 -4
- package/std/random.ts +66 -4
- package/std/regex.ts +4274 -0
- package/std/sqlite.ts +391 -0
- package/std/term-io.ts +978 -0
- package/std/term-pixels.ts +874 -0
- package/std/term-probe.ts +459 -0
- package/std/term-rate.ts +993 -0
- package/std/term.ts +2453 -0
- package/std/text.ts +90 -7
- package/std/yaml-lines.ts +141 -0
- 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`),
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
1222
|
-
* `
|
|
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
|
-
|
|
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.
|