@amritk/nish-x86_64-linux 0.29.0 → 0.31.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 +3 -3
- package/bin/nish +0 -0
- package/docs/AI.md +71 -4
- package/package.json +1 -1
- package/runtime/core/host.d.ts +2 -0
- package/runtime/core/host.mjs +9 -0
- package/runtime/nish.d.ts +48 -2
- package/runtime/nish.h +31 -3
- package/runtime/nish.mjs +36 -0
- package/runtime/runtime-net.c +32 -3
- package/runtime/runtime-os.c +33 -1
- package/runtime/runtime-region.c +243 -0
- package/runtime/runtime.c +19 -2
- package/scripts/build.sh +19 -6
- package/std/README.md +10 -7
- package/std/net/{http-client.ts → fetch.ts} +17 -17
- package/std/net/handler.ts +1 -1
- package/std/net/{http1-client.ts → http1-client-codec.ts} +276 -47
- package/std/net/{http1.ts → http1-codec.ts} +252 -49
- package/std/net/http1-server.ts +72 -13
- package/std/net/outbound.ts +2 -2
- package/std/net/postgres-carrier.ts +985 -0
- package/std/net/postgres.ts +680 -53
- package/std/net/prefork.ts +149 -13
- package/std/net/router.ts +1 -1
- package/std/net/upstream.ts +759 -0
- package/std/net/websocket.ts +5 -5
- package/std/region.ts +95 -0
package/std/net/websocket.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* `nish/net/websocket` — RFC 6455 WebSocket framing and both sides of the
|
|
3
3
|
* opening handshake, sans-IO: bytes in, events and bytes out.
|
|
4
4
|
*
|
|
5
|
-
* **The server's handshake.** `nish/net/http1` reads the client's request;
|
|
5
|
+
* **The server's handshake.** `nish/net/http1-codec` reads the client's request;
|
|
6
6
|
* `websocketRequestKey(parser)` answers its `Sec-WebSocket-Key` when the head
|
|
7
7
|
* is a valid opening handshake (§4.2.1), `websocketOfferedProtocols(parser)`
|
|
8
8
|
* the subprotocols it offers, and `websocketUpgradeResponse(key, protocol)`
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* random bytes as the key, `websocketUpgradeRequest(host, target, key,
|
|
16
16
|
* protocols)` writes the GET that asks to upgrade, and
|
|
17
17
|
* `websocketCheckResponse(parser, key, offered)` reads the server's answer,
|
|
18
|
-
* parsed by `nish/net/http1-client` after `expectUpgrade()`: it answers the
|
|
18
|
+
* parsed by `nish/net/http1-client-codec` after `expectUpgrade()`: it answers the
|
|
19
19
|
* negotiated subprotocol, or which rule of §4.1 the response broke. What
|
|
20
20
|
* `HTTP1_UPGRADE`'s `tunnelBytes()` answers is the first input for
|
|
21
21
|
* `WsDecoder(false, …)`. This module draws no randomness: the nonce and every
|
|
@@ -77,8 +77,8 @@ import {
|
|
|
77
77
|
http1ResponseHead,
|
|
78
78
|
http1SameWord,
|
|
79
79
|
http1Text,
|
|
80
|
-
} from "nish/net/http1"
|
|
81
|
-
import { Http1ResponseParser, http1UpgradeRequestHead } from "nish/net/http1-client"
|
|
80
|
+
} from "nish/net/http1-codec"
|
|
81
|
+
import { Http1ResponseParser, http1UpgradeRequestHead } from "nish/net/http1-client-codec"
|
|
82
82
|
|
|
83
83
|
/** The GUID RFC 6455 §1.3 appends to the client's key before hashing it. */
|
|
84
84
|
export const WS_GUID: string = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
|
@@ -954,7 +954,7 @@ export const websocketClientKey = (nonce: u8[]): string | null => {
|
|
|
954
954
|
* with `Host`, `Sec-WebSocket-Key`, `Sec-WebSocket-Version: 13`, the offered
|
|
955
955
|
* `protocols` in one `Sec-WebSocket-Protocol` field when there are any, and
|
|
956
956
|
* `Upgrade: websocket` and `Connection: Upgrade`, written by
|
|
957
|
-
* `nish/net/http1-client`'s `http1UpgradeRequestHead`. Answers `null` for a
|
|
957
|
+
* `nish/net/http1-client-codec`'s `http1UpgradeRequestHead`. Answers `null` for a
|
|
958
958
|
* key `websocketKeyIsValid` refuses, a protocol that is not a token (an empty
|
|
959
959
|
* one, or one holding a comma, a space, CR or LF), a protocol offered twice, an
|
|
960
960
|
* empty host, and everything the request writer refuses (CR, LF or another
|
package/std/region.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `nish:region` — memory a program frees when it says so (docs/LANGUAGE.md,
|
|
3
|
+
* "Regions").
|
|
4
|
+
*
|
|
5
|
+
* import { Region, enterWith, free, regionWith } from "nish:region"
|
|
6
|
+
*
|
|
7
|
+
* const r: Region<Session> = regionWith(id, open)
|
|
8
|
+
* const n: i32 = enterWith(r, out, serve)
|
|
9
|
+
* free(r)
|
|
10
|
+
*
|
|
11
|
+
* This file is the source behind the builtin module, and it is imported only
|
|
12
|
+
* by that name: `nish/region` is refused, so there is one spelling for the
|
|
13
|
+
* checker's rules to be read under (`src/region-check.ts`). What is written
|
|
14
|
+
* here is the meaning, over five intrinsics the compiler gives bodies of their
|
|
15
|
+
* own (`src/emit-region.ts`), which swap the thread's arena for the region's
|
|
16
|
+
* around the function they run:
|
|
17
|
+
*
|
|
18
|
+
* - `region(f)` makes a region, runs `f` with every allocation landing in
|
|
19
|
+
* it, and keeps what `f` answers as the region's root;
|
|
20
|
+
* - `enter(r, f)` runs `f(root)` the same way, and answers `f`'s scalar;
|
|
21
|
+
* - `free(r)` gives the region's memory back. A handle used after it is
|
|
22
|
+
* freed, or entered twice, or freed while entered, stops the program.
|
|
23
|
+
*
|
|
24
|
+
* A `Region<T>` is a handle, a 64-bit integer, and not a pointer: the root
|
|
25
|
+
* never leaves the region except through `enter`'s function, and that
|
|
26
|
+
* function answers a scalar, so nothing outside a region can point into it.
|
|
27
|
+
*
|
|
28
|
+
* Under Node the module is answered by `runtime/nish.mjs`, where a region is
|
|
29
|
+
* an entry in a table and `free` drops it.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A region whose root is a `T`. The compiler resolves the name to a type of
|
|
34
|
+
* its own, a 64-bit handle; this declaration is what `tsc` and the editor
|
|
35
|
+
* read through `runtime/nish.d.ts`.
|
|
36
|
+
*/
|
|
37
|
+
export class Region<T> {
|
|
38
|
+
/** Never read: the compiler's type has no fields. */
|
|
39
|
+
root: T | null = null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The five intrinsics below are the runtime's region calls. Each is written
|
|
43
|
+
// here as a call of itself, so it has a type and nothing more; the compiler
|
|
44
|
+
// gives every instance a body of its own (`src/emit-region.ts`), one call into
|
|
45
|
+
// `runtime/runtime-region.c`.
|
|
46
|
+
|
|
47
|
+
/** `nish_region_new`: a fresh handle, never 0. */
|
|
48
|
+
const handleNew = (): i64 => handleNew()
|
|
49
|
+
|
|
50
|
+
/** `nish_region_enter` on a new region, whose root is still null. */
|
|
51
|
+
const open = (h: i64): void => open(h)
|
|
52
|
+
|
|
53
|
+
/** `nish_region_leave` keeping `root`: the handle, typed by its root. */
|
|
54
|
+
const close = <T>(h: i64, root: T): Region<T> => close(h, root)
|
|
55
|
+
|
|
56
|
+
/** `nish_region_enter` on a made region: its root. */
|
|
57
|
+
const reopen = <T>(r: Region<T>): T => reopen(r)
|
|
58
|
+
|
|
59
|
+
/** `nish_region_leave` with the root `reopen` gave. */
|
|
60
|
+
const leave = <T>(r: Region<T>, root: T): void => leave(r, root)
|
|
61
|
+
|
|
62
|
+
/** A new region, whose root is what `f` answers; everything `f` allocates is in it. */
|
|
63
|
+
export const region = <T>(f: () => T): Region<T> => {
|
|
64
|
+
const h: i64 = handleNew()
|
|
65
|
+
open(h)
|
|
66
|
+
return close(h, f())
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** `region` with one argument for `f`, because the arrow `region` runs captures nothing. */
|
|
70
|
+
export const regionWith = <A, T>(arg: A, f: (arg: A) => T): Region<T> => {
|
|
71
|
+
const h: i64 = handleNew()
|
|
72
|
+
open(h)
|
|
73
|
+
return close(h, f(arg))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `f(root)`, allocating in the region: the one way to reach what a region holds. */
|
|
77
|
+
export const enter = <T, R>(r: Region<T>, f: (root: T) => R): R => {
|
|
78
|
+
const root: T = reopen(r)
|
|
79
|
+
const result: R = f(root)
|
|
80
|
+
leave(r, root)
|
|
81
|
+
return result
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** `enter` with one argument for `f`. */
|
|
85
|
+
export const enterWith = <T, A, R>(r: Region<T>, arg: A, f: (root: T, arg: A) => R): R => {
|
|
86
|
+
const root: T = reopen(r)
|
|
87
|
+
const result: R = f(root, arg)
|
|
88
|
+
leave(r, root)
|
|
89
|
+
return result
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Give the region's memory back. The handle is dead after it. The compiler writes the body. */
|
|
93
|
+
export const free = <T>(_r: Region<T>): void => {
|
|
94
|
+
// `nish_region_free`: see above.
|
|
95
|
+
}
|