@harmoniclabs/pebble 0.1.0-dev5 → 0.1.0-dev6
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/IRHash.d.ts +3 -3
- package/dist/IR/IRHash.js +47 -52
- package/dist/IR/IRNodes/IRApp.d.ts +12 -8
- package/dist/IR/IRNodes/IRApp.js +34 -20
- package/dist/IR/IRNodes/IRCase.d.ts +11 -7
- package/dist/IR/IRNodes/IRCase.js +33 -32
- package/dist/IR/IRNodes/IRConst.d.ts +7 -5
- package/dist/IR/IRNodes/IRConst.js +23 -13
- package/dist/IR/IRNodes/IRConstr.d.ts +11 -7
- package/dist/IR/IRNodes/IRConstr.js +34 -37
- package/dist/IR/IRNodes/IRDelayed.d.ts +12 -9
- package/dist/IR/IRNodes/IRDelayed.js +22 -18
- package/dist/IR/IRNodes/IRError.d.ts +9 -6
- package/dist/IR/IRNodes/IRError.js +12 -5
- package/dist/IR/IRNodes/IRForced.d.ts +9 -6
- package/dist/IR/IRNodes/IRForced.js +22 -18
- package/dist/IR/IRNodes/IRFunc.d.ts +14 -10
- package/dist/IR/IRNodes/IRFunc.js +35 -38
- package/dist/IR/IRNodes/IRHoisted.d.ts +16 -9
- package/dist/IR/IRNodes/IRHoisted.js +36 -18
- package/dist/IR/IRNodes/IRLetted.d.ts +14 -34
- package/dist/IR/IRNodes/IRLetted.js +65 -297
- package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +0 -2
- package/dist/IR/IRNodes/IRNative/IRNativeTag.js +0 -4
- package/dist/IR/IRNodes/IRNative/index.d.ts +9 -8
- package/dist/IR/IRNodes/IRNative/index.js +55 -18
- package/dist/IR/IRNodes/IRNative/isForcedNative.d.ts +2 -0
- package/dist/IR/IRNodes/IRNative/isForcedNative.js +1 -1
- package/dist/IR/IRNodes/IRRecursive.d.ts +18 -10
- package/dist/IR/IRNodes/IRRecursive.js +36 -44
- package/dist/IR/IRNodes/IRSelfCall.d.ts +10 -24
- package/dist/IR/IRNodes/IRSelfCall.js +25 -87
- package/dist/IR/IRNodes/IRVar.d.ts +11 -19
- package/dist/IR/IRNodes/IRVar.js +26 -54
- package/dist/IR/IRNodes/utils/dependsByDbns.d.ts +1 -1
- package/dist/IR/IRNodes/utils/dependsByDbns.js +5 -11
- package/dist/IR/IRNodes/utils/hashVarSym.d.ts +1 -0
- package/dist/IR/IRNodes/utils/hashVarSym.js +37 -0
- package/dist/IR/IRNodes/utils/makeArrayLikeProxy.d.ts +2 -1
- package/dist/IR/IRTerm.d.ts +7 -0
- package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +3 -0
- package/dist/IR/toUPLC/_internal/findAll.js +2 -73
- package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +7 -34
- package/dist/IR/toUPLC/_internal/iterTree.js +3 -17
- package/dist/IR/toUPLC/common_hoisted.d.ts +2 -0
- package/dist/IR/toUPLC/common_hoisted.js +4 -0
- package/dist/IR/toUPLC/compileIRToUPLC.d.ts +1 -1
- package/dist/IR/toUPLC/compileIRToUPLC.js +91 -14
- package/dist/IR/toUPLC/ctx/ToUplcCtx.d.ts +16 -0
- package/dist/IR/toUPLC/ctx/ToUplcCtx.js +75 -0
- package/dist/IR/toUPLC/subRoutines/_comptimeDropN.d.ts +8 -0
- package/dist/IR/toUPLC/subRoutines/_comptimeDropN.js +95 -0
- package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +7 -54
- package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +6 -13
- package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +67 -71
- package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +44 -170
- package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +7 -3
- package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +3 -2
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.d.ts +22 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.js +59 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts +0 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.js +217 -0
- package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +12 -49
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +1 -1
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +11 -14
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/{index.d.ts → performUplcOptimizationsAndReturnRoot.d.ts} +0 -2
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +151 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.d.ts +11 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.js +46 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.d.ts +2 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js +80 -0
- package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +18 -11
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +43 -0
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +255 -478
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.d.ts +2 -0
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +85 -0
- package/dist/IR/toUPLC/subRoutines/sanifyTree.js +1 -0
- package/dist/IR/toUPLC/utils/getApplicationTerms.d.ts +6 -0
- package/dist/IR/toUPLC/utils/getApplicationTerms.js +37 -0
- package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +2 -2
- package/dist/IR/tree_utils/_ir_lazyChooseList.js +4 -2
- package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +1 -1
- package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +4 -2
- package/dist/IR/tree_utils/_ir_let.d.ts +2 -1
- package/dist/IR/tree_utils/_ir_let.js +6 -2
- package/dist/IR/utils/isClosedIRTerm.d.ts +1 -0
- package/dist/IR/utils/isClosedIRTerm.js +39 -25
- package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
- package/dist/IR/utils/positiveIntAsBytes.js +4 -0
- package/dist/IR/utils/showIR.d.ts +10 -21
- package/dist/IR/utils/showIR.js +66 -64
- package/dist/ast/nodes/common/Identifier.d.ts +1 -0
- package/dist/ast/nodes/common/Identifier.js +3 -0
- package/dist/ast/nodes/expr/CaseExpr.d.ts +5 -5
- package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +2 -2
- package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +1 -1
- package/dist/ast/nodes/expr/PebbleExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/PropAccessExpr.d.ts +3 -3
- package/dist/ast/nodes/expr/TernaryExpr.d.ts +3 -3
- package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/TypeConversionExpr.js +2 -0
- package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +42 -42
- package/dist/ast/nodes/expr/functions/CallExpr.d.ts +1 -1
- package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/functions/FuncExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitContextExpr.d.ts +6 -0
- package/dist/ast/nodes/expr/litteral/LitContextExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitFailExpr.d.ts +6 -0
- package/dist/ast/nodes/expr/litteral/LitFailExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +3 -1
- package/dist/ast/nodes/expr/litteral/LitteralExpr.js +5 -1
- package/dist/ast/nodes/statements/AssertStmt.d.ts +2 -2
- package/dist/ast/nodes/statements/AssignmentStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/BlockStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/FailStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/ForOfStmt.d.ts +4 -2
- package/dist/ast/nodes/statements/ForOfStmt.js +6 -0
- package/dist/ast/nodes/statements/ForStmt.d.ts +6 -4
- package/dist/ast/nodes/statements/ForStmt.js +6 -0
- package/dist/ast/nodes/statements/IfStmt.d.ts +8 -5
- package/dist/ast/nodes/statements/IfStmt.js +13 -0
- package/dist/ast/nodes/statements/MatchStmt.d.ts +13 -4
- package/dist/ast/nodes/statements/MatchStmt.js +22 -1
- package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
- package/dist/ast/nodes/statements/PebbleStmt.js +3 -1
- package/dist/ast/nodes/statements/ReturnStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/WhileStmt.d.ts +4 -2
- package/dist/ast/nodes/statements/WhileStmt.js +6 -0
- package/dist/ast/nodes/statements/declarations/ContractDecl.d.ts +17 -0
- package/dist/ast/nodes/statements/declarations/ContractDecl.js +22 -0
- package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +2 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +6 -0
- package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +1 -1
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +6 -2
- package/dist/compiler/AstCompiler/AstCompiler.js +91 -24
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.d.ts +10 -0
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +777 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +8 -2
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +3 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +2 -2
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +2 -2
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +48 -24
- package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +2 -2
- package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +1 -1
- package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +4 -1
- package/dist/compiler/AstCompiler/scope/AstScope.js +4 -3
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
- package/dist/compiler/Compiler.js +3 -1
- package/dist/compiler/TirCompiler/compileTirProgram.js +3 -1
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +13 -3
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +41 -37
- package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +11 -2
- package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressify.js +82 -36
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +57 -8
- package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +1 -1
- package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +1 -0
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +131 -9
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +3 -1
- package/dist/compiler/io/IOutputStream.d.ts +1 -0
- package/dist/compiler/io/IOutputStream.js +18 -3
- package/dist/compiler/path/getAbsolutePath.js +4 -6
- package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
- package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
- package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
- package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
- package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
- package/dist/compiler/tir/expressions/TirCaseExpr.js +103 -60
- package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
- package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
- package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
- package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
- package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
- package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
- package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
- package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +5 -2
- package/dist/compiler/tir/expressions/TirLettedExpr.js +19 -4
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +8 -5
- package/dist/compiler/tir/expressions/TirNativeFunc.js +50 -22
- package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
- package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -0
- package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
- package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
- package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +7 -3
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +17 -7
- package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +16 -20
- package/dist/compiler/tir/expressions/ToIRTermCtx.js +67 -50
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +40 -0
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +174 -3
- package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
- package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
- package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
- package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
- package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
- package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
- package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
- package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
- package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
- package/dist/compiler/tir/program/TypedProgram.d.ts +1 -0
- package/dist/compiler/tir/program/TypedProgram.js +9 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +126 -126
- package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
- package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
- package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
- package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
- package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
- package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
- package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
- package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirForStmt.js +21 -0
- package/dist/compiler/tir/statements/TirIfStmt.d.ts +3 -0
- package/dist/compiler/tir/statements/TirIfStmt.js +19 -0
- package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
- package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
- package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
- package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
- package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
- package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
- package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
- package/dist/diagnostics/DiagnosticEmitter.js +1 -1
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
- package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
- package/dist/parser/Parser.d.ts +8 -3
- package/dist/parser/Parser.js +162 -30
- package/dist/tokenizer/Token.d.ts +81 -72
- package/dist/tokenizer/Token.js +82 -72
- package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
- package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
- package/dist/utils/BitUtils/index.js +1 -1
- package/dist/utils/UPLCFlatUtils/index.js +1 -1
- package/package.json +2 -1
- package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
- package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
- package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
- package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
- package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
- package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
- package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
- package/dist/IR/tree_utils/_ir_apps.js +0 -8
|
@@ -8,513 +8,290 @@ import { IRHoisted } from "../../../IRNodes/IRHoisted.js";
|
|
|
8
8
|
import { IRNative } from "../../../IRNodes/IRNative/index.js";
|
|
9
9
|
import { IRNativeTag } from "../../../IRNodes/IRNative/IRNativeTag.js";
|
|
10
10
|
import { IRVar } from "../../../IRNodes/IRVar.js";
|
|
11
|
-
import { _ir_apps } from "../../../tree_utils/_ir_apps.js";
|
|
12
11
|
import { IRRecursive } from "../../../IRNodes/IRRecursive.js";
|
|
13
12
|
import { IRSelfCall } from "../../../IRNodes/IRSelfCall.js";
|
|
14
|
-
import { IRError } from "../../../IRNodes/
|
|
13
|
+
import { IRError } from "../../../IRNodes/IRError.js";
|
|
14
|
+
import { _ir_apps } from "../../../IRNodes/IRApp.js";
|
|
15
15
|
import { _ir_let } from "../../../tree_utils/_ir_let.js";
|
|
16
|
+
import { _ir_lazyChooseList } from "../../../tree_utils/_ir_lazyChooseList.js";
|
|
16
17
|
import { _ir_lazyIfThenElse } from "../../../tree_utils/_ir_lazyIfThenElse.js";
|
|
17
|
-
|
|
18
|
+
import { hoisted_drop4, hoisted_drop2, hoisted_drop3 } from "../_comptimeDropN.js";
|
|
19
|
+
function _ir_strictAnd(left, right) {
|
|
20
|
+
return _ir_apps(IRNative.strictIfThenElse, left, right, IRConst.bool(false));
|
|
21
|
+
}
|
|
22
|
+
const id_arg_sym = Symbol("id_arg");
|
|
23
|
+
export const hoisted_id = new IRHoisted(new IRFunc([id_arg_sym], new IRVar(id_arg_sym)));
|
|
18
24
|
hoisted_id.hash;
|
|
19
|
-
const hoisted_not = new IRHoisted(
|
|
20
|
-
|
|
21
|
-
IRConst.bool(false),
|
|
22
|
-
|
|
23
|
-
)));
|
|
25
|
+
export const hoisted_not = new IRHoisted((() => {
|
|
26
|
+
const someBool = Symbol("someBool");
|
|
27
|
+
return new IRFunc([someBool], _ir_apps(IRNative.strictIfThenElse, new IRVar(someBool), IRConst.bool(false), IRConst.bool(true)));
|
|
28
|
+
})());
|
|
24
29
|
hoisted_not.hash;
|
|
25
|
-
const
|
|
26
|
-
_ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, new IRVar(0) // lst
|
|
27
|
-
))));
|
|
28
|
-
hoisted_drop2.hash;
|
|
29
|
-
const hoisted_drop3 = new IRHoisted(new IRFunc(1, // lst
|
|
30
|
-
_ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, new IRVar(0) // lst
|
|
31
|
-
)))));
|
|
32
|
-
hoisted_drop3.hash;
|
|
33
|
-
const hoisted_drop4 = new IRHoisted(new IRFunc(1, // lst
|
|
34
|
-
_ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, new IRVar(0) // lst
|
|
35
|
-
))))));
|
|
36
|
-
hoisted_drop4.hash;
|
|
37
|
-
const hoisted_drop8 = new IRHoisted(new IRFunc(1, // lst
|
|
38
|
-
_ir_apps(hoisted_drop4.clone(), _ir_apps(hoisted_drop4.clone(), new IRVar(0) // lst
|
|
39
|
-
))));
|
|
40
|
-
hoisted_drop8.hash;
|
|
41
|
-
const hoisted_drop16 = new IRHoisted(new IRFunc(1, // lst
|
|
42
|
-
_ir_apps(hoisted_drop8.clone(), _ir_apps(hoisted_drop8.clone(), new IRVar(0) // lst
|
|
43
|
-
))));
|
|
44
|
-
hoisted_drop16.hash;
|
|
45
|
-
const hoisted_drop32 = new IRHoisted(new IRFunc(1, // lst
|
|
46
|
-
_ir_apps(hoisted_drop16.clone(), _ir_apps(hoisted_drop16.clone(), new IRVar(0) // lst
|
|
47
|
-
))));
|
|
48
|
-
hoisted_drop32.hash;
|
|
49
|
-
const hoisted_incr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
|
|
30
|
+
export const hoisted_incr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
|
|
50
31
|
hoisted_incr.hash;
|
|
51
|
-
const hoisted_decr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
|
|
32
|
+
export const hoisted_decr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
|
|
52
33
|
hoisted_decr.hash;
|
|
53
|
-
const hoisted_isZero = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(0)));
|
|
34
|
+
export const hoisted_isZero = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(0)));
|
|
54
35
|
hoisted_isZero.hash;
|
|
55
|
-
const hoisted_isOne = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(1)));
|
|
36
|
+
export const hoisted_isOne = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(1)));
|
|
56
37
|
hoisted_isZero.hash;
|
|
57
|
-
const hoisted_isTwo = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(2)));
|
|
38
|
+
export const hoisted_isTwo = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(2)));
|
|
58
39
|
hoisted_isTwo.hash;
|
|
59
|
-
const hoisted_isThree = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(3)));
|
|
60
|
-
const hoisted_addOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
|
|
40
|
+
export const hoisted_isThree = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(3)));
|
|
41
|
+
export const hoisted_addOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
|
|
61
42
|
hoisted_addOne.hash;
|
|
62
|
-
const hoisted_subOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
|
|
43
|
+
export const hoisted_subOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
|
|
63
44
|
hoisted_subOne.hash;
|
|
64
|
-
const hoisted_isPositive = new IRHoisted(new IRApp(IRNative.lessThanInteger, IRConst.int(0)));
|
|
45
|
+
export const hoisted_isPositive = new IRHoisted(new IRApp(IRNative.lessThanInteger, IRConst.int(0)));
|
|
65
46
|
hoisted_isPositive.hash;
|
|
66
|
-
const hoisted_isNonNegative = new IRHoisted(new IRApp(IRNative.lessThanEqualInteger, IRConst.int(0)));
|
|
47
|
+
export const hoisted_isNonNegative = new IRHoisted(new IRApp(IRNative.lessThanEqualInteger, IRConst.int(0)));
|
|
67
48
|
hoisted_isNonNegative.hash;
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
), new IRVar(
|
|
73
|
-
)))
|
|
74
|
-
innerZ.hash;
|
|
75
|
-
const hoisted_z_comb = new IRHoisted(new IRFunc(1, // Z
|
|
76
|
-
new IRApp(innerZ.clone(), innerZ.clone())));
|
|
77
|
-
hoisted_z_comb.hash;
|
|
78
|
-
const hoisted_matchList = new IRHoisted(new IRFunc(3, // delayed_matchNil, matchCons, list
|
|
79
|
-
new IRForced(new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(0), // list, last argument of IRFunc above
|
|
80
|
-
new IRVar(2), // delayed_matchNil (`delayed( resultT )`)
|
|
81
|
-
new IRDelayed(// delay
|
|
82
|
-
_ir_apps(new IRVar(1), // matchCons
|
|
83
|
-
new IRApp(IRNative.headList, new IRVar(0) // list
|
|
84
|
-
), new IRApp(IRNative.tailList, new IRVar(0) // list
|
|
85
|
-
))))))));
|
|
49
|
+
export const hoisted_matchList = new IRHoisted((() => {
|
|
50
|
+
const delayed_matchNil = Symbol("delayed_matchNil");
|
|
51
|
+
const matchCons = Symbol("matchCons");
|
|
52
|
+
const list = Symbol("list");
|
|
53
|
+
return new IRFunc([delayed_matchNil, matchCons, list], new IRForced(new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(list), new IRVar(delayed_matchNil), new IRDelayed(_ir_apps(new IRVar(matchCons), new IRApp(IRNative.headList, new IRVar(list)), new IRApp(IRNative.tailList, new IRVar(list))))))));
|
|
54
|
+
})());
|
|
86
55
|
hoisted_matchList.hash;
|
|
87
|
-
|
|
88
|
-
|
|
56
|
+
// hoisted_recursiveList (needed by hoisted_foldr)
|
|
57
|
+
const recList_matchNil = Symbol("matchNil");
|
|
58
|
+
const recList_matchCons = Symbol("matchCons");
|
|
59
|
+
const recList_self = Symbol("recursiveList_self");
|
|
60
|
+
const recList_lst = Symbol("lst");
|
|
61
|
+
export const hoisted_recursiveList = new IRHoisted(new IRFunc([recList_matchNil, recList_matchCons], new IRRecursive(recList_self, new IRFunc([recList_lst], _ir_apps(hoisted_matchList.clone(), new IRApp(new IRVar(recList_matchNil), new IRSelfCall(recList_self)), new IRApp(new IRVar(recList_matchCons), new IRSelfCall(recList_self)), new IRVar(recList_lst))))));
|
|
62
|
+
hoisted_recursiveList.hash;
|
|
63
|
+
// hoisted_foldr
|
|
64
|
+
const foldr_reduce = Symbol("reduceFunc");
|
|
65
|
+
const foldr_acc = Symbol("accumulator");
|
|
66
|
+
const foldr__dummy = Symbol("_self");
|
|
67
|
+
const foldr_self = Symbol("self");
|
|
68
|
+
const foldr_head = Symbol("head");
|
|
69
|
+
const foldr_tail = Symbol("tail");
|
|
70
|
+
export const hoisted_foldr = new IRHoisted(new IRFunc([foldr_reduce, foldr_acc], _ir_apps(hoisted_recursiveList.clone(), new IRFunc([foldr__dummy], new IRDelayed(new IRVar(foldr_acc))), new IRFunc([foldr_self, foldr_head, foldr_tail], _ir_apps(new IRVar(foldr_reduce), new IRVar(foldr_head), new IRApp(new IRVar(foldr_self), new IRVar(foldr_tail)))))));
|
|
71
|
+
hoisted_foldr.hash;
|
|
72
|
+
export const hosited_lazyChooseList = new IRHoisted((() => {
|
|
73
|
+
const list = Symbol("list");
|
|
74
|
+
const delayed_caseNil = Symbol("delayed_caseNil");
|
|
75
|
+
const delayed_caseCons = Symbol("delayed_caseCons");
|
|
76
|
+
return new IRFunc([list, delayed_caseNil, delayed_caseCons], new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(list), new IRVar(delayed_caseNil), new IRVar(delayed_caseCons))));
|
|
77
|
+
})());
|
|
89
78
|
hosited_lazyChooseList.hash;
|
|
90
79
|
//*/
|
|
91
|
-
const hoisted_isMoreThanOrEqualTo4 = new IRHoisted(_ir_apps(IRNative.lessThanInteger, IRConst.int(4)));
|
|
80
|
+
export const hoisted_isMoreThanOrEqualTo4 = new IRHoisted(_ir_apps(IRNative.lessThanInteger, IRConst.int(4)));
|
|
92
81
|
hoisted_isMoreThanOrEqualTo4.hash;
|
|
93
|
-
const hoisted_sub4 = new IRHoisted(_ir_apps(IRNative.addInteger, IRConst.int(-4)));
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
),
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
),
|
|
106
|
-
// then
|
|
107
|
-
new IRVar(0), // lst
|
|
108
|
-
// else
|
|
109
|
-
_ir_lazyIfThenElse(_ir_apps(hoisted_isOne.clone(), new IRVar(1) // n
|
|
110
|
-
),
|
|
111
|
-
// then
|
|
112
|
-
_ir_apps(IRNative.tailList, new IRVar(0) // lst
|
|
113
|
-
),
|
|
114
|
-
// else
|
|
115
|
-
_ir_lazyIfThenElse(_ir_apps(hoisted_isTwo.clone(), new IRVar(1) // n
|
|
116
|
-
),
|
|
117
|
-
// then
|
|
118
|
-
_ir_apps(hoisted_drop2.clone(), new IRVar(0) // lst
|
|
119
|
-
),
|
|
120
|
-
// else
|
|
121
|
-
_ir_apps(hoisted_drop3.clone(), new IRVar(0) // lst
|
|
122
|
-
))))))));
|
|
82
|
+
export const hoisted_sub4 = new IRHoisted(_ir_apps(IRNative.addInteger, IRConst.int(-4)));
|
|
83
|
+
hoisted_sub4.hash;
|
|
84
|
+
const self_length = Symbol("self_length");
|
|
85
|
+
const length_list_sym = Symbol("length_list_sym");
|
|
86
|
+
export const hoisted_length = new IRHoisted(new IRRecursive(self_length, new IRFunc([length_list_sym], _ir_lazyChooseList(new IRVar(length_list_sym), IRConst.int(0), _ir_apps(hoisted_incr.clone(), new IRApp(new IRSelfCall(self_length), // self
|
|
87
|
+
new IRApp(IRNative.tailList, new IRVar(length_list_sym) // list
|
|
88
|
+
)))))));
|
|
89
|
+
hoisted_length.hash;
|
|
90
|
+
// REPLACED hoisted_dropList (was numeric arity + dbn)
|
|
91
|
+
const drop_self = Symbol("drop_self");
|
|
92
|
+
const drop_n = Symbol("n");
|
|
93
|
+
const drop_lst = Symbol("lst");
|
|
94
|
+
export const hoisted_dropList = new IRHoisted(new IRRecursive(drop_self, new IRFunc([drop_n, drop_lst], _ir_lazyIfThenElse(_ir_apps(hoisted_isMoreThanOrEqualTo4.clone(), new IRVar(drop_n)), _ir_apps(new IRSelfCall(drop_self), _ir_apps(hoisted_sub4.clone(), new IRVar(drop_n)), _ir_apps(hoisted_drop4.clone(), new IRVar(drop_lst))), _ir_lazyIfThenElse(_ir_apps(hoisted_isZero.clone(), new IRVar(drop_n)), new IRVar(drop_lst), _ir_lazyIfThenElse(_ir_apps(hoisted_isOne.clone(), new IRVar(drop_n)), _ir_apps(IRNative.tailList, new IRVar(drop_lst)), _ir_lazyIfThenElse(_ir_apps(hoisted_isTwo.clone(), new IRVar(drop_n)), _ir_apps(hoisted_drop2.clone(), new IRVar(drop_lst)), _ir_apps(hoisted_drop3.clone(), new IRVar(drop_lst)))))))));
|
|
123
95
|
hoisted_dropList.hash;
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
), new
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
new
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
))));
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
new
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
96
|
+
const MAX_WORD4 = 0xFFFFFFFF;
|
|
97
|
+
// Added missing symbols & refactored hoisted_sizeofPositiveInt if previously numeric
|
|
98
|
+
const sizeof_self = Symbol("sizeofPositiveInt_self");
|
|
99
|
+
const sizeof_n = Symbol("n");
|
|
100
|
+
const sizeof_countWords = Symbol("count_words");
|
|
101
|
+
export const hoisted_sizeofPositiveInt = new IRHoisted(_ir_apps(new IRRecursive(sizeof_self, new IRFunc([sizeof_n, sizeof_countWords], new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(sizeof_n)), new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(sizeof_countWords)), new IRDelayed(IRConst.int(4)), new IRDelayed(_ir_apps(IRNative.multiplyInteger, IRConst.int(4), new IRVar(sizeof_countWords)))))), new IRDelayed(_ir_apps(new IRSelfCall(sizeof_self), _ir_apps(hoisted_addOne.clone(), new IRVar(sizeof_countWords)), _ir_apps(IRNative.divideInteger, new IRVar(sizeof_n), IRConst.int(MAX_WORD4)))))))), IRConst.int(0)));
|
|
102
|
+
const foldl_reduce = Symbol("reduceFunc");
|
|
103
|
+
const foldl_self = Symbol("foldl_self");
|
|
104
|
+
const foldl_acc = Symbol("accum");
|
|
105
|
+
const foldl_head = Symbol("head");
|
|
106
|
+
const foldl_tail = Symbol("tail");
|
|
107
|
+
const hoiseted_foldl = new IRHoisted(new IRFunc([foldl_reduce], new IRRecursive(foldl_self, new IRFunc([foldl_acc], _ir_apps(hoisted_matchList.clone(), new IRDelayed(new IRVar(foldl_acc)), new IRFunc([foldl_head, foldl_tail], _ir_apps(new IRSelfCall(foldl_self), _ir_apps(new IRVar(foldl_reduce), new IRVar(foldl_acc), new IRVar(foldl_head)), new IRVar(foldl_tail))))))));
|
|
108
|
+
hoiseted_foldl.hash;
|
|
109
|
+
// hoisted _mkFindDataOptional
|
|
110
|
+
const mkFind_elemToData = Symbol("elemToData");
|
|
111
|
+
const mkFind_pred = Symbol("predicate");
|
|
112
|
+
const mkFind_self = Symbol("findOpt_self");
|
|
113
|
+
const mkFind_list = Symbol("list");
|
|
114
|
+
const mkFind_head = Symbol("head");
|
|
115
|
+
export const hoisted_mkFindDataOptional = new IRHoisted(new IRFunc([mkFind_elemToData, mkFind_pred], new IRRecursive(mkFind_self, new IRFunc([mkFind_list], new IRForced(_ir_apps(new IRApp(IRNative.strictChooseList, new IRVar(mkFind_list)), new IRDelayed(IRConst.data(new DataConstr(1, []))), new IRDelayed(new IRApp(new IRFunc([mkFind_head], new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRApp(new IRVar(mkFind_pred), new IRVar(mkFind_head)), new IRDelayed(_ir_apps(IRNative.constrData, IRConst.int(0), new IRApp(new IRVar(mkFind_elemToData), new IRVar(mkFind_head)))), new IRDelayed(new IRApp(new IRSelfCall(mkFind_self), new IRApp(IRNative.tailList, new IRVar(mkFind_list))))))), new IRApp(IRNative.headList, new IRVar(mkFind_list))))))))));
|
|
116
|
+
hoisted_mkFindDataOptional.hash;
|
|
117
|
+
// hoisted strictAnd / strictOr
|
|
118
|
+
const strictAnd_a = Symbol("a");
|
|
119
|
+
const strictAnd_b = Symbol("b");
|
|
120
|
+
export const hoisted_strictAnd = new IRHoisted(new IRFunc([strictAnd_a, strictAnd_b], _ir_apps(IRNative.strictIfThenElse, new IRVar(strictAnd_a), new IRVar(strictAnd_b), IRConst.bool(false))));
|
|
121
|
+
hoisted_strictAnd.hash;
|
|
122
|
+
const strictOr_a = Symbol("a");
|
|
123
|
+
const strictOr_b = Symbol("b");
|
|
124
|
+
export const hoisted_strictOr = new IRHoisted(new IRFunc([strictOr_a, strictOr_b], _ir_apps(IRNative.strictIfThenElse, new IRVar(strictOr_a), IRConst.bool(true), new IRVar(strictOr_b))));
|
|
125
|
+
hoisted_strictOr.hash;
|
|
126
|
+
// hoisted _some
|
|
127
|
+
const some_pred = Symbol("predicate");
|
|
128
|
+
const some_dummy = Symbol("_self");
|
|
129
|
+
const some_self = Symbol("self");
|
|
130
|
+
const some_head = Symbol("head");
|
|
131
|
+
const some_tail = Symbol("tail");
|
|
132
|
+
export const hoisted_some = new IRHoisted(new IRFunc([some_pred], _ir_apps(hoisted_recursiveList.clone(), new IRFunc([some_dummy], new IRDelayed(IRConst.bool(false))), new IRFunc([some_self, some_head, some_tail], new IRForced(_ir_apps(hoisted_strictOr.clone(), new IRDelayed(new IRApp(new IRVar(some_pred), new IRVar(some_head))), new IRDelayed(new IRApp(new IRVar(some_self), new IRVar(some_tail)))))))));
|
|
133
|
+
hoisted_some.hash;
|
|
134
|
+
// hoisted _every
|
|
135
|
+
const every_pred = Symbol("predicate");
|
|
136
|
+
const every_dummy = Symbol("_self");
|
|
137
|
+
const every_self = Symbol("self");
|
|
138
|
+
const every_head = Symbol("head");
|
|
139
|
+
const every_tail = Symbol("tail");
|
|
140
|
+
export const hoisted_every = new IRHoisted(new IRFunc([every_pred], _ir_apps(hoisted_recursiveList.clone(), new IRFunc([every_dummy], new IRDelayed(IRConst.bool(true))), new IRFunc([every_self, every_head, every_tail], new IRForced(_ir_apps(hoisted_strictAnd.clone(), new IRDelayed(new IRApp(new IRVar(every_pred), new IRVar(every_head))), new IRDelayed(new IRApp(new IRVar(every_self), new IRVar(every_tail)))))))));
|
|
141
|
+
hoisted_every.hash;
|
|
142
|
+
// hoisted _mkFilter
|
|
143
|
+
const filt_pnil = Symbol("pnilOfType");
|
|
144
|
+
const filt_pred = Symbol("predicate");
|
|
145
|
+
const filt_elem = Symbol("elem");
|
|
146
|
+
const filt_acc = Symbol("accum");
|
|
147
|
+
export const hoisted_mkFilter = new IRHoisted(new IRFunc([filt_pnil, filt_pred], _ir_apps(hoisted_foldr.clone(), new IRFunc([filt_elem, filt_acc], new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRApp(new IRVar(filt_pred), new IRVar(filt_elem)), new IRDelayed(_ir_apps(IRNative.mkCons, new IRVar(filt_elem), new IRVar(filt_acc))), new IRDelayed(new IRVar(filt_acc))))), new IRVar(filt_pnil))));
|
|
148
|
+
hoisted_mkFilter.hash;
|
|
149
|
+
// comparison & conversion hoisted (previously inline)
|
|
150
|
+
const gtbs_a = Symbol("a"), gtbs_b = Symbol("b");
|
|
151
|
+
export const hoisted_gtBS = new IRHoisted(new IRFunc([gtbs_a, gtbs_b], _ir_apps(IRNative.lessThanByteString, new IRVar(gtbs_b), new IRVar(gtbs_a))));
|
|
152
|
+
hoisted_gtBS.hash;
|
|
153
|
+
const gteqbs_a = Symbol("a"), gteqbs_b = Symbol("b");
|
|
154
|
+
export const hoisted_gtEqBS = new IRHoisted(new IRFunc([gteqbs_a, gteqbs_b], _ir_apps(IRNative.lessThanEqualsByteString, new IRVar(gteqbs_b), new IRVar(gteqbs_a))));
|
|
155
|
+
hoisted_gtEqBS.hash;
|
|
156
|
+
const gt_a = Symbol("a"), gt_b = Symbol("b");
|
|
157
|
+
export const hoisted_gtInt = new IRHoisted(new IRFunc([gt_a, gt_b], _ir_apps(IRNative.lessThanInteger, new IRVar(gt_b), new IRVar(gt_a))));
|
|
158
|
+
hoisted_gtInt.hash;
|
|
159
|
+
const gteq_a = Symbol("a"), gteq_b = Symbol("b");
|
|
160
|
+
export const hoisted_gtEqInt = new IRHoisted(new IRFunc([gteq_a, gteq_b], _ir_apps(IRNative.lessThanEqualInteger, new IRVar(gteq_b), new IRVar(gteq_a))));
|
|
161
|
+
hoisted_gtEqInt.hash;
|
|
162
|
+
const s2d_str = Symbol("str");
|
|
163
|
+
export const hoisted_strToData = new IRHoisted(new IRFunc([s2d_str], new IRApp(IRNative.bData, new IRApp(IRNative.encodeUtf8, new IRVar(s2d_str)))));
|
|
164
|
+
hoisted_strToData.hash;
|
|
165
|
+
const pdt_pair = Symbol("pair");
|
|
166
|
+
export const hoisted_pairDataToData = new IRHoisted(new IRFunc([pdt_pair], new IRApp(IRNative.listData, _ir_apps(IRNative.mkCons, new IRApp(IRNative.fstPair, new IRVar(pdt_pair)), _ir_apps(IRNative.mkCons, new IRApp(IRNative.sndPair, new IRVar(pdt_pair)), new IRApp(IRNative.mkNilData, IRConst.unit))))));
|
|
167
|
+
hoisted_pairDataToData.hash;
|
|
168
|
+
const dataStr = Symbol("data");
|
|
169
|
+
export const hoisted_strFromData = new IRHoisted(new IRFunc([dataStr], new IRApp(IRNative.decodeUtf8, new IRApp(IRNative.unBData, new IRVar(dataStr)))));
|
|
170
|
+
hoisted_strFromData.hash;
|
|
171
|
+
const pdfd_data = Symbol("data");
|
|
172
|
+
const pdfd_unlisted = Symbol("unlisted_data");
|
|
173
|
+
export const hoisted_pairDataFromData = new IRHoisted(new IRFunc([pdfd_data], new IRApp(new IRFunc([pdfd_unlisted], _ir_apps(IRNative.mkPairData, new IRApp(IRNative.headList, new IRVar(pdfd_unlisted)), new IRApp(IRNative.headList, new IRApp(IRNative.tailList, new IRVar(pdfd_unlisted))))), new IRApp(IRNative.unListData, new IRVar(pdfd_data)))));
|
|
174
|
+
hoisted_pairDataFromData.hash;
|
|
175
|
+
const boolSym = Symbol("bool");
|
|
176
|
+
export const hoisted_boolToInt = new IRHoisted(new IRFunc([boolSym], _ir_apps(IRNative.strictIfThenElse, new IRVar(boolSym), IRConst.int(1), IRConst.int(0))));
|
|
177
|
+
hoisted_boolToInt.hash;
|
|
178
|
+
const intSym = Symbol("int");
|
|
179
|
+
export const hoisted_intToBytesBE = new IRHoisted(new IRFunc([intSym], _ir_apps(IRNative.integerToByteString, IRConst.bool(true), _ir_apps(hoisted_sizeofPositiveInt.clone(), new IRVar(intSym)), new IRVar(intSym))));
|
|
180
|
+
hoisted_intToBytesBE.hash;
|
|
181
|
+
// hoisted exponentiateInteger
|
|
182
|
+
const baseSym = Symbol("base");
|
|
183
|
+
const expSym = Symbol("exponent");
|
|
184
|
+
const exp_self = Symbol("expInt_self");
|
|
185
|
+
const nSym = Symbol("n");
|
|
186
|
+
const xSym = Symbol("x");
|
|
187
|
+
export const hoisted_exponentiateInteger = new IRHoisted(new IRFunc([baseSym, expSym], new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isNonNegative.clone(), new IRVar(expSym)), new IRDelayed(new IRRecursive(exp_self, new IRFunc([nSym, xSym], new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(nSym)), new IRDelayed(IRConst.int(1)), new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isOne.clone(), new IRVar(nSym)), new IRDelayed(new IRVar(xSym)), new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), _ir_apps(IRNative.modInteger, new IRVar(nSym), IRConst.int(2))), new IRDelayed(_ir_let(_ir_apps(new IRSelfCall(exp_self), new IRVar(xSym), _ir_apps(IRNative.divideInteger, new IRVar(nSym), IRConst.int(2))), halfSym => _ir_apps(IRNative.multiplyInteger, new IRVar(halfSym), new IRVar(halfSym)))), new IRDelayed(_ir_apps(IRNative.multiplyInteger, new IRVar(xSym), _ir_apps(new IRSelfCall(exp_self), new IRVar(xSym), _ir_apps(hoisted_subOne.clone(), new IRVar(nSym)))))))))))))))), new IRDelayed(new IRError())))));
|
|
188
|
+
hoisted_exponentiateInteger.hash;
|
|
189
|
+
// already external: hoiseted_foldl
|
|
175
190
|
export function nativeToIR(native) {
|
|
176
191
|
// positive natives are translated to uplc builtins (no need to hoist)
|
|
177
192
|
if (native.tag >= 0)
|
|
178
193
|
return native;
|
|
179
194
|
switch (native.tag) {
|
|
180
|
-
case IRNativeTag._foldr:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
case IRNativeTag.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
case IRNativeTag.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
new IRDelayed(_ir_apps(IRNative.constrData, IRConst.int(0), // just contructor
|
|
213
|
-
new IRApp(new IRVar(4), // elemToData
|
|
214
|
-
new IRVar(0) // head
|
|
215
|
-
))),
|
|
216
|
-
// else
|
|
217
|
-
new IRDelayed(new IRApp(new IRSelfCall(2), // self
|
|
218
|
-
new IRApp(IRNative.tailList, new IRVar(1) // list
|
|
219
|
-
)))))), new IRApp(IRNative.headList, new IRVar(0) // list
|
|
220
|
-
)))))))));
|
|
221
|
-
break;
|
|
222
|
-
case IRNativeTag._length:
|
|
223
|
-
return new IRHoisted(new IRRecursive(// self
|
|
224
|
-
new IRFunc(1, // list
|
|
225
|
-
new IRForced(_ir_apps(new IRApp(IRNative.strictChooseList, new IRVar(0) // list
|
|
226
|
-
),
|
|
227
|
-
// then
|
|
228
|
-
IRConst.int(0),
|
|
229
|
-
// else
|
|
230
|
-
_ir_apps(hoisted_incr.clone(), new IRApp(new IRSelfCall(1), // self
|
|
231
|
-
new IRApp(// list.tail
|
|
232
|
-
IRNative.tailList, new IRVar(0) // list
|
|
233
|
-
))))))));
|
|
234
|
-
break;
|
|
235
|
-
case IRNativeTag._some:
|
|
236
|
-
return new IRHoisted(new IRFunc(1, // predicate
|
|
237
|
-
_ir_apps(hoisted_recursiveList.clone(), new IRFunc(1, // _self
|
|
238
|
-
new IRDelayed(// pdelay( pBool( true ) )
|
|
239
|
-
IRConst.bool(false))), new IRFunc(3, // self, head, tail
|
|
240
|
-
_ir_apps(hoisted_lazyOr.clone(), // lazy in second
|
|
241
|
-
new IRApp(new IRVar(3), // predicate ( 0, 1, 2 are of callback, 3 is predicate )
|
|
242
|
-
new IRVar(1)), new IRDelayed(new IRApp(new IRVar(2), // self
|
|
243
|
-
new IRVar(0) // tail
|
|
244
|
-
)))))));
|
|
245
|
-
break;
|
|
246
|
-
case IRNativeTag._every:
|
|
247
|
-
return new IRHoisted(new IRFunc(1, // predicate
|
|
248
|
-
_ir_apps(hoisted_recursiveList.clone(), new IRFunc(1, // _self
|
|
249
|
-
new IRDelayed(// pdelay( pBool( true ) )
|
|
250
|
-
IRConst.bool(true))), new IRFunc(3, // self, head, tail
|
|
251
|
-
_ir_apps(hoisted_lazyAnd.clone(), // lazy in second
|
|
252
|
-
new IRApp(new IRVar(3), // predicate ( 0, 1, 2 are of callback, 3 is predicate )
|
|
253
|
-
new IRVar(1)), new IRDelayed(new IRApp(new IRVar(2), // self
|
|
254
|
-
new IRVar(0) // tail
|
|
255
|
-
)))))));
|
|
256
|
-
break;
|
|
257
|
-
case IRNativeTag._mkFilter:
|
|
258
|
-
return new IRHoisted(new IRFunc(2, // pnilOfType, predicate
|
|
259
|
-
_ir_apps(hoisted_foldr.clone(), new IRFunc(2, // elem, accum
|
|
260
|
-
new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRApp(new IRVar(2), // predicate
|
|
261
|
-
new IRVar(1) // elem
|
|
262
|
-
),
|
|
263
|
-
// then
|
|
264
|
-
new IRDelayed(_ir_apps(IRNative.mkCons, new IRVar(1), // elem
|
|
265
|
-
new IRVar(0) // accum
|
|
266
|
-
)),
|
|
267
|
-
// else
|
|
268
|
-
// filter out this element
|
|
269
|
-
new IRDelayed(new IRVar(0) // accum
|
|
270
|
-
)))),
|
|
271
|
-
// initial accum
|
|
272
|
-
new IRVar(3) // pnilOfType
|
|
273
|
-
)));
|
|
274
|
-
break;
|
|
275
|
-
// case IRNativeTag._fstPair :
|
|
276
|
-
// return new IRHoisted();
|
|
277
|
-
// break;
|
|
278
|
-
// case IRNativeTag._sndPair :
|
|
279
|
-
// return new IRHoisted();
|
|
280
|
-
// break;
|
|
281
|
-
case IRNativeTag._id:
|
|
282
|
-
return hoisted_id.clone();
|
|
283
|
-
break;
|
|
284
|
-
case IRNativeTag._not:
|
|
285
|
-
return hoisted_not.clone();
|
|
286
|
-
break;
|
|
287
|
-
case IRNativeTag._strictAnd:
|
|
288
|
-
return new IRHoisted(new IRFunc(2, // a, b
|
|
289
|
-
_ir_apps(IRNative.strictIfThenElse, new IRVar(1), // a
|
|
290
|
-
new IRVar(0), // a == true -> whatever b is
|
|
291
|
-
IRConst.bool(false) // a == false -> false
|
|
292
|
-
)));
|
|
293
|
-
break;
|
|
294
|
-
case IRNativeTag._and:
|
|
295
|
-
return hoisted_lazyAnd.clone();
|
|
296
|
-
break;
|
|
297
|
-
case IRNativeTag._strictOr:
|
|
298
|
-
return new IRHoisted(new IRFunc(2, // a, b
|
|
299
|
-
_ir_apps(IRNative.strictIfThenElse, new IRVar(1), // a
|
|
300
|
-
IRConst.bool(true), // a == true -> true
|
|
301
|
-
new IRVar(0) // a == false -> whatever b is
|
|
302
|
-
)));
|
|
303
|
-
break;
|
|
304
|
-
case IRNativeTag._or:
|
|
305
|
-
return hoisted_lazyOr.clone();
|
|
306
|
-
break;
|
|
307
|
-
case IRNativeTag._gtBS:
|
|
308
|
-
return new IRHoisted(new IRFunc(2, // a, b
|
|
309
|
-
_ir_apps(IRNative.lessThanByteString, new IRVar(0), // b
|
|
310
|
-
new IRVar(1))));
|
|
311
|
-
break;
|
|
312
|
-
case IRNativeTag._gtEqBS:
|
|
313
|
-
return new IRHoisted(new IRFunc(2, // a, b
|
|
314
|
-
_ir_apps(IRNative.lessThanEqualsByteString, new IRVar(0), // b
|
|
315
|
-
new IRVar(1))));
|
|
316
|
-
break;
|
|
317
|
-
case IRNativeTag._gtInt:
|
|
318
|
-
return new IRHoisted(new IRFunc(2, // a, b
|
|
319
|
-
_ir_apps(IRNative.lessThanInteger, new IRVar(0), // b
|
|
320
|
-
new IRVar(1))));
|
|
321
|
-
break;
|
|
322
|
-
case IRNativeTag._gtEqInt:
|
|
323
|
-
return new IRHoisted(new IRFunc(2, // a, b
|
|
324
|
-
_ir_apps(IRNative.lessThanEqualInteger, new IRVar(0), // b
|
|
325
|
-
new IRVar(1))));
|
|
326
|
-
break;
|
|
327
|
-
case IRNativeTag._strToData:
|
|
328
|
-
return new IRHoisted(new IRFunc(1, // str
|
|
329
|
-
new IRApp(IRNative.bData, new IRApp(IRNative.encodeUtf8, new IRVar(0) // str
|
|
330
|
-
))));
|
|
331
|
-
break;
|
|
332
|
-
case IRNativeTag._pairDataToData:
|
|
333
|
-
return new IRHoisted(new IRFunc(1, // pair
|
|
334
|
-
new IRApp(IRNative.listData, _ir_apps(IRNative.mkCons, new IRApp(IRNative.fstPair, new IRVar(0)), _ir_apps(IRNative.mkCons, new IRApp(IRNative.sndPair, new IRVar(0)), new IRApp(IRNative.mkNilData, IRConst.unit))))));
|
|
335
|
-
break;
|
|
336
|
-
case IRNativeTag._strFromData:
|
|
337
|
-
return new IRHoisted(new IRFunc(1, // data
|
|
338
|
-
new IRApp(IRNative.decodeUtf8, new IRApp(IRNative.unBData, new IRVar(0) // data
|
|
339
|
-
))));
|
|
340
|
-
break;
|
|
341
|
-
case IRNativeTag._pairDataFromData:
|
|
342
|
-
return new IRHoisted(new IRFunc(1, // data
|
|
343
|
-
new IRApp(new IRFunc(1, // unlisted_data
|
|
344
|
-
_ir_apps(IRNative.mkPairData, new IRApp(IRNative.headList, new IRVar(0) // unlised_data
|
|
345
|
-
), new IRApp(IRNative.headList, new IRApp(IRNative.tailList, new IRVar(0) // unlised_data
|
|
346
|
-
)))), new IRApp(IRNative.unListData, new IRVar(0) // data
|
|
347
|
-
))));
|
|
348
|
-
break;
|
|
349
|
-
case IRNativeTag._mkMapList:
|
|
350
|
-
{
|
|
351
|
-
return new IRHoisted(new IRFunc(2, // nilListOfType, mapFn
|
|
352
|
-
new IRRecursive(// self
|
|
353
|
-
new IRFunc(1, // lst
|
|
354
|
-
new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(0), // lst
|
|
355
|
-
// case Nil
|
|
356
|
-
new IRDelayed(new IRVar(3)), // delay( nilListOfType )
|
|
357
|
-
// case Cons
|
|
358
|
-
new IRDelayed(_ir_apps(IRNative.mkCons, _ir_apps(new IRVar(2), // mapFn
|
|
359
|
-
_ir_apps(IRNative.headList, new IRVar(0) // lst
|
|
360
|
-
)), _ir_apps(new IRSelfCall(1), // self
|
|
361
|
-
_ir_apps(IRNative.tailList, new IRVar(0) // lst
|
|
362
|
-
))))))))));
|
|
363
|
-
}
|
|
364
|
-
break;
|
|
365
|
-
case IRNativeTag._equalBoolean:
|
|
366
|
-
{
|
|
367
|
-
return new IRHoisted(new IRFunc(1, _ir_apps(IRNative.strictIfThenElse, new IRVar(0), // a
|
|
368
|
-
hoisted_id.clone(), // a == true -> true
|
|
369
|
-
hoisted_not.clone() // a == false -> b ? false : true
|
|
370
|
-
)));
|
|
371
|
-
}
|
|
372
|
-
break;
|
|
373
|
-
case IRNativeTag._negateInt:
|
|
374
|
-
{
|
|
375
|
-
return new IRHoisted(_ir_apps(IRNative.subtractInteger, IRConst.int(0)));
|
|
376
|
-
}
|
|
377
|
-
break;
|
|
378
|
-
case IRNativeTag._bytesToIntBE:
|
|
379
|
-
{
|
|
380
|
-
return new IRHoisted(_ir_apps(IRNative.byteStringToInteger, IRConst.bool(true) // big endian
|
|
381
|
-
));
|
|
382
|
-
}
|
|
383
|
-
break;
|
|
384
|
-
case IRNativeTag._boolToInt:
|
|
385
|
-
{
|
|
386
|
-
return new IRHoisted(new IRFunc(1, // bool
|
|
387
|
-
_ir_apps(IRNative.strictIfThenElse, new IRVar(0), // bool
|
|
388
|
-
IRConst.int(1), // b == true -> 1
|
|
389
|
-
IRConst.int(0) // b == false -> 0
|
|
390
|
-
)));
|
|
391
|
-
}
|
|
392
|
-
break;
|
|
393
|
-
case IRNativeTag._intToBytesBE:
|
|
394
|
-
{
|
|
395
|
-
return new IRHoisted(new IRFunc(1, // int
|
|
396
|
-
_ir_apps(IRNative.integerToByteString, IRConst.bool(true), // big endian
|
|
397
|
-
_ir_apps(// int size
|
|
398
|
-
hoisted_sizeofPositiveInt.clone(),
|
|
399
|
-
// integerToByteString fails for negative integers
|
|
400
|
-
// so we don't bother converting negative to positive here
|
|
401
|
-
new IRVar(0) // int
|
|
402
|
-
), new IRVar(0) // int
|
|
403
|
-
)));
|
|
404
|
-
}
|
|
405
|
-
break;
|
|
406
|
-
case IRNativeTag._intToBool:
|
|
407
|
-
{
|
|
408
|
-
return hoisted_isNonNegative.clone();
|
|
409
|
-
}
|
|
410
|
-
break;
|
|
411
|
-
case IRNativeTag._exponentiateInteger:
|
|
412
|
-
{
|
|
413
|
-
return new IRHoisted(new IRFunc(2, // base, exponent
|
|
414
|
-
new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isNonNegative.clone(), new IRVar(0) // exponent
|
|
415
|
-
),
|
|
416
|
-
// then, normal exponentiation
|
|
417
|
-
new IRDelayed(new IRRecursive(new IRFunc(2, // expInt, x, n
|
|
418
|
-
new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(0) // n
|
|
419
|
-
),
|
|
420
|
-
// then (n == 0)
|
|
421
|
-
// yes, even `0 ** 0` is 1
|
|
422
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation#description
|
|
423
|
-
new IRDelayed(IRConst.int(1)), // return 1
|
|
424
|
-
// else (n > 0)
|
|
425
|
-
new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isOne.clone(), new IRVar(0) // n
|
|
426
|
-
),
|
|
427
|
-
// then (n == 1)
|
|
428
|
-
new IRDelayed(new IRVar(1)), // return x
|
|
429
|
-
// else (n > 1)
|
|
430
|
-
new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), _ir_apps(IRNative.modInteger, new IRVar(0), // exponent
|
|
431
|
-
IRConst.int(2))),
|
|
432
|
-
// then (exponent % 2 == 0)
|
|
433
|
-
new IRDelayed(_ir_let(_ir_apps(new IRSelfCall(2), // expInt
|
|
434
|
-
new IRVar(1), // x
|
|
435
|
-
_ir_apps(IRNative.divideInteger, new IRVar(0), // exponent
|
|
436
|
-
IRConst.int(2))), // half
|
|
437
|
-
_ir_apps(IRNative.multiplyInteger, new IRVar(0), // half
|
|
438
|
-
new IRVar(0) // half
|
|
439
|
-
))),
|
|
440
|
-
// else (exponent % 2 == 1)
|
|
441
|
-
new IRDelayed(_ir_apps(// x * expInt( x, n - 1 )
|
|
442
|
-
IRNative.multiplyInteger, new IRVar(1), // x
|
|
443
|
-
_ir_apps(new IRSelfCall(2), // expInt
|
|
444
|
-
new IRVar(1), // x
|
|
445
|
-
_ir_apps(hoisted_subOne.clone(), new IRVar(0)))))))))))))))),
|
|
446
|
-
// else (exponent < 0) fails
|
|
447
|
-
new IRDelayed(new IRError())))));
|
|
448
|
-
}
|
|
449
|
-
break;
|
|
450
|
-
case IRNativeTag._amountOfValue:
|
|
451
|
-
{
|
|
452
|
-
// ((policy => bool), value, (tokenName => bool)) => amount
|
|
453
|
-
return hoisted_amountOfValue.clone();
|
|
454
|
-
}
|
|
455
|
-
break;
|
|
456
|
-
case IRNativeTag._isZero:
|
|
457
|
-
{
|
|
458
|
-
return hoisted_isZero.clone();
|
|
459
|
-
}
|
|
460
|
-
break;
|
|
461
|
-
case IRNativeTag._sortedValueLovelaces:
|
|
462
|
-
{
|
|
463
|
-
return new IRHoisted(new IRFunc(1, // value
|
|
464
|
-
_ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, _ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, new IRVar(0) // value
|
|
465
|
-
))))))));
|
|
466
|
-
}
|
|
467
|
-
break;
|
|
468
|
-
case IRNativeTag._dropList:
|
|
469
|
-
{
|
|
470
|
-
return hoisted_dropList.clone();
|
|
471
|
-
}
|
|
472
|
-
break;
|
|
473
|
-
default: throw new Error("unknown (negative) native calling 'nativeToIR'; " +
|
|
474
|
-
"number: " + native.tag + "; " +
|
|
475
|
-
"name: " + IRNativeTag[native.tag]);
|
|
195
|
+
case IRNativeTag._foldr: return hoisted_foldr.clone();
|
|
196
|
+
case IRNativeTag._foldl: return hoiseted_foldl.clone();
|
|
197
|
+
case IRNativeTag._mkFindDataOptional: return hoisted_mkFindDataOptional.clone();
|
|
198
|
+
case IRNativeTag._length: return hoisted_length.clone();
|
|
199
|
+
case IRNativeTag._some: return hoisted_some.clone();
|
|
200
|
+
case IRNativeTag._every: return hoisted_every.clone();
|
|
201
|
+
case IRNativeTag._mkFilter: return hoisted_mkFilter.clone();
|
|
202
|
+
case IRNativeTag._id: return hoisted_id.clone();
|
|
203
|
+
case IRNativeTag._not: return hoisted_not.clone();
|
|
204
|
+
case IRNativeTag._strictAnd: return hoisted_strictAnd.clone();
|
|
205
|
+
case IRNativeTag._strictOr: return hoisted_strictOr.clone();
|
|
206
|
+
case IRNativeTag._gtBS: return hoisted_gtBS.clone();
|
|
207
|
+
case IRNativeTag._gtEqBS: return hoisted_gtEqBS.clone();
|
|
208
|
+
case IRNativeTag._gtInt: return hoisted_gtInt.clone();
|
|
209
|
+
case IRNativeTag._gtEqInt: return hoisted_gtEqInt.clone();
|
|
210
|
+
case IRNativeTag._strToData: return hoisted_strToData.clone();
|
|
211
|
+
case IRNativeTag._pairDataToData: return hoisted_pairDataToData.clone();
|
|
212
|
+
case IRNativeTag._strFromData: return hoisted_strFromData.clone();
|
|
213
|
+
case IRNativeTag._pairDataFromData: return hoisted_pairDataFromData.clone();
|
|
214
|
+
case IRNativeTag._boolToInt: return hoisted_boolToInt.clone();
|
|
215
|
+
case IRNativeTag._intToBytesBE: return hoisted_intToBytesBE.clone();
|
|
216
|
+
case IRNativeTag._intToBool: return hoisted_isNonNegative.clone();
|
|
217
|
+
case IRNativeTag._exponentiateInteger: return hoisted_exponentiateInteger.clone();
|
|
218
|
+
case IRNativeTag._amountOfValue: return hoisted_amountOfValue.clone();
|
|
219
|
+
case IRNativeTag._isZero: return hoisted_isZero.clone();
|
|
220
|
+
case IRNativeTag._sortedValueLovelaces: return hoisted_sortedValueLovelaces.clone?.() ?? (() => { throw new Error("_sortedValueLovelaces hoisted const missing"); })();
|
|
221
|
+
case IRNativeTag._dropList: return hoisted_dropList.clone();
|
|
222
|
+
case IRNativeTag._mkMapList: return hoisted_mkMapList.clone();
|
|
223
|
+
// case IRNativeTag._mkEqualsList: return hoisted_mkEqualsList.clone();
|
|
224
|
+
default:
|
|
225
|
+
throw new Error("unknown (negative) native calling 'nativeToIR'; " +
|
|
226
|
+
"number: " + native.tag + "; name: " + IRNativeTag[native.tag]);
|
|
476
227
|
}
|
|
477
228
|
}
|
|
229
|
+
// ( a => b => bool ) => [a] => [b] => bool
|
|
230
|
+
const eqList_eqFunc = Symbol("elemEq");
|
|
231
|
+
const eqList_self = Symbol("eqList_self");
|
|
232
|
+
const eqList_listA = Symbol("listA");
|
|
233
|
+
const eqList_listB = Symbol("listB");
|
|
234
|
+
export const hoisted_mkEqualsList = new IRHoisted(new IRFunc([eqList_eqFunc], new IRRecursive(eqList_self, new IRFunc([eqList_listA, eqList_listB], _ir_lazyChooseList(new IRVar(eqList_listA),
|
|
235
|
+
// case nil: check if listB is also nil
|
|
236
|
+
_ir_apps(IRNative.nullList, new IRVar(eqList_listB)),
|
|
237
|
+
// case cons
|
|
238
|
+
_ir_lazyChooseList(new IRVar(eqList_listB),
|
|
239
|
+
// listB is nil => false
|
|
240
|
+
IRConst.bool(false),
|
|
241
|
+
// both lists are cons
|
|
242
|
+
_ir_strictAnd(_ir_apps(new IRVar(eqList_eqFunc), new IRApp(IRNative.headList, new IRVar(eqList_listA)), new IRApp(IRNative.headList, new IRVar(eqList_listB))), _ir_apps(new IRSelfCall(eqList_self), new IRApp(IRNative.tailList, new IRVar(eqList_listA)), new IRApp(IRNative.tailList, new IRVar(eqList_listB))))))))));
|
|
243
|
+
hoisted_mkEqualsList.hash;
|
|
244
|
+
// (nil of type) => ( a => b ) => [a] => [b]
|
|
245
|
+
const mkMap_nil = Symbol("nilOfType");
|
|
246
|
+
const mkMap_mapFunc = Symbol("mapFunc");
|
|
247
|
+
const mkMap_map = Symbol("map_self");
|
|
248
|
+
const mkMap_list = Symbol("list");
|
|
249
|
+
export const hoisted_mkMapList = new IRHoisted(new IRFunc([mkMap_nil, mkMap_mapFunc], new IRRecursive(mkMap_map, new IRFunc([mkMap_list], _ir_lazyChooseList(new IRVar(mkMap_list),
|
|
250
|
+
// case nil: return nil of type
|
|
251
|
+
new IRVar(mkMap_nil),
|
|
252
|
+
// case cons
|
|
253
|
+
_ir_apps(IRNative.mkCons,
|
|
254
|
+
// mapFunc( head list )
|
|
255
|
+
_ir_apps(new IRVar(mkMap_mapFunc), new IRApp(IRNative.headList, new IRVar(mkMap_list))),
|
|
256
|
+
// recurse tail
|
|
257
|
+
_ir_apps(new IRSelfCall(mkMap_map), new IRApp(IRNative.tailList, new IRVar(mkMap_list)))))))));
|
|
258
|
+
hoisted_mkMapList.hash;
|
|
259
|
+
// If _sortedValueLovelaces was previously inline, hoist it:
|
|
260
|
+
const sorted_value = Symbol("value");
|
|
261
|
+
export const hoisted_sortedValueLovelaces = new IRHoisted(new IRFunc([sorted_value], _ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, _ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, new IRVar(sorted_value)))))))));
|
|
262
|
+
hoisted_sortedValueLovelaces.hash;
|
|
478
263
|
// ((policy => bool), value, (tokenName => bool)) => amount
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
)
|
|
264
|
+
// REPLACED hoisted_amountOfValue (symbol-based)
|
|
265
|
+
const amount_isPolicy = Symbol("isPolicy");
|
|
266
|
+
const amount_policyLoop = Symbol("policyLoop_self");
|
|
267
|
+
const amount_value = Symbol("value");
|
|
268
|
+
const amount_isTokenName = Symbol("isTokenName");
|
|
269
|
+
const amount_tokenNameLoop = Symbol("tokenNameLoop_self");
|
|
270
|
+
const amount_tokenMap = Symbol("tokenMap");
|
|
271
|
+
export const hoisted_amountOfValue = new IRHoisted(new IRFunc([amount_isPolicy], // (policy => bool)
|
|
272
|
+
new IRRecursive(amount_policyLoop, new IRFunc([amount_value], // value
|
|
273
|
+
new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(amount_value),
|
|
274
|
+
// case nil: return (tokenName => 0)
|
|
275
|
+
new IRDelayed(new IRFunc([amount_isTokenName], IRConst.int(0))),
|
|
486
276
|
// case cons
|
|
487
|
-
new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(
|
|
488
|
-
|
|
489
|
-
new
|
|
490
|
-
|
|
491
|
-
_ir_apps(
|
|
492
|
-
|
|
493
|
-
// then this is the policy
|
|
494
|
-
new IRDelayed(new IRFunc(1, // 4: isPolicy, 3: policyLoop, 2: value, 1: pairData, 0: isTokenName
|
|
495
|
-
_ir_apps(new IRRecursive(new IRFunc(1, // 6: isPolicy, 5: policyLoop, 4: value, 3: pairData, 2: isTokenName, 1: tokenNameLoop, 0: tokenMap
|
|
496
|
-
new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(0), // tokenMap
|
|
497
|
-
// case nil
|
|
277
|
+
new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(amount_value)), pairDataSym => new IRForced(_ir_apps(IRNative.strictIfThenElse,
|
|
278
|
+
// isPolicy( fst pairData as bytes )
|
|
279
|
+
_ir_apps(new IRVar(amount_isPolicy), _ir_apps(IRNative.unBData, _ir_apps(IRNative.fstPair, new IRVar(pairDataSym)))),
|
|
280
|
+
// then: build (tokenName => amount)
|
|
281
|
+
new IRDelayed(new IRFunc([amount_isTokenName], _ir_apps(new IRRecursive(amount_tokenNameLoop, new IRFunc([amount_tokenMap], new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(amount_tokenMap),
|
|
282
|
+
// token map empty => 0
|
|
498
283
|
new IRDelayed(IRConst.int(0)),
|
|
499
|
-
//
|
|
500
|
-
new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(
|
|
501
|
-
|
|
502
|
-
new
|
|
503
|
-
|
|
504
|
-
_ir_apps(IRNative.
|
|
505
|
-
|
|
506
|
-
//
|
|
507
|
-
new IRDelayed(_ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, new IRVar(0) // pairDataToken
|
|
508
|
-
))),
|
|
509
|
-
// else check next token entry
|
|
510
|
-
new IRDelayed(_ir_apps(new IRSelfCall(2), // tokenNameLoop
|
|
511
|
-
_ir_apps(IRNative.tailList, new IRVar(1) // tokenMap
|
|
284
|
+
// token map cons
|
|
285
|
+
new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(amount_tokenMap)), pairDataTokenSym => new IRForced(_ir_apps(IRNative.strictIfThenElse,
|
|
286
|
+
// isTokenName( fst pairDataToken as bytes )
|
|
287
|
+
_ir_apps(new IRVar(amount_isTokenName), _ir_apps(IRNative.unBData, _ir_apps(IRNative.fstPair, new IRVar(pairDataTokenSym))),
|
|
288
|
+
// then: return amount
|
|
289
|
+
new IRDelayed(_ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, new IRVar(pairDataTokenSym)))),
|
|
290
|
+
// else: recurse tail
|
|
291
|
+
new IRDelayed(_ir_apps(new IRSelfCall(amount_tokenNameLoop), _ir_apps(IRNative.tailList, new IRVar(amount_tokenMap) // tokenMap list
|
|
512
292
|
)))))))))))),
|
|
513
|
-
//
|
|
514
|
-
_ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, new IRVar(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
new IRDelayed(_ir_apps(new IRSelfCall(2), // policyLoop
|
|
518
|
-
_ir_apps(IRNative.tailList, new IRVar(1) // value
|
|
519
|
-
)))))))))))));
|
|
293
|
+
// pass token map (snd pairData)
|
|
294
|
+
_ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, new IRVar(pairDataSym)))))),
|
|
295
|
+
// else: recurse policyLoop on tail value list
|
|
296
|
+
new IRDelayed(_ir_apps(new IRSelfCall(amount_policyLoop), _ir_apps(IRNative.tailList, new IRVar(amount_value))))))))))))));
|
|
520
297
|
hoisted_amountOfValue.hash;
|