aontu 0.40.0 → 0.41.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.
Files changed (57) hide show
  1. package/dist/aontu.js +7 -0
  2. package/dist/aontu.js.map +1 -1
  3. package/dist/ctx.d.ts +9 -0
  4. package/dist/ctx.js +54 -8
  5. package/dist/ctx.js.map +1 -1
  6. package/dist/err.js +36 -15
  7. package/dist/err.js.map +1 -1
  8. package/dist/tsconfig.tsbuildinfo +1 -1
  9. package/dist/unify.js +85 -47
  10. package/dist/unify.js.map +1 -1
  11. package/dist/val/ConjunctVal.js +2 -2
  12. package/dist/val/ConjunctVal.js.map +1 -1
  13. package/dist/val/DisjunctVal.js +36 -10
  14. package/dist/val/DisjunctVal.js.map +1 -1
  15. package/dist/val/ExpectVal.js +2 -2
  16. package/dist/val/ExpectVal.js.map +1 -1
  17. package/dist/val/FuncBaseVal.js +2 -2
  18. package/dist/val/FuncBaseVal.js.map +1 -1
  19. package/dist/val/IntegerVal.js +1 -1
  20. package/dist/val/IntegerVal.js.map +1 -1
  21. package/dist/val/ListVal.js +7 -3
  22. package/dist/val/ListVal.js.map +1 -1
  23. package/dist/val/MapVal.js +20 -12
  24. package/dist/val/MapVal.js.map +1 -1
  25. package/dist/val/NilVal.d.ts +2 -1
  26. package/dist/val/NilVal.js +15 -1
  27. package/dist/val/NilVal.js.map +1 -1
  28. package/dist/val/OpBaseVal.js +1 -1
  29. package/dist/val/OpBaseVal.js.map +1 -1
  30. package/dist/val/PrefVal.js +3 -3
  31. package/dist/val/PrefVal.js.map +1 -1
  32. package/dist/val/RefVal.js +1 -1
  33. package/dist/val/RefVal.js.map +1 -1
  34. package/dist/val/Val.d.ts +2 -0
  35. package/dist/val/Val.js +88 -43
  36. package/dist/val/Val.js.map +1 -1
  37. package/dist/val/VarVal.js +1 -1
  38. package/dist/val/VarVal.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/aontu.ts +9 -1
  41. package/src/ctx.ts +79 -8
  42. package/src/err.ts +37 -17
  43. package/src/tsconfig.json +2 -1
  44. package/src/unify.ts +86 -57
  45. package/src/val/ConjunctVal.ts +2 -2
  46. package/src/val/DisjunctVal.ts +37 -11
  47. package/src/val/ExpectVal.ts +2 -2
  48. package/src/val/FuncBaseVal.ts +2 -2
  49. package/src/val/IntegerVal.ts +1 -1
  50. package/src/val/ListVal.ts +7 -3
  51. package/src/val/MapVal.ts +20 -12
  52. package/src/val/NilVal.ts +17 -1
  53. package/src/val/OpBaseVal.ts +1 -1
  54. package/src/val/PrefVal.ts +3 -3
  55. package/src/val/RefVal.ts +1 -1
  56. package/src/val/Val.ts +139 -48
  57. package/src/val/VarVal.ts +1 -1
package/src/val/Val.ts CHANGED
@@ -58,47 +58,50 @@ let ID = 1000
58
58
 
59
59
 
