@harmoniclabs/pebble 0.1.10 → 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 +35 -4
- 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 +31 -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 +34 -7
- package/dist/IR/toUPLC/CompilerOptions.js +19 -10
- 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/IR/tree_utils/bytesToHex.d.ts +8 -0
- package/dist/IR/tree_utils/bytesToHex.js +69 -0
- package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +16 -2
- package/dist/ast/nodes/expr/functions/FuncExpr.js +17 -0
- package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/litteral/LitteralExpr.js +2 -0
- package/dist/ast/nodes/expr/litteral/TemplateStrExpr.d.ts +30 -0
- package/dist/ast/nodes/expr/litteral/TemplateStrExpr.js +35 -0
- package/dist/ast/nodes/statements/ExportStmt.d.ts +3 -3
- package/dist/ast/nodes/statements/PebbleStmt.d.ts +4 -3
- package/dist/ast/nodes/statements/PebbleStmt.js +6 -2
- package/dist/ast/nodes/statements/TestParam.d.ts +18 -0
- package/dist/ast/nodes/statements/TestParam.js +18 -0
- package/dist/ast/nodes/statements/TestStmt.d.ts +5 -3
- package/dist/ast/nodes/statements/TestStmt.js +3 -1
- package/dist/ast/nodes/statements/UsingStmt.d.ts +32 -2
- package/dist/ast/nodes/statements/UsingStmt.js +39 -3
- package/dist/ast/nodes/statements/declarations/NamespaceDecl.d.ts +21 -0
- package/dist/ast/nodes/statements/declarations/NamespaceDecl.js +31 -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 +27 -0
- package/dist/compiler/AstCompiler/AstCompiler.js +244 -7
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +16 -5
- package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.js +97 -6
- package/dist/compiler/AstCompiler/internal/exprs/_compileCaseExpr.js +31 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +12 -5
- package/dist/compiler/AstCompiler/internal/exprs/_compileIsExpr.js +12 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +59 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.d.ts +2 -3
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +64 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +13 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +2 -0
- 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/internal/statements/_compileStatement.js +4 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.d.ts +15 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.js +70 -30
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.d.ts +11 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.js +26 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.d.ts +9 -4
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.js +51 -10
- package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +21 -2
- package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +17 -2
- package/dist/compiler/AstCompiler/scope/AstScope.d.ts +70 -1
- package/dist/compiler/AstCompiler/scope/AstScope.js +91 -0
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +36 -1
- package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.d.ts +36 -0
- package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.js +123 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.d.ts +28 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.js +95 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespacePath.d.ts +37 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespacePath.js +93 -0
- package/dist/compiler/Compiler.d.ts +9 -1
- package/dist/compiler/Compiler.js +218 -30
- 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 +49 -15
- package/dist/compiler/test/TestResult.d.ts +38 -0
- package/dist/compiler/test/TestResult.js +6 -0
- package/dist/compiler/test/fuzz/PRNG.d.ts +26 -0
- package/dist/compiler/test/fuzz/PRNG.js +59 -0
- 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/TirExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/TirExpr.js +2 -0
- 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 +18 -2
- package/dist/compiler/tir/expressions/TirNativeFunc.js +55 -118
- package/dist/compiler/tir/expressions/TirShowExpr.d.ts +52 -0
- package/dist/compiler/tir/expressions/TirShowExpr.js +199 -0
- package/dist/compiler/tir/expressions/TirToDataExpr.js +3 -0
- package/dist/compiler/tir/expressions/TirTraceExpr.js +11 -7
- 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/TypedProgram.d.ts +101 -0
- package/dist/compiler/tir/program/TypedProgram.js +43 -0
- package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.d.ts +17 -0
- package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.js +70 -0
- package/dist/compiler/tir/program/stdScope/populateStdNamespace.d.ts +22 -0
- package/dist/compiler/tir/program/stdScope/populateStdNamespace.js +619 -0
- package/dist/compiler/tir/program/stdScope/prelude/preludeTypesSrc.js +35 -2
- package/dist/compiler/tir/program/stdScope/stdScope.d.ts +8 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +84 -41
- package/dist/compiler/tir/statements/TirStmt.js +0 -1
- package/dist/compiler/tir/statements/TirTestStmt.d.ts +46 -0
- package/dist/compiler/tir/statements/TirTestStmt.js +35 -0
- 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 +53 -2
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +58 -1
- 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 +7 -2
- package/dist/compiler/tir/types/utils/canAssignTo.js +36 -1
- 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.d.ts +19 -0
- package/dist/compiler/tir/types/utils/inferTypeArgs.js +83 -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.d.ts +9 -0
- package/dist/compiler/tir/types/utils/substituteTypeParams.js +67 -0
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -0
- package/dist/diagnostics/diagnosticMessages.generated.js +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/parser/Parser.d.ts +73 -3
- package/dist/parser/Parser.js +362 -46
- package/dist/tokenizer/Token.d.ts +106 -102
- package/dist/tokenizer/Token.js +111 -109
- package/dist/tokenizer/utils/tokenFromKeyword.js +11 -6
- package/dist/utils/semverSatisfies.d.ts +1 -0
- package/dist/utils/semverSatisfies.js +161 -0
- package/dist/version.generated.d.ts +1 -0
- package/dist/version.generated.js +2 -0
- package/package.json +5 -4
- package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +0 -3
- package/dist/IR/tree_utils/_ir_lazyChooseList.js +0 -7
|
@@ -21,5 +21,6 @@ import { TirTraceExpr } from "./TirTraceExpr.js";
|
|
|
21
21
|
import { TirNativeFunc } from "./TirNativeFunc.js";
|
|
22
22
|
import { TirInlineClosedIR } from "./TirInlineClosedIR.js";
|
|
23
23
|
import { TirIsExpr } from "./TirIsExpr.js";
|
|
24
|
-
|
|
24
|
+
import { TirShowExpr } from "./TirShowExpr.js";
|
|
25
|
+
export type TirExpr = (TirUnaryPrefixExpr | TirLitteralExpr | TirParentesizedExpr | TirFuncExpr | TirCallExpr | TirCaseExpr | TirTypeConversionExpr | TirIsExpr | TirElemAccessExpr | TirTernaryExpr | TirPropAccessExpr | TirBinaryExpr | TirVariableAccessExpr | TirLettedExpr | TirNativeFunc | TirFailExpr | TirHoistedExpr | TirFromDataExpr | TirToDataExpr | TirAssertAndContinueExpr | TirTraceIfFalseExpr | TirTraceExpr | TirShowExpr | TirInlineClosedIR);
|
|
25
26
|
export declare function isTirExpr(thing: any): thing is TirExpr;
|
|
@@ -22,6 +22,7 @@ import { TirTraceExpr } from "./TirTraceExpr.js";
|
|
|
22
22
|
import { TirNativeFunc } from "./TirNativeFunc.js";
|
|
23
23
|
import { TirInlineClosedIR } from "./TirInlineClosedIR.js";
|
|
24
24
|
import { TirIsExpr } from "./TirIsExpr.js";
|
|
25
|
+
import { TirShowExpr } from "./TirShowExpr.js";
|
|
25
26
|
export function isTirExpr(thing) {
|
|
26
27
|
return isObject(thing) && (isTirUnaryPrefixExpr(thing)
|
|
27
28
|
|| isTirLitteralExpr(thing)
|
|
@@ -45,5 +46,6 @@ export function isTirExpr(thing) {
|
|
|
45
46
|
|| thing instanceof TirAssertAndContinueExpr
|
|
46
47
|
|| thing instanceof TirTraceIfFalseExpr
|
|
47
48
|
|| thing instanceof TirTraceExpr
|
|
49
|
+
|| thing instanceof TirShowExpr
|
|
48
50
|
|| thing instanceof TirInlineClosedIR);
|
|
49
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;
|
|
@@ -65,6 +64,23 @@ export declare class TirNativeFunc implements ITirExpr {
|
|
|
65
64
|
static get serialiseData(): TirNativeFunc;
|
|
66
65
|
static get verifyEcdsaSecp256k1Signature(): TirNativeFunc;
|
|
67
66
|
static get verifySchnorrSecp256k1Signature(): TirNativeFunc;
|
|
67
|
+
static get bls12_381_G1_add(): TirNativeFunc;
|
|
68
|
+
static get bls12_381_G1_neg(): TirNativeFunc;
|
|
69
|
+
static get bls12_381_G1_scalarMul(): TirNativeFunc;
|
|
70
|
+
static get bls12_381_G1_equal(): TirNativeFunc;
|
|
71
|
+
static get bls12_381_G1_hashToGroup(): TirNativeFunc;
|
|
72
|
+
static get bls12_381_G1_compress(): TirNativeFunc;
|
|
73
|
+
static get bls12_381_G1_uncompress(): TirNativeFunc;
|
|
74
|
+
static get bls12_381_G2_add(): TirNativeFunc;
|
|
75
|
+
static get bls12_381_G2_neg(): TirNativeFunc;
|
|
76
|
+
static get bls12_381_G2_scalarMul(): TirNativeFunc;
|
|
77
|
+
static get bls12_381_G2_equal(): TirNativeFunc;
|
|
78
|
+
static get bls12_381_G2_hashToGroup(): TirNativeFunc;
|
|
79
|
+
static get bls12_381_G2_compress(): TirNativeFunc;
|
|
80
|
+
static get bls12_381_G2_uncompress(): TirNativeFunc;
|
|
81
|
+
static get bls12_381_millerLoop(): TirNativeFunc;
|
|
82
|
+
static get bls12_381_mulMlResult(): TirNativeFunc;
|
|
83
|
+
static get bls12_381_finalVerify(): TirNativeFunc;
|
|
68
84
|
static get keccak_256(): TirNativeFunc;
|
|
69
85
|
static get blake2b_224(): TirNativeFunc;
|
|
70
86
|
static get integerToByteString(): TirNativeFunc;
|
|
@@ -81,7 +97,7 @@ export declare class TirNativeFunc implements ITirExpr {
|
|
|
81
97
|
static get countSetBits(): TirNativeFunc;
|
|
82
98
|
static get findFirstSetBit(): TirNativeFunc;
|
|
83
99
|
static get ripemd_160(): TirNativeFunc;
|
|
84
|
-
static
|
|
100
|
+
static dropList(elemT: TirType): TirNativeFunc;
|
|
85
101
|
static _foldr(elemT: TirType, returnT: TirType): TirNativeFunc;
|
|
86
102
|
static _foldl(elemT: TirType, returnT: TirType): TirNativeFunc;
|
|
87
103
|
static _findSopOptional(elems_t: 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, TirSopOptT } from "../types/TirNativeType/index.js";
|
|
5
|
+
import { TirUnConstrDataResultT, TirPairDataT, TirIntT, TirBytesT, TirDataT, TirBoolT, TirSopOptT, TirBlsG1T, TirBlsG2T, TirMlResultT } 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 { TirLinearMapEntryT } from "../types/TirNativeType/native/linearMapEntry.js";
|
|
@@ -229,16 +229,6 @@ export class TirNativeFunc {
|
|
|
229
229
|
void_t
|
|
230
230
|
], returnT));
|
|
231
231
|
}
|
|
232
|
-
static strictChooseList(elemT, returnT) {
|
|
233
|
-
return new TirNativeFunc(IRNativeTag.strictChooseList, new TirFuncT([
|
|
234
|
-
// list
|
|
235
|
-
new TirListT(elemT),
|
|
236
|
-
// caseNil
|
|
237
|
-
returnT,
|
|
238
|
-
// caseCons
|
|
239
|
-
returnT
|
|
240
|
-
], returnT));
|
|
241
|
-
}
|
|
242
232
|
// List operations with type parameters
|
|
243
233
|
static mkCons(elemT) {
|
|
244
234
|
return new TirNativeFunc(IRNativeTag.mkCons, new TirFuncT([
|
|
@@ -395,111 +385,58 @@ export class TirNativeFunc {
|
|
|
395
385
|
bytes_t
|
|
396
386
|
], bool_t));
|
|
397
387
|
}
|
|
398
|
-
// BLS12-381 operations
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
IRNativeTag.bls12_381_G2_neg,
|
|
451
|
-
new TirFuncT([bytes_t], bytes_t)
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
get bls12_381_G2_scalarMul(): TirNativeFunc {
|
|
455
|
-
return new TirNativeFunc(
|
|
456
|
-
IRNativeTag.bls12_381_G2_scalarMul,
|
|
457
|
-
new TirFuncT([bytes_t, int_t], bytes_t)
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
get bls12_381_G2_equal(): TirNativeFunc {
|
|
461
|
-
return new TirNativeFunc(
|
|
462
|
-
IRNativeTag.bls12_381_G2_equal,
|
|
463
|
-
new TirFuncT([bytes_t, bytes_t], bool_t)
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
get bls12_381_G2_hashToGroup(): TirNativeFunc {
|
|
467
|
-
return new TirNativeFunc(
|
|
468
|
-
IRNativeTag.bls12_381_G2_hashToGroup,
|
|
469
|
-
new TirFuncT([bytes_t], bytes_t)
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
get bls12_381_G2_compress(): TirNativeFunc {
|
|
473
|
-
return new TirNativeFunc(
|
|
474
|
-
IRNativeTag.bls12_381_G2_compress,
|
|
475
|
-
new TirFuncT([bytes_t], bytes_t)
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
get bls12_381_G2_uncompress(): TirNativeFunc {
|
|
479
|
-
return new TirNativeFunc(
|
|
480
|
-
IRNativeTag.bls12_381_G2_uncompress,
|
|
481
|
-
new TirFuncT([bytes_t], bytes_t)
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
get bls12_381_millerLoop(): TirNativeFunc {
|
|
485
|
-
return new TirNativeFunc(
|
|
486
|
-
IRNativeTag.bls12_381_millerLoop,
|
|
487
|
-
new TirFuncT([bytes_t, bytes_t], bytes_t)
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
get bls12_381_mulMlResult(): TirNativeFunc {
|
|
491
|
-
return new TirNativeFunc(
|
|
492
|
-
IRNativeTag.bls12_381_mulMlResult,
|
|
493
|
-
new TirFuncT([bytes_t, bytes_t], bytes_t)
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
get bls12_381_finalVerify(): TirNativeFunc {
|
|
497
|
-
return new TirNativeFunc(
|
|
498
|
-
IRNativeTag.bls12_381_finalVerify,
|
|
499
|
-
new TirFuncT([bytes_t, bytes_t], bool_t)
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
//*/
|
|
388
|
+
// BLS12-381 operations -- now exposed under `std.crypto.bls12_381`
|
|
389
|
+
static get bls12_381_G1_add() {
|
|
390
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G1_add, new TirFuncT([new TirBlsG1T(), new TirBlsG1T()], new TirBlsG1T()));
|
|
391
|
+
}
|
|
392
|
+
static get bls12_381_G1_neg() {
|
|
393
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G1_neg, new TirFuncT([new TirBlsG1T()], new TirBlsG1T()));
|
|
394
|
+
}
|
|
395
|
+
static get bls12_381_G1_scalarMul() {
|
|
396
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G1_scalarMul, new TirFuncT([int_t, new TirBlsG1T()], new TirBlsG1T()));
|
|
397
|
+
}
|
|
398
|
+
static get bls12_381_G1_equal() {
|
|
399
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G1_equal, new TirFuncT([new TirBlsG1T(), new TirBlsG1T()], bool_t));
|
|
400
|
+
}
|
|
401
|
+
static get bls12_381_G1_hashToGroup() {
|
|
402
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G1_hashToGroup, new TirFuncT([bytes_t, bytes_t], new TirBlsG1T()));
|
|
403
|
+
}
|
|
404
|
+
static get bls12_381_G1_compress() {
|
|
405
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G1_compress, new TirFuncT([new TirBlsG1T()], bytes_t));
|
|
406
|
+
}
|
|
407
|
+
static get bls12_381_G1_uncompress() {
|
|
408
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G1_uncompress, new TirFuncT([bytes_t], new TirBlsG1T()));
|
|
409
|
+
}
|
|
410
|
+
static get bls12_381_G2_add() {
|
|
411
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G2_add, new TirFuncT([new TirBlsG2T(), new TirBlsG2T()], new TirBlsG2T()));
|
|
412
|
+
}
|
|
413
|
+
static get bls12_381_G2_neg() {
|
|
414
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G2_neg, new TirFuncT([new TirBlsG2T()], new TirBlsG2T()));
|
|
415
|
+
}
|
|
416
|
+
static get bls12_381_G2_scalarMul() {
|
|
417
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G2_scalarMul, new TirFuncT([int_t, new TirBlsG2T()], new TirBlsG2T()));
|
|
418
|
+
}
|
|
419
|
+
static get bls12_381_G2_equal() {
|
|
420
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G2_equal, new TirFuncT([new TirBlsG2T(), new TirBlsG2T()], bool_t));
|
|
421
|
+
}
|
|
422
|
+
static get bls12_381_G2_hashToGroup() {
|
|
423
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G2_hashToGroup, new TirFuncT([bytes_t, bytes_t], new TirBlsG2T()));
|
|
424
|
+
}
|
|
425
|
+
static get bls12_381_G2_compress() {
|
|
426
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G2_compress, new TirFuncT([new TirBlsG2T()], bytes_t));
|
|
427
|
+
}
|
|
428
|
+
static get bls12_381_G2_uncompress() {
|
|
429
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_G2_uncompress, new TirFuncT([bytes_t], new TirBlsG2T()));
|
|
430
|
+
}
|
|
431
|
+
static get bls12_381_millerLoop() {
|
|
432
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_millerLoop, new TirFuncT([new TirBlsG1T(), new TirBlsG2T()], new TirMlResultT()));
|
|
433
|
+
}
|
|
434
|
+
static get bls12_381_mulMlResult() {
|
|
435
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_mulMlResult, new TirFuncT([new TirMlResultT(), new TirMlResultT()], new TirMlResultT()));
|
|
436
|
+
}
|
|
437
|
+
static get bls12_381_finalVerify() {
|
|
438
|
+
return new TirNativeFunc(IRNativeTag.bls12_381_finalVerify, new TirFuncT([new TirMlResultT(), new TirMlResultT()], bool_t));
|
|
439
|
+
}
|
|
503
440
|
// Additional hashing functions
|
|
504
441
|
static get keccak_256() {
|
|
505
442
|
return new TirNativeFunc(IRNativeTag.keccak_256, new TirFuncT([
|
|
@@ -630,8 +567,8 @@ export class TirNativeFunc {
|
|
|
630
567
|
], bytes_t));
|
|
631
568
|
}
|
|
632
569
|
// Custom utility functions
|
|
633
|
-
static
|
|
634
|
-
return new TirNativeFunc(IRNativeTag.
|
|
570
|
+
static dropList(elemT) {
|
|
571
|
+
return new TirNativeFunc(IRNativeTag.dropList, new TirFuncT([
|
|
635
572
|
// n
|
|
636
573
|
int_t,
|
|
637
574
|
// list
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { SourceRange } from "../../../ast/Source/SourceRange.js";
|
|
2
|
+
import { IRTerm } from "../../../IR/IRTerm.js";
|
|
3
|
+
import { TirType } from "../types/TirType.js";
|
|
4
|
+
import { ITirExpr } from "./ITirExpr.js";
|
|
5
|
+
import { TirExpr } from "./TirExpr.js";
|
|
6
|
+
import { ToIRTermCtx } from "./ToIRTermCtx.js";
|
|
7
|
+
/**
|
|
8
|
+
* `_showIR`-backed compile-time-dispatched show expression.
|
|
9
|
+
*
|
|
10
|
+
* Created when the user writes `expr.show()` on a built-in type whose Show
|
|
11
|
+
* impl the compiler provides (int, bytes, bool, data, void, string,
|
|
12
|
+
* List<T>, LinearMap<K,V>, data-encoded structs). For user-declared
|
|
13
|
+
* `type X implements Show { show(self): bytes { ... } }` impls the
|
|
14
|
+
* regular method-dispatch path in `expressifyVars` keeps applying — this
|
|
15
|
+
* expr is only emitted when no user impl is registered.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TirShowExpr implements ITirExpr {
|
|
18
|
+
readonly inner: TirExpr;
|
|
19
|
+
readonly range: SourceRange;
|
|
20
|
+
constructor(inner: TirExpr, range: SourceRange);
|
|
21
|
+
get type(): TirType;
|
|
22
|
+
get isConstant(): boolean;
|
|
23
|
+
toString(): string;
|
|
24
|
+
pretty(indent: number): string;
|
|
25
|
+
clone(): TirExpr;
|
|
26
|
+
deps(): string[];
|
|
27
|
+
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Inline an `IRTerm` of type `t` into its UTF-8 textual representation
|
|
31
|
+
* (also bytes). Returns the IR producing the show-encoded bytes.
|
|
32
|
+
*
|
|
33
|
+
* Mirrors `_inlineToData` — fully compile-time-dispatched per source type:
|
|
34
|
+
*
|
|
35
|
+
* int -> hoisted_intToUtf8Bytes (decimal, sign-aware)
|
|
36
|
+
* bytes -> hoisted_bytesToHex (lowercase hex)
|
|
37
|
+
* bool -> "true" / "false" via lazy ifThenElse
|
|
38
|
+
* data -> serialiseData -> bytesToHex
|
|
39
|
+
* void -> "()"
|
|
40
|
+
* string -> encodeUtf8 (treat as already-readable text)
|
|
41
|
+
* List<T> -> "[" + intercalate(", ", map(_showIR(T), elems)) + "]"
|
|
42
|
+
* LinearMap<K,V> -> "{" + intercalate(", ", map((k,v) -> showK(k) ++ ": " ++ showV(v), entries)) + "}"
|
|
43
|
+
*
|
|
44
|
+
* For struct-typed receivers (TirDataStructType / TirSoPStructType) this
|
|
45
|
+
* function does not produce IR — those should reach a user-declared
|
|
46
|
+
* `type X implements Show { show(self): bytes { ... } }` and dispatch
|
|
47
|
+
* through the regular method-call path. The caller is expected to detect
|
|
48
|
+
* that case before invoking `_showIR`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function _showIR(origin_t: TirType, exprIR: IRTerm): IRTerm;
|
|
51
|
+
/** A canonical 1-arg `(T) -> bytes` IR closure for use as a `Show` dictionary entry. */
|
|
52
|
+
export declare function _showUplcFunc(origin_t: TirType): IRTerm;
|