@mark1russell7/vex-compiler 0.13.2 → 0.13.4
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/build/index.d.ts +14 -13
- package/build/index.d.ts.map +1 -1
- package/build/index.js +499 -123
- package/build/index.js.map +1 -1
- package/package.json +4 -4
- package/src/facts.ts +37 -10
- package/src/index.ts +1 -1
- package/src/module.ts +462 -111
- package/src/sheet-order.ts +11 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/vex-compiler",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.4",
|
|
5
5
|
"description": "The Vex compiler: generated JavaScript for Vex programs, at run time and at build time, with the results of the interpreter.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vex",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@mark1russell7/cue": "github:mark1russell7/cue",
|
|
46
|
-
"@mark1russell7/vex-domains": "0.13.
|
|
47
|
-
"@mark1russell7/vex-testkit": "0.13.
|
|
46
|
+
"@mark1russell7/vex-domains": "0.13.4",
|
|
47
|
+
"@mark1russell7/vex-testkit": "0.13.4",
|
|
48
48
|
"@types/node": "^26.6.4",
|
|
49
49
|
"fast-check": "^4.10.2",
|
|
50
50
|
"typescript": "^7.0.2",
|
|
51
51
|
"vitest": "^5.0.3"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@mark1russell7/vex": "0.13.
|
|
54
|
+
"@mark1russell7/vex": "0.13.4"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsdown",
|
package/src/facts.ts
CHANGED
|
@@ -46,15 +46,26 @@ export type Kind = PrimitiveKind | `domain:${string}`;
|
|
|
46
46
|
/** This function gives the kind of the values of a domain. */
|
|
47
47
|
export const kindOfDomain = (d: AnyDomain): Kind => d.primitive ?? `domain:${d.name}`;
|
|
48
48
|
|
|
49
|
-
/** This function gives a kind if it is a primitive type, else `undefined`. */
|
|
50
|
-
export const primitiveOf = (k: Kind | undefined): PrimitiveKind | undefined => (k === "number" || k === "string" || k === "boolean" ? k : undefined);
|
|
49
|
+
/** This function gives a kind if it is a primitive type, else `undefined`. A kind of a list is not a primitive type. */
|
|
50
|
+
export const primitiveOf = (k: Kind | ListKind | undefined): PrimitiveKind | undefined => (k === "number" || k === "string" || k === "boolean" ? k : undefined);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The kind of a list: the kind of its items, which can be a list too. A column of lists of a module of a sheet has such a
|
|
54
|
+
* kind (COMPILE.MODULE.SHEET.LIST). With `texts`, a key of an item can be a key of a list literal or of `fill`, not the
|
|
55
|
+
* key of a record. A field of the schema can have such a kind too (COMPILE.MODULE.LIST.INPUT).
|
|
56
|
+
*/
|
|
57
|
+
export interface ListKind {
|
|
58
|
+
readonly list: Kind | ListKind;
|
|
59
|
+
readonly texts?: boolean;
|
|
60
|
+
}
|
|
51
61
|
|
|
52
62
|
/**
|
|
53
63
|
* The kinds that a host declares (docs/COMPILER.md §3.2): the kind of each field of the records, and of each variable of
|
|
54
64
|
* the run. A read of a declared field or variable checks the kind. When the check fails, tier 1 evaluates the program.
|
|
65
|
+
* A field can hold a list (COMPILE.MODULE.LIST.INPUT). Tier 2 does not check the kind of such a field.
|
|
55
66
|
*/
|
|
56
67
|
export interface Schema {
|
|
57
|
-
readonly fields?: Readonly<Record<string, Kind>>;
|
|
68
|
+
readonly fields?: Readonly<Record<string, Kind | ListKind>>;
|
|
58
69
|
readonly vars?: Readonly<Record<string, Kind>>;
|
|
59
70
|
}
|
|
60
71
|
|
|
@@ -118,15 +129,22 @@ export type StaticSite =
|
|
|
118
129
|
|
|
119
130
|
const STATIC_FREE: StaticSite = Object.freeze({ t: "free" });
|
|
120
131
|
|
|
132
|
+
/** The positions of the lists of a site without lists. */
|
|
133
|
+
const NO_LISTS: ReadonlySet<number> = new Set();
|
|
134
|
+
|
|
121
135
|
/** This function gives the kind of the result of an op of a domain, if the op declares it. */
|
|
122
136
|
function returnsOf(domain: AnyDomain, kind: ReturnKind | undefined): Kind | undefined {
|
|
123
137
|
if (kind === "domain") return kindOfDomain(domain);
|
|
124
138
|
return kind === "any" ? undefined : kind;
|
|
125
139
|
}
|
|
126
140
|
|
|
127
|
-
/**
|
|
128
|
-
function
|
|
141
|
+
/**
|
|
142
|
+
* This function tells if an argument of a kind fits a parameter, or `undefined` if the kind of the argument is unknown.
|
|
143
|
+
* A list fits only `any`, and the test `is` of a domain without a primitive type can accept it (COMPILE.MODULE.LIST.ARG).
|
|
144
|
+
*/
|
|
145
|
+
function fits(domain: AnyDomain, param: ParamKind | undefined, arg: Kind | undefined, list: boolean): boolean | undefined {
|
|
129
146
|
if (param === undefined || param === "any") return true;
|
|
147
|
+
if (list) return param === "domain" && domain.primitive === undefined ? undefined : false;
|
|
130
148
|
if (arg === undefined) return undefined;
|
|
131
149
|
return arg === (param === "domain" ? kindOfDomain(domain) : param);
|
|
132
150
|
}
|
|
@@ -152,14 +170,19 @@ export interface Facts {
|
|
|
152
170
|
/**
|
|
153
171
|
* This function gives the op of a site with the kinds of its values, the receiver first. When the kinds do not decide
|
|
154
172
|
* the op, it gives `undefined`. Each domain before the op must declare a primitive type. Then the interpreter takes
|
|
155
|
-
* the same op at each run.
|
|
173
|
+
* the same op at each run. `lists` has the positions of the values that are lists, after the receiver.
|
|
156
174
|
*/
|
|
157
|
-
staticSite(name: string, kinds: readonly (Kind | undefined)[]): StaticSite | undefined;
|
|
175
|
+
staticSite(name: string, kinds: readonly (Kind | undefined)[], lists?: ReadonlySet<number>): StaticSite | undefined;
|
|
158
176
|
/**
|
|
159
177
|
* This function gives the index of the domain that checks a result of a kind. When no domain accepts such a value,
|
|
160
178
|
* it gives -1. When a domain without a primitive type comes first, it gives `undefined`.
|
|
161
179
|
*/
|
|
162
180
|
checkOf(kind: Kind): number | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* This function tells if no domain and no function of the host has the op `name`. Then the interpreter takes its own
|
|
183
|
+
* op for each receiver, for example `fill` (LIST.FILL).
|
|
184
|
+
*/
|
|
185
|
+
own(name: string): boolean;
|
|
163
186
|
}
|
|
164
187
|
|
|
165
188
|
/** This function gives the facts of a set of options. */
|
|
@@ -169,7 +192,7 @@ export function factsOf(options: Options): Facts {
|
|
|
169
192
|
const last = domains.findLastIndex((d) => d.valid !== undefined);
|
|
170
193
|
return {
|
|
171
194
|
checks: domains.slice(0, last + 1).map((d) => d.valid !== undefined),
|
|
172
|
-
staticSite(name, kinds) {
|
|
195
|
+
staticSite(name, kinds, lists = NO_LISTS) {
|
|
173
196
|
const [self, ...args] = kinds;
|
|
174
197
|
// A primitive value is not a list, so a list op name is an op of a domain here, as in the interpreter.
|
|
175
198
|
if (self === undefined) return undefined;
|
|
@@ -184,8 +207,9 @@ export function factsOf(options: Options): Facts {
|
|
|
184
207
|
continue;
|
|
185
208
|
}
|
|
186
209
|
// A lifted number goes through fromScalar: the site keeps the dispatch of the runtime.
|
|
187
|
-
|
|
188
|
-
|
|
210
|
+
// A list is not a number, so the interpreter does not lift it.
|
|
211
|
+
if (d.fromScalar !== undefined && args.some((a, j) => a !== "string" && a !== "boolean" && !lists.has(j + 1) && liftsAt(e.spec.liftScalar, j))) return undefined;
|
|
212
|
+
const ok = args.map((a, j) => fits(d, e.spec.params?.[j], a, lists.has(j + 1)));
|
|
189
213
|
if (ok.includes(undefined)) return undefined;
|
|
190
214
|
return { t: "fn", domain: i, bad: ok.includes(false), returns: returnsOf(d, e.spec.returns) };
|
|
191
215
|
}
|
|
@@ -199,6 +223,9 @@ export function factsOf(options: Options): Facts {
|
|
|
199
223
|
}
|
|
200
224
|
return -1;
|
|
201
225
|
},
|
|
226
|
+
own(name) {
|
|
227
|
+
return domains.every((d) => entryOf(d, name) === undefined) && !(fns !== undefined && Object.hasOwn(fns, name));
|
|
228
|
+
},
|
|
202
229
|
site(name, arity) {
|
|
203
230
|
// Without values, the interpreter takes no op of a domain. A list op can have a list as its receiver.
|
|
204
231
|
if (arity === 0 || isListOp(name)) return undefined;
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { generate, load, tiered, type Generated, type GenerateOptions, type Tier2, type TieredProgram, type TierStats } from "./tiers.ts";
|
|
5
5
|
export type { Schema } from "./facts.ts";
|
|
6
|
-
export { emitModule, emitSheetModule, type Emitted, type ModuleOptions, type SheetModuleOptions } from "./module.ts";
|
|
6
|
+
export { emitModule, emitSheetModule, type Emitted, type ListKind, type ModuleOptions, type SheetModuleOptions } from "./module.ts";
|
|
7
7
|
export { FALLBACK, createRuntime, type Fallback, type Runtime, type RuntimeOptions } from "./runtime.ts";
|
|
8
8
|
export type { LExpr, LoopProgram, LStmt, PrimOp, RuntimeFn } from "./loop.ts";
|