@harmoniclabs/pebble 0.1.0-dev6 → 0.1.0-dev7

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 (67) hide show
  1. package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +3 -1
  2. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +4 -0
  3. package/dist/IR/IRNodes/IRNative/index.d.ts +1 -0
  4. package/dist/IR/IRNodes/IRNative/index.js +1 -0
  5. package/dist/IR/toUPLC/CompilerOptions.d.ts +5 -0
  6. package/dist/IR/toUPLC/CompilerOptions.js +10 -1
  7. package/dist/IR/toUPLC/compileIRToUPLC.js +1 -1
  8. package/dist/IR/toUPLC/ctx/ToUplcCtx.js +2 -10
  9. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +0 -2
  10. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +2 -0
  11. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +23 -1
  12. package/dist/IR/utils/isClosedIRTerm.js +1 -1
  13. package/dist/IR/utils/positiveIntAsBytes.js +0 -4
  14. package/dist/compiler/AstCompiler/AstCompiler.d.ts +1 -0
  15. package/dist/compiler/AstCompiler/AstCompiler.js +39 -2
  16. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +1 -1
  17. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +4 -0
  18. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +7 -4
  19. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +0 -1
  20. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
  21. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +7 -7
  22. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +2 -1
  23. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +2 -1
  24. package/dist/compiler/AstCompiler/scope/AstScope.d.ts +1 -0
  25. package/dist/compiler/AstCompiler/scope/AstScope.js +5 -0
  26. package/dist/compiler/Compiler.js +4 -0
  27. package/dist/compiler/TirCompiler/compileTirProgram.js +2 -1
  28. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +4 -2
  29. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +42 -16
  30. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +2 -0
  31. package/dist/compiler/TirCompiler/expressify/expressify.js +24 -9
  32. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +23 -7
  33. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
  34. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +15 -8
  35. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -9
  36. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +15 -4
  37. package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
  38. package/dist/compiler/internalVar.d.ts +1 -1
  39. package/dist/compiler/internalVar.js +31 -24
  40. package/dist/compiler/io/CompilerIoApi.d.ts +1 -1
  41. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +1 -1
  42. package/dist/compiler/tir/expressions/TirCallExpr.js +1 -1
  43. package/dist/compiler/tir/expressions/TirCaseExpr.js +2 -0
  44. package/dist/compiler/tir/expressions/TirFromDataExpr.js +2 -2
  45. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +1 -1
  46. package/dist/compiler/tir/expressions/TirFuncExpr.js +1 -1
  47. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +2 -2
  48. package/dist/compiler/tir/expressions/TirLettedExpr.js +4 -6
  49. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +1 -0
  50. package/dist/compiler/tir/expressions/TirNativeFunc.js +9 -1
  51. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +1 -2
  52. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +0 -1
  53. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +9 -5
  54. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +3 -0
  55. package/dist/compiler/tir/expressions/ToIRTermCtx.js +8 -1
  56. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +1 -0
  57. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +6 -1
  58. package/dist/compiler/tir/program/TypedProgram.d.ts +2 -2
  59. package/dist/compiler/tir/program/stdScope/stdScope.js +9 -23
  60. package/dist/compiler/tir/statements/TirIfStmt.d.ts +0 -1
  61. package/dist/compiler/tir/statements/TirIfStmt.js +0 -3
  62. package/dist/parser/Parser.js +18 -2
  63. package/dist/parser/Precedence.js +1 -0
  64. package/dist/utils/array/keepSortedArrInplace.js +1 -0
  65. package/package.json +2 -1
  66. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
  67. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -39
