@thi.ng/pointfree-lang 2.2.36 → 2.2.38

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:18Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
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
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 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.73 KB
100
+ Package sizes (brotli'd, pre-treeshake): ESM: 4.71 KB
101
101
 
102
102
  ## Dependencies
103
103
 
package/cli.js CHANGED
@@ -98,8 +98,7 @@ Usage: pointfree [opts] [file]
98
98
  paramWidth: 24
99
99
  },
100
100
  ctx: async (ctx) => {
101
- if (ctx.opts.debug)
102
- ctx.logger.level = LogLevel.DEBUG;
101
+ if (ctx.opts.debug) ctx.logger.level = LogLevel.DEBUG;
103
102
  return ctx;
104
103
  }
105
104
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/pointfree-lang",
3
- "version": "2.2.36",
3
+ "version": "2.2.38",
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://github.com/thi-ng/umbrella/tree/develop/packages/pointfree-lang#readme",
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.1",
44
- "@thi.ng/args": "^2.3.32",
45
- "@thi.ng/bench": "^3.5.5",
46
- "@thi.ng/errors": "^2.5.6",
47
- "@thi.ng/file-io": "^2.1.1",
48
- "@thi.ng/logger": "^3.0.11",
49
- "@thi.ng/pointfree": "^3.1.81"
43
+ "@thi.ng/api": "^8.11.3",
44
+ "@thi.ng/args": "^2.3.34",
45
+ "@thi.ng/bench": "^3.5.7",
46
+ "@thi.ng/errors": "^2.5.8",
47
+ "@thi.ng/file-io": "^2.1.3",
48
+ "@thi.ng/logger": "^3.0.13",
49
+ "@thi.ng/pointfree": "^3.1.83"
50
50
  },
51
51
  "devDependencies": {
52
- "@microsoft/api-extractor": "^7.43.0",
53
- "esbuild": "^0.20.2",
52
+ "@microsoft/api-extractor": "^7.47.0",
53
+ "esbuild": "^0.21.5",
54
54
  "pegjs": "0.11.0-master.b7b87ea",
55
- "typedoc": "^0.25.12",
56
- "typescript": "^5.4.3"
55
+ "typedoc": "^0.25.13",
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": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
109
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\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 nodeLoc = (node) => node.loc ? `line ${node.loc.join(":")} -` : "";
8
- const resolveSym = (node, ctx) => {
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(`${nodeLoc(node)} unknown symbol: ${id}`);
12
+ illegalArgs(`${__nodeLoc(node)} unknown symbol: ${id}`);
13
13
  }
14
14
  return w;
15
15
  };
16
- const resolveVar = (node, ctx) => {
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(`${nodeLoc(node)} unknown var: ${id}`);
20
+ illegalArgs(`${__nodeLoc(node)} unknown var: ${id}`);
21
21
  }
22
22
  if (!v.length) {
23
- illegalState(`${nodeLoc(node)} missing bindings for var: ${id}`);
23
+ illegalState(`${__nodeLoc(node)} missing bindings for var: ${id}`);
24
24
  }
25
25
  return v[0];
26
26
  };
27
- const resolveNode = (node, ctx) => {
27
+ const __resolveNode = (node, ctx) => {
28
28
  switch (node.type) {
29
29
  case "sym":
30
- return resolveSym(node, ctx);
30
+ return __resolveSym(node, ctx);
31
31
  case "var_deref":
32
- return resolveVar(node, ctx);
32
+ return __resolveVar(node, ctx);
33
33
  case "var_store":
34
- return storevar(node.id);
34
+ return __storeVar(node.id);
35
35
  case "array":
36
- return resolveArray(node, ctx);
36
+ return __resolveArray(node, ctx);
37
37
  case "obj":
38
- return resolveObject(node, ctx);
38
+ return __resolveObject(node, ctx);
39
39
  default:
40
40
  return node.body;
41
41
  }
42
42
  };
43
- const resolveArray = (node, ctx) => {
43
+ const __resolveArray = (node, ctx) => {
44
44
  const res = [];
45
45
  for (let n of node.body) {
46
- res.push(resolveNode(n, ctx));
46
+ res.push(__resolveNode(n, ctx));
47
47
  }
48
48
  return res;
49
49
  };
50
- const resolveObject = (node, ctx) => {
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 : resolveNode(k, ctx)] = resolveNode(
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 loadvar = (node) => (ctx) => {
61
- ctx[0].push(resolveVar(node, ctx));
60
+ const __loadVar = (node) => (ctx) => {
61
+ ctx[0].push(__resolveVar(node, ctx));
62
62
  return ctx;
63
63
  };
64
- const storevar = (id) => (ctx) => {
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 beginvar = (id) => (ctx) => {
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 endvar = (id) => (ctx) => {
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 visit = (node, ctx, state) => {
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 visitSym(node, ctx, state);
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 visitArray(node, ctx, state);
107
+ return __visitArray(node, ctx, state);
108
108
  case "obj":
109
- return visitObject(node, ctx, state);
109
+ return __visitObject(node, ctx, state);
110
110
  case "var_deref":
111
- return visitDeref(node, ctx, state);
111
+ return __visitDeref(node, ctx, state);
112
112
  case "var_store":
113
- return visitStore(node, ctx, state);
113
+ return __visitStore(node, ctx, state);
114
114
  case "word":
115
- return visitWord(node, ctx, state);
115
+ return __visitWord(node, ctx, state);
116
116
  case "stack_comment":
117
- visitStackComment(node, state);
117
+ __visitStackComment(node, state);
118
118
  default:
119
119
  LOGGER.fine("skipping node...");
120
120
  }
121
121
  return ctx;
122
122
  };
123
- const visitSym = (node, ctx, state) => {
124
- const w = resolveSym(node, ctx);
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 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);
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 pushLocals = (fn, wctx, locals) => {
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 visitWord = (node, ctx, state) => {
144
+ const __visitWord = (node, ctx, state) => {
145
145
  const id = node.id;
146
146
  if (state.word) {
147
147
  illegalState(
148
- `${nodeLoc(node)}: can't define words inside quotations (${id})`
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
- pushLocals(beginvar, wctx, locals);
154
+ __pushLocals(__beginvar, wctx, locals);
155
155
  for (let n of node.body) {
156
- wctx = visit(n, wctx, state);
156
+ wctx = __visit(n, wctx, state);
157
157
  }
158
- pushLocals(endvar, wctx, locals);
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 visitStackComment = (node, state) => {
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 visitWithResolver = (resolve) => (node, ctx, state) => {
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 visitArray = visitWithResolver(resolveArray);
182
- const visitObject = visitWithResolver(resolveObject);
183
- const ensureEnv = (env) => {
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 finalizeEnv = (ctx) => {
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, ensureEnv(env));
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 = visit(node, ctx, state);
217
+ ctx = __visit(node, ctx, state);
218
218
  }
219
- return finalizeEnv(ctx);
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 = []) => finalizeEnv(env.__words[id](pf.ctx(stack, ensureEnv(env))));
233
- const runWordU = (id, env, stack = [], n = 1) => pf.unwrap(finalizeEnv(env.__words[id](pf.ctx(stack, ensureEnv(env)))), n);
234
- const runWordE = (id, env, stack = []) => finalizeEnv(env.__words[id](pf.ctx(stack, ensureEnv(env))))[2];
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 = ensureEnv(env);
239
+ env = __ensureEnv(env);
237
240
  env.__words = { ...env.__words, ...words };
238
241
  return env;
239
242
  };