@harmoniclabs/pebble 0.1.0-dev4 → 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.d.ts +1 -0
- package/dist/compiler/path/getAbsolutePath.js +8 -5
- 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,36 +1,33 @@
|
|
|
1
1
|
import { IRApp } from "../../IRNodes/IRApp.js";
|
|
2
2
|
import { IRCase } from "../../IRNodes/IRCase.js";
|
|
3
3
|
import { IRConstr } from "../../IRNodes/IRConstr.js";
|
|
4
|
-
import { IRDelayed } from "../../IRNodes/IRDelayed.js";
|
|
5
|
-
import { IRForced } from "../../IRNodes/IRForced.js";
|
|
6
|
-
import { IRFunc } from "../../IRNodes/IRFunc.js";
|
|
7
4
|
import { IRHoisted } from "../../IRNodes/IRHoisted.js";
|
|
8
5
|
import { IRLetted } from "../../IRNodes/IRLetted.js";
|
|
9
|
-
import { IRRecursive } from "../../IRNodes/IRRecursive.js";
|
|
10
6
|
export function markRecursiveHoistsAsForced(_term) {
|
|
11
7
|
const stack = [{ term: _term, isInRecursiveTerm: false }];
|
|
12
8
|
while (stack.length > 0) {
|
|
13
9
|
const { term: t, isInRecursiveTerm, isIRAppArg } = stack.pop();
|
|
10
|
+
if (isInRecursiveTerm && (t instanceof IRHoisted
|
|
11
|
+
|| t instanceof IRLetted)) {
|
|
12
|
+
t.meta.forceHoist = true;
|
|
13
|
+
// don't push anything to the stack
|
|
14
|
+
// hoisted values are handled normally
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
14
17
|
if (t instanceof IRApp) {
|
|
15
|
-
|
|
16
|
-
// so that we can check if the function is the Z combinator before the arg is processed
|
|
17
|
-
stack.push({ term: t.arg, isIRAppArg: true, isInRecursiveTerm }, { term: t.fn, isInRecursiveTerm });
|
|
18
|
+
stack.push({ term: t.fn, isInRecursiveTerm }, { term: t.arg, isIRAppArg: true, isInRecursiveTerm });
|
|
18
19
|
continue;
|
|
19
20
|
}
|
|
20
21
|
if (t instanceof IRConstr) {
|
|
21
|
-
// must push the arg first and then the fucntion
|
|
22
|
-
// so that we can check if the function is the Z combinator before the arg is processed
|
|
23
22
|
stack.push(...Array.from(t.fields)
|
|
24
|
-
.map(
|
|
23
|
+
.map(f => ({
|
|
25
24
|
term: f,
|
|
26
|
-
isIRAppArg:
|
|
25
|
+
isIRAppArg: true,
|
|
27
26
|
isInRecursiveTerm
|
|
28
27
|
})));
|
|
29
28
|
continue;
|
|
30
29
|
}
|
|
31
30
|
if (t instanceof IRCase) {
|
|
32
|
-
// must push the arg first and then the fucntion
|
|
33
|
-
// so that we can check if the function is the Z combinator before the arg is processed
|
|
34
31
|
stack.push({
|
|
35
32
|
term: t.constrTerm,
|
|
36
33
|
isIRAppArg: false,
|
|
@@ -38,45 +35,11 @@ export function markRecursiveHoistsAsForced(_term) {
|
|
|
38
35
|
}, ...Array.from(t.continuations)
|
|
39
36
|
.map(cont => ({
|
|
40
37
|
term: cont,
|
|
41
|
-
isIRAppArg:
|
|
38
|
+
isIRAppArg: false,
|
|
42
39
|
isInRecursiveTerm
|
|
43
40
|
})));
|
|
44
41
|
continue;
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
t instanceof IRLetted) {
|
|
48
|
-
if (isInRecursiveTerm) {
|
|
49
|
-
t.meta.forceHoist = true;
|
|
50
|
-
// don't push anything to the stack
|
|
51
|
-
// hoisted values are handled normally
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
// otherwhise check in values too
|
|
55
|
-
else if (t instanceof IRLetted) {
|
|
56
|
-
stack.push({ term: t.value, isInRecursiveTerm });
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
else if (t instanceof IRHoisted) {
|
|
60
|
-
stack.push({ term: t.hoisted, isInRecursiveTerm });
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (t instanceof IRDelayed) {
|
|
65
|
-
stack.push({ term: t.delayed, isInRecursiveTerm });
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (t instanceof IRForced) {
|
|
69
|
-
stack.push({ term: t.forced, isInRecursiveTerm });
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (t instanceof IRFunc) {
|
|
73
|
-
stack.push({ term: t.body, isInRecursiveTerm });
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (t instanceof IRRecursive) {
|
|
77
|
-
stack.push({ term: t.body, isInRecursiveTerm: true });
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const tsEnsureExsaustiveCheck = t;
|
|
43
|
+
stack.push(...(t.children?.().map(c => ({ term: c, isInRecursiveTerm })) ?? []));
|
|
81
44
|
}
|
|
82
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IRFunc } from "../../../IRNodes/IRFunc.js";
|
|
2
2
|
import { IRTerm } from "../../../IRTerm.js";
|
|
3
|
-
export declare function getExpandedIRFunc(body: IRTerm,
|
|
3
|
+
export declare function getExpandedIRFunc(body: IRTerm, params: symbol[]): IRFunc;
|
|
4
4
|
export declare function expandFuncsAndReturnRoot(root: IRTerm): IRTerm;
|
package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js
CHANGED
|
@@ -9,10 +9,10 @@ import { IRLetted } from "../../../IRNodes/IRLetted.js";
|
|
|
9
9
|
import { IRRecursive } from "../../../IRNodes/IRRecursive.js";
|
|
10
10
|
import { IRSelfCall } from "../../../IRNodes/IRSelfCall.js";
|
|
11
11
|
import { _modifyChildFromTo } from "../../_internal/_modifyChildFromTo.js";
|
|
12
|
-
export function getExpandedIRFunc(body,
|
|
13
|
-
|
|
14
|
-
while (
|
|
15
|
-
body = new IRFunc(
|
|
12
|
+
export function getExpandedIRFunc(body, params) {
|
|
13
|
+
let introducedParam;
|
|
14
|
+
while (introducedParam = params.pop()) {
|
|
15
|
+
body = new IRFunc([introducedParam], body);
|
|
16
16
|
}
|
|
17
17
|
return body;
|
|
18
18
|
// if( arity === 1 ) return new IRFunc( 1, body );
|
|
@@ -28,13 +28,11 @@ export function expandFuncsAndReturnRoot(root) {
|
|
|
28
28
|
// all good
|
|
29
29
|
if (t.arity <= 1)
|
|
30
30
|
continue;
|
|
31
|
-
const expanded = getExpandedIRFunc(t.body, t.
|
|
32
|
-
if (t.parent)
|
|
31
|
+
const expanded = getExpandedIRFunc(t.body, t.params);
|
|
32
|
+
if (t.parent)
|
|
33
33
|
_modifyChildFromTo(t.parent, t, expanded);
|
|
34
|
-
|
|
35
|
-
else {
|
|
34
|
+
else
|
|
36
35
|
root = expanded;
|
|
37
|
-
}
|
|
38
36
|
continue;
|
|
39
37
|
}
|
|
40
38
|
if (t instanceof IRApp) {
|
|
@@ -57,12 +55,11 @@ export function expandFuncsAndReturnRoot(root) {
|
|
|
57
55
|
stack.push(t.forced);
|
|
58
56
|
continue;
|
|
59
57
|
}
|
|
60
|
-
if (t instanceof IRRecursive
|
|
61
|
-
t instanceof IRHoisted
|
|
62
|
-
t instanceof IRLetted
|
|
63
|
-
t instanceof IRSelfCall)
|
|
58
|
+
if (t instanceof IRRecursive
|
|
59
|
+
|| t instanceof IRHoisted
|
|
60
|
+
|| t instanceof IRLetted
|
|
61
|
+
|| t instanceof IRSelfCall)
|
|
64
62
|
throw new Error("Unexpected term while performing uplc optimizations");
|
|
65
|
-
}
|
|
66
63
|
}
|
|
67
64
|
return root;
|
|
68
65
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { IRTerm } from "../../../IRTerm.js";
|
|
2
2
|
import { CompilerOptions } from "../../CompilerOptions.js";
|
|
3
3
|
export declare function performUplcOptimizationsAndReturnRoot(root: IRTerm, options: CompilerOptions): IRTerm;
|
|
4
|
-
/** @experimental still can't figure how to make it work */
|
|
5
|
-
export declare function groupIndipendentLets(term: IRTerm, dbn: number): [args: IRTerm[], body: IRTerm];
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { IRConstr } from "../../../IRNodes/index.js";
|
|
2
|
+
import { IRApp } from "../../../IRNodes/IRApp.js";
|
|
3
|
+
import { IRCase } from "../../../IRNodes/IRCase.js";
|
|
4
|
+
import { IRFunc } from "../../../IRNodes/IRFunc.js";
|
|
5
|
+
import { IRHoisted } from "../../../IRNodes/IRHoisted.js";
|
|
6
|
+
import { IRLetted } from "../../../IRNodes/IRLetted.js";
|
|
7
|
+
import { IRRecursive } from "../../../IRNodes/IRRecursive.js";
|
|
8
|
+
import { IRSelfCall } from "../../../IRNodes/IRSelfCall.js";
|
|
9
|
+
import { IRVar } from "../../../IRNodes/IRVar.js";
|
|
10
|
+
import { _modifyChildFromTo } from "../../_internal/_modifyChildFromTo.js";
|
|
11
|
+
import { isDebugUplcOptimizations } from "../../CompilerOptions.js";
|
|
12
|
+
import { expandFuncsAndReturnRoot } from "./expandFuncsAndReturnRoot.js";
|
|
13
|
+
import { getApplicationTerms } from "../../utils/getApplicationTerms.js";
|
|
14
|
+
import { getUnboundedVars } from "../handleLetted/groupByScope.js";
|
|
15
|
+
export function performUplcOptimizationsAndReturnRoot(root, options) {
|
|
16
|
+
const opts = options.uplcOptimizations;
|
|
17
|
+
if (isDebugUplcOptimizations(opts))
|
|
18
|
+
return root;
|
|
19
|
+
const { groupApplications, inlineSingleUse: shouldInlineSingleUse, simplifyWrappedPartialFuncApps, removeForceDelay } = opts;
|
|
20
|
+
root = expandFuncsAndReturnRoot(root);
|
|
21
|
+
const stack = [root];
|
|
22
|
+
let t = root;
|
|
23
|
+
while (t = stack.pop()) {
|
|
24
|
+
if (t instanceof IRApp
|
|
25
|
+
&& isIdLike(t.fn)) {
|
|
26
|
+
const arg = t.arg;
|
|
27
|
+
if (t.parent)
|
|
28
|
+
_modifyChildFromTo(t.parent, t, arg);
|
|
29
|
+
else
|
|
30
|
+
root = arg;
|
|
31
|
+
stack.push(arg);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const indepApps = groupIndependentApplications(t);
|
|
35
|
+
if (indepApps) {
|
|
36
|
+
const { newRoot, args, nextBody } = indepApps;
|
|
37
|
+
if (newRoot)
|
|
38
|
+
root = newRoot;
|
|
39
|
+
stack.push(...args);
|
|
40
|
+
stack.push(nextBody);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (t instanceof IRRecursive ||
|
|
44
|
+
t instanceof IRHoisted ||
|
|
45
|
+
t instanceof IRLetted ||
|
|
46
|
+
t instanceof IRSelfCall)
|
|
47
|
+
throw new Error("Unexpected term while performing uplc optimizations");
|
|
48
|
+
stack.push(...t.children());
|
|
49
|
+
}
|
|
50
|
+
return root;
|
|
51
|
+
}
|
|
52
|
+
function isIdLike(term) {
|
|
53
|
+
return (term instanceof IRFunc &&
|
|
54
|
+
term.params.length === 1 &&
|
|
55
|
+
term.body instanceof IRVar &&
|
|
56
|
+
term.body.name === term.params[0]);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @returns either an object containing the new root, sorted args and next body
|
|
61
|
+
* or undefined if grouping wasnt possible (root is the same)
|
|
62
|
+
*/
|
|
63
|
+
function groupIndependentApplications(root) {
|
|
64
|
+
const parent = root.parent;
|
|
65
|
+
let applicaitonTerms = getApplicationTerms(root);
|
|
66
|
+
if (!applicaitonTerms)
|
|
67
|
+
return undefined;
|
|
68
|
+
let { func, args } = applicaitonTerms;
|
|
69
|
+
if (!(func instanceof IRFunc))
|
|
70
|
+
return undefined;
|
|
71
|
+
const params = func.params.slice();
|
|
72
|
+
while (true) {
|
|
73
|
+
applicaitonTerms = getApplicationTerms(func.body);
|
|
74
|
+
if (!applicaitonTerms)
|
|
75
|
+
break;
|
|
76
|
+
if (!(applicaitonTerms.func instanceof IRFunc))
|
|
77
|
+
break;
|
|
78
|
+
func = applicaitonTerms.func;
|
|
79
|
+
params.push(...func.params);
|
|
80
|
+
args.push(...applicaitonTerms.args);
|
|
81
|
+
if (params.length !== args.length)
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
const len = Math.min(params.length, args.length);
|
|
85
|
+
const finalParams = params.slice(len);
|
|
86
|
+
const finalArgs = args.slice(len);
|
|
87
|
+
params.length = len;
|
|
88
|
+
args.length = len;
|
|
89
|
+
const paramToArg = {};
|
|
90
|
+
for (let i = 0; i < len; i++) {
|
|
91
|
+
const p = params[i];
|
|
92
|
+
paramToArg[p] = args[i];
|
|
93
|
+
}
|
|
94
|
+
const globalUnbound = getUnboundedVars(root);
|
|
95
|
+
const groups = [[]];
|
|
96
|
+
for (let i = 0; i < len; i++) {
|
|
97
|
+
const p = params[i];
|
|
98
|
+
const arg = args[i];
|
|
99
|
+
const unbound = getUnboundedVars(arg, globalUnbound);
|
|
100
|
+
let highestIdx = -1;
|
|
101
|
+
for (let j = groups.length - 1; j >= 0; j--) {
|
|
102
|
+
const group = groups[j];
|
|
103
|
+
if (group.some(sym => unbound.has(sym))) {
|
|
104
|
+
highestIdx = j;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (highestIdx === groups.length - 1) {
|
|
109
|
+
groups.push([p]);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
groups[highestIdx + 1].push(p);
|
|
113
|
+
}
|
|
114
|
+
groups[groups.length - 1].push(...finalParams);
|
|
115
|
+
const sortedArgs = new Array(len);
|
|
116
|
+
const soretedParams = groups.flat();
|
|
117
|
+
for (let i = 0; i < len; i++) {
|
|
118
|
+
const p = soretedParams[i];
|
|
119
|
+
sortedArgs[i] = paramToArg[p];
|
|
120
|
+
}
|
|
121
|
+
let nextBody = func.body;
|
|
122
|
+
if (finalArgs.length > 0) {
|
|
123
|
+
if (finalArgs.length === 1) {
|
|
124
|
+
nextBody = new IRApp(nextBody, finalArgs[0]);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
nextBody = new IRCase(new IRConstr(0, finalArgs), [nextBody]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let newTerm = nextBody;
|
|
131
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
132
|
+
const group = groups[i];
|
|
133
|
+
if (group.length === 1) {
|
|
134
|
+
newTerm = new IRApp(new IRFunc(group, newTerm), paramToArg[group[0]]);
|
|
135
|
+
}
|
|
136
|
+
else if (group.length <= 0)
|
|
137
|
+
continue;
|
|
138
|
+
else {
|
|
139
|
+
newTerm = new IRCase(new IRConstr(0, group.map(p => paramToArg[p])), [new IRFunc(group, newTerm)]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (parent)
|
|
143
|
+
_modifyChildFromTo(parent, root, newTerm);
|
|
144
|
+
else
|
|
145
|
+
root = newTerm;
|
|
146
|
+
return {
|
|
147
|
+
newRoot: !parent ? root : undefined,
|
|
148
|
+
args: sortedArgs,
|
|
149
|
+
nextBody
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class RemoveUnusedVarsCtx {
|
|
2
|
+
readonly params: symbol[];
|
|
3
|
+
readonly parent: RemoveUnusedVarsCtx | undefined;
|
|
4
|
+
readonly localVars: Record<symbol, number>;
|
|
5
|
+
constructor(params: symbol[], parent: RemoveUnusedVarsCtx | undefined);
|
|
6
|
+
static root(params?: symbol[]): RemoveUnusedVarsCtx;
|
|
7
|
+
newChild(params: symbol[]): RemoveUnusedVarsCtx;
|
|
8
|
+
private keys;
|
|
9
|
+
incrementVarUse(sym: symbol): void;
|
|
10
|
+
getUnusedVars(): symbol[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class RemoveUnusedVarsCtx {
|
|
2
|
+
params;
|
|
3
|
+
parent;
|
|
4
|
+
localVars;
|
|
5
|
+
// MUST BE A GETTER TO REFLECT CHANGES IN PARENT
|
|
6
|
+
// DO NOT MODIFY
|
|
7
|
+
// private get _parentDbn(): number {
|
|
8
|
+
// return this.parent?.dbn ?? 0;
|
|
9
|
+
// }
|
|
10
|
+
// get dbn(): number {
|
|
11
|
+
// return this._parentDbn + Object.getOwnPropertySymbols( this.localVars ).length;
|
|
12
|
+
// }
|
|
13
|
+
constructor(params, parent) {
|
|
14
|
+
this.params = params;
|
|
15
|
+
this.parent = parent;
|
|
16
|
+
params = params.slice();
|
|
17
|
+
this.localVars = {};
|
|
18
|
+
for (const p of params)
|
|
19
|
+
this.localVars[p] = 0;
|
|
20
|
+
}
|
|
21
|
+
static root(params = []) {
|
|
22
|
+
return new RemoveUnusedVarsCtx(params, undefined);
|
|
23
|
+
}
|
|
24
|
+
newChild(params) {
|
|
25
|
+
return new RemoveUnusedVarsCtx(params, this);
|
|
26
|
+
}
|
|
27
|
+
keys() {
|
|
28
|
+
return Object.getOwnPropertySymbols(this.localVars);
|
|
29
|
+
}
|
|
30
|
+
incrementVarUse(sym) {
|
|
31
|
+
if (typeof this.localVars[sym] !== "number") {
|
|
32
|
+
if (this.parent)
|
|
33
|
+
this.parent.incrementVarUse(sym);
|
|
34
|
+
else {
|
|
35
|
+
console.error(sym);
|
|
36
|
+
throw new Error("trying to increment use of variable not in context");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
this.localVars[sym]++;
|
|
41
|
+
}
|
|
42
|
+
getUnusedVars() {
|
|
43
|
+
const keys = this.keys();
|
|
44
|
+
return keys.filter(k => this.localVars[k] === 0);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { _ir_apps, IRFunc } from "../../../IRNodes/index.js";
|
|
2
|
+
import { IRVar } from "../../../IRNodes/IRVar.js";
|
|
3
|
+
import { _modifyChildFromTo } from "../../_internal/_modifyChildFromTo.js";
|
|
4
|
+
import { getApplicationTerms } from "../../utils/getApplicationTerms.js";
|
|
5
|
+
import { RemoveUnusedVarsCtx } from "./RemoveUnusedVarsCtx.js";
|
|
6
|
+
export function removeUnusedVarsAndReturnRoot(term) {
|
|
7
|
+
// we need to go bottom up
|
|
8
|
+
// ONLY REMOVE UNUSED VARS IF NOT UNIT
|
|
9
|
+
// (in which case we need to keep it for eventual side effects (asserts and traces))
|
|
10
|
+
return _removeUnusedVars(term, RemoveUnusedVarsCtx.root());
|
|
11
|
+
}
|
|
12
|
+
function _removeUnusedVars(term, ctx) {
|
|
13
|
+
if (term instanceof IRVar) {
|
|
14
|
+
// increment used
|
|
15
|
+
ctx.incrementVarUse(term.name);
|
|
16
|
+
return term;
|
|
17
|
+
}
|
|
18
|
+
const applicationTerms = getApplicationTerms(term);
|
|
19
|
+
if (!applicationTerms) {
|
|
20
|
+
const childrens = term.children();
|
|
21
|
+
const nextCtx = term instanceof IRFunc
|
|
22
|
+
? ctx.newChild(term.params)
|
|
23
|
+
: ctx;
|
|
24
|
+
for (const c of childrens) {
|
|
25
|
+
_removeUnusedVars(c, nextCtx);
|
|
26
|
+
}
|
|
27
|
+
return term;
|
|
28
|
+
}
|
|
29
|
+
const { func, args } = applicationTerms;
|
|
30
|
+
if (!(func instanceof IRFunc)) {
|
|
31
|
+
for (const child of term.children()) {
|
|
32
|
+
// same as parent ctx
|
|
33
|
+
_removeUnusedVars(child, ctx);
|
|
34
|
+
}
|
|
35
|
+
return term;
|
|
36
|
+
}
|
|
37
|
+
const funcCtx = ctx.newChild(func.params);
|
|
38
|
+
func.body = _removeUnusedVars(func.body, funcCtx);
|
|
39
|
+
const unusedVars = funcCtx.getUnusedVars();
|
|
40
|
+
// if all variables are used, keep as is
|
|
41
|
+
if (unusedVars.length <= 0) {
|
|
42
|
+
for (const funcArg of args) {
|
|
43
|
+
// arguments passed have the same context of the function called
|
|
44
|
+
_removeUnusedVars(funcArg, ctx);
|
|
45
|
+
}
|
|
46
|
+
return term;
|
|
47
|
+
}
|
|
48
|
+
const originalParams = func.params.slice();
|
|
49
|
+
const filteredArgs = [];
|
|
50
|
+
for (let i = 0; i < originalParams.length; i++) {
|
|
51
|
+
const p = originalParams[i];
|
|
52
|
+
if (!unusedVars.includes(p))
|
|
53
|
+
filteredArgs.push(args[i]);
|
|
54
|
+
}
|
|
55
|
+
// remove vars here
|
|
56
|
+
filterParamsInplace(func.params, unusedVars);
|
|
57
|
+
for (const funcArg of filteredArgs) {
|
|
58
|
+
// arguments passed have the same context of the function called
|
|
59
|
+
_removeUnusedVars(funcArg, ctx);
|
|
60
|
+
}
|
|
61
|
+
const someArgsWereUsed = filteredArgs.length > 0;
|
|
62
|
+
const newTerm = someArgsWereUsed
|
|
63
|
+
? _ir_apps(func, ...filteredArgs)
|
|
64
|
+
: func.body; // all unused, remove function, just keep the body
|
|
65
|
+
const parent = term.parent;
|
|
66
|
+
if (parent)
|
|
67
|
+
_modifyChildFromTo(parent, term, newTerm);
|
|
68
|
+
return newTerm;
|
|
69
|
+
}
|
|
70
|
+
function filterParamsInplace(params, unusedVars) {
|
|
71
|
+
let writeIdx = 0;
|
|
72
|
+
for (let readIdx = 0; readIdx < params.length; readIdx++) {
|
|
73
|
+
const p = params[readIdx];
|
|
74
|
+
if (!unusedVars.includes(p)) {
|
|
75
|
+
params[writeIdx] = p;
|
|
76
|
+
writeIdx++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
params.length = writeIdx;
|
|
80
|
+
}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { IRHoisted } from "../../IRNodes/IRHoisted.js";
|
|
2
2
|
import { IRLetted } from "../../IRNodes/IRLetted.js";
|
|
3
3
|
import { _modifyChildFromTo } from "../_internal/_modifyChildFromTo.js";
|
|
4
|
-
|
|
4
|
+
const _hoisted_cache = new Map();
|
|
5
5
|
export function replaceHoistedWithLetted(term) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
// children first
|
|
7
|
+
const children = term.children();
|
|
8
|
+
for (const c of children)
|
|
9
|
+
replaceHoistedWithLetted(c);
|
|
10
|
+
// then check if hoisted
|
|
11
|
+
if (!(term instanceof IRHoisted))
|
|
12
|
+
return;
|
|
13
|
+
const parent = term.parent;
|
|
14
|
+
if (!parent)
|
|
15
|
+
throw new Error("hoisted node has no parent");
|
|
16
|
+
const cached = _hoisted_cache.get(term.hash)?.deref();
|
|
17
|
+
const letted = (cached ??
|
|
18
|
+
new IRLetted(term.name, term.hoisted, { isClosed: true })).clone();
|
|
19
|
+
if (!cached)
|
|
20
|
+
_hoisted_cache.set(term.hash, new WeakRef(letted));
|
|
21
|
+
// replace hoisted with letted
|
|
22
|
+
_modifyChildFromTo(parent, term, letted);
|
|
16
23
|
}
|
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
import { IRHoisted } from "../../../IRNodes/IRHoisted.js";
|
|
1
2
|
import { IRNative } from "../../../IRNodes/IRNative/index.js";
|
|
2
3
|
import { IRTerm } from "../../../IRTerm.js";
|
|
4
|
+
export declare const hoisted_id: IRHoisted;
|
|
5
|
+
export declare const hoisted_not: IRHoisted;
|
|
6
|
+
export declare const hoisted_incr: IRHoisted;
|
|
7
|
+
export declare const hoisted_decr: IRHoisted;
|
|
8
|
+
export declare const hoisted_isZero: IRHoisted;
|
|
9
|
+
export declare const hoisted_isOne: IRHoisted;
|
|
10
|
+
export declare const hoisted_isTwo: IRHoisted;
|
|
11
|
+
export declare const hoisted_isThree: IRHoisted;
|
|
12
|
+
export declare const hoisted_addOne: IRHoisted;
|
|
13
|
+
export declare const hoisted_subOne: IRHoisted;
|
|
14
|
+
export declare const hoisted_isPositive: IRHoisted;
|
|
15
|
+
export declare const hoisted_isNonNegative: IRHoisted;
|
|
16
|
+
export declare const hoisted_matchList: IRHoisted;
|
|
17
|
+
export declare const hoisted_recursiveList: IRHoisted;
|
|
18
|
+
export declare const hoisted_foldr: IRHoisted;
|
|
19
|
+
export declare const hosited_lazyChooseList: IRHoisted;
|
|
20
|
+
export declare const hoisted_isMoreThanOrEqualTo4: IRHoisted;
|
|
21
|
+
export declare const hoisted_sub4: IRHoisted;
|
|
22
|
+
export declare const hoisted_length: IRHoisted;
|
|
23
|
+
export declare const hoisted_dropList: IRHoisted;
|
|
24
|
+
export declare const hoisted_sizeofPositiveInt: IRHoisted;
|
|
25
|
+
export declare const hoisted_mkFindDataOptional: IRHoisted;
|
|
26
|
+
export declare const hoisted_strictAnd: IRHoisted;
|
|
27
|
+
export declare const hoisted_strictOr: IRHoisted;
|
|
28
|
+
export declare const hoisted_some: IRHoisted;
|
|
29
|
+
export declare const hoisted_every: IRHoisted;
|
|
30
|
+
export declare const hoisted_mkFilter: IRHoisted;
|
|
31
|
+
export declare const hoisted_gtBS: IRHoisted;
|
|
32
|
+
export declare const hoisted_gtEqBS: IRHoisted;
|
|
33
|
+
export declare const hoisted_gtInt: IRHoisted;
|
|
34
|
+
export declare const hoisted_gtEqInt: IRHoisted;
|
|
35
|
+
export declare const hoisted_strToData: IRHoisted;
|
|
36
|
+
export declare const hoisted_pairDataToData: IRHoisted;
|
|
37
|
+
export declare const hoisted_strFromData: IRHoisted;
|
|
38
|
+
export declare const hoisted_pairDataFromData: IRHoisted;
|
|
39
|
+
export declare const hoisted_boolToInt: IRHoisted;
|
|
40
|
+
export declare const hoisted_intToBytesBE: IRHoisted;
|
|
41
|
+
export declare const hoisted_exponentiateInteger: IRHoisted;
|
|
3
42
|
export declare function nativeToIR(native: IRNative): IRTerm;
|
|
43
|
+
export declare const hoisted_mkEqualsList: IRHoisted;
|
|
44
|
+
export declare const hoisted_mkMapList: IRHoisted;
|
|
45
|
+
export declare const hoisted_sortedValueLovelaces: IRHoisted;
|
|
46
|
+
export declare const hoisted_amountOfValue: IRHoisted;
|