@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
|
@@ -10,15 +10,27 @@ import { IRLetted } from "./IRLetted.js";
|
|
|
10
10
|
import { isIRParentTerm } from "../utils/isIRParentTerm.js";
|
|
11
11
|
import { IRConstr } from "./IRConstr.js";
|
|
12
12
|
import { IRCase } from "./IRCase.js";
|
|
13
|
-
import { equalIrHash, hashIrData, irHashToHex, isIRHash } from "../IRHash.js";
|
|
14
|
-
import { shallowEqualIRTermHash } from "../utils/equalIRTerm.js";
|
|
15
13
|
import { IRNodeKind } from "../IRNodeKind.js";
|
|
16
14
|
import { IRRecursive } from "./IRRecursive.js";
|
|
15
|
+
import { isIRHash, hashIrData, irHashToBytes, equalIrHash, irHashToHex } from "../IRHash.js";
|
|
16
|
+
import { IRNative } from "./IRNative/index.js";
|
|
17
|
+
import { nativeTagToString } from "./IRNative/IRNativeTag.js";
|
|
17
18
|
const defaultHoistedMeta = freezeAll({
|
|
18
19
|
forceHoist: false
|
|
19
20
|
});
|
|
21
|
+
const _hoisted_hash_to_symbol = new Map();
|
|
20
22
|
export class IRHoisted {
|
|
21
23
|
meta;
|
|
24
|
+
get name() {
|
|
25
|
+
const hash = this.hash;
|
|
26
|
+
const cached = _hoisted_hash_to_symbol.get(hash)?.deref();
|
|
27
|
+
if (typeof cached === "symbol")
|
|
28
|
+
return cached;
|
|
29
|
+
const sym = Symbol(tryInferName(this.hoisted) ?? "hoisted_" + irHashToHex(hash));
|
|
30
|
+
/// @ts-ignore Argument of type 'WeakRef<object>' is not assignable to parameter of type 'WeakRef<Symbol>'
|
|
31
|
+
_hoisted_hash_to_symbol.set(hash, new WeakRef(sym));
|
|
32
|
+
return sym;
|
|
33
|
+
}
|
|
22
34
|
constructor(hoisted, metadata = {}, _unsafeHash) {
|
|
23
35
|
// unwrap
|
|
24
36
|
// !!! IMPORTANT !!!
|
|
@@ -27,43 +39,45 @@ export class IRHoisted {
|
|
|
27
39
|
if (!isClosedIRTerm(hoisted)) {
|
|
28
40
|
throw new BasePlutsError("only closed terms can be hoisted");
|
|
29
41
|
}
|
|
42
|
+
this._parent = undefined;
|
|
30
43
|
// initialize without calling "set"
|
|
31
44
|
this._hoisted = hoisted;
|
|
32
45
|
this._hoisted.parent = this;
|
|
33
46
|
this._deps = undefined;
|
|
34
|
-
this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
|
|
35
|
-
this._parent = undefined;
|
|
36
47
|
this.meta = {
|
|
37
48
|
...defaultHoistedMeta,
|
|
38
49
|
...metadata,
|
|
39
50
|
name: this._hoisted.meta?.name ?? metadata.name
|
|
40
51
|
};
|
|
52
|
+
this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
|
|
53
|
+
}
|
|
54
|
+
toUPLC() {
|
|
55
|
+
throw new Error("Can't convert 'IRHoisted' to valid UPLC;");
|
|
41
56
|
}
|
|
42
|
-
static get kind() { return IRNodeKind.Hoisted; }
|
|
43
|
-
get kind() { return IRHoisted.kind; }
|
|
44
|
-
static get tag() { return new Uint8Array([IRHoisted.kind]); }
|
|
45
57
|
_hash;
|
|
46
58
|
get hash() {
|
|
47
|
-
if (
|
|
48
|
-
this._hash
|
|
49
|
-
|
|
59
|
+
if (isIRHash(this._hash))
|
|
60
|
+
return this._hash;
|
|
61
|
+
this._hash = hashIrData(concatUint8Arr(IRHoisted.tag, irHashToBytes(this.hoisted.hash)));
|
|
50
62
|
return this._hash;
|
|
51
63
|
}
|
|
64
|
+
isHashPresent() { return isIRHash(this._hash); }
|
|
52
65
|
markHashAsInvalid() {
|
|
53
66
|
this._hash = undefined;
|
|
54
|
-
this._deps = undefined;
|
|
55
67
|
this.parent?.markHashAsInvalid();
|
|
56
68
|
}
|
|
57
|
-
|
|
58
|
-
return
|
|
69
|
+
children() {
|
|
70
|
+
return [this.hoisted];
|
|
59
71
|
}
|
|
72
|
+
static get kind() { return IRNodeKind.Hoisted; }
|
|
73
|
+
get kind() { return IRHoisted.kind; }
|
|
74
|
+
static get tag() { return new Uint8Array([IRHoisted.kind]); }
|
|
60
75
|
_hoisted;
|
|
76
|
+
get value() { return this._hoisted; }
|
|
61
77
|
get hoisted() { return this._hoisted; }
|
|
62
78
|
set hoisted(newHoisted) {
|
|
63
79
|
if (!isClosedIRTerm(newHoisted))
|
|
64
80
|
throw new BasePlutsError("only closed terms can be hoisted");
|
|
65
|
-
if (!shallowEqualIRTermHash(this._hoisted, newHoisted))
|
|
66
|
-
this.markHashAsInvalid();
|
|
67
81
|
// dependencies need to be updated EVEN if hash is the same
|
|
68
82
|
// since the terms might be the same but maybe cloned
|
|
69
83
|
this._deps = undefined;
|
|
@@ -91,13 +105,12 @@ export class IRHoisted {
|
|
|
91
105
|
this._parent = newParent;
|
|
92
106
|
}
|
|
93
107
|
clone() {
|
|
94
|
-
return new IRHoisted(this.
|
|
108
|
+
return new IRHoisted(this.value.clone(), { ...this.meta }, this._hash);
|
|
95
109
|
}
|
|
96
110
|
toJSON() { return this.toJson(); }
|
|
97
111
|
toJson() {
|
|
98
112
|
return {
|
|
99
113
|
type: "IRHoisted",
|
|
100
|
-
hash: irHashToHex(this.hash),
|
|
101
114
|
hoisted: this.hoisted.toJson()
|
|
102
115
|
};
|
|
103
116
|
}
|
|
@@ -124,7 +137,7 @@ export function getSortedHoistedSet(hoistedTerms) {
|
|
|
124
137
|
for (let i = 0; i < _terms.length; i++) {
|
|
125
138
|
const thisHoistedEntry = _terms[i];
|
|
126
139
|
const thisHash = thisHoistedEntry.hoisted.hash;
|
|
127
|
-
const idxInSet = hashesSet.findIndex(
|
|
140
|
+
const idxInSet = hashesSet.findIndex(h => equalIrHash(h, thisHash));
|
|
128
141
|
// if( !hashesSet.includes( compiled ) )
|
|
129
142
|
// "includes" uses standard equality (===)
|
|
130
143
|
if (idxInSet < 0) // not present
|
|
@@ -210,3 +223,8 @@ export function cloneHoistedSetEntry({ hoisted, nReferences }) {
|
|
|
210
223
|
nReferences
|
|
211
224
|
};
|
|
212
225
|
}
|
|
226
|
+
export function tryInferName(value) {
|
|
227
|
+
if (value instanceof IRNative)
|
|
228
|
+
return nativeTagToString(value.tag);
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { IRMetadata } from "../interfaces/IRMetadata.js";
|
|
2
2
|
import { Cloneable } from "@harmoniclabs/cbor/dist/utils/Cloneable";
|
|
3
3
|
import { ToJson } from "../../utils/ToJson.js";
|
|
4
|
-
import { IRTerm } from "../IRTerm.js";
|
|
5
|
-
import {
|
|
4
|
+
import { IIRTerm, IRTerm } from "../IRTerm.js";
|
|
5
|
+
import { IIRParent } from "../interfaces/index.js";
|
|
6
6
|
import { IRParentTerm } from "../utils/isIRParentTerm.js";
|
|
7
7
|
import { BaseIRMetadata } from "./BaseIRMetadata.js";
|
|
8
8
|
import { IRHash } from "../IRHash.js";
|
|
9
9
|
import { IRNodeKind } from "../IRNodeKind.js";
|
|
10
|
+
import { UPLCTerm } from "@harmoniclabs/uplc";
|
|
10
11
|
export type LettedSetEntry = {
|
|
11
12
|
letted: IRLetted;
|
|
12
13
|
nReferences: number;
|
|
13
14
|
};
|
|
14
15
|
export declare function jsonLettedSetEntry(entry: LettedSetEntry): {
|
|
15
|
-
letted: string;
|
|
16
|
+
letted: string | undefined;
|
|
16
17
|
nReferences: number;
|
|
17
18
|
};
|
|
18
19
|
export declare function expandedJsonLettedSetEntry(entry: LettedSetEntry): {
|
|
19
|
-
letted: string;
|
|
20
|
+
letted: string | undefined;
|
|
21
|
+
letted_value: string[];
|
|
20
22
|
nReferences: number;
|
|
21
23
|
};
|
|
22
24
|
export interface IRLettedMeta extends BaseIRMetadata {
|
|
@@ -32,33 +34,25 @@ export interface IRLettedMeta extends BaseIRMetadata {
|
|
|
32
34
|
export interface IRLettedMetadata extends IRMetadata {
|
|
33
35
|
meta: IRLettedMeta;
|
|
34
36
|
}
|
|
35
|
-
export declare class IRLetted implements Cloneable<IRLetted>,
|
|
37
|
+
export declare class IRLetted implements IIRTerm, Cloneable<IRLetted>, IIRParent, ToJson, IRLettedMetadata {
|
|
38
|
+
private _name;
|
|
39
|
+
readonly meta: IRLettedMeta;
|
|
40
|
+
get name(): symbol;
|
|
41
|
+
constructor(name: symbol, toLet: IRTerm, metadata?: Partial<IRLettedMeta>, _unsafeHash?: IRHash | undefined);
|
|
42
|
+
toUPLC(): UPLCTerm;
|
|
36
43
|
private _hash;
|
|
37
44
|
get hash(): IRHash;
|
|
38
|
-
markHashAsInvalid(): void;
|
|
39
45
|
isHashPresent(): boolean;
|
|
46
|
+
markHashAsInvalid(): void;
|
|
40
47
|
private _value;
|
|
41
48
|
get value(): IRTerm;
|
|
42
49
|
set value(newVal: IRTerm);
|
|
43
|
-
private _dbn;
|
|
44
|
-
/**
|
|
45
|
-
* we need to keep track of the debruijn at which the `IRLetted` is instantiated
|
|
46
|
-
*
|
|
47
|
-
* this is because stuff like `new IRLetted( new IRVar(0) )` has different meaning
|
|
48
|
-
* at different DeBruijn levels
|
|
49
|
-
*
|
|
50
|
-
* knowing the DeBruijn we can differentiate them
|
|
51
|
-
*/
|
|
52
|
-
get dbn(): number;
|
|
53
|
-
set dbn(newDbn: number);
|
|
54
|
-
isClosedAtDbn(dbn: number): boolean;
|
|
55
50
|
private _deps;
|
|
56
51
|
get dependencies(): LettedSetEntry[];
|
|
57
52
|
private _parent;
|
|
58
53
|
get parent(): IRParentTerm | undefined;
|
|
59
54
|
set parent(newParent: IRParentTerm | undefined);
|
|
60
|
-
|
|
61
|
-
constructor(DeBruijn: number | bigint, toLet: IRTerm, metadata?: Partial<IRLettedMeta>, _unsafeHash?: IRHash | undefined);
|
|
55
|
+
children(): IRTerm[];
|
|
62
56
|
static get kind(): IRNodeKind.Letted;
|
|
63
57
|
get kind(): IRNodeKind.Letted;
|
|
64
58
|
static get tag(): Uint8Array;
|
|
@@ -92,17 +86,3 @@ export declare const default_getLettedTermsOptions: GetLettedTermsOptions;
|
|
|
92
86
|
* @returns direct letted terms (no possible dependencies)
|
|
93
87
|
*/
|
|
94
88
|
export declare function getLettedTerms(irTerm: IRTerm, options?: Partial<GetLettedTermsOptions>): LettedSetEntry[];
|
|
95
|
-
export declare function getNormalizedLettedArgs(lettedDbn: number, value: IRTerm): [normalized_dbn: number, noramlized_value: IRTerm] | undefined;
|
|
96
|
-
/**
|
|
97
|
-
*
|
|
98
|
-
* @param term the ir term to iter to search for vars
|
|
99
|
-
* @returns {number | undefined}
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```ts
|
|
103
|
-
* let minDbn = getMinVarDbn( new IRVar(0) ); // 0
|
|
104
|
-
* minDbn = getMinVarDbn( IRConst.unit ); // undefined
|
|
105
|
-
* minDbn = getMinVarDbn( new IRFunc( 1, new IRVar( 0 ) ) ); // 0
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export declare function getMinVarDbn(term: IRTerm): number | undefined;
|
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
import { iterTree } from "../toUPLC/_internal/iterTree.js";
|
|
2
|
-
import { IRVar } from "./IRVar.js";
|
|
3
|
-
import { positiveIntAsBytes } from "../utils/positiveIntAsBytes.js";
|
|
4
1
|
import { freezeAll } from "@harmoniclabs/obj-utils";
|
|
5
2
|
import { BasePlutsError } from "../../utils/BasePlutsError.js";
|
|
6
3
|
import { concatUint8Arr } from "../utils/concatUint8Arr.js";
|
|
7
4
|
import { isIRTerm } from "../utils/isIRTerm.js";
|
|
8
|
-
import { IRApp } from "./IRApp.js";
|
|
9
|
-
import { IRDelayed } from "./IRDelayed.js";
|
|
10
|
-
import { IRForced } from "./IRForced.js";
|
|
11
|
-
import { IRFunc } from "./IRFunc.js";
|
|
12
5
|
import { IRHoisted } from "./IRHoisted.js";
|
|
13
6
|
import { isIRParentTerm } from "../utils/isIRParentTerm.js";
|
|
14
|
-
import {
|
|
15
|
-
import { _getMinUnboundDbn } from "../toUPLC/subRoutines/handleLetted/groupByScope.js";
|
|
16
|
-
import { IRConstr } from "./IRConstr.js";
|
|
17
|
-
import { IRCase } from "./IRCase.js";
|
|
18
|
-
import { equalIrHash, hashIrData, irHashToHex, isIRHash } from "../IRHash.js";
|
|
19
|
-
import { shallowEqualIRTermHash } from "../utils/equalIRTerm.js";
|
|
7
|
+
import { hashIrData, irHashToBytes, isIRHash } from "../IRHash.js";
|
|
20
8
|
import { IRNodeKind } from "../IRNodeKind.js";
|
|
21
|
-
import {
|
|
22
|
-
import { IRSelfCall } from "./IRSelfCall.js";
|
|
9
|
+
import { prettyIR } from "../utils/showIR.js";
|
|
23
10
|
export function jsonLettedSetEntry(entry) {
|
|
24
11
|
return {
|
|
25
|
-
letted:
|
|
12
|
+
letted: entry.letted.name.description,
|
|
26
13
|
nReferences: entry.nReferences
|
|
27
14
|
};
|
|
28
15
|
}
|
|
29
16
|
export function expandedJsonLettedSetEntry(entry) {
|
|
30
17
|
return {
|
|
31
|
-
letted:
|
|
32
|
-
|
|
18
|
+
letted: entry.letted.name.description,
|
|
19
|
+
letted_value: prettyIR(entry.letted.value).text.split("\n"),
|
|
33
20
|
nReferences: entry.nReferences
|
|
34
21
|
};
|
|
35
22
|
}
|
|
@@ -38,65 +25,67 @@ const defaultLettedMeta = freezeAll({
|
|
|
38
25
|
__src__: undefined,
|
|
39
26
|
isClosed: false
|
|
40
27
|
});
|
|
41
|
-
|
|
28
|
+
const _letted_hash_to_symbol = new Map();
|
|
42
29
|
export class IRLetted {
|
|
30
|
+
_name;
|
|
31
|
+
meta;
|
|
32
|
+
get name() {
|
|
33
|
+
const hash = this.hash;
|
|
34
|
+
const cached = _letted_hash_to_symbol.get(hash)?.deref();
|
|
35
|
+
if (typeof cached === "symbol")
|
|
36
|
+
return cached;
|
|
37
|
+
if (typeof this._name !== "symbol")
|
|
38
|
+
throw new Error("IRLetted had invalid name");
|
|
39
|
+
const sym = this._name;
|
|
40
|
+
/// @ts-ignore Argument of type 'WeakRef<object>' is not assignable to parameter of type 'WeakRef<Symbol>'
|
|
41
|
+
_letted_hash_to_symbol.set(hash, new WeakRef(sym));
|
|
42
|
+
return sym;
|
|
43
|
+
}
|
|
44
|
+
constructor(name, toLet, metadata = {}, _unsafeHash) {
|
|
45
|
+
if (!(typeof name === "symbol"
|
|
46
|
+
&& typeof name.description === "string"
|
|
47
|
+
&& name.description.length > 0))
|
|
48
|
+
throw new BasePlutsError("invalid name for IRVar");
|
|
49
|
+
this._name = name;
|
|
50
|
+
while (toLet instanceof IRLetted
|
|
51
|
+
|| toLet instanceof IRHoisted)
|
|
52
|
+
toLet = toLet instanceof IRLetted ? toLet.value : toLet.hoisted;
|
|
53
|
+
if (!isIRTerm(toLet))
|
|
54
|
+
throw new BasePlutsError("letted value was not an IRTerm");
|
|
55
|
+
this._value = toLet;
|
|
56
|
+
this._value.parent = this;
|
|
57
|
+
this._deps = undefined;
|
|
58
|
+
this._parent = undefined;
|
|
59
|
+
this.meta = {
|
|
60
|
+
...defaultLettedMeta,
|
|
61
|
+
...metadata,
|
|
62
|
+
// isClosed: metadata.isClosed || this.isClosedAtDbn( 0 )
|
|
63
|
+
};
|
|
64
|
+
this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
|
|
65
|
+
}
|
|
66
|
+
toUPLC() {
|
|
67
|
+
throw new Error("Can't convert 'IRLetted' to valid UPLC");
|
|
68
|
+
}
|
|
43
69
|
_hash;
|
|
44
70
|
get hash() {
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
NEVER
|
|
50
|
-
NEVER
|
|
51
|
-
NEVER
|
|
52
|
-
|
|
53
|
-
NEVER GET THE HASH BASED ON THE METADATA
|
|
54
|
-
|
|
55
|
-
NEVER
|
|
56
|
-
*/
|
|
57
|
-
const normalized = getNormalizedLettedArgs(this.dbn, this._value);
|
|
58
|
-
if (normalized === undefined) {
|
|
59
|
-
// `_value` doesn't includes any `IRVar`
|
|
60
|
-
// aka. there is nothing to normalize
|
|
61
|
-
// just use the value regardless of the
|
|
62
|
-
// `IRLetted` dbn instantiation
|
|
63
|
-
this._hash = hashIrData(concatUint8Arr(IRLetted.tag, this._value.hash));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this._hash = hashIrData(concatUint8Arr(IRLetted.tag, positiveIntAsBytes(normalized[0]), normalized[1].hash));
|
|
67
|
-
/*
|
|
68
|
-
const [ normalized_dbn, normalized_value] = normalized;
|
|
69
|
-
if( toHex( hash ) === "ee84fb036ed2726e01b0415109246927" )
|
|
70
|
-
{
|
|
71
|
-
const original_value = _value.clone();
|
|
72
|
-
const minDbn = getMinVarDbn( original_value );
|
|
73
|
-
const minUnb = _getMinUnboundDbn( original_value );
|
|
74
|
-
console.log(
|
|
75
|
-
"_ee84fb036ed2726e01b0415109246927_",
|
|
76
|
-
"\noriginal value:", prettyIRJsonStr( original_value, 2, { hoisted: false } ),
|
|
77
|
-
"\nmin dbn:", minDbn,
|
|
78
|
-
"\nmin unbound:", minUnb,
|
|
79
|
-
"\nnormalized dbn:", normalized_dbn,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
//*/
|
|
83
|
-
}
|
|
84
|
-
}
|
|
71
|
+
if (isIRHash(this._hash))
|
|
72
|
+
return this._hash;
|
|
73
|
+
this._hash = hashIrData(concatUint8Arr(IRLetted.tag, irHashToBytes(this.value.hash)));
|
|
85
74
|
return this._hash;
|
|
86
75
|
}
|
|
76
|
+
isHashPresent() { return isIRHash(this._hash); }
|
|
87
77
|
markHashAsInvalid() {
|
|
88
78
|
this._hash = undefined;
|
|
89
|
-
this._deps = undefined;
|
|
90
79
|
this.parent?.markHashAsInvalid();
|
|
91
80
|
}
|
|
92
|
-
isHashPresent() { return isIRHash(this._hash); }
|
|
93
81
|
_value;
|
|
94
82
|
get value() { return this._value; }
|
|
95
83
|
set value(newVal) {
|
|
84
|
+
while (newVal instanceof IRLetted
|
|
85
|
+
|| newVal instanceof IRHoisted)
|
|
86
|
+
newVal = newVal instanceof IRLetted ? newVal.value : newVal.hoisted;
|
|
96
87
|
if (!isIRTerm(newVal))
|
|
97
88
|
throw new BasePlutsError("letted term was not IRTerm");
|
|
98
|
-
if (!shallowEqualIRTermHash(this._value, newVal))
|
|
99
|
-
this.markHashAsInvalid();
|
|
100
89
|
// remove deps even if the value is the same
|
|
101
90
|
// newValue might be a clone of the current value
|
|
102
91
|
// and so have different (new) objects
|
|
@@ -106,35 +95,6 @@ export class IRLetted {
|
|
|
106
95
|
this._value = newVal;
|
|
107
96
|
this._value.parent = this;
|
|
108
97
|
}
|
|
109
|
-
_dbn;
|
|
110
|
-
/**
|
|
111
|
-
* we need to keep track of the debruijn at which the `IRLetted` is instantiated
|
|
112
|
-
*
|
|
113
|
-
* this is because stuff like `new IRLetted( new IRVar(0) )` has different meaning
|
|
114
|
-
* at different DeBruijn levels
|
|
115
|
-
*
|
|
116
|
-
* knowing the DeBruijn we can differentiate them
|
|
117
|
-
*/
|
|
118
|
-
get dbn() { return this._dbn; }
|
|
119
|
-
set dbn(newDbn) {
|
|
120
|
-
if (!(Number.isSafeInteger(newDbn) && newDbn >= 0))
|
|
121
|
-
throw new BasePlutsError("invalid index for an `IRLetted` instance");
|
|
122
|
-
if (newDbn === this._dbn) {
|
|
123
|
-
// everything ok
|
|
124
|
-
// avoid calling `markHashAsInvalid`
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
this.markHashAsInvalid();
|
|
128
|
-
this._dbn = newDbn;
|
|
129
|
-
}
|
|
130
|
-
isClosedAtDbn(dbn) {
|
|
131
|
-
if (!Number.isSafeInteger(dbn))
|
|
132
|
-
throw new Error("unexpected unsafe dbn integer");
|
|
133
|
-
const minUnbound = _getMinUnboundDbn(this._value);
|
|
134
|
-
if (minUnbound === undefined)
|
|
135
|
-
return true;
|
|
136
|
-
return minUnbound < dbn;
|
|
137
|
-
}
|
|
138
98
|
_deps;
|
|
139
99
|
get dependencies() {
|
|
140
100
|
if (this._deps === undefined)
|
|
@@ -153,41 +113,20 @@ export class IRLetted {
|
|
|
153
113
|
return;
|
|
154
114
|
this._parent = newParent;
|
|
155
115
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
DeBruijn = typeof DeBruijn === "bigint" ? Number(DeBruijn) : DeBruijn;
|
|
159
|
-
if (!(Number.isSafeInteger(DeBruijn) && DeBruijn >= 0))
|
|
160
|
-
throw new BasePlutsError("invalid index for an `IRLetted` instance");
|
|
161
|
-
while (toLet instanceof IRLetted ||
|
|
162
|
-
toLet instanceof IRHoisted) {
|
|
163
|
-
toLet = toLet instanceof IRLetted ? toLet.value : toLet.hoisted;
|
|
164
|
-
}
|
|
165
|
-
if (!isIRTerm(toLet))
|
|
166
|
-
throw new BasePlutsError("letted value was not an IRTerm");
|
|
167
|
-
this._dbn = DeBruijn;
|
|
168
|
-
this._value = toLet;
|
|
169
|
-
this._value.parent = this;
|
|
170
|
-
// we need the has before setting dependecies
|
|
171
|
-
this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
|
|
172
|
-
this._deps = undefined;
|
|
173
|
-
this._parent = undefined;
|
|
174
|
-
this.meta = {
|
|
175
|
-
...defaultLettedMeta,
|
|
176
|
-
...metadata,
|
|
177
|
-
// isClosed: metadata.isClosed || this.isClosedAtDbn( 0 )
|
|
178
|
-
};
|
|
116
|
+
children() {
|
|
117
|
+
return [this._value];
|
|
179
118
|
}
|
|
180
119
|
static get kind() { return IRNodeKind.Letted; }
|
|
181
120
|
get kind() { return IRLetted.kind; }
|
|
182
121
|
static get tag() { return new Uint8Array([IRLetted.kind]); }
|
|
183
122
|
clone() {
|
|
184
|
-
return new IRLetted(this.
|
|
123
|
+
return new IRLetted(this.name, this.value.clone(), { ...this.meta }, this._hash);
|
|
185
124
|
}
|
|
186
125
|
toJSON() { return this.toJson(); }
|
|
187
126
|
toJson() {
|
|
188
127
|
return {
|
|
189
128
|
type: "IRLetted",
|
|
190
|
-
|
|
129
|
+
name: this.name.description,
|
|
191
130
|
value: this.value.toJson()
|
|
192
131
|
};
|
|
193
132
|
}
|
|
@@ -213,19 +152,12 @@ export function getSortedLettedSet(lettedTerms) {
|
|
|
213
152
|
function addToSet(_terms) {
|
|
214
153
|
for (let i = 0; i < _terms.length; i++) {
|
|
215
154
|
const thisLettedEntry = _terms[i];
|
|
216
|
-
const thisHash = thisLettedEntry.letted.
|
|
217
|
-
const idxInSet = hashesSet.
|
|
218
|
-
// if( !hashesSet.includes( hash ) )
|
|
219
|
-
// "includes" uses standard equality (===)
|
|
155
|
+
const thisHash = thisLettedEntry.letted.name;
|
|
156
|
+
const idxInSet = hashesSet.indexOf(thisHash);
|
|
220
157
|
if (idxInSet < 0) // not present
|
|
221
158
|
{
|
|
222
159
|
// add dependencies first
|
|
223
160
|
// dependencies don't have references to the current letted
|
|
224
|
-
// (of course, wouldn't be much of a dependecy otherwhise)
|
|
225
|
-
//
|
|
226
|
-
// don't add dependecies of dependecies since `dependecies` proerty
|
|
227
|
-
// already calls `getSortedLettedSet( getLettedTerms( _value ) )`
|
|
228
|
-
// so repeating it here would count deps twice (exponentially for deps of deps)
|
|
229
161
|
addToSet(getLettedTerms(thisLettedEntry.letted.value));
|
|
230
162
|
hashesSet.push(thisHash);
|
|
231
163
|
set.push({
|
|
@@ -263,182 +195,18 @@ export function getLettedTerms(irTerm, options) {
|
|
|
263
195
|
const stack = [irTerm];
|
|
264
196
|
while (stack.length > 0) {
|
|
265
197
|
const t = stack.pop();
|
|
198
|
+
if (t instanceof IRHoisted) {
|
|
199
|
+
if (includeHoisted)
|
|
200
|
+
stack.push(t.hoisted);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
266
203
|
if (t instanceof IRLetted) {
|
|
267
204
|
lettedTerms.push({ letted: t, nReferences: 1 });
|
|
268
|
-
if (all)
|
|
205
|
+
if (all)
|
|
269
206
|
stack.push(t.value);
|
|
270
|
-
}
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
if (t instanceof IRApp) {
|
|
274
|
-
stack.push(t.fn, t.arg);
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
if (t instanceof IRConstr) {
|
|
278
|
-
stack.push(...Array.from(t.fields));
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (t instanceof IRCase) {
|
|
282
|
-
stack.push(t.constrTerm, ...Array.from(t.continuations));
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
if (t instanceof IRFunc) {
|
|
286
|
-
stack.push(t.body);
|
|
287
207
|
continue;
|
|
288
208
|
}
|
|
289
|
-
|
|
290
|
-
stack.push(t.body);
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
if (t instanceof IRForced) {
|
|
294
|
-
stack.push(t.forced);
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
if (t instanceof IRDelayed) {
|
|
298
|
-
stack.push(t.delayed);
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
if (includeHoisted) {
|
|
302
|
-
if (t instanceof IRHoisted) {
|
|
303
|
-
stack.push(t.hoisted);
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
209
|
+
stack.push(...t.children());
|
|
307
210
|
}
|
|
308
211
|
return lettedTerms;
|
|
309
212
|
}
|
|
310
|
-
export function getNormalizedLettedArgs(lettedDbn, value) {
|
|
311
|
-
const normalized_value = value.clone();
|
|
312
|
-
const minDbn = getMinVarDbn(normalized_value);
|
|
313
|
-
if (minDbn === undefined)
|
|
314
|
-
return undefined;
|
|
315
|
-
if (minDbn !== 0)
|
|
316
|
-
iterTree(normalized_value, (node, relativeDbn) => {
|
|
317
|
-
if (node instanceof IRVar) {
|
|
318
|
-
node.dbn -= minDbn;
|
|
319
|
-
}
|
|
320
|
-
else if (node instanceof IRSelfCall) {
|
|
321
|
-
node.dbn -= minDbn;
|
|
322
|
-
}
|
|
323
|
-
//*
|
|
324
|
-
else if (node instanceof IRLetted) {
|
|
325
|
-
const max = getMaxVarDbn(node.value);
|
|
326
|
-
if (
|
|
327
|
-
// no vars
|
|
328
|
-
typeof max !== "number" ||
|
|
329
|
-
// defined outside of letted
|
|
330
|
-
max >= relativeDbn) {
|
|
331
|
-
node.dbn -= minDbn;
|
|
332
|
-
}
|
|
333
|
-
else // if depends on vars in this letted
|
|
334
|
-
{
|
|
335
|
-
// TODO: fix double checking already inlined values
|
|
336
|
-
//
|
|
337
|
-
// this is currently a workaround
|
|
338
|
-
//
|
|
339
|
-
// the real problem is that sometimes (when?)
|
|
340
|
-
// `iterTree` goes back checking some value that was already modified
|
|
341
|
-
// in the case of `IRApp` as parent, throwing an error
|
|
342
|
-
// because we don't know which value we should modify
|
|
343
|
-
if (node.parent instanceof IRApp) {
|
|
344
|
-
const parent = node.parent;
|
|
345
|
-
const currentChild = node;
|
|
346
|
-
if ( // parent is actually pointing to child
|
|
347
|
-
currentChild === parent.arg ||
|
|
348
|
-
currentChild === parent.fn ||
|
|
349
|
-
equalIrHash(parent.arg.hash, currentChild.hash) ||
|
|
350
|
-
equalIrHash(parent.fn.hash, currentChild.hash)) {
|
|
351
|
-
// inline
|
|
352
|
-
_modifyChildFromTo(node.parent, node, node.value);
|
|
353
|
-
return true; // modified parent
|
|
354
|
-
}
|
|
355
|
-
else
|
|
356
|
-
return false; // modified parent
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
if (node.parent) // only modify if not root
|
|
360
|
-
{
|
|
361
|
-
// inline
|
|
362
|
-
_modifyChildFromTo(node.parent, node, node.value);
|
|
363
|
-
return true; // modified parent
|
|
364
|
-
}
|
|
365
|
-
else
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
//*/
|
|
371
|
-
},
|
|
372
|
-
// shouldSkipNode ?
|
|
373
|
-
// hoisted terms are not really here
|
|
374
|
-
// will be substituted to variables when the time comes
|
|
375
|
-
// however now are here and we need to skip them
|
|
376
|
-
//
|
|
377
|
-
// !!! WARNING !! removing this causes strange uplc compilation BUGS
|
|
378
|
-
(node, dbn) => node instanceof IRHoisted);
|
|
379
|
-
// !!! IMPORTANT !!! _getMinUnboundDbn( value ) MUST be called on the original value; NOT the **modified** `normalized_value`
|
|
380
|
-
return [lettedDbn - (_getMinUnboundDbn(value) ?? minDbn), normalized_value];
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
*
|
|
384
|
-
* @param term the ir term to iter to search for vars
|
|
385
|
-
* @returns {number | undefined}
|
|
386
|
-
*
|
|
387
|
-
* @example
|
|
388
|
-
* ```ts
|
|
389
|
-
* let minDbn = getMinVarDbn( new IRVar(0) ); // 0
|
|
390
|
-
* minDbn = getMinVarDbn( IRConst.unit ); // undefined
|
|
391
|
-
* minDbn = getMinVarDbn( new IRFunc( 1, new IRVar( 0 ) ) ); // 0
|
|
392
|
-
* ```
|
|
393
|
-
*/
|
|
394
|
-
export function getMinVarDbn(term) {
|
|
395
|
-
let min = undefined;
|
|
396
|
-
let foundAny = false;
|
|
397
|
-
iterTree(term, (node) => {
|
|
398
|
-
if (node instanceof IRVar ||
|
|
399
|
-
node instanceof IRSelfCall) {
|
|
400
|
-
if (foundAny) {
|
|
401
|
-
min = Math.min(min, node.dbn);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
foundAny = true;
|
|
405
|
-
min = node.dbn;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
// shouldSkipNode ?
|
|
410
|
-
// hoisted terms are not really here
|
|
411
|
-
// will be substituted to variables when the time comes
|
|
412
|
-
// however now are here and we need to skip them
|
|
413
|
-
node => node instanceof IRHoisted // skip if hoisted
|
|
414
|
-
);
|
|
415
|
-
return min;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
*
|
|
419
|
-
* @param term the ir term to iter to search for vars
|
|
420
|
-
* @returns {number | undefined}
|
|
421
|
-
*/
|
|
422
|
-
function getMaxVarDbn(term) {
|
|
423
|
-
let max = undefined;
|
|
424
|
-
let foundAny = false;
|
|
425
|
-
iterTree(term, (node) => {
|
|
426
|
-
if (node instanceof IRVar ||
|
|
427
|
-
node instanceof IRSelfCall) {
|
|
428
|
-
if (foundAny) {
|
|
429
|
-
max = Math.max(max, node.dbn);
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
foundAny = true;
|
|
433
|
-
max = node.dbn;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
},
|
|
437
|
-
// shouldSkipNode ?
|
|
438
|
-
// hoisted terms are not really here
|
|
439
|
-
// will be substituted to variables when the time comes
|
|
440
|
-
// however now are here and we need to skip them
|
|
441
|
-
node => node instanceof IRHoisted // skip if hoisted
|
|
442
|
-
);
|
|
443
|
-
return max;
|
|
444
|
-
}
|
|
@@ -126,9 +126,7 @@ export var IRNativeTag;
|
|
|
126
126
|
IRNativeTag[IRNativeTag["_id"] = -15] = "_id";
|
|
127
127
|
IRNativeTag[IRNativeTag["_not"] = -16] = "_not";
|
|
128
128
|
IRNativeTag[IRNativeTag["_strictAnd"] = -17] = "_strictAnd";
|
|
129
|
-
IRNativeTag[IRNativeTag["_and"] = -18] = "_and";
|
|
130
129
|
IRNativeTag[IRNativeTag["_strictOr"] = -19] = "_strictOr";
|
|
131
|
-
IRNativeTag[IRNativeTag["_or"] = -20] = "_or";
|
|
132
130
|
IRNativeTag[IRNativeTag["_gtBS"] = -21] = "_gtBS";
|
|
133
131
|
IRNativeTag[IRNativeTag["_gtEqBS"] = -22] = "_gtEqBS";
|
|
134
132
|
IRNativeTag[IRNativeTag["_gtInt"] = -23] = "_gtInt";
|
|
@@ -175,9 +173,7 @@ export function nativeTagToString(nativeTag) {
|
|
|
175
173
|
case IRNativeTag._id: return "id";
|
|
176
174
|
case IRNativeTag._not: return "not";
|
|
177
175
|
case IRNativeTag._strictAnd: return "strictAnd";
|
|
178
|
-
case IRNativeTag._and: return "and";
|
|
179
176
|
case IRNativeTag._strictOr: return "strictOr";
|
|
180
|
-
case IRNativeTag._or: return "or";
|
|
181
177
|
case IRNativeTag._gtBS: return "gtBS";
|
|
182
178
|
case IRNativeTag._gtEqBS: return "gtEqBS";
|
|
183
179
|
case IRNativeTag._gtInt: return "gtInt";
|