60
60
  abstract class Val {
61
- isVal = true
62
-
63
- isTop = false
64
- isNil = false
65
- isMap = false
66
- isList = false
67
- isScalar = false
68
- isScalarKind = false
69
- isRef = false
70
- isPref = false
71
- isVar = false
72
- isBag = false
73
- isNumber = false
74
- isInteger = false
75
- isString = false
76
- isBoolean = false
77
- isConjunct = false
78
- isDisjunct = false
79
- isJunction = false
61
+ // Type-discriminator flags: defaults live on Val.prototype (see
62
+ // bottom of this file). Each subclass overrides only its own
63
+ // discriminator(s), so a plain Val instance writes zero flags.
64
+ declare isVal: boolean
65
+
66
+ declare isTop: boolean
67
+ declare isNil: boolean
68
+ declare isMap: boolean
69
+ declare isList: boolean
70
+ declare isScalar: boolean
71
+ declare isScalarKind: boolean
72
+ declare isRef: boolean
73
+ declare isPref: boolean
74
+ declare isVar: boolean
75
+ declare isBag: boolean
76
+ declare isNumber: boolean
77
+ declare isInteger: boolean
78
+ declare isString: boolean
79
+ declare isBoolean: boolean
80
+ declare isConjunct: boolean
81
+ declare isDisjunct: boolean
82
+ declare isJunction: boolean
80
83
 
81
84
  // Conjunct sort order. Lower values sort first in norm().
82
- cjo = 99999
83
-
84
- isOp = false
85
- isPlusOp = false
86
-
87
- isFunc = false
88
- isCloseFunc = false
89
- isCopyFunc = false
90
- isHideFunc = false
91
- isMoveFunc = false
92
- isKeyFunc = false
93
- isLowerFunc = false
94
- isOpenFunc = false
95
- isPathFunc = false
96
- isPrefFunc = false
97
- isSuperFunc = false
98
- isTypeFunc = false
99
- isUpperFunc = false
100
-
101
- isGenable = false
85
+ declare cjo: number
86
+
87
+ declare isOp: boolean
88
+ declare isPlusOp: boolean
89
+
90
+ declare isFunc: boolean
91
+ declare isCloseFunc: boolean
92
+ declare isCopyFunc: boolean
93
+ declare isHideFunc: boolean
94
+ declare isMoveFunc: boolean
95
+ declare isKeyFunc: boolean
96
+ declare isLowerFunc: boolean
97
+ declare isOpenFunc: boolean
98
+ declare isPathFunc: boolean
99
+ declare isPrefFunc: boolean
100
+ declare isSuperFunc: boolean
101
+ declare isTypeFunc: boolean
102
+ declare isUpperFunc: boolean
103
+
104
+ declare isGenable: boolean
102
105
 
103
106
  id: number
104
107
  dc: number = 0
@@ -151,7 +154,10 @@ abstract class Val {
151
154
  ; (this.peg as any)[SPREAD] = spread
152
155
  }
153
156
 
154
- this.path = ctx?.path || []
157
+ // spec.path takes precedence over ctx.path: lets callers (notably
158
+ // Val.clone) specify the target path without paying for a full
159
+ // ctx.clone just to carry it.
160
+ this.path = spec?.path ?? ctx?.path ?? []
155
161
 
156
162
  // TODO: make this work
157
163
  // this.id = spec?.id ?? (ctx ? ++ctx.vc : ++ID)
@@ -180,27 +186,26 @@ abstract class Val {
180
186
 
181
187
 
182
188
  clone(ctx: AontuContext, spec?: ValSpec): Val {
183
- let cloneCtx
184
-
185
189
  let path = spec?.path
186
190
  if (null == path) {
187
191
  let cut = this.path.indexOf('&')
188
192
  cut = -1 < cut ? cut + 1 : ctx.path.length
189
193
  path = ctx.path.concat(this.path.slice(cut))
190
194
  }
191
- // console.log('CLONE', path, this.canon)
192
- // console.trace()
193
-
194
- cloneCtx = ctx.clone({ path })
195
195
 
196
+ // Carry the target path via the spec instead of cloning ctx just
197
+ // to hold it: the Val constructor now reads spec.path first. This
198
+ // saves ~120k ctx.clone calls (two Object.create each) on a
199
+ // foo-sdk-sized model.
196
200
  let fullspec = {
197
201
  peg: this.peg,
198
202
  mark: { type: this.mark.type, hide: this.mark.hide },
199
- ...(spec ?? {})
203
+ ...(spec ?? {}),
204
+ path,
200
205
  }
201
206
 
202
207
  let out = new (this as any)
203
- .constructor(fullspec, cloneCtx)
208
+ .constructor(fullspec, ctx)
204
209
 
205
210
  out.dc = this.done ? DONE : out.dc
206
211
 
@@ -224,6 +229,42 @@ abstract class Val {
224
229
  }
225
230
 
226
231
 
232
+ // True if this Val's unification result depends on its own `path`
233
+ // — i.e. the tree contains a RefVal, KeyFuncVal, PathFuncVal,
234
+ // MoveFuncVal, or SuperFuncVal. Used by MapVal/ListVal.spreadClone
235
+ // to share the spread constraint across keys when it's safe.
236
+ // Lazy + cached: the answer is a function of the Val's immutable
237
+ // structure, so we compute once per Val.
238
+ _isPathDependent?: boolean
239
+ get isPathDependent(): boolean {
240
+ if (this._isPathDependent !== undefined) return this._isPathDependent
241
+ let dep =
242
+ this.isRef || this.isKeyFunc || this.isPathFunc ||
243
+ this.isMoveFunc || this.isSuperFunc
244
+ if (!dep) {
245
+ const peg = this.peg
246
+ if (Array.isArray(peg)) {
247
+ for (let i = 0; i < peg.length; i++) {
248
+ const c = peg[i]
249
+ if (c && c.isVal && c.isPathDependent) { dep = true; break }
250
+ }
251
+ }
252
+ else if (peg != null && typeof peg === 'object') {
253
+ for (const k in peg) {
254
+ const c = (peg as any)[k]
255
+ if (c && c.isVal && c.isPathDependent) { dep = true; break }
256
+ }
257
+ }
258
+ if (!dep) {
259
+ const spreadCj = (this as any).spread?.cj as Val | undefined
260
+ if (spreadCj && spreadCj.isPathDependent) dep = true
261
+ }
262
+ }
263
+ this._isPathDependent = dep
264
+ return dep
265
+ }
266
+
267
+
227
268
  place(v: Val) {
228
269
  v.site.row = this.site.row
229
270
  v.site.col = this.site.col
@@ -311,6 +352,56 @@ abstract class Val {
311
352
  }
312
353
 
313
354
 
355
+ // Prototype-level defaults for Val's type-discriminator flags.
356
+ // Keeping these on the prototype (instead of per-instance class-field
357
+ // initializers) removes ~35 property writes from every Val construction
358
+ // and eliminates the corresponding hidden-class transitions. Subclasses
359
+ // override only the flags that differ, via their own class-field
360
+ // initializers (e.g. `MapVal.isMap = true`).
361
+ Object.assign(Val.prototype, {
362
+ isVal: true,
363
+
364
+ isTop: false,
365
+ isNil: false,
366
+ isMap: false,
367
+ isList: false,
368
+ isScalar: false,
369
+ isScalarKind: false,
370
+ isRef: false,
371
+ isPref: false,
372
+ isVar: false,
373
+ isBag: false,
374
+ isNumber: false,
375
+ isInteger: false,
376
+ isString: false,
377
+ isBoolean: false,
378
+ isConjunct: false,
379
+ isDisjunct: false,
380
+ isJunction: false,
381
+
382
+ cjo: 99999,
383
+
384
+ isOp: false,
385
+ isPlusOp: false,
386
+
387
+ isFunc: false,
388
+ isCloseFunc: false,
389
+ isCopyFunc: false,
390
+ isHideFunc: false,
391
+ isMoveFunc: false,
392
+ isKeyFunc: false,
393
+ isLowerFunc: false,
394
+ isOpenFunc: false,
395
+ isPathFunc: false,
396
+ isPrefFunc: false,
397
+ isSuperFunc: false,
398
+ isTypeFunc: false,
399
+ isUpperFunc: false,
400
+
401
+ isGenable: false,
402
+ })
403
+
404
+
314
405
  function inspectpeg(peg: any, d: number) {
315
406
  const indent = ' '.repeat(d)
316
407
  return pretty(Array.isArray(peg) ?
package/src/val/VarVal.ts CHANGED
@@ -67,7 +67,7 @@ class VarVal extends FeatureVal {
67
67
  nameVal = this.peg
68
68
  }
69
69
  else {
70
- nameVal = this.peg.unify(peer, ctx.clone({ explain: ec(te, 'PEG') }))
70
+ nameVal = this.peg.unify(peer, te ? ctx.clone({ explain: ec(te, 'PEG') }) : ctx)
71
71
  }
72
72
  }
73
73
  else {