@dallaylaen/ski-interpreter 2.4.0 → 2.4.1

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.
@@ -67,7 +67,8 @@ function prepareWrapper(label) {
67
67
  // src/expr.ts
68
68
  var DEFAULTS = {
69
69
  max: 1e3,
70
- maxArgs: 32
70
+ maxArgs: 32,
71
+ maxSize: 1e6
71
72
  };
72
73
  var ORDER = {
73
74
  "leftmost-outermost": "LO",
@@ -89,6 +90,7 @@ var Expr = class _Expr {
89
90
  static {
90
91
  this.native = native;
91
92
  }
93
+ // rough estimate of the number of nodes in the tree
92
94
  /**
93
95
  *
94
96
  * @desc Define properties of the term based on user supplied options and/or inference results.
@@ -288,9 +290,12 @@ var Expr = class _Expr {
288
290
  */
289
291
  infer(options = {}) {
290
292
  const skipNames = {};
293
+ const skipSkip = /* @__PURE__ */ new Set();
291
294
  this.traverse((e) => {
292
- if (e instanceof Named)
295
+ if (e instanceof Named && !skipSkip.has(e))
293
296
  skipNames[e.name] = true;
297
+ if (e instanceof Lambda)
298
+ skipSkip.add(e.arg);
294
299
  return void 0;
295
300
  });
296
301
  return this._infer({
@@ -513,6 +518,8 @@ var Expr = class _Expr {
513
518
  final = true;
514
519
  break;
515
520
  }
521
+ if ((next.expr.size ?? 1) > (opt.maxSize ?? DEFAULTS.maxSize))
522
+ break;
516
523
  steps += next.steps;
517
524
  expr = next.expr;
518
525
  }
@@ -531,7 +538,7 @@ var Expr = class _Expr {
531
538
  let steps = 0;
532
539
  let expr = this;
533
540
  let final = false;
534
- while (steps < max) {
541
+ while (steps < max && (expr.size ?? 1) < (options.maxSize ?? DEFAULTS.maxSize)) {
535
542
  const next = expr.step();
536
543
  if (!next.changed)
537
544
  final = true;
@@ -752,6 +759,7 @@ var App = class _App extends Expr {
752
759
  super();
753
760
  this.arg = arg;
754
761
  this.fun = fun;
762
+ this.size = (fun.size ?? 1) + (arg.size ?? 1);
755
763
  }
756
764
  /** @property {boolean} [final] */
757
765
  _traverse_descend(options, change) {
@@ -924,6 +932,7 @@ var Lambda = class _Lambda extends Expr {
924
932
  this.arg = local;
925
933
  this.impl = impl.subst(arg, local) ?? impl;
926
934
  this.arity = 1;
935
+ this.size = (impl.size ?? 1) + 1;
927
936
  }
928
937
  invoke(arg) {
929
938
  return this.impl.subst(this.arg, arg) ?? this.impl;
@@ -1010,6 +1019,7 @@ var Alias = class extends Named {
1010
1019
  this._setup(options);
1011
1020
  this.terminal = options.terminal ?? this.props?.proper;
1012
1021
  this.invoke = waitn(impl, this.arity ?? 0);
1022
+ this.size = impl.size;
1013
1023
  }
1014
1024
  /**
1015
1025
  * @property {boolean} [outdated] - whether the alias is outdated