@amritk/nish-x86_64-linux 0.20.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.
- package/INSTALL.md +22 -10
- package/bin/nish +0 -0
- package/docs/AI.md +2759 -0
- package/package.json +2 -1
- package/runtime/browser.d.ts +14 -0
- package/runtime/browser.mjs +88 -0
- package/runtime/core/arrays.d.ts +18 -0
- package/runtime/core/arrays.mjs +125 -0
- package/runtime/core/checks.mjs +20 -0
- package/runtime/core/host.d.ts +70 -0
- package/runtime/core/host.mjs +311 -0
- package/runtime/core/numbers.d.ts +53 -0
- package/runtime/core/numbers.mjs +316 -0
- package/runtime/core/result.d.ts +41 -0
- package/runtime/core/result.mjs +127 -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 +44 -0
- package/runtime/nish.h +75 -2
- package/runtime/nish.mjs +23 -3
- package/runtime/node.mjs +383 -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-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 +261 -53
- package/std/LICENSE-fast-float +23 -0
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +31 -11
- package/std/base64.ts +116 -0
- package/std/bytes.ts +256 -0
- package/std/cli.ts +328 -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 +760 -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 +83 -1
- package/std/math.ts +608 -0
- package/std/net/http1-server.ts +85 -8
- package/std/net/http3-server.ts +50 -12
- package/std/net/postgres.ts +1875 -0
- package/std/net/quic-listener.ts +20 -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
|
|
@@ -1576,14 +1578,26 @@ const jsonWriterPutString = (w: JsonWriter, s: string): boolean => {
|
|
|
1576
1578
|
return true
|
|
1577
1579
|
}
|
|
1578
1580
|
|
|
1581
|
+
/**
|
|
1582
|
+
* The shortest window `jsonWriterPutBytes` hands to `skipJsonPlain` and
|
|
1583
|
+
* `copyBytes`; a shorter one keeps the byte loop, where the two calls cost
|
|
1584
|
+
* more than the bytes they would save (docs/wp38-simd.md, "JsonWriter's byte
|
|
1585
|
+
* writers").
|
|
1586
|
+
*/
|
|
1587
|
+
const JSON_PLAIN_RUN_MIN: i32 = 16
|
|
1588
|
+
|
|
1579
1589
|
/**
|
|
1580
1590
|
* `jsonWriterPutString` over `bytes[off .. off + len)`, a window the caller
|
|
1581
1591
|
* has checked: the same quotes and escapes, from the same three helpers, so
|
|
1582
1592
|
* the two write the same bytes for the same text. The loop is its own rather
|
|
1583
1593
|
* than shared with the string one, so that `string` and `key` keep the code
|
|
1584
|
-
* they had.
|
|
1594
|
+
* they had. A window of `JSON_PLAIN_RUN_MIN` bytes or more goes to
|
|
1595
|
+
* `jsonWriterPutRuns` instead.
|
|
1585
1596
|
*/
|
|
1586
1597
|
const jsonWriterPutBytes = (w: JsonWriter, bytes: u8[], off: i32, len: i32): boolean => {
|
|
1598
|
+
if (len >= JSON_PLAIN_RUN_MIN) {
|
|
1599
|
+
return jsonWriterPutRuns(w, bytes, off, len)
|
|
1600
|
+
}
|
|
1587
1601
|
const buf: u8[] = w.buf
|
|
1588
1602
|
const cap: i32 = toI32(buf.length)
|
|
1589
1603
|
let at: i32 = w.end
|
|
@@ -1637,6 +1651,74 @@ const jsonWriterPutBytes = (w: JsonWriter, bytes: u8[], off: i32, len: i32): boo
|
|
|
1637
1651
|
return true
|
|
1638
1652
|
}
|
|
1639
1653
|
|
|
1654
|
+
/**
|
|
1655
|
+
* `jsonWriterPutBytes` a run at a time: `skipJsonPlain` finds where the bytes
|
|
1656
|
+
* that need no escape end, `copyBytes` moves them in one copy, and only the
|
|
1657
|
+
* byte the walk stopped at is escaped. The same bytes as the byte loop, the
|
|
1658
|
+
* same all-or-nothing on a full buffer. Variable-time, as the loop is: this
|
|
1659
|
+
* writes text, never key material.
|
|
1660
|
+
*/
|
|
1661
|
+
const jsonWriterPutRuns = (w: JsonWriter, bytes: u8[], off: i32, len: i32): boolean => {
|
|
1662
|
+
const buf: u8[] = w.buf
|
|
1663
|
+
const cap: i32 = toI32(buf.length)
|
|
1664
|
+
let at: i32 = w.end
|
|
1665
|
+
if (at < 0 || at >= cap) {
|
|
1666
|
+
w.failed = JSON_WRITE_FULL
|
|
1667
|
+
return false
|
|
1668
|
+
}
|
|
1669
|
+
buf[at] = toU8(JSON_QUOTE)
|
|
1670
|
+
at += 1
|
|
1671
|
+
const stop: i32 = off + len
|
|
1672
|
+
let i: i32 = off
|
|
1673
|
+
while (i >= 0 && i < stop && i < toI32(bytes.length)) {
|
|
1674
|
+
const run: i32 = skipJsonPlain(bytes, i, stop)
|
|
1675
|
+
const count: i32 = run - i
|
|
1676
|
+
if (count > 0) {
|
|
1677
|
+
if (at > cap - count) {
|
|
1678
|
+
w.failed = JSON_WRITE_FULL
|
|
1679
|
+
return false
|
|
1680
|
+
}
|
|
1681
|
+
copyBytes(buf, at, bytes, i, count)
|
|
1682
|
+
at += count
|
|
1683
|
+
i = run
|
|
1684
|
+
}
|
|
1685
|
+
if (i < 0 || i >= stop || i >= toI32(bytes.length)) {
|
|
1686
|
+
break
|
|
1687
|
+
}
|
|
1688
|
+
const code: i32 = toI32(bytes[i])
|
|
1689
|
+
i += 1
|
|
1690
|
+
const letter: i32 = jsonShortEscape(code)
|
|
1691
|
+
if (letter !== 0) {
|
|
1692
|
+
if (at < 0 || at + 1 >= cap) {
|
|
1693
|
+
w.failed = JSON_WRITE_FULL
|
|
1694
|
+
return false
|
|
1695
|
+
}
|
|
1696
|
+
buf[at] = toU8(JSON_BACKSLASH)
|
|
1697
|
+
buf[at + 1] = toU8(letter)
|
|
1698
|
+
at += 2
|
|
1699
|
+
continue
|
|
1700
|
+
}
|
|
1701
|
+
if (at < 0 || at + 5 >= cap) {
|
|
1702
|
+
w.failed = JSON_WRITE_FULL
|
|
1703
|
+
return false
|
|
1704
|
+
}
|
|
1705
|
+
buf[at] = toU8(JSON_BACKSLASH)
|
|
1706
|
+
buf[at + 1] = toU8(JSON_LETTER_U)
|
|
1707
|
+
buf[at + 2] = toU8(JSON_DIGIT_ZERO)
|
|
1708
|
+
buf[at + 3] = toU8(JSON_DIGIT_ZERO)
|
|
1709
|
+
buf[at + 4] = toU8(jsonHexByte(code >> 4))
|
|
1710
|
+
buf[at + 5] = toU8(jsonHexByte(code & 15))
|
|
1711
|
+
at += 6
|
|
1712
|
+
}
|
|
1713
|
+
if (at >= cap) {
|
|
1714
|
+
w.failed = JSON_WRITE_FULL
|
|
1715
|
+
return false
|
|
1716
|
+
}
|
|
1717
|
+
buf[at] = toU8(JSON_QUOTE)
|
|
1718
|
+
w.end = at + 1
|
|
1719
|
+
return true
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1640
1722
|
/**
|
|
1641
1723
|
* The decimal digits of `v`, then `suffix` as one more digit when it is not
|
|
1642
1724
|
* negative, at the cursor; all of them or, with `JSON_WRITE_FULL`, none.
|