@harmoniclabs/pebble 0.1.3-dev7 → 0.1.3-dev8

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.
@@ -630,8 +630,19 @@ export class AstCompiler extends DiagnosticEmitter {
630
630
  // define on source top level scope
631
631
  if (isValue)
632
632
  srcImportsScope.variables.set(declName, importedSymbols.variables.get(declName));
633
- if (isFunction)
634
- srcImportsScope.functions.set(declName, importedSymbols.functions.get(declName));
633
+ if (isFunction) {
634
+ const tirFuncName = importedSymbols.functions.get(declName);
635
+ srcImportsScope.functions.set(declName, tirFuncName);
636
+ // also define as a value so that `resolveValue` can find it
637
+ // (mirrors what `_collectTopLevelFuncDeclSig` does for local functions)
638
+ const funcExpr = this.program.functions.get(tirFuncName);
639
+ if (funcExpr)
640
+ srcImportsScope.defineValue({
641
+ isConstant: true,
642
+ name: declName,
643
+ type: funcExpr.type,
644
+ });
645
+ }
635
646
  if (isType)
636
647
  srcImportsScope.types.set(declName, importedSymbols.types.get(declName));
637
648
  if (isInterface)
@@ -1,3 +1,4 @@
1
+ import { TirFuncExpr } from "../tir/expressions/TirFuncExpr.js";
1
2
  import { ToIRTermCtx } from "../tir/expressions/ToIRTermCtx.js";
2
3
  import { expressify } from "./expressify/expressify.js";
3
4
  /**
@@ -12,10 +13,18 @@ export function compileTypedProgram(cfg, tirProgram) {
12
13
  tirProgram,
13
14
  );
14
15
  //*/
16
+ // expressify all program functions (including imported ones)
17
+ // so they are ready for IR conversion when referenced via TirHoistedExpr.
18
+ // each TirFuncExpr may appear under multiple keys (ast name + tir name),
19
+ // so we use a Set to avoid expressifying the same function twice.
20
+ const expressified = new Set();
21
+ for (const func of tirProgram.functions.values()) {
22
+ if (func instanceof TirFuncExpr && !expressified.has(func)) {
23
+ expressify(func, undefined, tirProgram);
24
+ expressified.add(func);
25
+ }
26
+ }
15
27
  const mainFuncExpr = tirProgram.getMainOrThrow();
16
- // console.log("main func:", mainFuncExpr.pretty() );
17
- void expressify(mainFuncExpr, undefined, // loopReplacements
18
- tirProgram);
19
28
  // console.log("main func expressified:", mainFuncExpr.pretty() );
20
29
  return mainFuncExpr.toIR(ToIRTermCtx.root());
21
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble",
3
- "version": "0.1.3-dev7",
3
+ "version": "0.1.3-dev8",
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",