@@ -85,6 +85,7 @@ export declare class TirNativeFunc implements ITirExpr {
85
85
  static _foldr(elemT: TirType, returnT: TirType): TirNativeFunc;
86
86
  static _foldl(elemT: TirType, returnT: TirType): TirNativeFunc;
87
87
  static _mkFindDataOptional(elems_t: TirType): TirNativeFunc;
88
+ static _findSopOptional(elems_t: TirType): TirNativeFunc;
88
89
  static _length(elemT: TirType): TirNativeFunc;
89
90
  static _some(elemT: TirType): TirNativeFunc;
90
91
  static _every(elemT: TirType): TirNativeFunc;
@@ -2,7 +2,7 @@ import { SourceRange } from "../../../ast/Source/SourceRange.js";
2
2
  import { IRNativeTag } from "../../../IR/IRNodes/IRNative/IRNativeTag.js";
3
3
  import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
4
4
  import { bool_t, bytes_t, data_t, int_t, void_t } from "../program/stdScope/stdScope.js";
5
- import { TirUnConstrDataResultT, TirPairDataT, TirIntT, TirBytesT, TirDataT, TirBoolT } from "../types/TirNativeType/index.js";
5
+ import { TirUnConstrDataResultT, TirPairDataT, TirIntT, TirBytesT, TirDataT, TirBoolT, TirSopOptT } from "../types/TirNativeType/index.js";
6
6
  import { TirFuncT } from "../types/TirNativeType/native/function.js";
7
7
  import { TirLinearMapT } from "../types/TirNativeType/native/linearMap.js";
8
8
  import { TirListT } from "../types/TirNativeType/native/list.js";
@@ -673,6 +673,14 @@ export class TirNativeFunc {
673
673
  new TirListT(elems_t)
674
674
  ], new TirDataOptT(elems_t)));
675
675
  }
