@thi.ng/pointfree-lang 2.2.37 → 2.2.39
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/CHANGELOG.md +7 -1
- package/README.md +2 -2
- package/package.json +13 -13
- package/runtime.js +56 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-29T09:28:36Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [2.2.38](https://github.com/thi-ng/umbrella/tree/@thi.ng/pointfree-lang@2.2.38) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
### [2.2.17](https://github.com/thi-ng/umbrella/tree/@thi.ng/pointfree-lang@2.2.17) (2024-02-22)
|
|
13
19
|
|
|
14
20
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 189 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -97,7 +97,7 @@ For Node.js REPL:
|
|
|
97
97
|
const pfl = await import("@thi.ng/pointfree-lang");
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 4.
|
|
100
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.71 KB
|
|
101
101
|
|
|
102
102
|
## Dependencies
|
|
103
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/pointfree-lang",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.39",
|
|
4
4
|
"description": "Forth style syntax layer/compiler & CLI for the @thi.ng/pointfree DSL",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
15
15
|
},
|
|
16
|
-
"homepage": "https://
|
|
16
|
+
"homepage": "https://thi.ng/pointfree-lang",
|
|
17
17
|
"funding": [
|
|
18
18
|
{
|
|
19
19
|
"type": "github",
|
|
@@ -40,20 +40,20 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.11.
|
|
44
|
-
"@thi.ng/args": "^2.3.
|
|
45
|
-
"@thi.ng/bench": "^3.5.
|
|
46
|
-
"@thi.ng/errors": "^2.5.
|
|
47
|
-
"@thi.ng/file-io": "^2.1.
|
|
48
|
-
"@thi.ng/logger": "^3.0.
|
|
49
|
-
"@thi.ng/pointfree": "^3.1.
|
|
43
|
+
"@thi.ng/api": "^8.11.4",
|
|
44
|
+
"@thi.ng/args": "^2.3.35",
|
|
45
|
+
"@thi.ng/bench": "^3.5.8",
|
|
46
|
+
"@thi.ng/errors": "^2.5.9",
|
|
47
|
+
"@thi.ng/file-io": "^2.1.4",
|
|
48
|
+
"@thi.ng/logger": "^3.0.14",
|
|
49
|
+
"@thi.ng/pointfree": "^3.1.84"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@microsoft/api-extractor": "^7.
|
|
53
|
-
"esbuild": "^0.21.
|
|
52
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
53
|
+
"esbuild": "^0.21.5",
|
|
54
54
|
"pegjs": "0.11.0-master.b7b87ea",
|
|
55
55
|
"typedoc": "^0.25.13",
|
|
56
|
-
"typescript": "^5.
|
|
56
|
+
"typescript": "^5.5.2"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"ast",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"parent": "@thi.ng/pointfree",
|
|
107
107
|
"year": 2018
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
|
|
110
110
|
}
|
package/runtime.js
CHANGED
|
@@ -4,64 +4,64 @@ import * as pf from "@thi.ng/pointfree";
|
|
|
4
4
|
import { ALIASES } from "./api.js";
|
|
5
5
|
import { LOGGER } from "./logger.js";
|
|
6
6
|
import { SyntaxError, parse } from "./parser.js";
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const __nodeLoc = (node) => node.loc ? `line ${node.loc.join(":")} -` : "";
|
|
8
|
+
const __resolveSym = (node, ctx) => {
|
|
9
9
|
const id = node.id;
|
|
10
10
|
let w = ctx[2].__words[id] || ALIASES[id] || pf[id];
|
|
11
11
|
if (!w) {
|
|
12
|
-
illegalArgs(`${
|
|
12
|
+
illegalArgs(`${__nodeLoc(node)} unknown symbol: ${id}`);
|
|
13
13
|
}
|
|
14
14
|
return w;
|
|
15
15
|
};
|
|
16
|
-
const
|
|
16
|
+
const __resolveVar = (node, ctx) => {
|
|
17
17
|
const id = node.id;
|
|
18
18
|
const v = ctx[2].__vars[id];
|
|
19
19
|
if (!v) {
|
|
20
|
-
illegalArgs(`${
|
|
20
|
+
illegalArgs(`${__nodeLoc(node)} unknown var: ${id}`);
|
|
21
21
|
}
|
|
22
22
|
if (!v.length) {
|
|
23
|
-
illegalState(`${
|
|
23
|
+
illegalState(`${__nodeLoc(node)} missing bindings for var: ${id}`);
|
|
24
24
|
}
|
|
25
25
|
return v[0];
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const __resolveNode = (node, ctx) => {
|
|
28
28
|
switch (node.type) {
|
|
29
29
|
case "sym":
|
|
30
|
-
return
|
|
30
|
+
return __resolveSym(node, ctx);
|
|
31
31
|
case "var_deref":
|
|
32
|
-
return
|
|
32
|
+
return __resolveVar(node, ctx);
|
|
33
33
|
case "var_store":
|
|
34
|
-
return
|
|
34
|
+
return __storeVar(node.id);
|
|
35
35
|
case "array":
|
|
36
|
-
return
|
|
36
|
+
return __resolveArray(node, ctx);
|
|
37
37
|
case "obj":
|
|
38
|
-
return
|
|
38
|
+
return __resolveObject(node, ctx);
|
|
39
39
|
default:
|
|
40
40
|
return node.body;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
const
|
|
43
|
+
const __resolveArray = (node, ctx) => {
|
|
44
44
|
const res = [];
|
|
45
45
|
for (let n of node.body) {
|
|
46
|
-
res.push(
|
|
46
|
+
res.push(__resolveNode(n, ctx));
|
|
47
47
|
}
|
|
48
48
|
return res;
|
|
49
49
|
};
|
|
50
|
-
const
|
|
50
|
+
const __resolveObject = (node, ctx) => {
|
|
51
51
|
const res = {};
|
|
52
52
|
for (let [k, v] of node.body) {
|
|
53
|
-
res[k.type === "sym" ? k.id :
|
|
53
|
+
res[k.type === "sym" ? k.id : __resolveNode(k, ctx)] = __resolveNode(
|
|
54
54
|
v,
|
|
55
55
|
ctx
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
return res;
|
|
59
59
|
};
|
|
60
|
-
const
|
|
61
|
-
ctx[0].push(
|
|
60
|
+
const __loadVar = (node) => (ctx) => {
|
|
61
|
+
ctx[0].push(__resolveVar(node, ctx));
|
|
62
62
|
return ctx;
|
|
63
63
|
};
|
|
64
|
-
const
|
|
64
|
+
const __storeVar = (id) => (ctx) => {
|
|
65
65
|
pf.ensureStack(ctx[0], 1);
|
|
66
66
|
const v = ctx[2].__vars[id];
|
|
67
67
|
if (v === void 0) {
|
|
@@ -71,7 +71,7 @@ const storevar = (id) => (ctx) => {
|
|
|
71
71
|
}
|
|
72
72
|
return ctx;
|
|
73
73
|
};
|
|
74
|
-
const
|
|
74
|
+
const __beginvar = (id) => (ctx) => {
|
|
75
75
|
pf.ensureStack(ctx[0], 1);
|
|
76
76
|
const v = ctx[2].__vars[id];
|
|
77
77
|
if (v === void 0) {
|
|
@@ -81,7 +81,7 @@ const beginvar = (id) => (ctx) => {
|
|
|
81
81
|
}
|
|
82
82
|
return ctx;
|
|
83
83
|
};
|
|
84
|
-
const
|
|
84
|
+
const __endvar = (id) => (ctx) => {
|
|
85
85
|
const v = ctx[2].__vars[id];
|
|
86
86
|
if (v === void 0 || v.length === 0) {
|
|
87
87
|
illegalState(`can't end scope for var: ${id}`);
|
|
@@ -92,11 +92,11 @@ const endvar = (id) => (ctx) => {
|
|
|
92
92
|
}
|
|
93
93
|
return ctx;
|
|
94
94
|
};
|
|
95
|
-
const
|
|
95
|
+
const __visit = (node, ctx, state) => {
|
|
96
96
|
LOGGER.fine("visit", node.type, node, ctx[0].toString());
|
|
97
97
|
switch (node.type) {
|
|
98
98
|
case "sym":
|
|
99
|
-
return
|
|
99
|
+
return __visitSym(node, ctx, state);
|
|
100
100
|
case "number":
|
|
101
101
|
case "boolean":
|
|
102
102
|
case "string":
|
|
@@ -104,24 +104,24 @@ const visit = (node, ctx, state) => {
|
|
|
104
104
|
ctx[0].push(node.body);
|
|
105
105
|
return ctx;
|
|
106
106
|
case "array":
|
|
107
|
-
return
|
|
107
|
+
return __visitArray(node, ctx, state);
|
|
108
108
|
case "obj":
|
|
109
|
-
return
|
|
109
|
+
return __visitObject(node, ctx, state);
|
|
110
110
|
case "var_deref":
|
|
111
|
-
return
|
|
111
|
+
return __visitDeref(node, ctx, state);
|
|
112
112
|
case "var_store":
|
|
113
|
-
return
|
|
113
|
+
return __visitStore(node, ctx, state);
|
|
114
114
|
case "word":
|
|
115
|
-
return
|
|
115
|
+
return __visitWord(node, ctx, state);
|
|
116
116
|
case "stack_comment":
|
|
117
|
-
|
|
117
|
+
__visitStackComment(node, state);
|
|
118
118
|
default:
|
|
119
119
|
LOGGER.fine("skipping node...");
|
|
120
120
|
}
|
|
121
121
|
return ctx;
|
|
122
122
|
};
|
|
123
|
-
const
|
|
124
|
-
const w =
|
|
123
|
+
const __visitSym = (node, ctx, state) => {
|
|
124
|
+
const w = __resolveSym(node, ctx);
|
|
125
125
|
if (state.word) {
|
|
126
126
|
ctx[0].push(w);
|
|
127
127
|
return ctx;
|
|
@@ -129,40 +129,40 @@ const visitSym = (node, ctx, state) => {
|
|
|
129
129
|
return w(ctx);
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const store =
|
|
132
|
+
const __visitDeref = (node, ctx, state) => (ctx[0].push(state.word ? __loadVar(node) : __resolveVar(node, ctx)), ctx);
|
|
133
|
+
const __visitStore = (node, ctx, state) => {
|
|
134
|
+
const store = __storeVar(node.id);
|
|
135
135
|
return state.word ? (ctx[0].push(store), ctx) : store(ctx);
|
|
136
136
|
};
|
|
137
|
-
const
|
|
137
|
+
const __pushLocals = (fn, wctx, locals) => {
|
|
138
138
|
if (locals) {
|
|
139
139
|
for (let stack = wctx[0], i = locals.length; i-- > 0; ) {
|
|
140
140
|
stack.push(fn(locals[i]));
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
|
-
const
|
|
144
|
+
const __visitWord = (node, ctx, state) => {
|
|
145
145
|
const id = node.id;
|
|
146
146
|
if (state.word) {
|
|
147
147
|
illegalState(
|
|
148
|
-
`${
|
|
148
|
+
`${__nodeLoc(node)}: can't define words inside quotations (${id})`
|
|
149
149
|
);
|
|
150
150
|
}
|
|
151
151
|
let wctx = pf.ctx([], ctx[2]);
|
|
152
152
|
state.word = { name: id, loc: node.loc };
|
|
153
153
|
const locals = node.locals;
|
|
154
|
-
|
|
154
|
+
__pushLocals(__beginvar, wctx, locals);
|
|
155
155
|
for (let n of node.body) {
|
|
156
|
-
wctx =
|
|
156
|
+
wctx = __visit(n, wctx, state);
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
__pushLocals(__endvar, wctx, locals);
|
|
159
159
|
const w = pf.defWord(wctx[0]);
|
|
160
160
|
w.__meta = state.word;
|
|
161
161
|
ctx[2].__words[id] = w;
|
|
162
162
|
state.word = void 0;
|
|
163
163
|
return ctx;
|
|
164
164
|
};
|
|
165
|
-
const
|
|
165
|
+
const __visitStackComment = (node, state) => {
|
|
166
166
|
const word = state.word;
|
|
167
167
|
if (word && !word.stack) {
|
|
168
168
|
word.stack = node.body.join(" -- ");
|
|
@@ -172,15 +172,15 @@ const visitStackComment = (node, state) => {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
|
-
const
|
|
175
|
+
const __visitWithResolver = (resolve) => (node, ctx, state) => {
|
|
176
176
|
ctx[0].push(
|
|
177
177
|
state.word ? (_ctx) => (_ctx[0].push(resolve(node, _ctx)), _ctx) : resolve(node, ctx)
|
|
178
178
|
);
|
|
179
179
|
return ctx;
|
|
180
180
|
};
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
181
|
+
const __visitArray = __visitWithResolver(__resolveArray);
|
|
182
|
+
const __visitObject = __visitWithResolver(__resolveObject);
|
|
183
|
+
const __ensureEnv = (env) => {
|
|
184
184
|
env = env || {};
|
|
185
185
|
if (!env.__words) {
|
|
186
186
|
env.__words = {};
|
|
@@ -196,7 +196,7 @@ const ensureEnv = (env) => {
|
|
|
196
196
|
}
|
|
197
197
|
return env;
|
|
198
198
|
};
|
|
199
|
-
const
|
|
199
|
+
const __finalizeEnv = (ctx) => {
|
|
200
200
|
const env = ctx[2];
|
|
201
201
|
const vars = env.__vars;
|
|
202
202
|
delete env.__vars;
|
|
@@ -210,13 +210,13 @@ const finalizeEnv = (ctx) => {
|
|
|
210
210
|
return ctx;
|
|
211
211
|
};
|
|
212
212
|
const run = (src, env, stack = []) => {
|
|
213
|
-
let ctx = pf.ctx(stack,
|
|
213
|
+
let ctx = pf.ctx(stack, __ensureEnv(env));
|
|
214
214
|
const state = {};
|
|
215
215
|
try {
|
|
216
216
|
for (let node of parse(src)) {
|
|
217
|
-
ctx =
|
|
217
|
+
ctx = __visit(node, ctx, state);
|
|
218
218
|
}
|
|
219
|
-
return
|
|
219
|
+
return __finalizeEnv(ctx);
|
|
220
220
|
} catch (e) {
|
|
221
221
|
if (e instanceof SyntaxError) {
|
|
222
222
|
throw new Error(
|
|
@@ -229,11 +229,14 @@ const run = (src, env, stack = []) => {
|
|
|
229
229
|
};
|
|
230
230
|
const runU = (src, env, stack, n = 1) => pf.unwrap(run(src, env, stack), n);
|
|
231
231
|
const runE = (src, env, stack) => run(src, env, stack)[2];
|
|
232
|
-
const runWord = (id, env, stack = []) =>
|
|
233
|
-
const runWordU = (id, env, stack = [], n = 1) => pf.unwrap(
|
|
234
|
-
|
|
232
|
+
const runWord = (id, env, stack = []) => __finalizeEnv(env.__words[id](pf.ctx(stack, __ensureEnv(env))));
|
|
233
|
+
const runWordU = (id, env, stack = [], n = 1) => pf.unwrap(
|
|
234
|
+
__finalizeEnv(env.__words[id](pf.ctx(stack, __ensureEnv(env)))),
|
|
235
|
+
n
|
|
236
|
+
);
|
|
237
|
+
const runWordE = (id, env, stack = []) => __finalizeEnv(env.__words[id](pf.ctx(stack, __ensureEnv(env))))[2];
|
|
235
238
|
const ffi = (env, words) => {
|
|
236
|
-
env =
|
|
239
|
+
env = __ensureEnv(env);
|
|
237
240
|
env.__words = { ...env.__words, ...words };
|
|
238
241
|
return env;
|
|
239
242
|
};
|