@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
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { fromUtf8, concatUint8Array, toUtf8 } from "@harmoniclabs/uint8array-utils";
|
|
2
2
|
export class ConsoleLogStream {
|
|
3
|
+
_pending = "";
|
|
3
4
|
write(chunk) {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const newChunk = (chunk instanceof Uint8Array) ? toUtf8(chunk) : chunk.toString();
|
|
6
|
+
if (newChunk.includes("\n")) {
|
|
7
|
+
const parts = newChunk.split("\n");
|
|
8
|
+
if (parts.length === 1) {
|
|
9
|
+
// only one \n
|
|
10
|
+
console.log(this._pending + parts[0]);
|
|
11
|
+
this._pending = "";
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// multiple \n
|
|
15
|
+
console.log(this._pending + parts[0]);
|
|
16
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
17
|
+
console.log(parts[i]);
|
|
18
|
+
}
|
|
19
|
+
this._pending = parts[parts.length - 1];
|
|
20
|
+
}
|
|
6
21
|
}
|
|
7
22
|
else {
|
|
8
|
-
|
|
23
|
+
this._pending += newChunk;
|
|
9
24
|
}
|
|
10
25
|
}
|
|
11
26
|
}
|
|
@@ -58,17 +58,15 @@ export function getEnvRelativePath(filePath, projectRoot) {
|
|
|
58
58
|
if (!(typeof filePath === 'string' &&
|
|
59
59
|
typeof projectRoot === 'string'))
|
|
60
60
|
return undefined;
|
|
61
|
+
projectRoot = projectRoot.trim();
|
|
62
|
+
if (!projectRoot.endsWith(PATH_DELIMITER))
|
|
63
|
+
projectRoot += PATH_DELIMITER;
|
|
61
64
|
if (isAbsolutePath(filePath))
|
|
62
65
|
return filePath;
|
|
63
|
-
projectRoot = projectRoot.trim();
|
|
64
66
|
filePath = getAbsolutePath(filePath.trim(), projectRoot);
|
|
65
67
|
if (!filePath)
|
|
66
68
|
return undefined;
|
|
67
|
-
|
|
68
|
-
projectRoot = projectRoot + PATH_DELIMITER;
|
|
69
|
-
while (filePath.startsWith(PATH_DELIMITER))
|
|
70
|
-
filePath = filePath.slice(PATH_DELIMITER.length);
|
|
71
|
-
return projectRoot + filePath;
|
|
69
|
+
return filePath.startsWith(projectRoot) ? filePath : projectRoot + filePath;
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
72
|
* Takes a relative path and an absolute path, and returns the absolute path
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SourceRange } from "../../../ast/Source/SourceRange.js";
|
|
2
|
-
import { IRTerm } from "../../../IR/IRTerm.js";
|
|
2
|
+
import type { IRTerm } from "../../../IR/IRTerm.js";
|
|
3
3
|
import { TirAssertStmt } from "../statements/TirAssertStmt.js";
|
|
4
4
|
import { TirType } from "../types/TirType.js";
|
|
5
5
|
import { ITirExpr } from "./ITirExpr.js";
|
|
@@ -11,7 +11,9 @@ export declare class TirAssertAndContinueExpr implements ITirExpr {
|
|
|
11
11
|
readonly range: SourceRange;
|
|
12
12
|
get type(): TirType;
|
|
13
13
|
constructor(conditions: TirExpr[], continuation: TirExpr, range: SourceRange);
|
|
14
|
-
|
|
14
|
+
toString(): string;
|
|
15
|
+
pretty(indent: number): string;
|
|
16
|
+
clone(): TirExpr;
|
|
15
17
|
static fromStmtsAndContinuation(assertions: TirAssertStmt[], continuation: TirExpr): TirExpr;
|
|
16
18
|
deps(): string[];
|
|
17
19
|
get isConstant(): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
1
2
|
import { IRDelayed } from "../../../IR/IRNodes/IRDelayed.js";
|
|
2
3
|
import { IRError } from "../../../IR/IRNodes/IRError.js";
|
|
3
4
|
import { IRForced } from "../../../IR/IRNodes/IRForced.js";
|
|
4
5
|
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
5
|
-
import { _ir_apps } from "../../../IR/tree_utils/_ir_apps.js";
|
|
6
6
|
import { mergeSortedStrArrInplace } from "../../../utils/array/mergeSortedStrArrInplace.js";
|
|
7
7
|
export class TirAssertAndContinueExpr {
|
|
8
8
|
conditions;
|
|
@@ -16,6 +16,18 @@ export class TirAssertAndContinueExpr {
|
|
|
16
16
|
this.continuation = continuation;
|
|
17
17
|
this.range = range;
|
|
18
18
|
}
|
|
19
|
+
toString() {
|
|
20
|
+
return `assert ${this.conditions.map(c => c.toString()).join(" && ")} then ${this.continuation.toString()}`;
|
|
21
|
+
}
|
|
22
|
+
pretty(indent) {
|
|
23
|
+
const singleIndent = " ";
|
|
24
|
+
const indent_base = singleIndent.repeat(indent);
|
|
25
|
+
const indent_0 = "\n" + indent_base;
|
|
26
|
+
const indent_1 = indent_0 + singleIndent;
|
|
27
|
+
const conditionsPart = this.conditions.map(c => c.pretty(indent)).join(` &&${indent_1}`);
|
|
28
|
+
return (`assert ${conditionsPart}` +
|
|
29
|
+
`${indent_0}then ${this.continuation.pretty(indent)}`);
|
|
30
|
+
}
|
|
19
31
|
/// @ts-ignore Return type annotation circularly references itself.
|
|
20
32
|
clone() {
|
|
21
33
|
return new TirAssertAndContinueExpr(this.conditions.map(c => c.clone()), this.continuation.clone(), this.range.clone());
|
|
@@ -23,7 +35,9 @@ export class TirAssertAndContinueExpr {
|
|
|
23
35
|
static fromStmtsAndContinuation(assertions, continuation) {
|
|
24
36
|
if (assertions.length <= 0)
|
|
25
37
|
return continuation;
|
|
26
|
-
|
|
38
|
+
const correctAssertions = assertions.map(a => a.toSafeCondition());
|
|
39
|
+
assertions.length = 0;
|
|
40
|
+
return new TirAssertAndContinueExpr(correctAssertions, continuation, continuation.range);
|
|
27
41
|
}
|
|
28
42
|
deps() {
|
|
29
43
|
return (this.conditions
|
|
@@ -10,7 +10,9 @@ export declare class TirCallExpr implements ITirExpr {
|
|
|
10
10
|
readonly type: TirType;
|
|
11
11
|
readonly range: SourceRange;
|
|
12
12
|
constructor(func: TirExpr, args: TirExpr[], type: TirType, range: SourceRange);
|
|
13
|
-
|
|
13
|
+
toString(): string;
|
|
14
|
+
pretty(indent: number): string;
|
|
15
|
+
clone(): TirExpr;
|
|
14
16
|
deps(): string[];
|
|
15
17
|
get isConstant(): boolean;
|
|
16
18
|
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ir_apps } from "../../../IR/
|
|
1
|
+
import { _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
2
2
|
import { mergeSortedStrArrInplace } from "../../../utils/array/mergeSortedStrArrInplace.js";
|
|
3
3
|
export class TirCallExpr {
|
|
4
4
|
func;
|
|
@@ -11,6 +11,21 @@ export class TirCallExpr {
|
|
|
11
11
|
this.type = type;
|
|
12
12
|
this.range = range;
|
|
13
13
|
}
|
|
14
|
+
toString() {
|
|
15
|
+
return `${this.func.toString()}( ${this.args.map(a => a.toString()).join(", ")} )`;
|
|
16
|
+
}
|
|
17
|
+
pretty(indent) {
|
|
18
|
+
const singleIndent = " ";
|
|
19
|
+
const indent_base = singleIndent.repeat(indent);
|
|
20
|
+
const indent_0 = "\n" + indent_base;
|
|
21
|
+
const indent_1 = indent_0 + singleIndent;
|
|
22
|
+
if (this.args.length === 0) {
|
|
23
|
+
return `${this.func.pretty(indent)}()`;
|
|
24
|
+
}
|
|
25
|
+
return (`${this.func.pretty(indent)}(` +
|
|
26
|
+
indent_1 + this.args.map(arg => arg.pretty(indent + 1)).join(`,${indent_1}`) +
|
|
27
|
+
`${indent_0})`);
|
|
28
|
+
}
|
|
14
29
|
clone() {
|
|
15
30
|
return new TirCallExpr(this.func.clone(), this.args.map(a => a.clone()), this.type.clone(), this.range.clone());
|
|
16
31
|
}
|
|
@@ -12,8 +12,11 @@ export declare class TirCaseExpr implements ITirExpr {
|
|
|
12
12
|
readonly wildcardCase: TirWildcardCaseMatcher | undefined;
|
|
13
13
|
readonly type: TirType;
|
|
14
14
|
readonly range: SourceRange;
|
|
15
|
+
private readonly _creationStack;
|
|
15
16
|
constructor(matchExpr: TirExpr, cases: TirCaseMatcher[], wildcardCase: TirWildcardCaseMatcher | undefined, type: TirType, range: SourceRange);
|
|
16
|
-
|
|
17
|
+
toString(): string;
|
|
18
|
+
pretty(indent: number): string;
|
|
19
|
+
clone(): TirExpr;
|
|
17
20
|
deps(): string[];
|
|
18
21
|
get isConstant(): boolean;
|
|
19
22
|
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
@@ -27,10 +30,12 @@ export declare class TirCaseMatcher implements HasSourceRange {
|
|
|
27
30
|
readonly range: SourceRange;
|
|
28
31
|
constructor(pattern: TirCasePattern, body: TirExpr, range: SourceRange);
|
|
29
32
|
deps(): string[];
|
|
33
|
+
pretty(indent: number): string;
|
|
30
34
|
}
|
|
31
35
|
export declare class TirWildcardCaseMatcher implements HasSourceRange {
|
|
32
36
|
body: TirExpr;
|
|
33
37
|
readonly range: SourceRange;
|
|
34
38
|
constructor(body: TirExpr, range: SourceRange);
|
|
35
39
|
deps(): string[];
|
|
40
|
+
pretty(indent: number): string;
|
|
36
41
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRApp, _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
1
2
|
import { IRCase } from "../../../IR/IRNodes/IRCase.js";
|
|
2
3
|
import { IRConst } from "../../../IR/IRNodes/IRConst.js";
|
|
3
4
|
import { IRDelayed } from "../../../IR/IRNodes/IRDelayed.js";
|
|
@@ -6,8 +7,8 @@ import { IRForced } from "../../../IR/IRNodes/IRForced.js";
|
|
|
6
7
|
import { IRFunc } from "../../../IR/IRNodes/IRFunc.js";
|
|
7
8
|
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
8
9
|
import { IRVar } from "../../../IR/IRNodes/IRVar.js";
|
|
9
|
-
import {
|
|
10
|
-
import { _ir_let } from "../../../IR/tree_utils/_ir_let.js";
|
|
10
|
+
import { _ir_lazyIfThenElse } from "../../../IR/tree_utils/_ir_lazyIfThenElse.js";
|
|
11
|
+
import { _ir_let, _ir_let_sym } from "../../../IR/tree_utils/_ir_let.js";
|
|
11
12
|
import { filterSortedStrArrInplace } from "../../../utils/array/filterSortedStrArrInplace.js";
|
|
12
13
|
import { mergeSortedStrArrInplace } from "../../../utils/array/mergeSortedStrArrInplace.js";
|
|
13
14
|
import { TirSimpleVarDecl } from "../statements/TirVarDecl/TirSimpleVarDecl.js";
|
|
@@ -23,12 +24,35 @@ export class TirCaseExpr {
|
|
|
23
24
|
wildcardCase;
|
|
24
25
|
type;
|
|
25
26
|
range;
|
|
27
|
+
_creationStack;
|
|
26
28
|
constructor(matchExpr, cases, wildcardCase, type, range) {
|
|
27
29
|
this.matchExpr = matchExpr;
|
|
28
30
|
this.cases = cases;
|
|
29
31
|
this.wildcardCase = wildcardCase;
|
|
30
32
|
this.type = type;
|
|
31
33
|
this.range = range;
|
|
34
|
+
// this._creationStack = (new Error()).stack;
|
|
35
|
+
}
|
|
36
|
+
toString() {
|
|
37
|
+
const casesStr = this.cases.map(c => `is ${c.pattern.toString()} => ${c.body.toString()}`).join(" ");
|
|
38
|
+
const wildcardStr = this.wildcardCase
|
|
39
|
+
? `else ${this.wildcardCase.body.toString()}`
|
|
40
|
+
: "";
|
|
41
|
+
return `(case ${this.matchExpr.toString()} ${casesStr} ${wildcardStr})`;
|
|
42
|
+
}
|
|
43
|
+
pretty(indent) {
|
|
44
|
+
const singleIndent = " ";
|
|
45
|
+
const indent_base = singleIndent.repeat(indent);
|
|
46
|
+
const indent_0 = "\n" + indent_base;
|
|
47
|
+
const indent_1 = indent_0 + singleIndent;
|
|
48
|
+
const casesPart = this.cases.map(c => `${indent_1}is ${c.pattern.pretty(indent + 1)} => ${c.body.pretty(indent + 1)}`).join("");
|
|
49
|
+
const wildcardPart = this.wildcardCase
|
|
50
|
+
? `${indent_1}else ${this.wildcardCase.body.pretty(indent + 1)}`
|
|
51
|
+
: "";
|
|
52
|
+
return (`(case ${this.matchExpr.pretty(indent + 1)}` +
|
|
53
|
+
casesPart +
|
|
54
|
+
wildcardPart +
|
|
55
|
+
`${indent_0})`);
|
|
32
56
|
}
|
|
33
57
|
/// @ts-ignore Return type annotation circularly references itself.
|
|
34
58
|
clone() {
|
|
@@ -52,6 +76,7 @@ export class TirCaseExpr {
|
|
|
52
76
|
if (matchExprType instanceof TirDataStructType
|
|
53
77
|
|| matchExprType instanceof TirDataOptT)
|
|
54
78
|
return this._dataStructToIR(matchExprType, ctx);
|
|
79
|
+
console.error(this);
|
|
55
80
|
throw new Error("`case` expressions are only supported on Sum-of-Products or Data Struct types; got: "
|
|
56
81
|
+ this.matchExpr.type.toString());
|
|
57
82
|
}
|
|
@@ -60,45 +85,52 @@ export class TirCaseExpr {
|
|
|
60
85
|
const wildcardBodyIR = this.wildcardCase?.body.toIR(ctx) ?? new IRError();
|
|
61
86
|
const someBranchCtx = ctx.newChild();
|
|
62
87
|
const someBranch = this.cases.find(c => c.pattern.constrName === "Some");
|
|
88
|
+
let someBranchVarSym = Symbol("some_value_unused");
|
|
63
89
|
if (someBranch) {
|
|
64
90
|
const varDecl = someBranch.pattern.fields.values().next().value;
|
|
65
91
|
if (!(varDecl instanceof TirSimpleVarDecl))
|
|
66
92
|
throw new Error("case pattern not expressified.");
|
|
67
|
-
someBranchCtx.defineVar(varDecl.name);
|
|
93
|
+
someBranchVarSym = someBranchCtx.defineVar(varDecl.name);
|
|
68
94
|
}
|
|
69
95
|
const someBranchIR = someBranch?.body.toIR(someBranchCtx) ?? wildcardBodyIR;
|
|
70
96
|
const noneBranchIR = this.cases.find(c => c.pattern.constrName === "None")?.body.toIR(ctx) ?? wildcardBodyIR;
|
|
71
97
|
return new IRCase(this.matchExpr.toIR(ctx), [
|
|
72
98
|
// Some{ value }
|
|
73
|
-
new IRFunc(
|
|
99
|
+
new IRFunc([someBranchVarSym], someBranchIR),
|
|
74
100
|
// None
|
|
75
101
|
noneBranchIR
|
|
76
102
|
]);
|
|
77
103
|
}
|
|
78
104
|
// TirSopStructType
|
|
79
105
|
const wildcardBodyIR = this.wildcardCase?.body.toIR(ctx) ?? new IRError();
|
|
80
|
-
const branches = matchExprType.constructors.map(ctor => {
|
|
81
|
-
const
|
|
82
|
-
? (body) => body
|
|
83
|
-
: (body) => new IRFunc(ctor.fields.length, body);
|
|
106
|
+
const branches = matchExprType.constructors.map((ctor, ctorIdx) => {
|
|
107
|
+
const nFields = ctor.fields.length;
|
|
84
108
|
const branchCtx = ctx.newChild();
|
|
85
109
|
const branch = this.cases.find(c => c.pattern.constrName === ctor.name);
|
|
86
|
-
if (!branch)
|
|
87
|
-
|
|
110
|
+
if (!branch) {
|
|
111
|
+
if (nFields <= 0)
|
|
112
|
+
return wildcardBodyIR;
|
|
113
|
+
const introducedVars = Array(nFields).fill(0).map(() => branchCtx.pushUnusedVar());
|
|
114
|
+
return new IRFunc(introducedVars, wildcardBodyIR);
|
|
115
|
+
}
|
|
88
116
|
const pattern = branch.pattern;
|
|
89
|
-
|
|
117
|
+
const introducedVars = new Array(nFields);
|
|
118
|
+
for (let i = 0; i < nFields; i++) {
|
|
119
|
+
const field = ctor.fields[i];
|
|
90
120
|
const varDecl = pattern.fields.get(field.name);
|
|
91
121
|
if (!varDecl) {
|
|
92
122
|
// increment debrujin
|
|
93
123
|
// variable is still introduced, even if unused
|
|
94
|
-
branchCtx.pushUnusedVar();
|
|
124
|
+
introducedVars[i] = branchCtx.pushUnusedVar();
|
|
95
125
|
continue;
|
|
96
126
|
}
|
|
97
127
|
if (!(varDecl instanceof TirSimpleVarDecl))
|
|
98
128
|
throw new Error("case pattern not expressified.");
|
|
99
|
-
branchCtx.defineVar(varDecl.name);
|
|
129
|
+
introducedVars[i] = branchCtx.defineVar(varDecl.name);
|
|
100
130
|
}
|
|
101
|
-
|
|
131
|
+
if (nFields <= 0)
|
|
132
|
+
return branch.body.toIR(branchCtx);
|
|
133
|
+
return new IRFunc(introducedVars, branch.body.toIR(branchCtx));
|
|
102
134
|
});
|
|
103
135
|
// branches at the end that are supposed to "just fail"
|
|
104
136
|
// can be omitted, as the CEK machine will fail if no branch for
|
|
@@ -107,46 +139,38 @@ export class TirCaseExpr {
|
|
|
107
139
|
branches.pop();
|
|
108
140
|
return branches.length > 0 ? new IRCase(this.matchExpr.toIR(ctx), branches) : new IRError(); // all branches fail, so the whole expression fails
|
|
109
141
|
}
|
|
110
|
-
// TODO: optimization
|
|
111
|
-
// expect data-encoded patterns to be empty after `expressify`
|
|
112
|
-
// because accessed field should use `IRLetted` instead
|
|
113
142
|
_dataStructToIR(matchExprType, ctx) {
|
|
114
143
|
if (matchExprType instanceof TirDataOptT) {
|
|
115
144
|
const stmtCtx = ctx.newChild();
|
|
116
145
|
stmtCtx.pushUnusedVar(); // debrujin un constr data result
|
|
117
146
|
const wildcardBodyIR = this.wildcardCase?.body.toIR(stmtCtx) ?? new IRError();
|
|
118
|
-
const someBranchCtx = stmtCtx.newChild();
|
|
119
147
|
const someBranch = this.cases.find(c => c.pattern.constrName === "Some");
|
|
148
|
+
let someBranchIR = () => new IRFunc([Symbol("unused_some_value")], wildcardBodyIR);
|
|
120
149
|
if (someBranch) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
someBranchCtx.defineVar(varDecl.name);
|
|
131
|
-
}
|
|
150
|
+
const pattern = someBranch.pattern;
|
|
151
|
+
const valueDecl = pattern.fields.get("value");
|
|
152
|
+
if (valueDecl
|
|
153
|
+
&& !(valueDecl instanceof TirSimpleVarDecl))
|
|
154
|
+
throw new Error("case pattern not expressified.");
|
|
155
|
+
const someBranchCtx = stmtCtx.newChild();
|
|
156
|
+
const someBranchVarSym = valueDecl ? someBranchCtx.defineVar(valueDecl.name) : Symbol("some_value_unused");
|
|
157
|
+
someBranchIR = (unConstrMatchSym) => new IRApp(new IRFunc([someBranchVarSym], someBranch.body.toIR(someBranchCtx)), _inlineFromData(getOptTypeArg(matchExprType), _ir_apps(IRNative.sndPair, new IRVar(unConstrMatchSym) // unConstrData result
|
|
158
|
+
)));
|
|
132
159
|
}
|
|
133
|
-
const someBranchIR = someBranch?.body.toIR(someBranchCtx); // ?? wildcardBodyIR;
|
|
134
160
|
const noneBranchIR = this.cases.find(c => c.pattern.constrName === "None")?.body.toIR(stmtCtx) ?? wildcardBodyIR;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
161
|
+
return new IRForced(_ir_let(_ir_apps(IRNative.unConstrData, this.matchExpr.toIR(ctx)), unConstrMatchSym => _ir_lazyIfThenElse(
|
|
162
|
+
// condition
|
|
163
|
+
_ir_apps(IRNative.equalsInteger, IRConst.int(0), _ir_apps(IRNative.fstPair, new IRVar(unConstrMatchSym) // unConstrData result
|
|
138
164
|
)),
|
|
139
165
|
// then Just{ value }
|
|
140
|
-
|
|
141
|
-
_ir_let(_inlineFromData(getOptTypeArg(matchExprType), _ir_apps(IRNative.sndPair, new IRVar(0) // unConstrData result
|
|
142
|
-
)), new IRDelayed(someBranchIR)),
|
|
166
|
+
someBranchIR(unConstrMatchSym),
|
|
143
167
|
// else None
|
|
144
|
-
|
|
168
|
+
noneBranchIR)));
|
|
145
169
|
}
|
|
146
170
|
// TirDataStructType
|
|
147
171
|
const stmtCtx = ctx.newChild();
|
|
148
|
-
stmtCtx.pushUnusedVar(); // unconstrStruct
|
|
149
|
-
stmtCtx.pushUnusedVar(); // isConstrIdx
|
|
172
|
+
const unConstrStructSym = stmtCtx.pushUnusedVar("unconstrStruct"); // unconstrStruct
|
|
173
|
+
const isConstrIdxSym = stmtCtx.pushUnusedVar("isConstrIdx"); // isConstrIdx
|
|
150
174
|
const noVarsWildcardBodyIR = (this.wildcardCase?.body.toIR(stmtCtx)
|
|
151
175
|
?? new IRError());
|
|
152
176
|
const delayedNoVarWildcardBodyIR = new IRDelayed(noVarsWildcardBodyIR);
|
|
@@ -167,12 +191,14 @@ export class TirCaseExpr {
|
|
|
167
191
|
const usedFieldsCtorNames = (ctor.fields.map(f => f.name)
|
|
168
192
|
.filter(fName => pattern.fields.has(fName)));
|
|
169
193
|
if (usedFieldsCtorNames.length <= 0) {
|
|
170
|
-
ifThenElseMatchingStatements =
|
|
194
|
+
ifThenElseMatchingStatements = _ir_lazyIfThenElse(
|
|
195
|
+
// condition
|
|
196
|
+
_ir_apps(new IRVar(isConstrIdxSym), // isConstrIdx
|
|
171
197
|
IRConst.int(ctorIdx)),
|
|
172
198
|
// then
|
|
173
|
-
|
|
199
|
+
body.toIR(stmtCtx),
|
|
174
200
|
// else
|
|
175
|
-
|
|
201
|
+
ifThenElseMatchingStatements);
|
|
176
202
|
continue;
|
|
177
203
|
}
|
|
178
204
|
function indexOfField(fieldName) {
|
|
@@ -187,45 +213,52 @@ export class TirCaseExpr {
|
|
|
187
213
|
const patternVarDecl = pattern.fields.get(fName);
|
|
188
214
|
if (!(patternVarDecl instanceof TirSimpleVarDecl))
|
|
189
215
|
throw new Error("case pattern not expressified.");
|
|
190
|
-
thenCtx.defineVar(patternVarDecl.name);
|
|
191
|
-
const thenCase =
|
|
216
|
+
const introVar = thenCtx.defineVar(patternVarDecl.name);
|
|
217
|
+
const thenCase = _ir_let_sym(introVar, _inlineFromData(patternVarDecl.type, _ir_apps(IRNative.headList, _ir_apps(IRNative._dropList, IRConst.int(indexOfField(fName)), // constr field index
|
|
192
218
|
_ir_apps(// fileds as data list
|
|
193
|
-
IRNative.sndPair, new IRVar(
|
|
219
|
+
IRNative.sndPair, new IRVar(unConstrStructSym) // unconstrStruct
|
|
194
220
|
)))), body.toIR(thenCtx));
|
|
195
|
-
ifThenElseMatchingStatements =
|
|
221
|
+
ifThenElseMatchingStatements = _ir_lazyIfThenElse(
|
|
222
|
+
// condition
|
|
223
|
+
_ir_apps(new IRVar(isConstrIdxSym), // isConstrIdx
|
|
196
224
|
IRConst.int(ctorIdx)),
|
|
197
225
|
// then
|
|
198
|
-
|
|
226
|
+
thenCase,
|
|
199
227
|
// else
|
|
200
|
-
|
|
228
|
+
ifThenElseMatchingStatements);
|
|
201
229
|
continue;
|
|
202
|
-
}
|
|
230
|
+
} // single field used edge case
|
|
203
231
|
// multiple fields used
|
|
204
232
|
const thenCtx = stmtCtx.newChild();
|
|
233
|
+
const fieldsAsDataList = thenCtx.pushUnusedVar(); // fileds as data list
|
|
205
234
|
const sortedUsedFields = [...usedFieldsCtorNames].sort((a, b) => indexOfField(a) - indexOfField(b));
|
|
206
|
-
|
|
235
|
+
const introducedVars = new Array(sortedUsedFields.length);
|
|
236
|
+
for (let fIdx = 0; fIdx < sortedUsedFields.length; fIdx++) {
|
|
237
|
+
const fName = sortedUsedFields[fIdx];
|
|
207
238
|
const patternVarDecl = pattern.fields.get(fName);
|
|
208
239
|
if (!(patternVarDecl instanceof TirSimpleVarDecl))
|
|
209
240
|
throw new Error("case pattern not expressified.");
|
|
210
|
-
thenCtx.defineVar(patternVarDecl.name);
|
|
241
|
+
introducedVars[fIdx] = thenCtx.defineVar(patternVarDecl.name);
|
|
211
242
|
}
|
|
212
243
|
const extractedFields = sortedUsedFields.map(fName => _inlineFromData(ctor.fields.find(f => f.name === fName).type, _ir_apps(IRNative.headList, _ir_apps(IRNative._dropList, IRConst.int(indexOfField(fName)), // constr field index
|
|
213
|
-
new IRVar(
|
|
244
|
+
new IRVar(fieldsAsDataList) // fileds as data list
|
|
214
245
|
))));
|
|
215
|
-
const thenCase =
|
|
246
|
+
const thenCase = _ir_let_sym(fieldsAsDataList, _ir_apps(IRNative.sndPair, new IRVar(unConstrStructSym) // unconstrStruct
|
|
216
247
|
), // fileds as data list
|
|
217
|
-
_ir_apps(new IRFunc(
|
|
218
|
-
ifThenElseMatchingStatements =
|
|
248
|
+
_ir_apps(new IRFunc(introducedVars, body.toIR(thenCtx)), ...extractedFields));
|
|
249
|
+
ifThenElseMatchingStatements = _ir_lazyIfThenElse(
|
|
250
|
+
// condition
|
|
251
|
+
_ir_apps(new IRVar(isConstrIdxSym), // isConstrIdx
|
|
219
252
|
IRConst.int(ctorIdx)),
|
|
220
253
|
// then
|
|
221
|
-
|
|
254
|
+
thenCase,
|
|
222
255
|
// else
|
|
223
|
-
|
|
256
|
+
ifThenElseMatchingStatements);
|
|
224
257
|
}
|
|
225
|
-
return
|
|
226
|
-
|
|
258
|
+
return _ir_let_sym(unConstrStructSym, _ir_apps(IRNative.unConstrData, this.matchExpr.toIR(ctx)), // unconstrStruct
|
|
259
|
+
_ir_let_sym(isConstrIdxSym, _ir_apps(IRNative.equalsInteger, _ir_apps(IRNative.fstPair, new IRVar(unConstrStructSym) // unConstrData result
|
|
227
260
|
)), // isConstrIdx
|
|
228
|
-
ifThenElseMatchingStatements))
|
|
261
|
+
ifThenElseMatchingStatements));
|
|
229
262
|
}
|
|
230
263
|
}
|
|
231
264
|
export class TirCaseMatcher {
|
|
@@ -243,6 +276,11 @@ export class TirCaseMatcher {
|
|
|
243
276
|
filterSortedStrArrInplace(deps, nonDeps);
|
|
244
277
|
return deps;
|
|
245
278
|
}
|
|
279
|
+
pretty(indent) {
|
|
280
|
+
const singleIndent = " ";
|
|
281
|
+
const indent_base = singleIndent.repeat(indent);
|
|
282
|
+
return `is ${this.pattern.pretty(indent)} => ${this.body.pretty(indent)}`;
|
|
283
|
+
}
|
|
246
284
|
}
|
|
247
285
|
export class TirWildcardCaseMatcher {
|
|
248
286
|
body;
|
|
@@ -254,4 +292,9 @@ export class TirWildcardCaseMatcher {
|
|
|
254
292
|
deps() {
|
|
255
293
|
return this.body.deps();
|
|
256
294
|
}
|
|
295
|
+
pretty(indent) {
|
|
296
|
+
const singleIndent = " ";
|
|
297
|
+
const indent_base = singleIndent.repeat(indent);
|
|
298
|
+
return `else ${this.body.pretty(indent)}`;
|
|
299
|
+
}
|
|
257
300
|
}
|
|
@@ -13,7 +13,9 @@ export declare class TirElemAccessExpr implements ITirExpr {
|
|
|
13
13
|
readonly type: TirType;
|
|
14
14
|
readonly range: SourceRange;
|
|
15
15
|
constructor(arrLikeExpr: TirExpr, indexExpr: TirExpr, type: TirType, range: SourceRange);
|
|
16
|
-
|
|
16
|
+
toString(): string;
|
|
17
|
+
pretty(indent: number): string;
|
|
18
|
+
clone(): TirExpr;
|
|
17
19
|
deps(): string[];
|
|
18
20
|
get isConstant(): boolean;
|
|
19
21
|
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
@@ -2,8 +2,8 @@ import { CEKConst, Machine } from "@harmoniclabs/plutus-machine";
|
|
|
2
2
|
import { IRConst } from "../../../IR/IRNodes/IRConst.js";
|
|
3
3
|
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
4
4
|
import { mergeSortedStrArrInplace } from "../../../utils/array/mergeSortedStrArrInplace.js";
|
|
5
|
-
import { _ir_apps } from "../../../IR/tree_utils/_ir_apps.js";
|
|
6
5
|
import { compileIRToUPLC } from "../../../IR/toUPLC/compileIRToUPLC.js";
|
|
6
|
+
import { _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
7
7
|
/**
|
|
8
8
|
* `arrLikeExpr[ indexExpr ]`
|
|
9
9
|
*/
|
|
@@ -18,6 +18,14 @@ export class TirElemAccessExpr {
|
|
|
18
18
|
this.type = type;
|
|
19
19
|
this.range = range;
|
|
20
20
|
}
|
|
21
|
+
toString() {
|
|
22
|
+
return `${this.arrLikeExpr.toString()}[ ${this.indexExpr.toString()} ]`;
|
|
23
|
+
}
|
|
24
|
+
pretty(indent) {
|
|
25
|
+
const singleIndent = " ";
|
|
26
|
+
const indent_base = singleIndent.repeat(indent);
|
|
27
|
+
return `${this.arrLikeExpr.pretty(indent)}[ ${this.indexExpr.pretty(indent)} ]`;
|
|
28
|
+
}
|
|
21
29
|
clone() {
|
|
22
30
|
return new TirElemAccessExpr(this.arrLikeExpr.clone(), this.indexExpr.clone(), this.type.clone(), this.range.clone());
|
|
23
31
|
}
|
|
@@ -12,7 +12,9 @@ export declare class TirFailExpr implements ITirExpr {
|
|
|
12
12
|
constructor(
|
|
13
13
|
/** must be string (or utf8 bytes) */
|
|
14
14
|
failMsgExpr: TirExpr | undefined, type: TirType, range: SourceRange);
|
|
15
|
-
|
|
15
|
+
toString(): string;
|
|
16
|
+
pretty(indent: number): string;
|
|
17
|
+
clone(): TirExpr;
|
|
16
18
|
deps(): string[];
|
|
17
19
|
get isConstant(): boolean;
|
|
18
20
|
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
1
2
|
import { IRError } from "../../../IR/IRNodes/IRError.js";
|
|
2
3
|
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
3
|
-
import { _ir_apps } from "../../../IR/tree_utils/_ir_apps.js";
|
|
4
4
|
export class TirFailExpr {
|
|
5
5
|
failMsgExpr;
|
|
6
6
|
type;
|
|
@@ -12,6 +12,14 @@ export class TirFailExpr {
|
|
|
12
12
|
this.type = type;
|
|
13
13
|
this.range = range;
|
|
14
14
|
}
|
|
15
|
+
toString() {
|
|
16
|
+
return `(fail${this.failMsgExpr ? ` ${this.failMsgExpr.toString()}` : ""})`;
|
|
17
|
+
}
|
|
18
|
+
pretty(indent) {
|
|
19
|
+
const singleIndent = " ";
|
|
20
|
+
const indent_base = singleIndent.repeat(indent);
|
|
21
|
+
return `(fail${this.failMsgExpr ? ` ${this.failMsgExpr.pretty(indent)}` : ""})`;
|
|
22
|
+
}
|
|
15
23
|
clone() {
|
|
16
24
|
return new TirFailExpr(this.failMsgExpr?.clone(), this.type.clone(), this.range.clone());
|
|
17
25
|
}
|
|
@@ -10,11 +10,12 @@ export declare class TirFromDataExpr implements ITirExpr {
|
|
|
10
10
|
readonly type: TirType;
|
|
11
11
|
readonly range: SourceRange;
|
|
12
12
|
constructor(dataExpr: TirExpr, type: TirType, range: SourceRange);
|
|
13
|
-
|
|
13
|
+
toString(): string;
|
|
14
|
+
pretty(indent: number): string;
|
|
15
|
+
clone(): TirExpr;
|
|
14
16
|
get isConstant(): boolean;
|
|
15
17
|
deps(): string[];
|
|
16
18
|
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
17
|
-
toString(): string;
|
|
18
19
|
}
|
|
19
20
|
export declare function _inlineFromData(target_t: TirType, dataExprIR: IRTerm): IRTerm;
|
|
20
21
|
export declare function _fromDataUplcFunc(_target_t: TirType): IRTerm;
|