@fraczak/k 6.0.4 → 6.1.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/AGENTS.md +2 -2
- package/CHANGELOG.md +22 -5
- package/CLAUDE.md +4 -4
- package/DOCS/BIG_PICTURE.md +5 -5
- package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +9 -9
- package/DOCS/PATTERNS.md +6 -5
- package/DOCS/REPL.md +2 -2
- package/DOCS/book/06-values-in-memory.md +1 -1
- package/DOCS/book.md +20 -24
- package/README.md +200 -274
- package/codecs/README.md +21 -2
- package/codecs/example-pipeline.mjs +14 -0
- package/codecs/ieee.mjs +13 -3
- package/codecs/int.mjs +13 -3
- package/codecs/json.mjs +13 -3
- package/codecs/k-parse.mjs +5 -0
- package/codecs/k-print.mjs +16 -1
- package/codecs/show.mjs +15 -1
- package/codecs/unit.mjs +13 -3
- package/codecs/utf16.mjs +13 -3
- package/codecs/utf8.mjs +13 -3
- package/k-vscode/README.md +3 -2
- package/k.mjs +9 -1
- package/objects/README.md +11 -8
- package/package.json +13 -7
- package/{repl2.mjs → repl.mjs} +19 -0
- package/{test-repl2.mjs → test-repl.mjs} +4 -4
package/codecs/ieee.mjs
CHANGED
|
@@ -6,6 +6,13 @@ import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
|
|
|
6
6
|
import { FLOAT64_PATTERN } from "./runtime/ieee-pattern.mjs";
|
|
7
7
|
const UNIT = new Product({});
|
|
8
8
|
|
|
9
|
+
function usage(stream = console.error) {
|
|
10
|
+
stream(`Usage: ${argv[1]} --parse | --print`);
|
|
11
|
+
stream(" --parse Read a float literal from stdin, write binary pattern+value stream.");
|
|
12
|
+
stream(" --print Read binary pattern+value stream from stdin, write a float literal.");
|
|
13
|
+
stream(" -h, --help Show this help.");
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
function bitValue(bit) {
|
|
10
17
|
return new Variant(bit === 0 ? "0" : "1", UNIT);
|
|
11
18
|
}
|
|
@@ -116,10 +123,13 @@ function readAll(stream) {
|
|
|
116
123
|
|
|
117
124
|
async function main() {
|
|
118
125
|
const args = argv.slice(2);
|
|
126
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
127
|
+
usage(console.log);
|
|
128
|
+
exit(0);
|
|
129
|
+
}
|
|
130
|
+
|
|
119
131
|
if (args.length !== 1 || (args[0] !== "--parse" && args[0] !== "--print")) {
|
|
120
|
-
|
|
121
|
-
console.error(" --parse read a float literal from stdin, write binary pattern+value stream");
|
|
122
|
-
console.error(" --print read binary pattern+value stream from stdin, write a float literal");
|
|
132
|
+
usage();
|
|
123
133
|
exit(1);
|
|
124
134
|
}
|
|
125
135
|
|
package/codecs/int.mjs
CHANGED
|
@@ -17,6 +17,13 @@ import { stdin, stdout, argv, exit } from "node:process";
|
|
|
17
17
|
import { Product, Variant } from "../Value.mjs";
|
|
18
18
|
import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
|
|
19
19
|
|
|
20
|
+
function usage(stream = console.error) {
|
|
21
|
+
stream(`Usage: ${argv[1]} --parse | --print`);
|
|
22
|
+
stream(" --parse Read a decimal integer from stdin, write binary pattern+value stream.");
|
|
23
|
+
stream(" --print Read binary pattern+value stream from stdin, write decimal integer.");
|
|
24
|
+
stream(" -h, --help Show this help.");
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
// Closed pattern for $ int = < bits '+', bits '-' >
|
|
21
28
|
// with $ bits = < {} _, bits 0, bits 1 >
|
|
22
29
|
const INT_PATTERN = [
|
|
@@ -79,10 +86,13 @@ function printIntValue(value) {
|
|
|
79
86
|
|
|
80
87
|
async function main() {
|
|
81
88
|
const args = argv.slice(2);
|
|
89
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
90
|
+
usage(console.log);
|
|
91
|
+
exit(0);
|
|
92
|
+
}
|
|
93
|
+
|
|
82
94
|
if (args.length !== 1 || (args[0] !== "--parse" && args[0] !== "--print")) {
|
|
83
|
-
|
|
84
|
-
console.error(" --parse read a decimal integer from stdin, write binary pattern+value stream");
|
|
85
|
-
console.error(" --print read binary pattern+value stream from stdin, write decimal integer");
|
|
95
|
+
usage();
|
|
86
96
|
exit(1);
|
|
87
97
|
}
|
|
88
98
|
|
package/codecs/json.mjs
CHANGED
|
@@ -4,6 +4,13 @@ import { stdin, stdout, argv, exit } from "node:process";
|
|
|
4
4
|
import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
|
|
5
5
|
import { fromJsonValue, toJsonValue, patternFromJsonValue } from "./json-codec.mjs";
|
|
6
6
|
|
|
7
|
+
function usage(stream = console.error) {
|
|
8
|
+
stream(`Usage: ${argv[1]} --parse | --print`);
|
|
9
|
+
stream(" --parse Read JSON from stdin, write binary pattern+value stream.");
|
|
10
|
+
stream(" --print Read binary pattern+value stream from stdin, write JSON.");
|
|
11
|
+
stream(" -h, --help Show this help.");
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
function readAll(stream) {
|
|
8
15
|
return new Promise((resolve, reject) => {
|
|
9
16
|
const chunks = [];
|
|
@@ -15,10 +22,13 @@ function readAll(stream) {
|
|
|
15
22
|
|
|
16
23
|
async function main() {
|
|
17
24
|
const args = argv.slice(2);
|
|
25
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
26
|
+
usage(console.log);
|
|
27
|
+
exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
if (args.length !== 1 || (args[0] !== "--parse" && args[0] !== "--print")) {
|
|
19
|
-
|
|
20
|
-
console.error(" --parse read JSON from stdin, write binary pattern+value stream");
|
|
21
|
-
console.error(" --print read binary pattern+value stream from stdin, write JSON");
|
|
31
|
+
usage();
|
|
22
32
|
exit(1);
|
|
23
33
|
}
|
|
24
34
|
|
package/codecs/k-parse.mjs
CHANGED
|
@@ -49,6 +49,11 @@ async function main() {
|
|
|
49
49
|
const prog = argv[1];
|
|
50
50
|
const args = argv.slice(2);
|
|
51
51
|
|
|
52
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
53
|
+
usage(prog);
|
|
54
|
+
return exit(0);
|
|
55
|
+
}
|
|
56
|
+
|
|
52
57
|
let inputTypeArg = null;
|
|
53
58
|
let inputPatternArg = null;
|
|
54
59
|
let valueFile = null;
|
package/codecs/k-print.mjs
CHANGED
|
@@ -4,6 +4,15 @@ import fs from "node:fs";
|
|
|
4
4
|
import { argv, stdin, stdout } from "node:process";
|
|
5
5
|
import { decodeWire } from "./runtime/prefix-codec.mjs";
|
|
6
6
|
|
|
7
|
+
function usage(stream = console.error) {
|
|
8
|
+
stream(`Usage: ${argv[1]} [--debug] [file]`);
|
|
9
|
+
stream(" Read a binary pattern+value stream and print the decoded textual value.");
|
|
10
|
+
stream("");
|
|
11
|
+
stream("Options:");
|
|
12
|
+
stream(" --debug Print decoded pattern and value as JSON.");
|
|
13
|
+
stream(" -h, --help Show this help.");
|
|
14
|
+
}
|
|
15
|
+
|
|
7
16
|
function readAll(stream) {
|
|
8
17
|
return new Promise((resolve, reject) => {
|
|
9
18
|
const chunks = [];
|
|
@@ -15,6 +24,11 @@ function readAll(stream) {
|
|
|
15
24
|
|
|
16
25
|
async function main() {
|
|
17
26
|
const args = argv.slice(2);
|
|
27
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
28
|
+
usage(console.log);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
let debug = false;
|
|
19
33
|
let fileArg = null;
|
|
20
34
|
|
|
@@ -24,7 +38,8 @@ async function main() {
|
|
|
24
38
|
} else if (fileArg == null) {
|
|
25
39
|
fileArg = arg;
|
|
26
40
|
} else {
|
|
27
|
-
|
|
41
|
+
usage();
|
|
42
|
+
process.exit(1);
|
|
28
43
|
}
|
|
29
44
|
}
|
|
30
45
|
|
package/codecs/show.mjs
CHANGED
|
@@ -5,6 +5,15 @@ import { argv, stdin, stdout, stderr } from "node:process";
|
|
|
5
5
|
import { decodeWire } from "./runtime/prefix-codec.mjs";
|
|
6
6
|
import { propertyListToFilter, valueToK } from "./runtime/show-value.mjs";
|
|
7
7
|
|
|
8
|
+
function usage(stream = console.error) {
|
|
9
|
+
stream(`Usage: ${argv[1]} [wire-file]`);
|
|
10
|
+
stream(" Pass the wire stream through unchanged on stdout.");
|
|
11
|
+
stream(" Print the decoded value and filter to stderr.");
|
|
12
|
+
stream("");
|
|
13
|
+
stream("Options:");
|
|
14
|
+
stream(" -h, --help Show this help.");
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
function readAll(stream) {
|
|
9
18
|
return new Promise((resolve, reject) => {
|
|
10
19
|
const chunks = [];
|
|
@@ -16,10 +25,15 @@ function readAll(stream) {
|
|
|
16
25
|
|
|
17
26
|
async function main() {
|
|
18
27
|
const args = argv.slice(2);
|
|
28
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
29
|
+
usage(console.log);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
let fileArg = null;
|
|
20
34
|
for (const arg of args) {
|
|
21
35
|
if (fileArg == null) fileArg = arg;
|
|
22
|
-
else {
|
|
36
|
+
else { usage(); process.exit(1); }
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
const buffer = fileArg ? fs.readFileSync(fileArg) : await readAll(stdin);
|
package/codecs/unit.mjs
CHANGED
|
@@ -4,6 +4,13 @@ import { stdin, stdout, argv, exit } from "node:process";
|
|
|
4
4
|
import { Product } from "../Value.mjs";
|
|
5
5
|
import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
|
|
6
6
|
|
|
7
|
+
function usage(stream = console.error) {
|
|
8
|
+
stream(`Usage: ${argv[1]} --parse | --print`);
|
|
9
|
+
stream(" --parse Ignore stdin and write the unit binary pattern+value stream.");
|
|
10
|
+
stream(" --print Validate the unit binary pattern+value stream and write {}.");
|
|
11
|
+
stream(" -h, --help Show this help.");
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
const UNIT_PATTERN = [
|
|
8
15
|
["closed-product", []]
|
|
9
16
|
];
|
|
@@ -23,10 +30,13 @@ function unitEncoding() {
|
|
|
23
30
|
|
|
24
31
|
async function main() {
|
|
25
32
|
const args = argv.slice(2);
|
|
33
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
34
|
+
usage(console.log);
|
|
35
|
+
exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
if (args.length !== 1 || (args[0] !== "--parse" && args[0] !== "--print")) {
|
|
27
|
-
|
|
28
|
-
console.error(" --parse ignore stdin and write the unit binary pattern+value stream");
|
|
29
|
-
console.error(" --print validate the unit binary pattern+value stream and write {}");
|
|
39
|
+
usage();
|
|
30
40
|
exit(1);
|
|
31
41
|
}
|
|
32
42
|
|
package/codecs/utf16.mjs
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
import { stdin, stdout, argv, exit } from "node:process";
|
|
4
4
|
import { encodeText, decodeText } from "./string-codec.mjs";
|
|
5
5
|
|
|
6
|
+
function usage(stream = console.error) {
|
|
7
|
+
stream(`Usage: ${argv[1]} --parse | --print`);
|
|
8
|
+
stream(" --parse Read UTF-16 text from stdin (BOM-aware), write binary pattern+value stream of k string.");
|
|
9
|
+
stream(" --print Read binary pattern+value stream of k string, write UTF-16LE text with BOM.");
|
|
10
|
+
stream(" -h, --help Show this help.");
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
function readAll(stream) {
|
|
7
14
|
return new Promise((resolve, reject) => {
|
|
8
15
|
const chunks = [];
|
|
@@ -43,10 +50,13 @@ function encodeUtf16Output(text) {
|
|
|
43
50
|
|
|
44
51
|
async function main() {
|
|
45
52
|
const args = argv.slice(2);
|
|
53
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
54
|
+
usage(console.log);
|
|
55
|
+
exit(0);
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
if (args.length !== 1 || (args[0] !== "--parse" && args[0] !== "--print")) {
|
|
47
|
-
|
|
48
|
-
console.error(" --parse read UTF-16 text from stdin (BOM-aware), write binary pattern+value stream of k string");
|
|
49
|
-
console.error(" --print read binary pattern+value stream of k string, write UTF-16LE text with BOM");
|
|
59
|
+
usage();
|
|
50
60
|
exit(1);
|
|
51
61
|
}
|
|
52
62
|
|
package/codecs/utf8.mjs
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
import { stdin, stdout, argv, exit } from "node:process";
|
|
4
4
|
import { encodeText, decodeText } from "./string-codec.mjs";
|
|
5
5
|
|
|
6
|
+
function usage(stream = console.error) {
|
|
7
|
+
stream(`Usage: ${argv[1]} --parse | --print`);
|
|
8
|
+
stream(" --parse Read UTF-8 text from stdin, write binary pattern+value stream of k string.");
|
|
9
|
+
stream(" --print Read binary pattern+value stream of k string, write UTF-8 text.");
|
|
10
|
+
stream(" -h, --help Show this help.");
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
function readAll(stream) {
|
|
7
14
|
return new Promise((resolve, reject) => {
|
|
8
15
|
const chunks = [];
|
|
@@ -14,10 +21,13 @@ function readAll(stream) {
|
|
|
14
21
|
|
|
15
22
|
async function main() {
|
|
16
23
|
const args = argv.slice(2);
|
|
24
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
25
|
+
usage(console.log);
|
|
26
|
+
exit(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
if (args.length !== 1 || (args[0] !== "--parse" && args[0] !== "--print")) {
|
|
18
|
-
|
|
19
|
-
console.error(" --parse read UTF-8 text from stdin, write binary pattern+value stream of k string");
|
|
20
|
-
console.error(" --print read binary pattern+value stream of k string, write UTF-8 text");
|
|
30
|
+
usage();
|
|
21
31
|
exit(1);
|
|
22
32
|
}
|
|
23
33
|
|
package/k-vscode/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# k language — VS Code extension
|
|
2
2
|
|
|
3
|
-
Syntax highlighting and snippets for the **k language**: a language for
|
|
4
|
-
|
|
3
|
+
Syntax highlighting and snippets for the **k language**: a small language for
|
|
4
|
+
typed data transformations over algebraic data types (products and tagged
|
|
5
|
+
unions).
|
|
5
6
|
|
|
6
7
|
## Features
|
|
7
8
|
|
package/k.mjs
CHANGED
|
@@ -13,7 +13,10 @@ let kScript, inputStream;
|
|
|
13
13
|
|
|
14
14
|
function usage() {
|
|
15
15
|
console.error(`Usage: ${prog} [ --lib lib-file ]... ( k-expr | -k file ) [ input-file ]`);
|
|
16
|
-
console.error(` E.g., echo '["zebara","ela"]' |
|
|
16
|
+
console.error(` E.g., echo '["zebara","ela"]' | k-parse --input-type '$x=<{} zebara, {} ela>; $v={x 0, x 1}; $v' | ${prog} '{.1 0}'`);
|
|
17
|
+
console.error("Options:");
|
|
18
|
+
console.error(" --lib file Load a .klib dependency before compiling. May be repeated.");
|
|
19
|
+
console.error(" -h, --help Show this help.");
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
function compileFile(path, libraries) {
|
|
@@ -27,6 +30,11 @@ function compileFile(path, libraries) {
|
|
|
27
30
|
|
|
28
31
|
({ kScript, inputStream } = ((args) => {
|
|
29
32
|
try {
|
|
33
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
34
|
+
usage();
|
|
35
|
+
return exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
const libraries = [];
|
|
31
39
|
// Parse --lib flags
|
|
32
40
|
while (args.length > 0 && args[0] === "--lib") {
|
package/objects/README.md
CHANGED
|
@@ -4,17 +4,17 @@ CLI tools for compiling and inspecting k object files (`.ko`) and library files
|
|
|
4
4
|
|
|
5
5
|
## Tools
|
|
6
6
|
|
|
7
|
-
### compile
|
|
7
|
+
### `k-compile`
|
|
8
8
|
|
|
9
9
|
Compiles a `.k` source file into an executable object file (`.ko`).
|
|
10
10
|
The output contains only the codes and relations reachable from `main`.
|
|
11
11
|
Each stored relation includes `typeDerivation.status` for backend eligibility.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
|
|
14
|
+
k-compile [--lib lib-file]... [k-file [object-file]]
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
### compile-lib
|
|
17
|
+
### `k-compile-lib`
|
|
18
18
|
|
|
19
19
|
Compiles a `.k` source file into a library file (`.klib`).
|
|
20
20
|
The output is plain JSON with no binary header. It contains the library closure
|
|
@@ -25,27 +25,30 @@ Each stored relation includes `typeDerivation.status`; libraries may contain a
|
|
|
25
25
|
mix of converged and non-converged relations.
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
|
|
28
|
+
k-compile-lib [--lib lib-file]... [k-file [lib-file]]
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
### decompile
|
|
31
|
+
### `k-decompile`
|
|
32
32
|
|
|
33
33
|
Decompiles a `.ko` or `.klib` back into human-readable k source.
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
|
|
36
|
+
k-decompile [object-file [k-file]]
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
### extract-aliases
|
|
39
|
+
### `k-extract-aliases`
|
|
40
40
|
|
|
41
41
|
Extracts metadata aliases from a `.ko` or `.klib` as a valid k definition
|
|
42
42
|
snippet. Output is grouped by metadata type (`code`, then `rel`), then sorted by
|
|
43
43
|
alias name and `compiledAt`.
|
|
44
44
|
|
|
45
45
|
```bash
|
|
46
|
-
|
|
46
|
+
k-extract-aliases [object-file [k-file]]
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
The installed names are `k-` plus the source basename without `.mjs`. Every
|
|
50
|
+
installed object binary supports `-h` and `--help`.
|
|
51
|
+
|
|
49
52
|
## Current Format Notes
|
|
50
53
|
|
|
51
54
|
- `.klib` files are plain UTF-8 JSON, not binary containers.
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraczak/k",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "k — a language for composing first-order partial functions over algebraic data types (products and tagged unions); includes runtime, type derivation, REPL, and codec toolchain",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepare": "jiwson -m es6 parser.jison -o parser.mjs; jiwson -m es6 valueParser.jison -o valueParser.mjs; ",
|
|
8
|
-
"test": "node test.mjs; for f in Code-derivation-tests/*.mjs; do echo $f; node $f; done; node test-fingerprint.mjs; node test-hash-fuzz.mjs; node test-hash-normalization.mjs; node test-k-object.mjs; node test-
|
|
8
|
+
"test": "node test.mjs; for f in Code-derivation-tests/*.mjs; do echo $f; node $f; done; node test-fingerprint.mjs; node test-hash-fuzz.mjs; node test-hash-normalization.mjs; node test-k-object.mjs; node test-repl.mjs; ./tests.sh",
|
|
9
9
|
"deps:graph": "node scripts/generate-dependency-graph.mjs"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
@@ -16,14 +16,20 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"bin": {
|
|
18
18
|
"k": "./k.mjs",
|
|
19
|
-
"k-compile
|
|
20
|
-
"k-
|
|
19
|
+
"k-compile": "./objects/compile.mjs",
|
|
20
|
+
"k-compile-lib": "./objects/compile-lib.mjs",
|
|
21
|
+
"k-decompile": "./objects/decompile.mjs",
|
|
21
22
|
"k-extract-aliases": "./objects/extract-aliases.mjs",
|
|
23
|
+
"k-ieee": "./codecs/ieee.mjs",
|
|
24
|
+
"k-int": "./codecs/int.mjs",
|
|
25
|
+
"k-json": "./codecs/json.mjs",
|
|
22
26
|
"k-parse": "./codecs/k-parse.mjs",
|
|
23
|
-
"k-pattern": "./patterns/from-k.mjs",
|
|
24
27
|
"k-print": "./codecs/k-print.mjs",
|
|
25
|
-
"k-repl": "./
|
|
26
|
-
"k-
|
|
28
|
+
"k-repl": "./repl.mjs",
|
|
29
|
+
"k-show": "./codecs/show.mjs",
|
|
30
|
+
"k-unit": "./codecs/unit.mjs",
|
|
31
|
+
"k-utf16": "./codecs/utf16.mjs",
|
|
32
|
+
"k-utf8": "./codecs/utf8.mjs"
|
|
27
33
|
},
|
|
28
34
|
"devDependencies": {
|
|
29
35
|
"jiwson": "^0.1.2"
|
package/{repl2.mjs → repl.mjs}
RENAMED
|
@@ -840,6 +840,16 @@ function helpText() {
|
|
|
840
840
|
].join("\n");
|
|
841
841
|
}
|
|
842
842
|
|
|
843
|
+
function cliUsage() {
|
|
844
|
+
console.log("Usage: k-repl");
|
|
845
|
+
console.log(" k-repl -h");
|
|
846
|
+
console.log("");
|
|
847
|
+
console.log("Start the interactive k interpreter. Type :help inside the REPL for commands.");
|
|
848
|
+
console.log("");
|
|
849
|
+
console.log("Options:");
|
|
850
|
+
console.log(" -h, --help Show this help.");
|
|
851
|
+
}
|
|
852
|
+
|
|
843
853
|
function startRepl() {
|
|
844
854
|
const state = createState();
|
|
845
855
|
const rl = readline.createInterface({
|
|
@@ -916,6 +926,15 @@ function startRepl() {
|
|
|
916
926
|
}
|
|
917
927
|
|
|
918
928
|
if (isMainEntrypoint()) {
|
|
929
|
+
const args = argv.slice(2);
|
|
930
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
931
|
+
cliUsage();
|
|
932
|
+
exit(0);
|
|
933
|
+
}
|
|
934
|
+
if (args.length > 0) {
|
|
935
|
+
cliUsage();
|
|
936
|
+
exit(1);
|
|
937
|
+
}
|
|
919
938
|
startRepl();
|
|
920
939
|
}
|
|
921
940
|
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
isMainEntrypoint,
|
|
16
16
|
lineHasExplicitContinuation,
|
|
17
17
|
lineTerminatesSnippet
|
|
18
|
-
} from "./
|
|
18
|
+
} from "./repl.mjs";
|
|
19
19
|
import { decodeObject, objectToFunction } from "./object.mjs";
|
|
20
20
|
import { Product } from "./Value.mjs";
|
|
21
21
|
|
|
@@ -78,11 +78,11 @@ await assert.rejects(
|
|
|
78
78
|
/Type Error in 'filter' \(lines 1:1\.\.\.1:4\)/
|
|
79
79
|
);
|
|
80
80
|
|
|
81
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "k-
|
|
81
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "k-repl-"));
|
|
82
82
|
const libPath = path.join(tmpDir, "session.klib");
|
|
83
83
|
const koPath = path.join(tmpDir, "succ.ko");
|
|
84
84
|
const sourcePath = path.join(tmpDir, "session.k");
|
|
85
|
-
const symlinkPath = path.resolve(".test-k-
|
|
85
|
+
const symlinkPath = path.resolve(".test-k-repl-link");
|
|
86
86
|
output = await evaluateInput(`:klib ${libPath}`, state);
|
|
87
87
|
assert.equal(output[0], `saved ${libPath}`);
|
|
88
88
|
|
|
@@ -106,7 +106,7 @@ assert.match(output[0], /^nat = @/m);
|
|
|
106
106
|
output = await evaluateInput(":rels", loadedSource);
|
|
107
107
|
assert.match(output[0], /^succ = @/m);
|
|
108
108
|
|
|
109
|
-
const replPath = fileURLToPath(new URL("./
|
|
109
|
+
const replPath = fileURLToPath(new URL("./repl.mjs", import.meta.url));
|
|
110
110
|
try {
|
|
111
111
|
fs.rmSync(symlinkPath, { force: true });
|
|
112
112
|
} catch {}
|