@amritk/nish-aarch64-linux 0.46.0 → 0.47.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/bin/nish +0 -0
- package/docs/AI.md +29 -18
- package/package.json +1 -1
- package/runtime/nish.h +1 -0
- package/runtime/runtime-bytes.c +167 -7
- package/runtime/runtime-net.c +69 -25
- package/runtime/runtime-uring.c +111 -62
- package/runtime/sqlite/nish-sqlite.c +166 -39
- package/std/README.md +2 -2
- package/std/base64.ts +28 -30
- package/std/crypto/aes.ts +81 -45
- package/std/crypto/bcrypt-batch.ts +23 -4
- package/std/crypto/bcrypt.ts +36 -11
- package/std/crypto/chacha20poly1305.ts +93 -52
- package/std/crypto/x25519.ts +7 -4
- package/std/host/game.ts +52 -20
- package/std/host/ring.ts +115 -31
- package/std/host/text.ts +9 -3
- package/std/json.ts +83 -0
- package/std/math.ts +161 -131
- package/std/net/http1-server.ts +36 -11
- package/std/net/prefork.ts +1 -2
- package/std/net/static.ts +7 -2
- package/std/random.ts +34 -51
- package/std/raster.ts +360 -110
- package/std/regex.ts +46 -15
- package/std/release.ts +19 -13
- package/std/sqlite.ts +380 -16
- package/std/synth.ts +11 -2
- package/std/temporal.ts +740 -363
- package/std/term-io.ts +81 -33
- package/std/term-pixels.ts +287 -112
- package/std/term-probe.ts +7 -3
- package/std/term-rate.ts +142 -66
- package/std/term.ts +782 -406
- package/std/testing.ts +14 -7
package/std/net/static.ts
CHANGED
|
@@ -1411,9 +1411,14 @@ export class StaticFiles {
|
|
|
1411
1411
|
}
|
|
1412
1412
|
return
|
|
1413
1413
|
}
|
|
1414
|
-
|
|
1414
|
+
const path: u8[] = this.path
|
|
1415
|
+
const m: i32 = this.pathLength
|
|
1416
|
+
// `0 <= pathLength <= path.length` holds once `staticResolve` sets it;
|
|
1417
|
+
// the guard keeps `String.fromBytes` proven for a `--deny-panics` caller.
|
|
1418
|
+
if (status !== 304 && m >= 0 && m <= toI32(path.length)) {
|
|
1419
|
+
const type: string = staticContentType(String.fromBytes(path, 0, m))
|
|
1415
1420
|
names.push(httpFieldBytes("content-type"))
|
|
1416
|
-
values.push(httpFieldBytes(
|
|
1421
|
+
values.push(httpFieldBytes(type))
|
|
1417
1422
|
}
|
|
1418
1423
|
if (this.etagLength > 0) {
|
|
1419
1424
|
names.push(httpFieldBytes("etag"))
|
package/std/random.ts
CHANGED
|
@@ -22,19 +22,15 @@
|
|
|
22
22
|
* mixing function is the shape of SplitMix (Steele, Lea and Flood, "Fast
|
|
23
23
|
* splittable pseudorandom number generators", OOPSLA 2014), on 32 bits.
|
|
24
24
|
*
|
|
25
|
-
* **The same bits under Node.**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* **The same bits under Node.** A wrapping multiply is `Math.imul`, the low
|
|
26
|
+
* 32 bits of the product both ways. Every other sum, difference and remainder
|
|
27
|
+
* is taken in `f64` on the state read as an unsigned count below 2^32, where
|
|
28
|
+
* each answer is an integer below 2^33 and so exact, and comes back to an
|
|
29
|
+
* `i32` only once a compare has put it in range. Every shift has a constant
|
|
29
30
|
* count, and `^` and `>>> 16` answer the same 32 bits in JavaScript as in the
|
|
30
|
-
* compiled program.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* (whose conversions saturate under Node): the sign bit flipped orders them
|
|
34
|
-
* under a signed compare, and the remainder is taken in pieces that stay below
|
|
35
|
-
* 2^31. `nextF64` builds its double from integers below 2^53, so its products
|
|
36
|
-
* and sums are exact both ways. The program a test prints under Node is the one
|
|
37
|
-
* it prints compiled (docs/RUN_UNDER_NODE.md).
|
|
31
|
+
* compiled program. `nextF64` builds its double from integers below 2^53, so
|
|
32
|
+
* its products and sums are exact both ways. The program a test prints under
|
|
33
|
+
* Node is the one it prints compiled (docs/RUN_UNDER_NODE.md).
|
|
38
34
|
*
|
|
39
35
|
* **It is not for cryptography**: a key or a nonce comes from
|
|
40
36
|
* `crypto.getRandomValues`.
|
|
@@ -45,10 +41,9 @@
|
|
|
45
41
|
* would be a write their caller can see, and is refused as any such write is;
|
|
46
42
|
* give each task its own, seeded from its index.
|
|
47
43
|
*/
|
|
48
|
-
import { wrappingAdd, wrappingMul, wrappingSub } from "nish:unsafe"
|
|
49
44
|
|
|
50
|
-
/** 0x9E3779B9
|
|
51
|
-
const GOLDEN:
|
|
45
|
+
/** 0x9E3779B9, the Weyl increment: odd, so the walk visits every state. */
|
|
46
|
+
const GOLDEN: f64 = 2654435769.0
|
|
52
47
|
|
|
53
48
|
/** 0x85EBCA6B as an `i32`: MurmurHash3's first finaliser multiplier (public domain). */
|
|
54
49
|
const MIX_1: i32 = -2048144789
|
|
@@ -59,45 +54,32 @@ const MIX_2: i32 = -1028477387
|
|
|
59
54
|
/** 2^26, the weight of the high draw in `nextF64`'s 53 bits. */
|
|
60
55
|
const TWO_26: f64 = 67108864.0
|
|
61
56
|
|
|
62
|
-
/** 2^
|
|
63
|
-
const
|
|
57
|
+
/** 2^31: an unsigned count at least this is a negative `i32`. */
|
|
58
|
+
const TWO_31: f64 = 2147483648.0
|
|
64
59
|
|
|
65
|
-
/**
|
|
66
|
-
const
|
|
60
|
+
/** 2^32, the number of states. */
|
|
61
|
+
const TWO_32: f64 = 4294967296.0
|
|
67
62
|
|
|
68
|
-
/** 2^
|
|
69
|
-
const
|
|
63
|
+
/** 2^53, which scales a 53-bit integer into [0, 1). */
|
|
64
|
+
const TWO_53: f64 = 9007199254740992.0
|
|
70
65
|
|
|
71
|
-
/**
|
|
72
|
-
const
|
|
66
|
+
/** The bits of `x` read as an unsigned count, from 0 to 2^32 - 1. */
|
|
67
|
+
const unsigned = (x: i32): f64 => (x < 0 ? toF64(x) + TWO_32 : toF64(x))
|
|
73
68
|
|
|
74
69
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
70
|
+
* The `i32` whose bits read as the unsigned count `u`, which is an integer
|
|
71
|
+
* from 0 to 2^32 - 1: below 2^31 it is `u`, and from there `u - 2^32`, so
|
|
72
|
+
* each `toI32` converts a value inside the `i32` range.
|
|
78
73
|
*/
|
|
79
|
-
const
|
|
80
|
-
if (m < 0) {
|
|
81
|
-
// m is 2^31 or more, so a is less than 2m: at most one m comes off.
|
|
82
|
-
return below(a, m) ? a : wrappingSub(a, m)
|
|
83
|
-
}
|
|
84
|
-
if (a >= 0) {
|
|
85
|
-
return a % m
|
|
86
|
-
}
|
|
87
|
-
// a is 2^31 + low, so a mod m is low plus 2^31 mod m, added mod m.
|
|
88
|
-
const low: i32 = (a ^ SIGN) % m
|
|
89
|
-
const high: i32 = wrappingAdd(MAX % m, 1) % m
|
|
90
|
-
const room: i32 = wrappingSub(m, high)
|
|
91
|
-
return low >= room ? wrappingSub(low, room) : wrappingAdd(low, high)
|
|
92
|
-
}
|
|
74
|
+
const bits = (u: f64): i32 => (u < TWO_31 ? toI32(u) : toI32(u - TWO_32))
|
|
93
75
|
|
|
94
76
|
/** MurmurHash3's `fmix32`: every bit of `h` into every bit of the answer, a bijection on 32 bits. */
|
|
95
77
|
const mix = (h: i32): i32 => {
|
|
96
78
|
let x: i32 = h
|
|
97
79
|
x = x ^ (x >>> 16)
|
|
98
|
-
x =
|
|
80
|
+
x = Math.imul(x, MIX_1)
|
|
99
81
|
x = x ^ (x >>> 13)
|
|
100
|
-
x =
|
|
82
|
+
x = Math.imul(x, MIX_2)
|
|
101
83
|
x = x ^ (x >>> 16)
|
|
102
84
|
return x
|
|
103
85
|
}
|
|
@@ -128,7 +110,8 @@ export class Rng {
|
|
|
128
110
|
* steps once.
|
|
129
111
|
*/
|
|
130
112
|
nextI32(): i32 {
|
|
131
|
-
|
|
113
|
+
const next: f64 = unsigned(this.state) + GOLDEN
|
|
114
|
+
this.state = bits(next < TWO_32 ? next : next - TWO_32)
|
|
132
115
|
return mix(this.state)
|
|
133
116
|
}
|
|
134
117
|
|
|
@@ -168,16 +151,16 @@ export class Rng {
|
|
|
168
151
|
if (lo > hi) {
|
|
169
152
|
panic("Rng.nextInt: lo is greater than hi")
|
|
170
153
|
}
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
// From 1 to 2^32, and lo plus any remainder of it is at most hi.
|
|
155
|
+
const span: f64 = toF64(hi) - toF64(lo) + 1.0
|
|
156
|
+
if (span === TWO_32) {
|
|
173
157
|
return this.nextI32()
|
|
174
158
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
draw = this.nextI32()
|
|
159
|
+
const refused: f64 = TWO_32 % span
|
|
160
|
+
let draw: f64 = unsigned(this.nextI32())
|
|
161
|
+
while (draw < refused) {
|
|
162
|
+
draw = unsigned(this.nextI32())
|
|
180
163
|
}
|
|
181
|
-
return
|
|
164
|
+
return toI32(toF64(lo) + (draw % span))
|
|
182
165
|
}
|
|
183
166
|
}
|