@harmoniclabs/pebble 0.1.0-dev5 → 0.1.0-dev7
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 +3 -3
- package/dist/IR/IRNodes/IRNative/IRNativeTag.js +4 -4
- package/dist/IR/IRNodes/IRNative/index.d.ts +10 -8
- package/dist/IR/IRNodes/IRNative/index.js +56 -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/CompilerOptions.d.ts +5 -0
- package/dist/IR/toUPLC/CompilerOptions.js +10 -1
- 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 +67 -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 +65 -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 +45 -0
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +277 -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 +40 -26
- package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
- package/dist/IR/utils/positiveIntAsBytes.js +4 -4
- 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 +7 -2
- package/dist/compiler/AstCompiler/AstCompiler.js +129 -25
- 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 +5 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +7 -4
- 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 +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +8 -8
- 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.d.ts +2 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +4 -3
- 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.d.ts +1 -0
- package/dist/compiler/AstCompiler/scope/AstScope.js +9 -3
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
- package/dist/compiler/Compiler.js +7 -1
- package/dist/compiler/TirCompiler/compileTirProgram.js +4 -1
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +17 -5
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +79 -49
- package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +13 -2
- package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressify.js +102 -41
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +77 -12
- package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +16 -9
- package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -8
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +146 -13
- package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
- package/dist/compiler/internalVar.d.ts +1 -1
- package/dist/compiler/internalVar.js +31 -24
- package/dist/compiler/io/CompilerIoApi.d.ts +1 -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 +105 -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 +6 -3
- package/dist/compiler/tir/expressions/TirLettedExpr.js +20 -7
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +9 -5
- package/dist/compiler/tir/expressions/TirNativeFunc.js +58 -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 -1
- 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 +6 -3
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +22 -8
- package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +19 -20
- package/dist/compiler/tir/expressions/ToIRTermCtx.js +74 -50
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +41 -0
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +180 -4
- 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 +3 -2
- package/dist/compiler/tir/program/TypedProgram.js +9 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +135 -149
- 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 +2 -0
- package/dist/compiler/tir/statements/TirIfStmt.js +16 -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 +180 -32
- package/dist/parser/Precedence.js +1 -0
- 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/dist/utils/array/keepSortedArrInplace.js +1 -0
- package/package.json +3 -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
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -37
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { IRApp } from "../../../IRNodes/IRApp.js";
|
|
2
|
-
import { IRCase } from "../../../IRNodes/IRCase.js";
|
|
3
|
-
import { IRConstr } from "../../../IRNodes/IRConstr.js";
|
|
4
1
|
import { IRDelayed } from "../../../IRNodes/IRDelayed.js";
|
|
5
|
-
import { IRForced } from "../../../IRNodes/IRForced.js";
|
|
6
2
|
import { IRFunc } from "../../../IRNodes/IRFunc.js";
|
|
7
|
-
import { IRLetted } from "../../../IRNodes/IRLetted.js";
|
|
8
3
|
import { IRRecursive } from "../../../IRNodes/IRRecursive.js";
|
|
9
4
|
import { IRSelfCall } from "../../../IRNodes/IRSelfCall.js";
|
|
10
5
|
import { IRVar } from "../../../IRNodes/IRVar.js";
|
|
11
|
-
import { mapArrayLike } from "../../../IRNodes/utils/mapArrayLike.js";
|
|
12
6
|
export function groupByScope(letteds) {
|
|
13
7
|
const scopes = [];
|
|
14
8
|
function pushScope(scope, letted) {
|
|
@@ -23,85 +17,85 @@ export function groupByScope(letteds) {
|
|
|
23
17
|
scopeEntry.group.push(letted);
|
|
24
18
|
}
|
|
25
19
|
for (const { letted, nReferences } of letteds) {
|
|
26
|
-
|
|
27
|
-
if (minUnboundDbn === undefined) {
|
|
28
|
-
pushScope(undefined, { letted, nReferences });
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
let maxScope = letted.parent;
|
|
32
|
-
if (maxScope instanceof IRFunc ||
|
|
33
|
-
maxScope instanceof IRRecursive) {
|
|
34
|
-
minUnboundDbn -= maxScope.arity;
|
|
35
|
-
}
|
|
36
|
-
while (minUnboundDbn >= 0) {
|
|
37
|
-
maxScope = maxScope?.parent;
|
|
38
|
-
if (maxScope instanceof IRFunc ||
|
|
39
|
-
maxScope instanceof IRRecursive) {
|
|
40
|
-
minUnboundDbn -= maxScope.arity;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
20
|
+
const maxScope = getMaxScope(letted.value);
|
|
43
21
|
pushScope(maxScope, { letted, nReferences });
|
|
44
22
|
}
|
|
45
23
|
return scopes;
|
|
46
24
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
while (stack.length > 0) {
|
|
61
|
-
const { term, dbn } = stack.pop();
|
|
62
|
-
if (term instanceof IRVar ||
|
|
63
|
-
term instanceof IRSelfCall) {
|
|
64
|
-
if (term.dbn >= dbn) // some val outside
|
|
65
|
-
{
|
|
66
|
-
const outsideDbn = term.dbn - dbn;
|
|
67
|
-
minDbn = minDbn === undefined ? outsideDbn : Math.min(outsideDbn, minDbn);
|
|
25
|
+
export function getMaxScope(term) {
|
|
26
|
+
const unbounded = getUnboundedVars(term);
|
|
27
|
+
if (unbounded.size === 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
while (term.parent) {
|
|
30
|
+
term = term.parent;
|
|
31
|
+
if (term instanceof IRDelayed)
|
|
32
|
+
return term;
|
|
33
|
+
if (term instanceof IRFunc
|
|
34
|
+
|| term instanceof IRRecursive) {
|
|
35
|
+
for (const param of term.params) {
|
|
36
|
+
if (unbounded.has(param))
|
|
37
|
+
return term;
|
|
68
38
|
}
|
|
69
39
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
40
|
+
}
|
|
41
|
+
throw new Error("Unbounded var not found in any parent term");
|
|
42
|
+
}
|
|
43
|
+
export function getUnboundedIRVars(term) {
|
|
44
|
+
const accessedVars = new Map();
|
|
45
|
+
const boundedVars = new Set();
|
|
46
|
+
const stack = [term];
|
|
47
|
+
while (stack.length > 0) {
|
|
48
|
+
const t = stack.pop();
|
|
49
|
+
if (t instanceof IRVar
|
|
50
|
+
|| t instanceof IRSelfCall) {
|
|
51
|
+
let vars = accessedVars.get(t.name);
|
|
52
|
+
if (!Array.isArray(vars)) {
|
|
53
|
+
vars = [];
|
|
54
|
+
accessedVars.set(t.name, vars);
|
|
55
|
+
}
|
|
56
|
+
vars.push(t);
|
|
84
57
|
continue;
|
|
85
58
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
59
|
+
if (t instanceof IRFunc
|
|
60
|
+
|| t instanceof IRRecursive) {
|
|
61
|
+
for (const param of t.params)
|
|
62
|
+
boundedVars.add(param);
|
|
63
|
+
stack.push(t.body);
|
|
88
64
|
continue;
|
|
89
65
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
66
|
+
stack.push(...t.children());
|
|
67
|
+
}
|
|
68
|
+
for (const v of boundedVars)
|
|
69
|
+
accessedVars.delete(v);
|
|
70
|
+
return [...accessedVars.values()].flat();
|
|
71
|
+
}
|
|
72
|
+
export function getUnboundedVars(term, knownVars) {
|
|
73
|
+
const accessedVars = new Set();
|
|
74
|
+
const boundedVars = new Set();
|
|
75
|
+
if (knownVars instanceof Set) {
|
|
76
|
+
for (const v of knownVars) {
|
|
77
|
+
if (typeof v === "symbol")
|
|
78
|
+
boundedVars.add(v);
|
|
93
79
|
}
|
|
94
|
-
|
|
95
|
-
|
|
80
|
+
}
|
|
81
|
+
const stack = [term];
|
|
82
|
+
while (stack.length > 0) {
|
|
83
|
+
const t = stack.pop();
|
|
84
|
+
if (t instanceof IRVar
|
|
85
|
+
|| t instanceof IRSelfCall) {
|
|
86
|
+
accessedVars.add(t.name);
|
|
96
87
|
continue;
|
|
97
88
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
89
|
+
if (t instanceof IRFunc
|
|
90
|
+
|| t instanceof IRRecursive) {
|
|
91
|
+
for (const param of t.params)
|
|
92
|
+
boundedVars.add(param);
|
|
93
|
+
stack.push(t.body);
|
|
101
94
|
continue;
|
|
102
95
|
}
|
|
103
|
-
|
|
104
|
-
// if( term instanceof IRHoisted )
|
|
96
|
+
stack.push(...t.children());
|
|
105
97
|
}
|
|
106
|
-
|
|
98
|
+
for (const v of boundedVars)
|
|
99
|
+
accessedVars.delete(v);
|
|
100
|
+
return accessedVars;
|
|
107
101
|
}
|
|
@@ -4,23 +4,19 @@ import { getSortedLettedSet, getLettedTerms, IRLetted } from "../../../IRNodes/I
|
|
|
4
4
|
import { IRVar } from "../../../IRNodes/IRVar.js";
|
|
5
5
|
import { _modifyChildFromTo } from "../../_internal/_modifyChildFromTo.js";
|
|
6
6
|
import { findAllNoHoisted } from "../../_internal/findAll.js";
|
|
7
|
-
import {
|
|
8
|
-
import { _getMinUnboundDbn } from "./groupByScope.js";
|
|
7
|
+
import { getMaxScope } from "./groupByScope.js";
|
|
9
8
|
import { IRDelayed } from "../../../IRNodes/IRDelayed.js";
|
|
10
|
-
import { IRForced } from "../../../IRNodes/IRForced.js";
|
|
11
9
|
import { lowestCommonAncestor } from "../../_internal/lowestCommonAncestor.js";
|
|
12
10
|
import { isIRTerm } from "../../../utils/isIRTerm.js";
|
|
13
11
|
import { markRecursiveHoistsAsForced } from "../markRecursiveHoistsAsForced.js";
|
|
14
12
|
import { IRConst } from "../../../IRNodes/IRConst.js";
|
|
15
|
-
import { incrementUnboundDbns } from "./incrementUnboundDbns.js";
|
|
16
13
|
import { equalIrHash, irHashToHex } from "../../../IRHash.js";
|
|
17
14
|
import { sanifyTree } from "../sanifyTree.js";
|
|
18
|
-
import { mapArrayLike } from "../../../IRNodes/utils/mapArrayLike.js";
|
|
19
|
-
import { IRCase } from "../../../IRNodes/IRCase.js";
|
|
20
|
-
import { IRConstr } from "../../../IRNodes/IRConstr.js";
|
|
21
15
|
import { IRRecursive } from "../../../IRNodes/IRRecursive.js";
|
|
22
16
|
import { IRSelfCall } from "../../../IRNodes/IRSelfCall.js";
|
|
23
17
|
import { findHighestRecursiveParent } from "./findHighestRecursiveParent.js";
|
|
18
|
+
import { IRNative } from "../../../IRNodes/IRNative/index.js";
|
|
19
|
+
import { isForcedNativeTag } from "../../../IRNodes/IRNative/isForcedNative.js";
|
|
24
20
|
export function handleLettedAndReturnRoot(term) {
|
|
25
21
|
// console.log(" ------------------------------------------- handleLetted ------------------------------------------- ");
|
|
26
22
|
// console.log( prettyIRText( term ))
|
|
@@ -28,52 +24,60 @@ export function handleLettedAndReturnRoot(term) {
|
|
|
28
24
|
// pre-execuded terms (hence constants)
|
|
29
25
|
if (term instanceof IRConst)
|
|
30
26
|
return term;
|
|
27
|
+
sanifyTree(term);
|
|
31
28
|
// TODO: should probably merge `markRecursiveHoistsAsForced` inside `getLettedTerms` to iter once
|
|
32
29
|
markRecursiveHoistsAsForced(term);
|
|
33
30
|
// in case there are no letted terms there is no work to do
|
|
34
31
|
while (true) {
|
|
32
|
+
// console.log(` ------------------ letted loop ------------------ `);
|
|
35
33
|
const allDirectLetted = getLettedTerms(term, { all: false, includeHoisted: false });
|
|
36
34
|
if (allDirectLetted.length === 0)
|
|
37
35
|
return term;
|
|
36
|
+
// // console.log("allDirectLetted", allDirectLetted.map( expandedJsonLettedSetEntry ) );
|
|
38
37
|
const sortedLettedSet = getSortedLettedSet(allDirectLetted);
|
|
38
|
+
// console.log("sortedLettedSet", sortedLettedSet.map( expandedJsonLettedSetEntry ) );
|
|
39
|
+
// `sortedLettedSet` is sorted from least to most dependencies
|
|
40
|
+
// so we'll have "0 dependencies" letted terms at the start of the array
|
|
41
|
+
// and "n dependencies" letted terms at the end of the array
|
|
42
|
+
//
|
|
43
|
+
// we process the "most dependent" terms first
|
|
44
|
+
// so their values are inlined
|
|
45
|
+
// and later, its dependencies will be replaced with `IRVar`
|
|
46
|
+
// whereever these dependent are inlined
|
|
47
|
+
//
|
|
48
|
+
// hence why `pop` (and not `shift`)
|
|
39
49
|
const { letted, nReferences } = sortedLettedSet.pop();
|
|
40
|
-
|
|
41
|
-
const _lettedValue_ = letted.value;
|
|
42
|
-
const shouldLog = (
|
|
43
|
-
_lettedValue_ instanceof IRApp &&
|
|
44
|
-
_lettedValue_.fn instanceof IRFunc &&
|
|
45
|
-
_lettedValue_.fn.arity === 1 &&
|
|
46
|
-
_lettedValue_.fn.body instanceof IRLetted &&
|
|
47
|
-
equalIrHash( _lettedValue_.fn.body.hash, new Uint32Array( fromHex("71030a2d7560e563fe25fd782edd847f").buffer ) as IRHash ) &&
|
|
48
|
-
_lettedValue_.arg instanceof IRLetted &&
|
|
49
|
-
equalIrHash( _lettedValue_.arg.hash, new Uint32Array( fromHex("82dfb8a2f2703fe59fb25f8372e5e958").buffer ) as IRHash )
|
|
50
|
-
);
|
|
51
|
-
//*/
|
|
52
|
-
// shouldLog && console.log("nReferences", nReferences);
|
|
50
|
+
// shouldLog && // console.log("nReferences", nReferences);
|
|
53
51
|
// console.log(` ------------------ working with ${lettedToStr(letted)} ------------------ `);
|
|
54
52
|
if (nReferences === 1) {
|
|
55
53
|
// console.log("inlining letted (single reference) with value", prettyIRText( letted.value ) )
|
|
56
54
|
_modifyChildFromTo(letted.parent, letted, letted.value);
|
|
57
55
|
continue;
|
|
58
56
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
57
|
+
// console.log("--------- not inilning ("+ nReferences +" references)");
|
|
58
|
+
const maxScope = getMaxScope(letted) ?? term;
|
|
59
|
+
// const maxScope = getMaxScope( letted ) ?? ((): IRTerm => {
|
|
60
|
+
// if( letted.meta.isClosed || isClosedTerm( letted.value ) )
|
|
61
|
+
// {
|
|
62
|
+
// // value is closed (hoisted),
|
|
63
|
+
// // so the max scope is the entire script
|
|
64
|
+
// return term;
|
|
65
|
+
// }
|
|
66
|
+
// else throw new Error(
|
|
67
|
+
// `could not find a max scope for letted value with hash ${irHashToHex(letted.hash)}`
|
|
68
|
+
// );
|
|
69
|
+
// })();
|
|
68
70
|
const lettedTermCanBeHoisted = maxScope === term;
|
|
69
71
|
const minScope = findHighestRecursiveParent(letted, maxScope);
|
|
70
72
|
sanifyTree(maxScope);
|
|
71
73
|
const lettedHash = letted.hash;
|
|
72
74
|
const sameLettedRefs = findAllNoHoisted(maxScope, node => node instanceof IRLetted &&
|
|
73
75
|
equalIrHash(node.hash, lettedHash));
|
|
76
|
+
// console.log("sameLettedRefs", sameLettedRefs.length );
|
|
74
77
|
if (sameLettedRefs.length <= 0) {
|
|
75
|
-
console.warn("how did you get here? 0 references found for letted term;\n
|
|
76
|
-
"
|
|
78
|
+
console.warn("how did you get here? 0 references found for letted term;\n" +
|
|
79
|
+
"the compiler can easly recover this edge case, but something funny is going on with this contract.\n\n" +
|
|
80
|
+
"!!! PLEASE OPEN AN ISSUE ON GITHUB (https://github.com/HarmonicLabs/plu-ts/issues) !!!\n");
|
|
77
81
|
continue;
|
|
78
82
|
}
|
|
79
83
|
// just in case
|
|
@@ -83,8 +87,10 @@ export function handleLettedAndReturnRoot(term) {
|
|
|
83
87
|
continue;
|
|
84
88
|
}
|
|
85
89
|
// always inline letted vars
|
|
86
|
-
if (letted.value instanceof IRVar
|
|
87
|
-
letted.value instanceof IRSelfCall
|
|
90
|
+
if (letted.value instanceof IRVar
|
|
91
|
+
|| letted.value instanceof IRSelfCall
|
|
92
|
+
|| (letted.value instanceof IRNative
|
|
93
|
+
&& !isForcedNativeTag(letted.value.tag))) {
|
|
88
94
|
// console.log("inlining letted (value is var) with value", prettyIRText( letted.value ) )
|
|
89
95
|
for (const elem of sameLettedRefs) {
|
|
90
96
|
// inline
|
|
@@ -126,25 +132,16 @@ export function handleLettedAndReturnRoot(term) {
|
|
|
126
132
|
const parentNode = lca;
|
|
127
133
|
const parentNodeDirectChild = (parentNode instanceof IRFunc ||
|
|
128
134
|
parentNode instanceof IRRecursive) ? parentNode.body : parentNode.delayed;
|
|
129
|
-
// add 1 to every var's DeBruijn that accesses stuff outside the parent node
|
|
130
|
-
// not including the `parentNode` node
|
|
131
|
-
// since the new function introdcued substituting the letted term
|
|
132
|
-
// is added inside the `parentNode` node
|
|
133
|
-
incrementUnboundDbns(parentNodeDirectChild,
|
|
134
|
-
// `shouldNotModifyLetted` arg (given the hash returns `true` if it should NOT modify the term)
|
|
135
|
-
// this callback is ONLY called on LETTED terms
|
|
136
|
-
({ hash }) => equalIrHash(hash, lettedHash));
|
|
137
135
|
// now we replace
|
|
138
136
|
const lettedValue = letted.value.clone();
|
|
139
|
-
|
|
140
|
-
const newNode = new IRApp(new IRFunc(1, parentNodeDirectChild), lettedValue, { __src__: letted.meta.__src__ });
|
|
137
|
+
const newNode = new IRApp(new IRFunc([letted.name], parentNodeDirectChild), lettedValue, { __src__: letted.meta.__src__ });
|
|
141
138
|
// replace child with new node
|
|
142
139
|
if (parentNode instanceof IRFunc || parentNode instanceof IRRecursive)
|
|
143
140
|
parentNode.body = newNode;
|
|
144
141
|
else
|
|
145
142
|
parentNode.delayed = newNode;
|
|
146
143
|
for (const ref of sameLettedRefs) {
|
|
147
|
-
_modifyChildFromTo(ref.parent, ref, new IRVar(
|
|
144
|
+
_modifyChildFromTo(ref.parent, ref, new IRVar(ref.name));
|
|
148
145
|
}
|
|
149
146
|
// const delayed = parentNode instanceof IRDelayed;
|
|
150
147
|
// let finalMaxScope: IRFunc | IRDelayed = parentNode;
|
|
@@ -155,141 +152,18 @@ export function handleLettedAndReturnRoot(term) {
|
|
|
155
152
|
// {
|
|
156
153
|
// finalMaxScope = (finalMaxScope as any).parent as any
|
|
157
154
|
// }
|
|
158
|
-
// console.log("final max scope (delayed: " + delayed + ")" , prettyIRText( finalMaxScope ) )
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
*
|
|
163
|
-
* @param letted
|
|
164
|
-
* @returns {IRFunc} the lowest `IRFunc` in the tree that defines all the variables needed for the
|
|
165
|
-
*/
|
|
166
|
-
function findLettedMaxScope(letted) {
|
|
167
|
-
let minUnboundDbn = _getMinUnboundDbn(letted.value);
|
|
168
|
-
if (minUnboundDbn === undefined) {
|
|
169
|
-
let tmp = letted;
|
|
170
|
-
let maxScope = undefined;
|
|
171
|
-
while (tmp.parent) {
|
|
172
|
-
tmp = tmp.parent;
|
|
173
|
-
if (tmp instanceof IRFunc || tmp instanceof IRDelayed)
|
|
174
|
-
maxScope = tmp;
|
|
175
|
-
}
|
|
176
|
-
;
|
|
177
|
-
return maxScope;
|
|
178
|
-
}
|
|
179
|
-
let tmp = letted;
|
|
180
|
-
let maxScope = undefined;
|
|
181
|
-
while (minUnboundDbn >= 0) {
|
|
182
|
-
if (!tmp.parent) {
|
|
183
|
-
throw new Error(`could not find a max scope for letted value with hash ${irHashToHex(letted.hash)}; ` +
|
|
184
|
-
`the max parent found leaves the term open (reached root)`);
|
|
185
|
-
}
|
|
186
|
-
tmp = tmp.parent;
|
|
187
|
-
if (tmp instanceof IRRecursive) {
|
|
188
|
-
minUnboundDbn -= tmp.arity;
|
|
189
|
-
// maxScope = tmp; // recursive cannot be a max scope
|
|
190
|
-
}
|
|
191
|
-
else if (tmp instanceof IRFunc) {
|
|
192
|
-
minUnboundDbn -= tmp.arity;
|
|
193
|
-
maxScope = tmp;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
// just ts sillyness here
|
|
197
|
-
if (!maxScope) {
|
|
198
|
-
throw new Error(`could not find a max scope for letted value with hash ${irHashToHex(letted.hash)}; ` +
|
|
199
|
-
`no IRFunc found`);
|
|
200
|
-
}
|
|
201
|
-
return maxScope;
|
|
202
|
-
}
|
|
203
|
-
function modifyValueToLetDbns(lettedValue, diffDbn) {
|
|
204
|
-
if (diffDbn <= 0)
|
|
205
|
-
return;
|
|
206
|
-
// if there is any actual difference between the letted term
|
|
207
|
-
// and the position where it will be finally placed
|
|
208
|
-
// the value needs to be modified accoridingly
|
|
209
|
-
const stack = [{ term: lettedValue, dbn: 0 }];
|
|
210
|
-
while (stack.length > 0) {
|
|
211
|
-
const { term: t, dbn } = stack.pop();
|
|
212
|
-
if ((t instanceof IRVar ||
|
|
213
|
-
t instanceof IRSelfCall) &&
|
|
214
|
-
t.dbn > dbn) {
|
|
215
|
-
t.dbn -= diffDbn;
|
|
216
|
-
}
|
|
217
|
-
if (t instanceof IRLetted) {
|
|
218
|
-
t.dbn -= diffDbn;
|
|
219
|
-
// reduce dbn in letted value too
|
|
220
|
-
stack.push({ term: t.value, dbn });
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
if (t instanceof IRApp) {
|
|
224
|
-
stack.push({ term: t.arg, dbn }, { term: t.fn, dbn });
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (t instanceof IRCase) {
|
|
228
|
-
stack.push({ term: t.constrTerm, dbn }, ...mapArrayLike(t.continuations, continuation => ({ term: continuation, dbn })));
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
if (t instanceof IRConstr) {
|
|
232
|
-
stack.push(...mapArrayLike(t.fields, field => ({ term: field, dbn })));
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (t instanceof IRDelayed) {
|
|
236
|
-
stack.push({ term: t.delayed, dbn });
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
if (t instanceof IRForced) {
|
|
240
|
-
stack.push({ term: t.forced, dbn });
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
if (t instanceof IRFunc) {
|
|
244
|
-
stack.push({ term: t.body, dbn: dbn + t.arity });
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (t instanceof IRRecursive) {
|
|
248
|
-
stack.push({ term: t.body, dbn: dbn + t.arity });
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
// no hoisted
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* @returns the difference in DeBruijn
|
|
256
|
-
* between the maxScope and the letted term
|
|
257
|
-
*/
|
|
258
|
-
function getDiffDbn(letted, parentNode) {
|
|
259
|
-
// get the difference in DeBruijn
|
|
260
|
-
// between the maxScope and the letted term
|
|
261
|
-
let diffDbn = 0;
|
|
262
|
-
//*
|
|
263
|
-
let tmpNode = letted;
|
|
264
|
-
while (tmpNode !== parentNode) {
|
|
265
|
-
tmpNode = tmpNode.parent;
|
|
266
|
-
if ( // is an intermediate `IRFunc`
|
|
267
|
-
(tmpNode instanceof IRFunc ||
|
|
268
|
-
tmpNode instanceof IRRecursive) &&
|
|
269
|
-
tmpNode !== parentNode // avoid counting parent node arity if IRFunc
|
|
270
|
-
) {
|
|
271
|
-
// increment differential in DeBruijn by n vars indroduced here
|
|
272
|
-
diffDbn += tmpNode.arity;
|
|
273
|
-
}
|
|
155
|
+
// // // console.log("final max scope (delayed: " + delayed + ")" , prettyIRText( finalMaxScope ) )
|
|
274
156
|
}
|
|
275
|
-
return diffDbn;
|
|
276
157
|
}
|
|
277
158
|
function handleLettedAsHoistedAndReturnRoot(letted, lca, sameLettedRefs, currentRoot) {
|
|
278
159
|
const lettedHash = letted.hash;
|
|
279
160
|
let parentNode = lca.parent;
|
|
280
161
|
const parentNodeDirectChild = lca;
|
|
281
|
-
// add 1 to every var's DeBruijn that accesses stuff outside the parent node
|
|
282
|
-
// not including the `parentNode` node
|
|
283
|
-
// since the new function introdcued substituting the letted term
|
|
284
|
-
// is added inside the `parentNode` node
|
|
285
|
-
incrementUnboundDbns(parentNodeDirectChild,
|
|
286
|
-
// `shouldNotModifyLetted` arg (given the hash returns `true` if it should NOT modify the term)
|
|
287
|
-
({ hash }) => equalIrHash(hash, lettedHash));
|
|
288
162
|
// now we replace
|
|
289
163
|
const lettedValue = letted.value; //.clone();
|
|
290
164
|
// no need to modify letted value dbns, since closed
|
|
291
165
|
// modifyValueToLetDbns( lettedValue, getDiffDbn( letted, parentNode ) );
|
|
292
|
-
const newNode = new IRApp(new IRFunc(
|
|
166
|
+
const newNode = new IRApp(new IRFunc([letted.name], parentNodeDirectChild), lettedValue, { __src__: letted.meta.__src__ });
|
|
293
167
|
// replace child with new node
|
|
294
168
|
if (parentNode) {
|
|
295
169
|
_modifyChildFromTo(parentNode, parentNodeDirectChild, newNode);
|
|
@@ -298,7 +172,7 @@ function handleLettedAsHoistedAndReturnRoot(letted, lca, sameLettedRefs, current
|
|
|
298
172
|
currentRoot = newNode;
|
|
299
173
|
}
|
|
300
174
|
for (const ref of sameLettedRefs) {
|
|
301
|
-
_modifyChildFromTo(ref.parent, ref, new IRVar(
|
|
175
|
+
_modifyChildFromTo(ref.parent, ref, new IRVar(ref.name));
|
|
302
176
|
}
|
|
303
177
|
return currentRoot;
|
|
304
178
|
}
|
|
@@ -9,12 +9,14 @@ import { _modifyChildFromTo } from "../_internal/_modifyChildFromTo.js";
|
|
|
9
9
|
export function handleRecursiveTerms(term) {
|
|
10
10
|
if (term instanceof IRRecursive) {
|
|
11
11
|
const bodyPtr = term.body;
|
|
12
|
-
|
|
12
|
+
const recBody = Symbol("recBody");
|
|
13
|
+
const self = term.name;
|
|
14
|
+
_modifyChildFromTo(term.parent, term, new IRApp(new IRHoisted(new IRFunc([recBody], new IRApp(new IRVar(recBody), new IRVar(recBody)))), new IRFunc([self], bodyPtr)));
|
|
13
15
|
handleRecursiveTerms(bodyPtr);
|
|
14
16
|
return;
|
|
15
17
|
}
|
|
16
18
|
if (term instanceof IRSelfCall) {
|
|
17
|
-
_modifyChildFromTo(term.parent, term, new IRApp(new IRVar(term.
|
|
19
|
+
_modifyChildFromTo(term.parent, term, new IRApp(new IRVar(term.name), new IRVar(term.name)));
|
|
18
20
|
return;
|
|
19
21
|
}
|
|
20
22
|
getChildren(term).forEach(handleRecursiveTerms);
|
|
@@ -22,7 +24,9 @@ export function handleRecursiveTerms(term) {
|
|
|
22
24
|
export function handleRootRecursiveTerm(term) {
|
|
23
25
|
if (term instanceof IRRecursive) {
|
|
24
26
|
const bodyPtr = term.body;
|
|
25
|
-
const
|
|
27
|
+
const recBody = Symbol("recBody");
|
|
28
|
+
const self = term.name;
|
|
29
|
+
const newRoot = new IRApp(new IRHoisted(new IRFunc([recBody], new IRApp(new IRVar(recBody), new IRVar(recBody)))), new IRFunc([self], bodyPtr));
|
|
26
30
|
handleRecursiveTerms(bodyPtr);
|
|
27
31
|
return newRoot;
|
|
28
32
|
}
|
|
@@ -38,10 +38,11 @@ export function hoistForcedNatives(term) {
|
|
|
38
38
|
const nodes = toHoist[tag];
|
|
39
39
|
if (nodes.length <= 0)
|
|
40
40
|
continue; // also single use (might be inside loop)
|
|
41
|
+
const varSym = Symbol(tagStr);
|
|
41
42
|
for (const node of nodes) {
|
|
42
|
-
_modifyChildFromTo(node.parent, node, new IRVar(
|
|
43
|
+
_modifyChildFromTo(node.parent, node, new IRVar(varSym));
|
|
43
44
|
}
|
|
44
|
-
term = new IRApp(new IRFunc(
|
|
45
|
+
term = new IRApp(new IRFunc([varSym], term), new IRNative(tag));
|
|
45
46
|
}
|
|
46
47
|
return term;
|
|
47
48
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare enum InlineSingleUseVarsFlags {
|
|
2
|
+
none = 0,
|
|
3
|
+
isRecursiveFunction = 1
|
|
4
|
+
}
|
|
5
|
+
interface InlineSingleUseCtxMeta {
|
|
6
|
+
readonly isRecursiveContext: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class InlineSingleUseCtx {
|
|
9
|
+
readonly params: symbol[];
|
|
10
|
+
readonly parent: InlineSingleUseCtx | undefined;
|
|
11
|
+
readonly localVarsUses: Record<symbol, number>;
|
|
12
|
+
readonly localVarsFlags: Record<symbol, InlineSingleUseVarsFlags>;
|
|
13
|
+
readonly meta: InlineSingleUseCtxMeta;
|
|
14
|
+
constructor(params: symbol[], parent: InlineSingleUseCtx | undefined, meta: InlineSingleUseCtxMeta);
|
|
15
|
+
static root(params?: symbol[]): InlineSingleUseCtx;
|
|
16
|
+
newChild(params: symbol[], meta?: InlineSingleUseCtxMeta): InlineSingleUseCtx;
|
|
17
|
+
private keys;
|
|
18
|
+
private getIncrement;
|
|
19
|
+
incrementVarUse(sym: symbol): void;
|
|
20
|
+
getSingleUseVars(): symbol[];
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export var InlineSingleUseVarsFlags;
|
|
2
|
+
(function (InlineSingleUseVarsFlags) {
|
|
3
|
+
InlineSingleUseVarsFlags[InlineSingleUseVarsFlags["none"] = 0] = "none";
|
|
4
|
+
InlineSingleUseVarsFlags[InlineSingleUseVarsFlags["isRecursiveFunction"] = 1] = "isRecursiveFunction";
|
|
5
|
+
})(InlineSingleUseVarsFlags || (InlineSingleUseVarsFlags = {}));
|
|
6
|
+
const defaultInlineMeta = Object.freeze({
|
|
7
|
+
isRecursiveContext: false
|
|
8
|
+
});
|
|
9
|
+
export class InlineSingleUseCtx {
|
|
10
|
+
params;
|
|
11
|
+
parent;
|
|
12
|
+
localVarsUses;
|
|
13
|
+
localVarsFlags;
|
|
14
|
+
meta;
|
|
15
|
+
constructor(params, parent, meta) {
|
|
16
|
+
this.params = params;
|
|
17
|
+
this.parent = parent;
|
|
18
|
+
params = params.slice();
|
|
19
|
+
this.localVarsUses = {};
|
|
20
|
+
this.localVarsFlags = {};
|
|
21
|
+
for (const p of params) {
|
|
22
|
+
this.localVarsUses[p] = 0;
|
|
23
|
+
this.localVarsFlags[p] = InlineSingleUseVarsFlags.none;
|
|
24
|
+
}
|
|
25
|
+
meta = {
|
|
26
|
+
...meta,
|
|
27
|
+
isRecursiveContext: parent?.meta.isRecursiveContext ?? defaultInlineMeta.isRecursiveContext
|
|
28
|
+
};
|
|
29
|
+
this.meta = meta;
|
|
30
|
+
}
|
|
31
|
+
static root(params = []) {
|
|
32
|
+
return new InlineSingleUseCtx(params, undefined, defaultInlineMeta);
|
|
33
|
+
}
|
|
34
|
+
newChild(params, meta = defaultInlineMeta) {
|
|
35
|
+
return new InlineSingleUseCtx(params, this, meta);
|
|
36
|
+
}
|
|
37
|
+
keys() {
|
|
38
|
+
return Object.getOwnPropertySymbols(this.localVarsUses);
|
|
39
|
+
}
|
|
40
|
+
getIncrement() {
|
|
41
|
+
return this.meta.isRecursiveContext ? 10 : 1;
|
|
42
|
+
}
|
|
43
|
+
incrementVarUse(sym) {
|
|
44
|
+
if (typeof this.localVarsUses[sym] !== "number") {
|
|
45
|
+
if (this.parent)
|
|
46
|
+
this.parent.incrementVarUse(sym);
|
|
47
|
+
else {
|
|
48
|
+
console.error(sym);
|
|
49
|
+
throw new Error("trying to increment use of variable not in context");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
this.localVarsUses[sym] += this.getIncrement();
|
|
54
|
+
}
|
|
55
|
+
getSingleUseVars() {
|
|
56
|
+
const keys = this.keys();
|
|
57
|
+
return keys.filter(k => this.localVarsUses[k] === 1);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts
ADDED
|
File without changes
|