676
+ static _findSopOptional(elems_t) {
677
+ return new TirNativeFunc(IRNativeTag._findSopOptional, new TirFuncT([
678
+ // predicate: (elemT) => bool
679
+ new TirFuncT([elems_t], bool_t),
680
+ // list<elemT>
681
+ new TirListT(elems_t)
682
+ ], new TirSopOptT(elems_t)));
683
+ }
676
684
  static _length(elemT) {
677
685
  return new TirNativeFunc(IRNativeTag._length, new TirFuncT([
678
686
  // list
@@ -32,7 +32,6 @@ export class TirPropAccessExpr {
32
32
  }
33
33
  get isConstant() { return false; }
34
34
  toIR(ctx) {
35
- console.log(this);
36
- throw new Error("property access cannot be translated to IR");
35
+ throw new Error("property access cannot be translated to IR (missed expressify). Expr: " + this.toString());
37
36
  }
38
37
  }
@@ -9,7 +9,6 @@ import { ToIRTermCtx } from "./ToIRTermCtx.js";
9
9
  export declare class TirVariableAccessExpr implements ITirExpr {
10
10
  readonly range: SourceRange;
11
11
  readonly resolvedValue: Readonly<ResolveValueResult>;
12
- private readonly _creationStack;
13
12
  get type(): TirType;
14
13
  constructor(resolvedValue: ResolveValueResult, range: SourceRange);
15
14
  toString(): string;
@@ -3,14 +3,12 @@ import { IRVar } from "../../../IR/IRNodes/IRVar.js";
3
3
  export class TirVariableAccessExpr {
4
4
  range;
5
5
  resolvedValue;
6
- _creationStack;
7
6
  get type() {
8
7
  return this.resolvedValue.variableInfos.type;
9
8
  }
10
9
  constructor(resolvedValue, range) {
11
10
  this.range = range;
12
11
  this.resolvedValue = Object.freeze(resolvedValue);
13
- this._creationStack = (new Error()).stack;
14
12
  }
15
13
  toString() {
16
14
  return this.varName;
@@ -21,7 +19,14 @@ export class TirVariableAccessExpr {
21
19
  return `${this.varName}`;
22
20
  }
23
21
  clone() {
24
- return new TirVariableAccessExpr(this.resolvedValue, this.range.clone());
22
+ return new TirVariableAccessExpr({
23
+ ...this.resolvedValue,
24
+ variableInfos: {
25
+ ...this.resolvedValue.variableInfos,
26
+ type: this.resolvedValue.variableInfos.type.clone()
27
+ },
28
+ // isDefinedOutsideFuncScope: this.resolvedValue.isDefinedOutsideFuncScope
29
+ }, this.range.clone());
25
30
  }
26
31
  get isConstant() { return false; }
27
32
  get varName() {
@@ -32,8 +37,7 @@ export class TirVariableAccessExpr {
32
37
  const ir = ctx.getVarAccessIR(this.varName);
33
38
  if (!(ir instanceof IRVar
34
39
  || ir instanceof IRSelfCall)) {
35
- console.log(this.resolvedValue);
36
- throw new Error(`variable '${this.varName}' is missing`);
40
+ throw new Error(`variable '${this.varName}' is missing in [${ctx.allVariables().join(", ")}]`);
37
41
  }
38
42
  return ir;
39
43
  }
@@ -2,9 +2,12 @@ import { IRVar } from "../../../IR/IRNodes/IRVar.js";
2
2
  import { IRSelfCall } from "../../../IR/IRNodes/IRSelfCall.js";
3
3
  export declare class ToIRTermCtx {
4
4
  readonly parent: ToIRTermCtx | undefined;
5
+ readonly _creationStack?: string | undefined;
5
6
  private readonly localVars;
6
7
  private _firstVariableIsRecursive;
8
+ _children: ToIRTermCtx[];
7
9
  constructor(parent: ToIRTermCtx | undefined);
10
+ localVariables(): string[];
8
11
  allVariables(): string[];
9
12
  static root(): ToIRTermCtx;
10
13
  newChild(): ToIRTermCtx;
@@ -3,19 +3,26 @@ import { IRSelfCall } from "../../../IR/IRNodes/IRSelfCall.js";
3
3
  const _1n = BigInt(1);
4
4
  export class ToIRTermCtx {
5
5
  parent;
6
+ _creationStack;
6
7
  localVars = new Map();
7
8
  _firstVariableIsRecursive = false;
9
+ _children = [];
8
10
  constructor(parent) {
9
11
  this.parent = parent;
12
+ this.parent?._children.push(this);
13
+ this._creationStack = new Error().stack;
10
14
  this.localVars = new Map();
11
15
  // DO NOT SET _parentDbn HERE
12
16
  // it must be a getter to reflect changes in parent
13
17
  // (parent dbn can change)
14
18
  this._firstVariableIsRecursive = false;
15
19
  }
20
+ localVariables() {
21
+ return [...this.localVars.keys()];
22
+ }
16
23
  allVariables() {
17
24
  return ((this.parent?.allVariables() ?? [])
18
- .concat([...this.localVars.keys()]));
25
+ .concat([...this.localVariables()]));
19
26
  }
20
27
  static root() {
21
28
  return new ToIRTermCtx(undefined);
@@ -105,6 +105,7 @@ export declare class TirAddExpr implements ITirBinaryExpr {
105
105
  left: TirExpr;
106
106
  right: TirExpr;
107
107
  readonly range: SourceRange;
108
+ private _creationStack;
108
109
  get type(): TirType;
109
110
  constructor(left: TirExpr, right: TirExpr, range: SourceRange);
110
111
  toString(): string;
@@ -277,15 +277,17 @@ export class TirNotEqualExpr {
277
277
  return deps;
278
278
  }
279
279
  }
280
+ let n_logs = 0;
280
281
  export class TirAddExpr {
281
282
  left;
282
283
  right;
283
284
  range;
285
+ _creationStack;
284
286
  get type() {
285
287
  const leftType = getUnaliased(this.left.type);
286
288
  if (leftType instanceof TirIntT
287
289
  || leftType instanceof TirBytesT)
288
- return this.type;
290
+ return leftType;
289
291
  throw new Error("invalid type for addition");
290
292
  }
291
293
  constructor(left, right, range) {
@@ -297,6 +299,9 @@ export class TirAddExpr {
297
299
  return `(${this.left.toString()} + ${this.right.toString()})`;
298
300
  }
299
301
  pretty(indent) {
302
+ n_logs++;
303
+ if (!(n_logs % 100))
304
+ console.log(this);
300
305
  const singleIndent = " ";
301
306
  const indent_base = singleIndent.repeat(indent);
302
307
  return `(${this.left.pretty(indent)} + ${this.right.pretty(indent)})`;
@@ -2,9 +2,9 @@ import { DiagnosticEmitter } from "../../../diagnostics/DiagnosticEmitter.js";
2
2
  import { DiagnosticMessage } from "../../../diagnostics/DiagnosticMessage.js";
3
3
  import { AstScope } from "../../AstCompiler/scope/AstScope.js";
4
4
  import { UidGenerator } from "../../internalVar.js";
5
- import { TirExpr } from "../expressions/TirExpr.js";
6
5
  import { TirFuncExpr } from "../expressions/TirFuncExpr.js";
7
6
  import { TirInlineClosedIR } from "../expressions/TirInlineClosedIR.js";
7
+ import { TirSimpleVarDecl } from "../statements/TirVarDecl/TirSimpleVarDecl.js";
8
8
  import { TirType } from "../types/TirType.js";
9
9
  import { StdTypes } from "./stdScope/StdTypes.js";
10
10
  export interface IGenericType {
@@ -17,7 +17,7 @@ export interface IGenericType {
17
17
  * TODO: support libraries
18
18
  */
19
19
  export declare class TypedProgram extends DiagnosticEmitter {
20
- readonly constants: Map<string, TirExpr>;
20
+ readonly constants: Map<string, TirSimpleVarDecl>;
21
21
  readonly functions: Map<string, TirFuncExpr | TirInlineClosedIR>;
22
22
  readonly types: Map<string, TirType>;
23
23
  private readonly genericTypes;
@@ -139,7 +139,7 @@ export function populatePreludeScope(program) {
139
139
  return { sop, data };
140
140
  }
141
141
  function defineMultiConstructorStruct(name, constrs, opts, methodsNames = new Map()) {
142
- const { sop, data } = mkMultiConstructorStruct(name, constrs);
142
+ const { sop, data } = mkMultiConstructorStruct(name, constrs, methodsNames);
143
143
  const sop_key = sop.toTirTypeKey();
144
144
  const data_key = data.toTirTypeKey();
145
145
  if (opts.sop)
@@ -166,6 +166,7 @@ export function populatePreludeScope(program) {
166
166
  id: txHash_t,
167
167
  index: int_t
168
168
  }, onlyData);
169
+ const getCredentialHashFuncName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "getCredentialHash";
169
170
  const { data: credential_t } = defineMultiConstructorStruct("Credential", {
170
171
  PubKey: {
171
172
  hash: pubKeyHash_t
@@ -173,28 +174,13 @@ export function populatePreludeScope(program) {
173
174
  Script: {
174
175
  hash: scriptHash_t
175
176
  }
176
- }, onlyData);
177
- // TODO:
178
- // understand how to describe function impls
179
- // const credential_t_impl = new TirInterfaceType(
180
- // undefined,
181
- // [],
182
- // []
183
- // )
184
- // credential_t_impl.methods.push(
185
- // new TirInterfaceMethod(
186
- // credential_t_impl,
187
- // "hash",
188
- // [],
189
- // hash28_t
190
- // )
191
- // );
192
- // credential_t.impls.push(
193
- // new TirInterfaceImpl(
194
- // credential_t,
195
- // credential_t_impl
196
- // )
197
- // );
177
+ }, onlyData, new Map([
178
+ [
179
+ "hash",
180
+ getCredentialHashFuncName
181
+ ],
182
+ ]));
183
+ preludeScope.program.functions.set(getCredentialHashFuncName, new TirInlineClosedIR(new TirFuncT([credential_t], hash28_t), (ctx) => IRNative._getCredentialsHash, SourceRange.unknown));
198
184
  const changeParams_t = _defineUnambigousAlias("ChangedParameters", map_int_data_t);
199
185
  const { data: rational_t } = defineSingleConstructorStruct("Rational", {
200
186
  numerator: int_t,
@@ -6,7 +6,6 @@ export declare class TirIfStmt implements ITirStmt {
6
6
  thenBranch: TirStmt;
7
7
  elseBranch: TirStmt | undefined;
8
8
  readonly range: SourceRange;
9
- private _creationStack?;
10
9
  constructor(condition: TirExpr, thenBranch: TirStmt, elseBranch: TirStmt | undefined, range: SourceRange);
11
10
  toString(): string;
12
11
  pretty(indent: number): string;
@@ -4,13 +4,11 @@ export class TirIfStmt {
4
4
  thenBranch;
5
5
  elseBranch;
6
6
  range;
7
- _creationStack;
8
7
  constructor(condition, thenBranch, elseBranch, range) {
9
8
  this.condition = condition;
10
9
  this.thenBranch = thenBranch;
11
10
  this.elseBranch = elseBranch;
12
11
  this.range = range;
13
- this._creationStack = new Error().stack;
14
12
  }
15
13
  toString() {
16
14
  return (`if( ${this.condition.toString()} ) ` +
@@ -29,7 +27,6 @@ export class TirIfStmt {
29
27
  (this.elseBranch ? ` else ${this.elseBranch.pretty(indent)}` : ""));
30
28
  }
31
29
  definitelyTerminates() {
32
- console.log(this._creationStack);
33
30
  return (this.thenBranch.definitelyTerminates()
34
31
  && (this.elseBranch?.definitelyTerminates() ?? false));
35
32
  }
@@ -1139,7 +1139,9 @@ export class Parser extends DiagnosticEmitter {
1139
1139
  // precedence climbing
1140
1140
  // see: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
1141
1141
  let nextPrecedence;
1142
- while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
1142
+ let prevState;
1143
+ outer_while: while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
1144
+ prevState = tn.mark();
1143
1145
  const token = tn.next();
1144
1146
  // DO NOT DIRECTLY RETURN FROM HERE
1145
1147
  // we need to loop to support right associative operators
@@ -1320,6 +1322,11 @@ export class Parser extends DiagnosticEmitter {
1320
1322
  expr = makeBinaryExpr(token, expr, next, tn.range(startPos, tn.pos));
1321
1323
  break;
1322
1324
  }
1325
+ // comma operator handled in caller (only valid in for statements)
1326
+ case Token.Comma: {
1327
+ tn.reset(prevState);
1328
+ break outer_while;
1329
+ }
1323
1330
  default: {
1324
1331
  return this.error(DiagnosticCode.Expression_expected, tn.range());
1325
1332
  }
@@ -2016,6 +2023,12 @@ export class Parser extends DiagnosticEmitter {
2016
2023
  case Token.Question_Question_Equals: {
2017
2024
  return this.error(DiagnosticCode.Not_implemented_0, tn.range(), "??=");
2018
2025
  }
2026
+ case Token.Plus_Plus: {
2027
+ return makeAssignmentStmt(varIdentifier, Token.Plus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
2028
+ }
2029
+ case Token.Minus_Minus: {
2030
+ return makeAssignmentStmt(varIdentifier, Token.Minus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
2031
+ }
2019
2032
  default: {
2020
2033
  return this.error(DiagnosticCode._0_expected, tn.range(), "=");
2021
2034
  }
@@ -2180,8 +2193,11 @@ export class Parser extends DiagnosticEmitter {
2180
2193
  return this.error(DiagnosticCode.Invalid_for_statement_update, update.range);
2181
2194
  updates.push(update);
2182
2195
  } while (tn.skip(Token.Comma)); // comma expression (allowed only in for update part)
2183
- if (!tn.skip(Token.CloseParen))
2196
+ if (!tn.skip(Token.CloseParen)) {
2197
+ const next = tn.peek();
2198
+ console.error('next token after for updates:', Token[next]);
2184
2199
  return this.error(DiagnosticCode._0_expected, tn.range(), ")");
2200
+ }
2185
2201
  }
2186
2202
  const body = this.parseStatement();
2187
2203
  if (!body)
@@ -89,6 +89,7 @@ export function determinePrecedence(kind) {
89
89
  case Token.Plus_Plus:
90
90
  case Token.Minus_Minus: return Precedence.UnaryPostfix;
91
91
  case Token.Dot:
92
+ case Token.Exclamation_Dot:
92
93
  case Token.Question_Dot:
93
94
  case Token.OpenBracket:
94
95
  case Token.Exclamation: return Precedence.MemberAccess;
@@ -21,6 +21,7 @@ export function keepSortedStrArrInplace(target, source) {
21
21
  target.length = i + 1; // truncate target to current index
22
22
  return target; // no more elements to keep
23
23
  }
24
+ continue; // element is in source, check next without removing this
24
25
  }
25
26
  // not equal, remove the element
26
27
  target.splice(i, 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble",
3
- "version": "0.1.0-dev6",
3
+ "version": "0.1.0-dev7",
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",
@@ -20,6 +20,7 @@
20
20
  "build-and-replace": "npm run build && cp -r ./dist ../pebble-cli/node_modules/@harmoniclabs/pebble",
21
21
  "genDiagnosticMessages": "node ./scripts/genDiagnosticMessages.js",
22
22
  "test": "jest",
23
+ "test-dbg": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
23
24
  "test:debug": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
24
25
  "clear-jest": "jest --clearCache",
25
26
  "test-watch": "jest --watchman",
@@ -1,5 +0,0 @@
1
- import { TirHoistedExpr } from "../../tir/expressions/TirHoistedExpr.js";
2
- import { TirNativeFunc } from "../../tir/expressions/TirNativeFunc.js";
3
- import { TypedProgram } from "../../tir/program/TypedProgram.js";
4
- import { DepsNode } from "./deps/DepsNode.js";
5
- export declare function _compileHoistedDeps(program: TypedProgram, hoistedMap: Map<string, TirHoistedExpr | TirNativeFunc>, deps: string[], depsStack: DepsNode): void;
@@ -1,39 +0,0 @@
1
- import { TirHoistedExpr } from "../../tir/expressions/TirHoistedExpr.js";
2
- import { ExpressifyCtx } from "../expressify/ExpressifyCtx.js";
3
- import { expressifyVars } from "../expressify/expressifyVars.js";
4
- export function _compileHoistedDeps(program, hoistedMap, deps, depsStack) {
5
- let depName;
6
- if (deps.some(dep => depsStack.includes(dep)))
7
- throw new Error("Circular dependency in hoisted expressions NOT YET IMPLEMENTED");
8
- while (depName = deps.pop()) {
9
- const funcDecl = program.functions.get(depName);
10
- if (funcDecl) {
11
- _compileHoistedDeps(program, hoistedMap, funcDecl.deps(), depsStack.getNext(depName));
12
- /*
13
- const funcExpr = funcDecl instanceof TirInlineClosedIR ? funcDecl : expressify(
14
- funcDecl,
15
- undefined, // loopReplacements
16
- program,
17
- new ExpressifyCtx(
18
- undefined,
19
- funcDecl.returnType,
20
- program,
21
- hoistedMap
22
- )
23
- );
24
- //*/
25
- const hoistedExpr = new TirHoistedExpr(depName, funcDecl);
26
- hoistedMap.set(depName, hoistedExpr);
27
- continue;
28
- }
29
- const constDecl = program.constants.get(depName);
30
- if (constDecl) {
31
- _compileHoistedDeps(program, hoistedMap, constDecl.deps(), depsStack.getNext(depName));
32
- const expr = expressifyVars(new ExpressifyCtx(undefined, constDecl.type, program, hoistedMap), constDecl);
33
- const hoistedExpr = new TirHoistedExpr(depName, expr);
34
- hoistedMap.set(depName, hoistedExpr);
35
- continue;
36
- }
37
- throw new Error(`Hoisted dependency "${depName}" not found in program`);
38
- }
39
- }