@harmoniclabs/pebble 0.3.3 → 0.3.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.
@@ -32,8 +32,30 @@ export class ToUplcCtx {
32
32
  return ctx._parentDbn + idx + 1;
33
33
  }
34
34
  getVarAccessDbn(sym) {
35
- const declDbn = this.getVarDeclDbn(sym);
36
- return this.dbn - declDbn;
35
+ // Resolve the de Bruijn index LEXICALLY, against this access's own
36
+ // scope chain — i.e. the number of binders between the access and the
37
+ // NEAREST (innermost) enclosing binder of `sym`.
38
+ //
39
+ // The previous implementation looked `sym` up in a single tree-wide
40
+ // `ctxMap` (last writer wins). That is incorrect whenever the same
41
+ // binder symbol appears in sibling scopes — which happens routinely
42
+ // because cloned IR reuses its binder symbols (e.g. the shared
43
+ // `const { tx } = context` destructuring duplicated across a
44
+ // contract's purpose-match cases). An access in one branch would then
45
+ // resolve against another branch's binder, yielding a wrong and
46
+ // sometimes NEGATIVE index ("invalid deBruijn index").
47
+ let offset = 0;
48
+ let ctx = this;
49
+ while (ctx) {
50
+ const vars = ctx._variables;
51
+ for (let i = vars.length - 1; i >= 0; i--) {
52
+ if (vars[i] === sym)
53
+ return offset + (vars.length - 1 - i);
54
+ }
55
+ offset += vars.length;
56
+ ctx = ctx.parent;
57
+ }
58
+ throw new Error("Variable not found in scope chain: " + String(sym.description));
37
59
  }
38
60
  toJson() {
39
61
  let obj = {};
@@ -1 +1 @@
1
- export declare const COMPILER_VERSION = "0.3.3";
1
+ export declare const COMPILER_VERSION = "0.3.4";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated by scripts/genVersion.js. Do not edit.
2
- export const COMPILER_VERSION = "0.3.3";
2
+ export const COMPILER_VERSION = "0.3.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "A simple, yet rock solid, functional language with an imperative bias, targeting UPLC",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",