@amritk/nish 0.12.0 → 0.13.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/README.md +25 -23
- package/bin/launcher.js +45 -41
- package/bin/packaging.js +39 -33
- package/docs/AI.md +95 -10
- package/docs/INSTALL.md +13 -13
- package/package.json +9 -6
- package/runtime/nish.d.ts +20 -1
- package/runtime/nish.h +31 -11
- package/runtime/nish.mjs +3 -3
- package/runtime/{runtime_os.c → runtime-os.c} +1 -1
- package/runtime/{runtime_parallel.c → runtime-parallel.c} +112 -4
- package/runtime/{runtime_wasm.c → runtime-wasm.c} +6 -1
- package/runtime/runtime.c +5 -5
- package/runtime/shim.mjs +6 -6
- package/scripts/bootstrap.sh +29 -29
- package/scripts/build.sh +14 -9
- package/scripts/changelog-gen.mjs +260 -192
- package/scripts/ci-profile.mjs +80 -68
- package/scripts/codes-registry.js +25 -13
- package/scripts/gen-diagnostic-codes.mjs +86 -69
- package/scripts/nish-compiler.sh +2 -0
- package/scripts/platform-package.mjs +26 -26
- package/scripts/postinstall.mjs +46 -36
- package/scripts/size-report.sh +3 -3
- package/scripts/smoke.sh +1 -1
- package/std/README.md +2 -2
- package/std/collections.ts +194 -188
- package/std/json.ts +136 -136
- package/std/map.ts +9 -7
- package/std/pair.ts +2 -2
- package/std/testing.ts +67 -67
- package/std/text.ts +54 -54
- package/std/threads.ts +126 -38
package/scripts/postinstall.mjs
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
*
|
|
29
29
|
* **The compiler resolves the link itself as of 0.6.0** -- the real path of
|
|
30
30
|
* whatever `argv[0]` named is a candidate for the package root
|
|
31
|
-
* ([wp19 §5a](../docs/wp19-stage0-retirement.md) item 4, in `
|
|
31
|
+
* ([wp19 §5a](../docs/wp19-stage0-retirement.md) item 4, in `src/`) -- so this
|
|
32
32
|
* `exec` is no longer what makes a copy work, and the reason it is still here is
|
|
33
33
|
* the 91 ms above rather than the defect. It also still carries whoever never
|
|
34
34
|
* ran this script: a shim npm linked and nothing swapped now finds its own
|
|
@@ -45,44 +45,54 @@
|
|
|
45
45
|
* postinstall that can break `npm ci` is a worse bug than the startup cost it
|
|
46
46
|
* exists to remove.
|
|
47
47
|
*/
|
|
48
|
-
import fs from "node:fs"
|
|
49
|
-
import path from "node:path"
|
|
50
|
-
import { createRequire } from "node:module"
|
|
51
|
-
import { pathToFileURL } from "node:url"
|
|
48
|
+
import fs from "node:fs"
|
|
49
|
+
import path from "node:path"
|
|
50
|
+
import { createRequire } from "node:module"
|
|
51
|
+
import { pathToFileURL } from "node:url"
|
|
52
52
|
|
|
53
|
-
const root = path.resolve(import.meta.dirname, "..")
|
|
53
|
+
const root = path.resolve(import.meta.dirname, "..")
|
|
54
54
|
|
|
55
55
|
const swap = async () => {
|
|
56
56
|
// A checkout, not an install. The repository is its own package, so `npm ci`
|
|
57
57
|
// here installs this package's own optionalDependencies -- and without this
|
|
58
58
|
// guard, the first `npm ci` after they are published would overwrite the
|
|
59
59
|
// tracked `bin/nish` with a binary and leave the working tree dirty. The
|
|
60
|
-
// landmark is `
|
|
61
|
-
// makes and is not in `files`; it used to be `src/launcher.ts`, which stopped
|
|
60
|
+
// landmark is `src/compile.ts`, which is the check `scripts/bootstrap.sh`
|
|
61
|
+
// makes and is not in `files`; it used to be stage0's `src/launcher.ts`, which stopped
|
|
62
62
|
// being a landmark when the launcher moved into `bin/` and ships.
|
|
63
|
-
if (fs.existsSync(path.join(root, "
|
|
63
|
+
if (fs.existsSync(path.join(root, "src", "compile.ts"))) {
|
|
64
|
+
return "a checkout, so the shim stays"
|
|
65
|
+
}
|
|
64
66
|
|
|
65
|
-
const shim = path.join(root, "bin", "nish")
|
|
66
|
-
if (!fs.existsSync(shim))
|
|
67
|
+
const shim = path.join(root, "bin", "nish")
|
|
68
|
+
if (!fs.existsSync(shim)) {
|
|
69
|
+
return "no bin/nish to replace"
|
|
70
|
+
}
|
|
67
71
|
|
|
68
|
-
const packaging = path.join(root, "bin", "packaging.js")
|
|
69
|
-
if (!fs.existsSync(packaging))
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const packaging = path.join(root, "bin", "packaging.js")
|
|
73
|
+
if (!fs.existsSync(packaging)) {
|
|
74
|
+
return "bin/packaging.js is missing"
|
|
75
|
+
}
|
|
76
|
+
const { assetFor, platformPackageName } = await import(pathToFileURL(packaging).href)
|
|
77
|
+
const asset = assetFor(process.platform, process.arch)
|
|
78
|
+
if (asset === null) {
|
|
79
|
+
return `no prebuilt binary for ${process.platform}/${process.arch}`
|
|
80
|
+
}
|
|
73
81
|
|
|
74
82
|
const name = platformPackageName(
|
|
75
83
|
JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8")).name,
|
|
76
84
|
asset
|
|
77
|
-
)
|
|
78
|
-
let binary
|
|
85
|
+
)
|
|
86
|
+
let binary
|
|
79
87
|
try {
|
|
80
|
-
const manifest = createRequire(import.meta.url).resolve(`${name}/package.json`)
|
|
81
|
-
binary = path.join(path.dirname(manifest), "bin", "nish")
|
|
88
|
+
const manifest = createRequire(import.meta.url).resolve(`${name}/package.json`)
|
|
89
|
+
binary = path.join(path.dirname(manifest), "bin", "nish")
|
|
82
90
|
} catch {
|
|
83
|
-
return `${name} is not installed
|
|
91
|
+
return `${name} is not installed`
|
|
92
|
+
}
|
|
93
|
+
if (!fs.existsSync(binary)) {
|
|
94
|
+
return `${name} carries no bin/nish`
|
|
84
95
|
}
|
|
85
|
-
if (!fs.existsSync(binary)) return `${name} carries no bin/nish`;
|
|
86
96
|
|
|
87
97
|
// The absolute path is baked in at install time, which is the one thing this
|
|
88
98
|
// gives up: a `node_modules` copied to a different path without a reinstall
|
|
@@ -99,35 +109,35 @@ const swap = async () => {
|
|
|
99
109
|
// have ended up in, the shell would expand them. A home directory with a `$`
|
|
100
110
|
// in it is unusual and entirely legal. In POSIX sh nothing is special inside
|
|
101
111
|
// single quotes, so the only thing to handle is a single quote itself.
|
|
102
|
-
const shellQuote = (value) => `'${value.split("'").join(`'\\''`)}'
|
|
103
|
-
const target = shellQuote(binary)
|
|
112
|
+
const shellQuote = (value) => `'${value.split("'").join(`'\\''`)}'`
|
|
113
|
+
const target = shellQuote(binary)
|
|
104
114
|
const script =
|
|
105
115
|
"#!/bin/sh\n" +
|
|
106
116
|
"# Written by scripts/postinstall.mjs. `npm rebuild` regenerates it.\n" +
|
|
107
117
|
`if [ -x ${target} ]; then exec ${target} "$@"; fi\n` +
|
|
108
118
|
// Exit 3 is this project's toolchain code: the compiler could not be run,
|
|
109
119
|
// which is exactly what has happened (docs/wp12-release.md, "Exit codes").
|
|
110
|
-
|
|
111
|
-
"exit 3\n"
|
|
112
|
-
const temp = `${shim}.${process.pid}.tmp
|
|
120
|
+
"echo \"nish: the prebuilt compiler is not where it was installed; run 'npm rebuild' to repoint this\" >&2\n" +
|
|
121
|
+
"exit 3\n"
|
|
122
|
+
const temp = `${shim}.${process.pid}.tmp`
|
|
113
123
|
try {
|
|
114
|
-
fs.writeFileSync(temp, script)
|
|
115
|
-
fs.chmodSync(temp, 0o755)
|
|
116
|
-
fs.renameSync(temp, shim)
|
|
124
|
+
fs.writeFileSync(temp, script)
|
|
125
|
+
fs.chmodSync(temp, 0o755)
|
|
126
|
+
fs.renameSync(temp, shim)
|
|
117
127
|
} catch (err) {
|
|
118
128
|
try {
|
|
119
|
-
fs.rmSync(temp, { force: true })
|
|
129
|
+
fs.rmSync(temp, { force: true })
|
|
120
130
|
} catch {
|
|
121
131
|
// Nothing to do about it, and it is not worth a second message.
|
|
122
132
|
}
|
|
123
|
-
throw err
|
|
133
|
+
throw err
|
|
124
134
|
}
|
|
125
|
-
return `bin/nish now execs the native compiler in ${name}
|
|
126
|
-
}
|
|
135
|
+
return `bin/nish now execs the native compiler in ${name}`
|
|
136
|
+
}
|
|
127
137
|
|
|
128
138
|
try {
|
|
129
|
-
console.log(`nish: ${await swap()}`)
|
|
139
|
+
console.log(`nish: ${await swap()}`)
|
|
130
140
|
} catch (err) {
|
|
131
141
|
// Deliberately not an error: the shim is still there and still works.
|
|
132
|
-
console.log(`nish: keeping the node launcher (${err instanceof Error ? err.message : String(err)})`)
|
|
142
|
+
console.log(`nish: keeping the node launcher (${err instanceof Error ? err.message : String(err)})`)
|
|
133
143
|
}
|
package/scripts/size-report.sh
CHANGED
|
@@ -51,13 +51,13 @@ text_sum() { # text_sum <object>: every .text* secti
|
|
|
51
51
|
}
|
|
52
52
|
sect() { size -A "$2" | awk -v s="$1" '$1 == s { print $2 }'; }
|
|
53
53
|
"${CC:-clang}" -Oz -c runtime/runtime.c -o build/size/runtime.o
|
|
54
|
-
"${CC:-clang}" -Oz -c runtime/
|
|
54
|
+
"${CC:-clang}" -Oz -c runtime/runtime-os.c -o build/size/runtime_os.o
|
|
55
55
|
row runtime "$(text_sum build/size/runtime.o)" \
|
|
56
56
|
"clang -Oz -c runtime/runtime.c && size -A (.text*; budget 3584)"
|
|
57
57
|
row runtime_os "$(text_sum build/size/runtime_os.o)" \
|
|
58
|
-
"clang -Oz -c runtime/
|
|
58
|
+
"clang -Oz -c runtime/runtime-os.c && size -A (.text*; budget 1280)"
|
|
59
59
|
row rodata "$(sect .rodata build/size/runtime.o)" "the core object's .rodata (no budget; the Ryu tables live here)"
|
|
60
|
-
# `scripts/build.sh` compiles
|
|
60
|
+
# `scripts/build.sh` compiles runtime-os.c beside any runtime.c it is handed, so naming the
|
|
61
61
|
# core here builds the whole runtime -- and `--gc-sections` then drops whatever this module
|
|
62
62
|
# never calls, which for `examples/add.ts` is all of it.
|
|
63
63
|
for p in debug speed size; do
|
package/scripts/smoke.sh
CHANGED
package/std/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Nish modules written in Nish, for Nish programs to import. There is no magic
|
|
|
4
4
|
here and — with three exceptions, `threads.ts`, `collections.ts` and `map.ts` —
|
|
5
5
|
nothing the compiler knows about: a module in this directory is an ordinary Nish source file, compiled as part of
|
|
6
6
|
whatever program imports it, and subject to the same rules as `examples/` or
|
|
7
|
-
`
|
|
7
|
+
`src/` ([`docs/LANGUAGE.md`](../docs/LANGUAGE.md) is the style guide).
|
|
8
8
|
|
|
9
9
|
| Module | What it is |
|
|
10
10
|
| --- | --- |
|
|
@@ -130,7 +130,7 @@ that are *not* this package.
|
|
|
130
130
|
stdout. `tests/link/std_text_f64` is the same corpus under
|
|
131
131
|
`--number-mode f64`, which is where a module that spelled its widths and forgot
|
|
132
132
|
a `toI32` is caught.
|
|
133
|
-
- **`std/` is not on the compiler's dependency list.** Nothing in `
|
|
133
|
+
- **`std/` is not on the compiler's dependency list.** Nothing in `src/`
|
|
134
134
|
imports it, and nothing should: the compiler is the thing that has to
|
|
135
135
|
build before the library means anything.
|
|
136
136
|
|