@harmoniclabs/pebble 0.2.0 → 0.3.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.
- package/dist/IR/CompilationCtx.d.ts +40 -0
- package/dist/IR/CompilationCtx.js +54 -0
- package/dist/IR/IRHash.d.ts +23 -2
- package/dist/IR/IRHash.js +10 -60
- package/dist/IR/IRNodes/IRConst.js +22 -2
- package/dist/IR/IRNodes/IRHoisted.d.ts +0 -1
- package/dist/IR/IRNodes/IRHoisted.js +4 -6
- package/dist/IR/IRNodes/IRLetted.d.ts +0 -1
- package/dist/IR/IRNodes/IRLetted.js +4 -6
- package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +22 -2
- package/dist/IR/IRNodes/IRNative/IRNativeTag.js +26 -2
- package/dist/IR/IRNodes/IRNative/index.d.ts +16 -1
- package/dist/IR/IRNodes/IRNative/index.js +27 -2
- package/dist/IR/IRNodes/utils/hashVarSym.d.ts +0 -1
- package/dist/IR/IRNodes/utils/hashVarSym.js +27 -33
- package/dist/IR/toUPLC/CompilerOptions.d.ts +12 -0
- package/dist/IR/toUPLC/CompilerOptions.js +14 -9
- package/dist/IR/toUPLC/compileIRToUPLC.js +39 -3
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseLetBindingsAndReturnRoot.d.ts +23 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseLetBindingsAndReturnRoot.js +263 -0
- package/dist/IR/toUPLC/subRoutines/introduceCaseForDualHeadTailAndReturnRoot.d.ts +35 -0
- package/dist/IR/toUPLC/subRoutines/introduceCaseForDualHeadTailAndReturnRoot.js +169 -0
- package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.d.ts +0 -1
- package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +6 -6
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +2 -3
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +106 -65
- package/dist/IR/toUPLC/subRoutines/rewriteHeadTailInCaseConsAndReturnRoot.d.ts +30 -0
- package/dist/IR/toUPLC/subRoutines/rewriteHeadTailInCaseConsAndReturnRoot.js +95 -0
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +36 -5
- package/dist/IR/toUPLC/subRoutines/rewriteToCaseOverConstAndReturnRoot.d.ts +35 -0
- package/dist/IR/toUPLC/subRoutines/rewriteToCaseOverConstAndReturnRoot.js +169 -0
- package/dist/IR/tree_utils/_ir_caseList.d.ts +15 -0
- package/dist/IR/tree_utils/_ir_caseList.js +19 -0
- package/dist/ast/nodes/statements/declarations/StructDecl.d.ts +16 -2
- package/dist/ast/nodes/statements/declarations/StructDecl.js +15 -1
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +1 -0
- package/dist/compiler/AstCompiler/AstCompiler.js +41 -4
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +3 -3
- package/dist/compiler/AstCompiler/internal/exprs/_compileCaseExpr.js +31 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileIsExpr.js +12 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +36 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +13 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileAddExpr.js +18 -5
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileEqualExpr.js +3 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanEqualExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanEqualExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileMultExpr.js +24 -6
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileNotEqualExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileSubExpr.js +16 -5
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +33 -20
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +11 -0
- package/dist/compiler/Compiler.js +20 -27
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +1 -1
- package/dist/compiler/TirCompiler/expressify/expressify.js +30 -2
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +45 -7
- package/dist/compiler/TirCompiler/expressify/expressifyVars.d.ts +0 -1
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +23 -8
- package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +9 -0
- package/dist/compiler/tir/expressions/TirCaseExpr.js +144 -122
- package/dist/compiler/tir/expressions/TirElemAccessExpr.js +2 -2
- package/dist/compiler/tir/expressions/TirFromDataExpr.js +102 -67
- package/dist/compiler/tir/expressions/TirIsExpr.js +14 -1
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +1 -2
- package/dist/compiler/tir/expressions/TirNativeFunc.js +2 -12
- package/dist/compiler/tir/expressions/TirToDataExpr.js +3 -0
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +10 -0
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +2 -3
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +1 -4
- package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +20 -3
- package/dist/compiler/tir/expressions/ToIRTermCtx.js +48 -3
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +2 -2
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +45 -8
- package/dist/compiler/tir/expressions/litteral/TirLitEnumMemberExpr.d.ts +19 -0
- package/dist/compiler/tir/expressions/litteral/TirLitEnumMemberExpr.js +24 -0
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +2 -0
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +4 -1
- package/dist/compiler/tir/program/stdScope/populateStdNamespace.js +49 -4
- package/dist/compiler/tir/program/stdScope/prelude/preludeTypesSrc.js +35 -2
- package/dist/compiler/tir/program/stdScope/stdScope.d.ts +7 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +83 -40
- package/dist/compiler/tir/types/TirEnumType.d.ts +21 -0
- package/dist/compiler/tir/types/TirEnumType.js +36 -0
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.d.ts +4 -2
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +5 -0
- package/dist/compiler/tir/types/TirNativeType/native/array.d.ts +16 -0
- package/dist/compiler/tir/types/TirNativeType/native/array.js +38 -0
- package/dist/compiler/tir/types/TirNativeType/native/index.d.ts +2 -0
- package/dist/compiler/tir/types/TirNativeType/native/index.js +2 -0
- package/dist/compiler/tir/types/TirNativeType/native/value.d.ts +18 -0
- package/dist/compiler/tir/types/TirNativeType/native/value.js +17 -0
- package/dist/compiler/tir/types/TirStructType.js +6 -1
- package/dist/compiler/tir/types/TirType.d.ts +3 -2
- package/dist/compiler/tir/types/TirType.js +4 -1
- package/dist/compiler/tir/types/utils/canAssignTo.js +28 -0
- package/dist/compiler/tir/types/utils/canCastTo.js +14 -1
- package/dist/compiler/tir/types/utils/getDeconstructableType.d.ts +2 -1
- package/dist/compiler/tir/types/utils/getDeconstructableType.js +2 -0
- package/dist/compiler/tir/types/utils/inferTypeArgs.js +4 -0
- package/dist/compiler/tir/types/utils/normalizeEnumToInt.d.ts +10 -0
- package/dist/compiler/tir/types/utils/normalizeEnumToInt.js +17 -0
- package/dist/compiler/tir/types/utils/substituteTypeParams.js +5 -0
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +5 -0
- package/dist/diagnostics/diagnosticMessages.generated.js +10 -0
- package/dist/parser/Parser.js +29 -13
- package/dist/tokenizer/Token.d.ts +8 -7
- package/dist/tokenizer/Token.js +8 -7
- package/dist/tokenizer/utils/tokenFromKeyword.js +2 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +3 -3
- package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +0 -3
- package/dist/IR/tree_utils/_ir_lazyChooseList.js +0 -7
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { IRApp, _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
2
2
|
import { IRCase } from "../../../IR/IRNodes/IRCase.js";
|
|
3
3
|
import { IRConst } from "../../../IR/IRNodes/IRConst.js";
|
|
4
|
-
import { IRDelayed } from "../../../IR/IRNodes/IRDelayed.js";
|
|
5
4
|
import { IRError } from "../../../IR/IRNodes/IRError.js";
|
|
6
5
|
import { IRFunc } from "../../../IR/IRNodes/IRFunc.js";
|
|
6
|
+
import { IRLetted } from "../../../IR/IRNodes/IRLetted.js";
|
|
7
7
|
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
8
8
|
import { IRVar } from "../../../IR/IRNodes/IRVar.js";
|
|
9
|
-
import {
|
|
10
|
-
import { _ir_let, _ir_let_sym } from "../../../IR/tree_utils/_ir_let.js";
|
|
9
|
+
import { _ir_let_sym } from "../../../IR/tree_utils/_ir_let.js";
|
|
11
10
|
import { filterSortedStrArrInplace } from "../../../utils/array/filterSortedStrArrInplace.js";
|
|
12
11
|
import { mergeSortedStrArrInplace } from "../../../utils/array/mergeSortedStrArrInplace.js";
|
|
13
12
|
import { TirSimpleVarDecl } from "../statements/TirVarDecl/TirSimpleVarDecl.js";
|
|
14
13
|
import { TirDataOptT } from "../types/TirNativeType/native/Optional/data.js";
|
|
15
14
|
import { TirSopOptT } from "../types/TirNativeType/native/Optional/sop.js";
|
|
16
15
|
import { TirDataStructType, TirSoPStructType } from "../types/TirStructType.js";
|
|
17
|
-
import {
|
|
16
|
+
import { TirEnumType } from "../types/TirEnumType.js";
|
|
18
17
|
import { getUnaliased } from "../types/utils/getUnaliased.js";
|
|
19
18
|
import { _inlineFromData } from "./TirFromDataExpr.js";
|
|
20
19
|
export class TirCaseExpr {
|
|
@@ -73,13 +72,83 @@ export class TirCaseExpr {
|
|
|
73
72
|
if (matchExprType instanceof TirSoPStructType
|
|
74
73
|
|| matchExprType instanceof TirSopOptT)
|
|
75
74
|
return this._sopStructToIR(matchExprType, ctx);
|
|
75
|
+
if (matchExprType instanceof TirDataStructType
|
|
76
|
+
&& matchExprType.untagged)
|
|
77
|
+
return this._untaggedDataStructToIR(matchExprType, ctx);
|
|
76
78
|
if (matchExprType instanceof TirDataStructType
|
|
77
79
|
|| matchExprType instanceof TirDataOptT)
|
|
78
80
|
return this._dataStructToIR(matchExprType, ctx);
|
|
81
|
+
if (matchExprType instanceof TirEnumType)
|
|
82
|
+
return this._enumToIR(matchExprType, ctx);
|
|
79
83
|
console.error(this);
|
|
80
84
|
throw new Error("`case` expressions are only supported on Sum-of-Products or Data Struct types; got: "
|
|
81
85
|
+ this.matchExpr.type.toString());
|
|
82
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Lowers a `case` over an untagged data struct (single constructor;
|
|
89
|
+
* runtime form is `listData(fields)`). No constructor dispatch is
|
|
90
|
+
* needed — there's only one possible ctor — so the lowering is just
|
|
91
|
+
* "find the matching arm (or wildcard), extract any bound fields, run
|
|
92
|
+
* the body".
|
|
93
|
+
*/
|
|
94
|
+
_untaggedDataStructToIR(matchExprType, ctx) {
|
|
95
|
+
if (matchExprType.constructors.length !== 1) {
|
|
96
|
+
throw new Error("untagged data struct must have exactly one constructor");
|
|
97
|
+
}
|
|
98
|
+
const ctor = matchExprType.constructors[0];
|
|
99
|
+
const wildcardBodyIR = this.wildcardCase?.body.toIR(ctx) ?? new IRError();
|
|
100
|
+
const matchedArm = this.cases.find(c => c.pattern.constrName === ctor.name);
|
|
101
|
+
if (!matchedArm) {
|
|
102
|
+
// no matching arm: just run the wildcard body (the scrutinee is
|
|
103
|
+
// evaluated for side-effects via `unListData` only if any field
|
|
104
|
+
// would have been bound; here, nothing).
|
|
105
|
+
return wildcardBodyIR;
|
|
106
|
+
}
|
|
107
|
+
const pattern = matchedArm.pattern;
|
|
108
|
+
const usedFields = ctor.fields
|
|
109
|
+
.map((f, idx) => ({ name: f.name, type: f.type, idx }))
|
|
110
|
+
.filter(f => pattern.fields.has(f.name));
|
|
111
|
+
// 0 bound fields → just run the body; no extraction.
|
|
112
|
+
if (usedFields.length === 0)
|
|
113
|
+
return matchedArm.body.toIR(ctx);
|
|
114
|
+
// fields-list = unListData(scrutinee), bound once and reused via
|
|
115
|
+
// IRLetted so the let-handling pass elides or shares as appropriate.
|
|
116
|
+
const fieldsListLetted = new IRLetted(Symbol("untaggedFields"), _ir_apps(IRNative.unListData, this.matchExpr.toIR(ctx)));
|
|
117
|
+
const branchCtx = ctx.newChild();
|
|
118
|
+
// bind each used field with a let in declaration order.
|
|
119
|
+
// sort by ctor field index so earlier extractions don't need to
|
|
120
|
+
// re-drop past already-bound fields.
|
|
121
|
+
usedFields.sort((a, b) => a.idx - b.idx);
|
|
122
|
+
const bindings = usedFields.map(f => {
|
|
123
|
+
const varDecl = pattern.fields.get(f.name);
|
|
124
|
+
if (!(varDecl instanceof TirSimpleVarDecl))
|
|
125
|
+
throw new Error("case pattern not expressified.");
|
|
126
|
+
const sym = branchCtx.defineVar(varDecl.name);
|
|
127
|
+
return {
|
|
128
|
+
sym,
|
|
129
|
+
extract: _inlineFromData(f.type, _ir_apps(IRNative.headList, _ir_apps(IRNative.dropList, IRConst.int(f.idx), fieldsListLetted.clone())))
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
// build nested let-bindings around the body
|
|
133
|
+
let result = matchedArm.body.toIR(branchCtx);
|
|
134
|
+
for (let i = bindings.length - 1; i >= 0; i--) {
|
|
135
|
+
const { sym, extract } = bindings[i];
|
|
136
|
+
result = _ir_let_sym(sym, extract, result);
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
_enumToIR(enumType, ctx) {
|
|
141
|
+
const wildcardBodyIR = this.wildcardCase?.body.toIR(ctx) ?? new IRError();
|
|
142
|
+
const branches = enumType.members.map(memberName => {
|
|
143
|
+
const branch = this.cases.find(c => c.pattern.constrName === memberName);
|
|
144
|
+
return branch ? branch.body.toIR(ctx) : wildcardBodyIR;
|
|
145
|
+
});
|
|
146
|
+
while (branches.length > 0 && branches[branches.length - 1] instanceof IRError)
|
|
147
|
+
branches.pop();
|
|
148
|
+
return branches.length > 0
|
|
149
|
+
? new IRCase(this.matchExpr.toIR(ctx), branches)
|
|
150
|
+
: new IRError();
|
|
151
|
+
}
|
|
83
152
|
_sopStructToIR(matchExprType, ctx) {
|
|
84
153
|
if (matchExprType instanceof TirSopOptT) {
|
|
85
154
|
const wildcardBodyIR = this.wildcardCase?.body.toIR(ctx) ?? new IRError();
|
|
@@ -172,134 +241,87 @@ export class TirCaseExpr {
|
|
|
172
241
|
return branches.length > 0 ? new IRCase(this.matchExpr.toIR(ctx), branches) : new IRError(); // all branches fail, so the whole expression fails
|
|
173
242
|
}
|
|
174
243
|
_dataStructToIR(matchExprType, ctx) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
)),
|
|
197
|
-
// then Just{ value }
|
|
198
|
-
someBranchIR(unConstrMatchSym),
|
|
199
|
-
// else None
|
|
200
|
-
noneBranchIR));
|
|
201
|
-
}
|
|
202
|
-
// TirDataStructType
|
|
203
|
-
const stmtCtx = ctx.newChild();
|
|
204
|
-
const unConstrStructSym = stmtCtx.pushUnusedVar("unconstrStruct"); // unconstrStruct
|
|
205
|
-
const isConstrIdxSym = stmtCtx.pushUnusedVar("isConstrIdx"); // isConstrIdx
|
|
206
|
-
const noVarsWildcardBodyIR = (this.wildcardCase?.body.toIR(stmtCtx)
|
|
207
|
-
?? new IRError());
|
|
208
|
-
const delayedNoVarWildcardBodyIR = new IRDelayed(noVarsWildcardBodyIR);
|
|
209
|
-
let ifThenElseMatchingStatements = noVarsWildcardBodyIR;
|
|
244
|
+
// TirDataOptT extends TirDataStructType (constructors Some{value}, None{}),
|
|
245
|
+
// so the same logic handles it.
|
|
246
|
+
//
|
|
247
|
+
// Lowering structure (UPLC `Case` accepts pair / int scrutinees
|
|
248
|
+
// as untagged constructors):
|
|
249
|
+
//
|
|
250
|
+
// Case (unConstrData scrutinee) [
|
|
251
|
+
// \idxSym fieldsSym ->
|
|
252
|
+
// Case idxSym [body_0, body_1, ..., body_(maxParent)]
|
|
253
|
+
// ]
|
|
254
|
+
//
|
|
255
|
+
// - The outer `Case` over the `pair(int, list<data>)` returned by
|
|
256
|
+
// `unConstrData` extracts both halves via a single 2-arg branch
|
|
257
|
+
// (pair is treated as `constr 0 [fst, snd]`).
|
|
258
|
+
// - The inner `Case` over `idxSym` dispatches by tag in O(1) —
|
|
259
|
+
// no `equalsInteger` chain, no `lazyIfThenElse`.
|
|
260
|
+
// - Each inner branch takes 0 args (an int N is treated as
|
|
261
|
+
// `constr N []`). The branch body extracts fields lazily from
|
|
262
|
+
// `fieldsSym` via deferred access on `thenCtx`, wrapped in
|
|
263
|
+
// `IRLetted` so the letted-handling pass dedups, inlines or
|
|
264
|
+
// elides as appropriate.
|
|
210
265
|
if (this.cases.some(({ pattern }) => matchExprType.constructors.findIndex(ctor => ctor.name === pattern.constrName) < 0))
|
|
211
266
|
throw new Error("case expression includes unknown constructor.");
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
267
|
+
const stmtCtx = ctx.newChild();
|
|
268
|
+
const wildcardBodyIR = this.wildcardCase?.body.toIR(stmtCtx) ?? new IRError();
|
|
269
|
+
// outer destructuring binders — symbols allocated up-front so
|
|
270
|
+
// per-arm deferred accesses (closures) reference the same syms
|
|
271
|
+
const idxSym = Symbol("ctorIdx");
|
|
272
|
+
const fieldsListSym = Symbol("fieldsList");
|
|
273
|
+
// The runtime value's ctor tag spans all parent indices known to
|
|
274
|
+
// this type — not just the indices that appear as arm patterns.
|
|
275
|
+
// Size the inner-Case branch array to cover all of them and fill
|
|
276
|
+
// missing slots with the wildcard.
|
|
277
|
+
const armsByParentIdx = new Map();
|
|
278
|
+
// TirDataOptT extends TirDataStructType, so both have parentCtorIdx
|
|
279
|
+
const allParentIdxs = matchExprType.constructors.map((_, i) => matchExprType.parentCtorIdx(i));
|
|
280
|
+
let maxParentIdx = allParentIdxs.reduce((m, x) => x > m ? x : m, -1);
|
|
281
|
+
for (const matchCase of this.cases) {
|
|
282
|
+
const { pattern, body } = matchCase;
|
|
219
283
|
const ctorIdx = matchExprType.constructors.findIndex(ctor => ctor.name === pattern.constrName);
|
|
220
|
-
if (ctorIdx < 0)
|
|
221
|
-
throw new Error("case expression includes unknown constructor."); // unreachable
|
|
222
284
|
const ctor = matchExprType.constructors[ctorIdx];
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
body.toIR(stmtCtx),
|
|
235
|
-
// else
|
|
236
|
-
ifThenElseMatchingStatements);
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
function indexOfField(fieldName) {
|
|
240
|
-
const idx = ctor.fields.findIndex(f => f.name === fieldName);
|
|
241
|
-
if (idx < 0)
|
|
242
|
-
throw new Error("case pattern not expressified.");
|
|
243
|
-
return idx;
|
|
244
|
-
}
|
|
245
|
-
if (usedFieldsCtorNames.length === 1) {
|
|
246
|
-
const thenCtx = stmtCtx.newChild();
|
|
247
|
-
const fName = usedFieldsCtorNames[0];
|
|
285
|
+
const parentCtorIdx = matchExprType instanceof TirDataStructType
|
|
286
|
+
? matchExprType.parentCtorIdx(ctorIdx)
|
|
287
|
+
: ctorIdx;
|
|
288
|
+
// bind each pattern-named field as a deferred access on
|
|
289
|
+
// `fieldsListSym`. Each access produces an `IRLetted`
|
|
290
|
+
// wrapping `_inlineFromData(type, headList(_dropList(idx, fields)))`.
|
|
291
|
+
const armCtx = stmtCtx.newChild();
|
|
292
|
+
const usedFieldsCtorNames = ctor.fields
|
|
293
|
+
.map(f => f.name)
|
|
294
|
+
.filter(fName => pattern.fields.has(fName));
|
|
295
|
+
for (const fName of usedFieldsCtorNames) {
|
|
248
296
|
const patternVarDecl = pattern.fields.get(fName);
|
|
249
297
|
if (!(patternVarDecl instanceof TirSimpleVarDecl))
|
|
250
298
|
throw new Error("case pattern not expressified.");
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
_ir_apps(// fileds as data list
|
|
254
|
-
IRNative.sndPair, new IRVar(unConstrStructSym) // unconstrStruct
|
|
255
|
-
)))), body.toIR(thenCtx));
|
|
256
|
-
ifThenElseMatchingStatements = _ir_lazyIfThenElse(
|
|
257
|
-
// condition (compare against the PARENT ctor index — the
|
|
258
|
-
// value's runtime tag is unaffected by narrowing)
|
|
259
|
-
_ir_apps(new IRVar(isConstrIdxSym), // isConstrIdx
|
|
260
|
-
IRConst.int(matchExprType instanceof TirDataStructType
|
|
261
|
-
? matchExprType.parentCtorIdx(ctorIdx)
|
|
262
|
-
: ctorIdx)),
|
|
263
|
-
// then
|
|
264
|
-
thenCase,
|
|
265
|
-
// else
|
|
266
|
-
ifThenElseMatchingStatements);
|
|
267
|
-
continue;
|
|
268
|
-
} // single field used edge case
|
|
269
|
-
// multiple fields used
|
|
270
|
-
const thenCtx = stmtCtx.newChild();
|
|
271
|
-
const fieldsAsDataList = thenCtx.pushUnusedVar(); // fileds as data list
|
|
272
|
-
const sortedUsedFields = [...usedFieldsCtorNames].sort((a, b) => indexOfField(a) - indexOfField(b));
|
|
273
|
-
const introducedVars = new Array(sortedUsedFields.length);
|
|
274
|
-
for (let fIdx = 0; fIdx < sortedUsedFields.length; fIdx++) {
|
|
275
|
-
const fName = sortedUsedFields[fIdx];
|
|
276
|
-
const patternVarDecl = pattern.fields.get(fName);
|
|
277
|
-
if (!(patternVarDecl instanceof TirSimpleVarDecl))
|
|
299
|
+
const fieldIdx = ctor.fields.findIndex(f => f.name === fName);
|
|
300
|
+
if (fieldIdx < 0)
|
|
278
301
|
throw new Error("case pattern not expressified.");
|
|
279
|
-
|
|
302
|
+
const fieldType = patternVarDecl.type;
|
|
303
|
+
armCtx.defineDeferredAccess(patternVarDecl.name, () => new IRLetted(Symbol(`${ctor.name}_${fName}`), _inlineFromData(fieldType, _ir_apps(IRNative.headList, _ir_apps(IRNative.dropList, IRConst.int(fieldIdx), new IRVar(fieldsListSym))))));
|
|
280
304
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
// condition (compare against the PARENT ctor index — the
|
|
289
|
-
// value's runtime tag is unaffected by narrowing)
|
|
290
|
-
_ir_apps(new IRVar(isConstrIdxSym), // isConstrIdx
|
|
291
|
-
IRConst.int(matchExprType instanceof TirDataStructType
|
|
292
|
-
? matchExprType.parentCtorIdx(ctorIdx)
|
|
293
|
-
: ctorIdx)),
|
|
294
|
-
// then
|
|
295
|
-
thenCase,
|
|
296
|
-
// else
|
|
297
|
-
ifThenElseMatchingStatements);
|
|
305
|
+
armsByParentIdx.set(parentCtorIdx, body.toIR(armCtx));
|
|
306
|
+
}
|
|
307
|
+
// build inner-Case branches sized to `maxParentIdx + 1`, filling
|
|
308
|
+
// missing slots with the wildcard body
|
|
309
|
+
const innerBranches = new Array(maxParentIdx + 1);
|
|
310
|
+
for (let i = 0; i < innerBranches.length; i++) {
|
|
311
|
+
innerBranches[i] = armsByParentIdx.get(i) ?? wildcardBodyIR;
|
|
298
312
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
313
|
+
// trailing `IRError` branches can be omitted — the CEK machine
|
|
314
|
+
// fails naturally if no branch exists for the runtime tag
|
|
315
|
+
while (innerBranches.length > 0
|
|
316
|
+
&& innerBranches[innerBranches.length - 1] instanceof IRError)
|
|
317
|
+
innerBranches.pop();
|
|
318
|
+
const innerCase = innerBranches.length > 0
|
|
319
|
+
? new IRCase(new IRVar(idxSym), innerBranches)
|
|
320
|
+
: new IRError();
|
|
321
|
+
// outer Case over the pair: single branch destructures (idx, fields)
|
|
322
|
+
return new IRCase(_ir_apps(IRNative.unConstrData, this.matchExpr.toIR(ctx)), [
|
|
323
|
+
new IRFunc([idxSym, fieldsListSym], innerCase)
|
|
324
|
+
]);
|
|
303
325
|
}
|
|
304
326
|
}
|
|
305
327
|
export class TirCaseMatcher {
|
|
@@ -44,8 +44,8 @@ export class TirElemAccessExpr {
|
|
|
44
44
|
const result = Machine.evalSimple(compileIRToUPLC(irIndex));
|
|
45
45
|
if ((result instanceof CEKConst)
|
|
46
46
|
&& (typeof result.value === "number" || typeof result.value === "bigint"))
|
|
47
|
-
return _ir_apps(IRNative.headList, _ir_apps(IRNative.
|
|
47
|
+
return _ir_apps(IRNative.headList, _ir_apps(IRNative.dropList, IRConst.int(result.value), irArr));
|
|
48
48
|
}
|
|
49
|
-
return _ir_apps(IRNative.headList, _ir_apps(IRNative.
|
|
49
|
+
return _ir_apps(IRNative.headList, _ir_apps(IRNative.dropList, irIndex, irArr));
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { _ir_apps
|
|
1
|
+
import { _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
2
|
+
import { IRCase } from "../../../IR/IRNodes/IRCase.js";
|
|
2
3
|
import { IRConst } from "../../../IR/IRNodes/IRConst.js";
|
|
3
4
|
import { IRConstr } from "../../../IR/IRNodes/IRConstr.js";
|
|
4
|
-
import { IRDelayed } from "../../../IR/IRNodes/IRDelayed.js";
|
|
5
|
-
import { IRForced } from "../../../IR/IRNodes/IRForced.js";
|
|
6
5
|
import { IRFunc } from "../../../IR/IRNodes/IRFunc.js";
|
|
7
6
|
import { IRHoisted } from "../../../IR/IRNodes/IRHoisted.js";
|
|
8
7
|
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
9
8
|
import { IRVar } from "../../../IR/IRNodes/IRVar.js";
|
|
10
|
-
import { _ir_let } from "../../../IR/tree_utils/_ir_let.js";
|
|
11
9
|
import { TirBoolT } from "../types/TirNativeType/native/bool.js";
|
|
12
10
|
import { TirBytesT } from "../types/TirNativeType/native/bytes.js";
|
|
13
11
|
import { TirDataT } from "../types/TirNativeType/native/data.js";
|
|
@@ -19,7 +17,10 @@ import { TirDataOptT } from "../types/TirNativeType/native/Optional/data.js";
|
|
|
19
17
|
import { TirSopOptT } from "../types/TirNativeType/native/Optional/sop.js";
|
|
20
18
|
import { TirStringT } from "../types/TirNativeType/native/string.js";
|
|
21
19
|
import { TirVoidT } from "../types/TirNativeType/native/void.js";
|
|
20
|
+
import { TirValueT } from "../types/TirNativeType/native/value.js";
|
|
21
|
+
import { TirArrayT } from "../types/TirNativeType/native/array.js";
|
|
22
22
|
import { TirDataStructType, TirSoPStructType } from "../types/TirStructType.js";
|
|
23
|
+
import { TirEnumType } from "../types/TirEnumType.js";
|
|
23
24
|
import { isTirType } from "../types/TirType.js";
|
|
24
25
|
import { getListTypeArg } from "../types/utils/getListTypeArg.js";
|
|
25
26
|
import { getOptTypeArg } from "../types/utils/getOptTypeArg.js";
|
|
@@ -68,6 +69,20 @@ export function _inlineFromData(target_t, dataExprIR) {
|
|
|
68
69
|
// LinearMapEntry is Pair<Data,Data> at runtime — no conversion needed
|
|
69
70
|
if (to_t instanceof TirLinearMapEntryT)
|
|
70
71
|
return dataExprIR;
|
|
72
|
+
// Native Value: data -> Value via `unValueData`
|
|
73
|
+
if (to_t instanceof TirValueT)
|
|
74
|
+
return _ir_apps(IRNative.unValueData, dataExprIR);
|
|
75
|
+
// Native Array<T>: data -> [data] (unListData) -> Array<T>
|
|
76
|
+
// for non-data element types we map elements through their fromData first.
|
|
77
|
+
if (to_t instanceof TirArrayT) {
|
|
78
|
+
const elems_t = getUnaliased(to_t.typeArg);
|
|
79
|
+
const listOfDataExpr = _ir_apps(IRNative.unListData, dataExprIR);
|
|
80
|
+
if (elems_t instanceof TirDataStructType
|
|
81
|
+
|| elems_t instanceof TirDataOptT
|
|
82
|
+
|| elems_t instanceof TirDataT)
|
|
83
|
+
return _ir_apps(IRNative.listToArray, listOfDataExpr);
|
|
84
|
+
return _ir_apps(IRNative.listToArray, _ir_apps(IRNative._mkMapList, IRConst.listOf(elems_t)([]), _fromDataUplcFunc(elems_t), listOfDataExpr));
|
|
85
|
+
}
|
|
71
86
|
if (to_t instanceof TirListT) {
|
|
72
87
|
const elems_t = getUnaliased(getListTypeArg(to_t));
|
|
73
88
|
const listOfDataExpr = _ir_apps(IRNative.unListData, dataExprIR);
|
|
@@ -81,16 +96,24 @@ export function _inlineFromData(target_t, dataExprIR) {
|
|
|
81
96
|
const value_t = getOptTypeArg(to_t);
|
|
82
97
|
if (!isTirType(value_t))
|
|
83
98
|
throw new Error("TirFromDataExpr: unreachable");
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
// Case(unConstrData(data), [\idxSym fieldsSym ->
|
|
100
|
+
// Case(idxSym, [
|
|
101
|
+
// IRConstr(0, [fromData(headList(fieldsSym))]), -- Some
|
|
102
|
+
// IRConstr(1, []) -- None
|
|
103
|
+
// ])
|
|
104
|
+
// ])
|
|
105
|
+
const idxSym = Symbol("optIdx");
|
|
106
|
+
const fieldsListSym = Symbol("optFields");
|
|
107
|
+
return new IRCase(_ir_apps(IRNative.unConstrData, dataExprIR), [
|
|
108
|
+
new IRFunc([idxSym, fieldsListSym], new IRCase(new IRVar(idxSym), [
|
|
109
|
+
// ctor 0: Some
|
|
110
|
+
new IRConstr(0, [
|
|
111
|
+
_ir_apps(_fromDataUplcFunc(value_t), _ir_apps(IRNative.headList, new IRVar(fieldsListSym)))
|
|
112
|
+
]),
|
|
113
|
+
// ctor 1: None
|
|
114
|
+
new IRHoisted(new IRConstr(1, []))
|
|
115
|
+
]))
|
|
116
|
+
]);
|
|
94
117
|
}
|
|
95
118
|
if (to_t instanceof TirSoPStructType) {
|
|
96
119
|
return _inlineMultiSopConstrFromData(to_t, dataExprIR);
|
|
@@ -106,6 +129,8 @@ export function _fromDataUplcFunc(_target_t) {
|
|
|
106
129
|
return IRNative._id;
|
|
107
130
|
if (target_t instanceof TirIntT)
|
|
108
131
|
return IRNative.unIData;
|
|
132
|
+
if (target_t instanceof TirEnumType)
|
|
133
|
+
return IRNative.unIData;
|
|
109
134
|
if (target_t instanceof TirBytesT)
|
|
110
135
|
return IRNative.unBData;
|
|
111
136
|
if (target_t instanceof TirVoidT)
|
|
@@ -114,6 +139,9 @@ export function _fromDataUplcFunc(_target_t) {
|
|
|
114
139
|
return _boolFromData.clone();
|
|
115
140
|
if (target_t instanceof TirStringT)
|
|
116
141
|
return _strFromData.clone();
|
|
142
|
+
// Native Value: data -> Value via `unValueData`
|
|
143
|
+
if (target_t instanceof TirValueT)
|
|
144
|
+
return IRNative.unValueData;
|
|
117
145
|
if (target_t instanceof TirLinearMapT)
|
|
118
146
|
// linear maps only have pairs as elements
|
|
119
147
|
// and we only support pairs of data (bc we only have `mkPairData`)
|
|
@@ -136,8 +164,21 @@ export function _fromDataUplcFunc(_target_t) {
|
|
|
136
164
|
const _unitFromDataSym = Symbol("unit");
|
|
137
165
|
const _mkUnit = new IRHoisted(new IRFunc([_unitFromDataSym], IRConst.unit));
|
|
138
166
|
const _boolFromDataDataSym = Symbol("boolData");
|
|
167
|
+
// Case(unConstrData(data), [\idxSym _fieldsSym ->
|
|
168
|
+
// Case(idxSym, [
|
|
169
|
+
// IRConst.bool(true), -- ctor 0 → true (preserves equalsInteger(_, 0) semantics)
|
|
170
|
+
// IRConst.bool(false) -- ctor 1 → false
|
|
171
|
+
// ])
|
|
172
|
+
// ])
|
|
173
|
+
const _boolFromDataIdxSym = Symbol("boolIdx");
|
|
174
|
+
const _boolFromDataFieldsSym = Symbol("boolFields_unused");
|
|
139
175
|
const _boolFromData = new IRHoisted(new IRFunc([_boolFromDataDataSym], // data
|
|
140
|
-
|
|
176
|
+
new IRCase(_ir_apps(IRNative.unConstrData, new IRVar(_boolFromDataDataSym)), [
|
|
177
|
+
new IRFunc([_boolFromDataIdxSym, _boolFromDataFieldsSym], new IRCase(new IRVar(_boolFromDataIdxSym), [
|
|
178
|
+
IRConst.bool(true),
|
|
179
|
+
IRConst.bool(false)
|
|
180
|
+
]))
|
|
181
|
+
])));
|
|
141
182
|
const _strFromDataDataSym = Symbol("strData");
|
|
142
183
|
const _strFromData = new IRHoisted(new IRFunc([_strFromDataDataSym], // data
|
|
143
184
|
_ir_apps(IRNative.decodeUtf8, _ir_apps(IRNative.unBData, new IRVar(_strFromDataDataSym)))));
|
|
@@ -147,63 +188,57 @@ export function _inilneSingeSopConstrFromData(sop_t, dataExprIR) {
|
|
|
147
188
|
const constr = sop_t.constructors[0];
|
|
148
189
|
if (constr.fields.length === 0)
|
|
149
190
|
return new IRHoisted(new IRConstr(0, []));
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
throw new Error("TirFromDataExpr: unreachable");
|
|
166
|
-
return _inlineFromData(field_t, _ir_apps(IRNative.headList, i === 0
|
|
167
|
-
? new IRVar(fieldsListSym)
|
|
168
|
-
: _ir_apps(IRNative._dropList, IRConst.int(i), new IRVar(fieldsListSym))));
|
|
169
|
-
})));
|
|
191
|
+
// Case(unConstrData(data), [\_idxSym fieldsListSym -> IRConstr(0, [...fields])])
|
|
192
|
+
// Single ctor, so the index is ignored — the outer Case destructures
|
|
193
|
+
// the pair via a 2-arg branch and we only consume the fields list.
|
|
194
|
+
const idxSym = Symbol("singleCtorIdx_unused");
|
|
195
|
+
const fieldsListSym = Symbol("fieldsList");
|
|
196
|
+
return new IRCase(_ir_apps(IRNative.unConstrData, dataExprIR), [
|
|
197
|
+
new IRFunc([idxSym, fieldsListSym], new IRConstr(0, constr.fields.map((field, i) => {
|
|
198
|
+
const field_t = getUnaliased(field.type);
|
|
199
|
+
if (!isTirType(field_t))
|
|
200
|
+
throw new Error("TirFromDataExpr: unreachable");
|
|
201
|
+
return _inlineFromData(field_t, _ir_apps(IRNative.headList, i === 0
|
|
202
|
+
? new IRVar(fieldsListSym)
|
|
203
|
+
: _ir_apps(IRNative.dropList, IRConst.int(i), new IRVar(fieldsListSym))));
|
|
204
|
+
})))
|
|
205
|
+
]);
|
|
170
206
|
}
|
|
171
207
|
export function _inlineMultiSopConstrFromData(sop_t, dataExprIR) {
|
|
172
208
|
if (sop_t.constructors.length <= 1)
|
|
173
209
|
return _inilneSingeSopConstrFromData(sop_t, dataExprIR);
|
|
174
|
-
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const field_t = getUnaliased(field.type);
|
|
194
|
-
if (!isTirType(field_t))
|
|
195
|
-
throw new Error("TirFromDataExpr: unreachable");
|
|
196
|
-
return _inlineFromData(field_t, _ir_apps(IRNative.headList, i === 0
|
|
197
|
-
? new IRVar(fieldsListSym)
|
|
198
|
-
: _ir_apps(IRNative._dropList, IRConst.int(i), new IRVar(fieldsListSym))));
|
|
199
|
-
}));
|
|
200
|
-
});
|
|
201
|
-
let finalIfThenElseChain = continuations[continuations.length - 1];
|
|
202
|
-
for (let i = continuations.length - 2; i >= 0; i--) {
|
|
203
|
-
finalIfThenElseChain = new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(new IRVar(isConstrIdxSym), IRConst.int(i)), new IRDelayed(continuations[i]), new IRDelayed(finalIfThenElseChain)));
|
|
210
|
+
// Case(unConstrData(data), [\idxSym fieldsListSym ->
|
|
211
|
+
// Case(idxSym, [
|
|
212
|
+
// IRConstr(0, [...fields_of_ctor_0]),
|
|
213
|
+
// IRConstr(1, [...fields_of_ctor_1]),
|
|
214
|
+
// ...
|
|
215
|
+
// ])
|
|
216
|
+
// ])
|
|
217
|
+
const idxSym = Symbol("ctorIdx");
|
|
218
|
+
const fieldsListSym = Symbol("fieldsList");
|
|
219
|
+
const continuations = sop_t.constructors.map((constr, constrIdx) => {
|
|
220
|
+
if (constr.fields.length === 0)
|
|
221
|
+
return new IRHoisted(new IRConstr(constrIdx, []));
|
|
222
|
+
if (constr.fields.length === 1) {
|
|
223
|
+
const value_t = getUnaliased(constr.fields[0].type);
|
|
224
|
+
if (!isTirType(value_t))
|
|
225
|
+
throw new Error("TirFromDataExpr: unreachable");
|
|
226
|
+
return new IRConstr(constrIdx, [
|
|
227
|
+
_inlineFromData(value_t, _ir_apps(IRNative.headList, new IRVar(fieldsListSym)))
|
|
228
|
+
]);
|
|
204
229
|
}
|
|
205
|
-
return
|
|
206
|
-
|
|
230
|
+
return new IRConstr(constrIdx, constr.fields.map((field, i) => {
|
|
231
|
+
const field_t = getUnaliased(field.type);
|
|
232
|
+
if (!isTirType(field_t))
|
|
233
|
+
throw new Error("TirFromDataExpr: unreachable");
|
|
234
|
+
return _inlineFromData(field_t, _ir_apps(IRNative.headList, i === 0
|
|
235
|
+
? new IRVar(fieldsListSym)
|
|
236
|
+
: _ir_apps(IRNative.dropList, IRConst.int(i), new IRVar(fieldsListSym))));
|
|
237
|
+
}));
|
|
238
|
+
});
|
|
239
|
+
return new IRCase(_ir_apps(IRNative.unConstrData, dataExprIR), [
|
|
240
|
+
new IRFunc([idxSym, fieldsListSym], new IRCase(new IRVar(idxSym), continuations))
|
|
241
|
+
]);
|
|
207
242
|
}
|
|
208
243
|
// new cached hoisted helpers (mirroring TirToDataExpr pattern)
|
|
209
244
|
const _mapListFromDataOfType = {};
|
|
@@ -4,6 +4,7 @@ import { IRConst } from "../../../IR/IRNodes/IRConst.js";
|
|
|
4
4
|
import { IRFunc } from "../../../IR/IRNodes/IRFunc.js";
|
|
5
5
|
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
6
6
|
import { TirDataStructType, TirSoPStructType } from "../types/TirStructType.js";
|
|
7
|
+
import { TirEnumType } from "../types/TirEnumType.js";
|
|
7
8
|
import { getUnaliased } from "../types/utils/getUnaliased.js";
|
|
8
9
|
export class TirIsExpr {
|
|
9
10
|
instanceExpr;
|
|
@@ -34,8 +35,20 @@ export class TirIsExpr {
|
|
|
34
35
|
}
|
|
35
36
|
get isConstant() { return this.instanceExpr.isConstant; }
|
|
36
37
|
toIR(ctx) {
|
|
37
|
-
const
|
|
38
|
+
const unaliased = getUnaliased(this.instanceExpr.type);
|
|
39
|
+
if (unaliased instanceof TirEnumType) {
|
|
40
|
+
// enums lower to a plain int; `is Member` is integer equality
|
|
41
|
+
return _ir_apps(IRNative.equalsInteger, IRConst.int(this.parentCtorIdx), this.instanceExpr.toIR(ctx));
|
|
42
|
+
}
|
|
43
|
+
const structType = unaliased;
|
|
38
44
|
if (structType instanceof TirDataStructType) {
|
|
45
|
+
// untagged data structs have exactly one constructor; the
|
|
46
|
+
// runtime value carries no tag — `is Ctor` is statically true.
|
|
47
|
+
// We still evaluate `instanceExpr` to preserve any error it
|
|
48
|
+
// would produce (the redundancy is also flagged with a warning
|
|
49
|
+
// at AstCompiler time).
|
|
50
|
+
if (structType.untagged)
|
|
51
|
+
return _ir_apps(new IRFunc([Symbol("_unused_is_untagged")], IRConst.bool(true)), this.instanceExpr.toIR(ctx));
|
|
39
52
|
// equalsInteger(parentCtorIdx, fstPair(unConstrData(<instance>)))
|
|
40
53
|
return _ir_apps(IRNative.equalsInteger, IRConst.int(this.parentCtorIdx), _ir_apps(IRNative.fstPair, _ir_apps(IRNative.unConstrData, this.instanceExpr.toIR(ctx))));
|
|
41
54
|
}
|
|
@@ -42,7 +42,6 @@ export declare class TirNativeFunc implements ITirExpr {
|
|
|
42
42
|
static get verifyEd25519Signature(): TirNativeFunc;
|
|
43
43
|
static strictIfThenElse(returnT: TirType): TirNativeFunc;
|
|
44
44
|
static chooseUnit(returnT: TirType): TirNativeFunc;
|
|
45
|
-
static strictChooseList(elemT: TirType, returnT: TirType): TirNativeFunc;
|
|
46
45
|
static mkCons(elemT: TirType): TirNativeFunc;
|
|
47
46
|
static headList(elemT: TirType): TirNativeFunc;
|
|
48
47
|
static tailList(elemT: TirType): TirNativeFunc;
|
|
@@ -98,7 +97,7 @@ export declare class TirNativeFunc implements ITirExpr {
|
|
|
98
97
|
static get countSetBits(): TirNativeFunc;
|
|
99
98
|
static get findFirstSetBit(): TirNativeFunc;
|
|
100
99
|
static get ripemd_160(): TirNativeFunc;
|
|
101
|
-
static
|
|
100
|
+
static dropList(elemT: TirType): TirNativeFunc;
|
|
102
101
|
static _foldr(elemT: TirType, returnT: TirType): TirNativeFunc;
|
|
103
102
|
static _foldl(elemT: TirType, returnT: TirType): TirNativeFunc;
|
|
104
103
|
static _findSopOptional(elems_t: TirType): TirNativeFunc;
|