@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
package/dist/IR/IRNodes/IRVar.js
CHANGED
|
@@ -1,49 +1,43 @@
|
|
|
1
1
|
import { BasePlutsError } from "../../utils/BasePlutsError.js";
|
|
2
2
|
import { concatUint8Arr } from "../utils/concatUint8Arr.js";
|
|
3
|
-
import { positiveIntAsBytes } from "../utils/positiveIntAsBytes.js";
|
|
4
3
|
import { isIRParentTerm } from "../utils/isIRParentTerm.js";
|
|
5
4
|
import { hashIrData, isIRHash } from "../IRHash.js";
|
|
6
5
|
import { IRNodeKind } from "../IRNodeKind.js";
|
|
6
|
+
import { hashVarSym } from "./utils/hashVarSym.js";
|
|
7
|
+
import { UPLCVar } from "@harmoniclabs/uplc";
|
|
7
8
|
export class IRVar {
|
|
9
|
+
_creationStack;
|
|
10
|
+
meta;
|
|
11
|
+
name;
|
|
12
|
+
constructor(name, _unsafeHash) {
|
|
13
|
+
if (!(typeof name === "symbol"
|
|
14
|
+
&& typeof name.description === "string"
|
|
15
|
+
&& name.description.length > 0))
|
|
16
|
+
throw new BasePlutsError("invalid name for IRVar");
|
|
17
|
+
this.name = name;
|
|
18
|
+
this._parent = undefined;
|
|
19
|
+
this.meta = {};
|
|
20
|
+
this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
|
|
21
|
+
this._creationStack = (new Error()).stack ?? "unknown";
|
|
22
|
+
}
|
|
23
|
+
toUPLC(ctx) {
|
|
24
|
+
return new UPLCVar(ctx.getVarAccessDbn(this.name));
|
|
25
|
+
}
|
|
8
26
|
_hash;
|
|
9
27
|
get hash() {
|
|
10
|
-
if (
|
|
11
|
-
this._hash
|
|
12
|
-
|
|
28
|
+
if (isIRHash(this._hash))
|
|
29
|
+
return this._hash;
|
|
30
|
+
this._hash = hashIrData(concatUint8Arr(IRVar.tag, hashVarSym(this.name)));
|
|
13
31
|
return this._hash;
|
|
14
32
|
}
|
|
15
|
-
|
|
16
|
-
* called inside the dbn setter
|
|
17
|
-
*/
|
|
33
|
+
isHashPresent() { return isIRHash(this._hash); }
|
|
18
34
|
markHashAsInvalid() {
|
|
19
35
|
this._hash = undefined;
|
|
20
36
|
this.parent?.markHashAsInvalid();
|
|
21
37
|
}
|
|
22
|
-
isHashPresent() { return true; }
|
|
23
|
-
_dbn;
|
|
24
|
-
/**
|
|
25
|
-
* the IR DeBruijn index is not necessarly the same of the UPLC
|
|
26
|
-
* ( more ofthen than not it won't be the same )
|
|
27
|
-
*
|
|
28
|
-
* this is because in the IR things like `IRLetted` and `IRHoisted`
|
|
29
|
-
* are skipping some DeBruijin levels that are instead present
|
|
30
|
-
* in the final UPLC
|
|
31
|
-
**/
|
|
32
|
-
get dbn() { return this._dbn; }
|
|
33
|
-
set dbn(newDbn) {
|
|
34
|
-
if (!(Number.isSafeInteger(newDbn) && newDbn >= 0)) {
|
|
35
|
-
// console.log( e.stack );
|
|
36
|
-
throw new BasePlutsError("invalid index for an `IRVar` instance; new DeBruijn was: " + newDbn);
|
|
37
|
-
}
|
|
38
|
-
if (newDbn === this._dbn)
|
|
39
|
-
return; // everything ok
|
|
40
|
-
this.markHashAsInvalid();
|
|
41
|
-
this._dbn = newDbn;
|
|
42
|
-
}
|
|
43
38
|
static get kind() { return IRNodeKind.Var; }
|
|
44
39
|
get kind() { return IRVar.kind; }
|
|
45
40
|
static get tag() { return new Uint8Array([IRVar.kind]); }
|
|
46
|
-
meta;
|
|
47
41
|
_parent;
|
|
48
42
|
get parent() { return this._parent; }
|
|
49
43
|
set parent(newParent) {
|
|
@@ -57,37 +51,15 @@ export class IRVar {
|
|
|
57
51
|
// change parent
|
|
58
52
|
this._parent = newParent;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
Object.defineProperty(this, "meta", {
|
|
62
|
-
value: {},
|
|
63
|
-
writable: false,
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: false
|
|
66
|
-
});
|
|
67
|
-
this._hash = undefined;
|
|
68
|
-
DeBruijn = typeof DeBruijn === "number" ? DeBruijn : Number(DeBruijn);
|
|
69
|
-
this._dbn = DeBruijn;
|
|
70
|
-
// call setter to check for validity
|
|
71
|
-
this.dbn = DeBruijn;
|
|
72
|
-
this._parent = undefined;
|
|
73
|
-
}
|
|
54
|
+
children() { return []; }
|
|
74
55
|
clone() {
|
|
75
|
-
return new IRVar(this.
|
|
56
|
+
return new IRVar(this.name, this._hash);
|
|
76
57
|
}
|
|
77
58
|
toJSON() { return this.toJson(); }
|
|
78
59
|
toJson() {
|
|
79
60
|
return {
|
|
80
61
|
type: "IRVar",
|
|
81
|
-
|
|
62
|
+
name: this.name
|
|
82
63
|
};
|
|
83
64
|
}
|
|
84
65
|
}
|
|
85
|
-
const _bdnVarHashCache = new Map();
|
|
86
|
-
function getVarHashAtDbn(dbn) {
|
|
87
|
-
const cached = _bdnVarHashCache.get(dbn)?.deref();
|
|
88
|
-
if (isIRHash(cached))
|
|
89
|
-
return cached;
|
|
90
|
-
const hash = hashIrData(concatUint8Arr(IRVar.tag, positiveIntAsBytes(dbn)));
|
|
91
|
-
_bdnVarHashCache.set(dbn, new WeakRef(hash));
|
|
92
|
-
return hash;
|
|
93
|
-
}
|
|
@@ -2,4 +2,4 @@ import { IRTerm } from "../../IRTerm.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* returns true if the term depends on *ANY* of the deBrujin indices specified
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function dependsByVars(term: IRTerm, depsVars: readonly symbol[]): boolean;
|
|
@@ -4,20 +4,14 @@ import { IRVar } from "../IRVar.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* returns true if the term depends on *ANY* of the deBrujin indices specified
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
8
|
-
if (
|
|
7
|
+
export function dependsByVars(term, depsVars) {
|
|
8
|
+
if (depsVars.length === 0)
|
|
9
9
|
return false;
|
|
10
10
|
let doesDepend = false;
|
|
11
11
|
iterTree(term, (node, diff) => {
|
|
12
|
-
if (node instanceof IRVar
|
|
13
|
-
node instanceof IRSelfCall) {
|
|
14
|
-
doesDepend = doesDepend ||
|
|
15
|
-
const realDbn = dbn + diff;
|
|
16
|
-
// realDbn === 0 implies no variables are in scope
|
|
17
|
-
// so if node.dbn === 0 and realDbn === 1 then the
|
|
18
|
-
// variable is pointing to that definition
|
|
19
|
-
return node.dbn === realDbn;
|
|
20
|
-
});
|
|
12
|
+
if (node instanceof IRVar
|
|
13
|
+
|| node instanceof IRSelfCall) {
|
|
14
|
+
doesDepend = doesDepend || depsVars.some(sym => node.name === sym);
|
|
21
15
|
}
|
|
22
16
|
},
|
|
23
17
|
// shouldSkipNode
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hashVarSym(s: symbol): Uint8Array;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// HASH GENERATOR
|
|
2
|
+
import { fromHex } from "@harmoniclabs/uint8array-utils";
|
|
3
|
+
const MAX_SAFE_INTEGER = Number(globalThis.Number?.MAX_SAFE_INTEGER ?? ((2 ** 53) - 1));
|
|
4
|
+
const MIN_SAFE_INTEGER = Number(globalThis.Number?.MIN_SAFE_INTEGER ?? -MAX_SAFE_INTEGER);
|
|
5
|
+
/// @ts-ignore Type 'symbol' does not satisfy the constraint 'object'.
|
|
6
|
+
const _sym_to_hash = new WeakMap();
|
|
7
|
+
// we cannot store the symbol itself as it would prevent garbage collection
|
|
8
|
+
/// @ts-ignore Type 'symbol' does not satisfy the constraint 'object'.
|
|
9
|
+
const _hash_to_sym = new Map();
|
|
10
|
+
let _next_hash = MIN_SAFE_INTEGER;
|
|
11
|
+
const unusedHashes = [];
|
|
12
|
+
function _collectUnusedHashes() {
|
|
13
|
+
for (const [h, s] of _hash_to_sym) {
|
|
14
|
+
const newSymbol = s.deref();
|
|
15
|
+
if (!newSymbol
|
|
16
|
+
|| !_sym_to_hash.has(newSymbol)) {
|
|
17
|
+
_hash_to_sym.delete(h);
|
|
18
|
+
unusedHashes.push(h);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function hashVarSym(s) {
|
|
23
|
+
const limitReached = _next_hash >= MAX_SAFE_INTEGER;
|
|
24
|
+
if (_next_hash % 0xffff === 0
|
|
25
|
+
|| limitReached)
|
|
26
|
+
_collectUnusedHashes();
|
|
27
|
+
if (limitReached
|
|
28
|
+
&& unusedHashes.length <= 0)
|
|
29
|
+
throw new Error("ran out of IR hashes");
|
|
30
|
+
const result_hash = unusedHashes.shift() ?? _next_hash++;
|
|
31
|
+
_sym_to_hash.set(s, result_hash);
|
|
32
|
+
/// @ts-ignore Argument of type 'WeakRef<object>' is not assignable to parameter of type 'WeakRef<symbol>'
|
|
33
|
+
_hash_to_sym.set(result_hash, new WeakRef(s));
|
|
34
|
+
return fromHex((BigInt(result_hash) + BigInt(MAX_SAFE_INTEGER))
|
|
35
|
+
.toString(16)
|
|
36
|
+
.padStart(16, "0"));
|
|
37
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { MutArrayLike } from "../../utils/MutArrayLike.js";
|
|
2
|
+
export declare function makeArrayLikeProxy<T>(arr: ArrayLike<T>, isValidElem: (elem: T) => boolean, initModifyElem: (elem: T) => T, modifyElem: (elem: T, oldElem: T) => T): MutArrayLike<T>;
|
package/dist/IR/IRTerm.d.ts
CHANGED
|
@@ -12,4 +12,11 @@ import { IRConstr } from "./IRNodes/IRConstr.js";
|
|
|
12
12
|
import { IRCase } from "./IRNodes/IRCase.js";
|
|
13
13
|
import { IRRecursive } from "./IRNodes/IRRecursive.js";
|
|
14
14
|
import { IRSelfCall } from "./IRNodes/IRSelfCall.js";
|
|
15
|
+
import { IHash } from "./interfaces/index.js";
|
|
16
|
+
import { UPLCTerm } from "@harmoniclabs/uplc";
|
|
17
|
+
import { ToUplcCtx } from "./toUPLC/ctx/ToUplcCtx.js";
|
|
15
18
|
export type IRTerm = IRVar | IRFunc | IRApp | IRConst | IRNative | IRLetted | IRHoisted | IRError | IRForced | IRDelayed | IRConstr | IRCase | IRRecursive | IRSelfCall;
|
|
19
|
+
export interface IIRTerm extends IHash {
|
|
20
|
+
children(): IRTerm[];
|
|
21
|
+
toUPLC(ctx: ToUplcCtx): UPLCTerm;
|
|
22
|
+
}
|
|
@@ -33,6 +33,10 @@ export interface CompilerOptions {
|
|
|
33
33
|
* path to the output directory
|
|
34
34
|
*/
|
|
35
35
|
readonly outDir: string;
|
|
36
|
+
/**
|
|
37
|
+
* if `true` silences all compiler output
|
|
38
|
+
*/
|
|
39
|
+
readonly silent: boolean;
|
|
36
40
|
/**
|
|
37
41
|
* uplc version (encoded in the script)
|
|
38
42
|
*/
|
|
@@ -76,5 +80,6 @@ export declare const extremeOptions: CompilerOptions;
|
|
|
76
80
|
export declare const productionOptions: CompilerOptions;
|
|
77
81
|
export declare const debugOptions: CompilerOptions;
|
|
78
82
|
export declare const defaultOptions: CompilerOptions;
|
|
83
|
+
export declare const testOptions: CompilerOptions;
|
|
79
84
|
export declare const defulatCompilerOptions: CompilerOptions;
|
|
80
85
|
export declare function completeCompilerOptions(options: Partial<CompilerOptions>, complete?: CompilerOptions): CompilerOptions;
|
|
@@ -36,6 +36,7 @@ export const extremeOptions = Object.freeze({
|
|
|
36
36
|
entry: "./src/index.pebble",
|
|
37
37
|
root: ".",
|
|
38
38
|
outDir: "./out",
|
|
39
|
+
silent: false,
|
|
39
40
|
targetUplcVersion: defaultUplcVersion,
|
|
40
41
|
removeTraces: true,
|
|
41
42
|
delayHoists: true,
|
|
@@ -46,6 +47,7 @@ export const productionOptions = Object.freeze({
|
|
|
46
47
|
entry: "./src/index.pebble",
|
|
47
48
|
root: ".",
|
|
48
49
|
outDir: "./out",
|
|
50
|
+
silent: false,
|
|
49
51
|
targetUplcVersion: defaultUplcVersion,
|
|
50
52
|
removeTraces: true,
|
|
51
53
|
delayHoists: true,
|
|
@@ -56,13 +58,20 @@ export const debugOptions = Object.freeze({
|
|
|
56
58
|
entry: "./src/index.pebble",
|
|
57
59
|
root: ".",
|
|
58
60
|
outDir: "./out",
|
|
61
|
+
silent: false,
|
|
59
62
|
targetUplcVersion: defaultUplcVersion,
|
|
60
63
|
removeTraces: false,
|
|
61
64
|
delayHoists: false,
|
|
62
65
|
uplcOptimizations: debugUplcOptimizations,
|
|
63
66
|
addMarker: false
|
|
64
67
|
});
|
|
65
|
-
export const defaultOptions =
|
|
68
|
+
export const defaultOptions = Object.freeze({
|
|
69
|
+
...productionOptions,
|
|
70
|
+
});
|
|
71
|
+
export const testOptions = Object.freeze({
|
|
72
|
+
...debugOptions,
|
|
73
|
+
silent: true
|
|
74
|
+
});
|
|
66
75
|
export const defulatCompilerOptions = defaultOptions;
|
|
67
76
|
export function completeCompilerOptions(options, complete = defaultOptions) {
|
|
68
77
|
let targetUplcVersion = options.targetUplcVersion instanceof UPLCVersion ? complete.targetUplcVersion : defaultUplcVersion;
|
|
@@ -138,4 +138,7 @@ export function _modifyChildFromTo(parent, currentChild, newChild) {
|
|
|
138
138
|
parent.value = newChild;
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
+
const tsEnsureExhaustiveCheck = parent;
|
|
142
|
+
throw new Error("unknown parent type in '_modifyChildFromTo': " +
|
|
143
|
+
parent.constructor?.name);
|
|
141
144
|
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { IRCase, IRConstr } from "../../IRNodes/index.js";
|
|
2
|
-
import { IRApp } from "../../IRNodes/IRApp.js";
|
|
3
|
-
import { IRDelayed } from "../../IRNodes/IRDelayed.js";
|
|
4
|
-
import { IRForced } from "../../IRNodes/IRForced.js";
|
|
5
|
-
import { IRFunc } from "../../IRNodes/IRFunc.js";
|
|
6
1
|
import { IRHoisted } from "../../IRNodes/IRHoisted.js";
|
|
7
|
-
import { IRLetted } from "../../IRNodes/IRLetted.js";
|
|
8
|
-
import { IRRecursive } from "../../IRNodes/IRRecursive.js";
|
|
9
2
|
export function findAll(term, predicate) {
|
|
10
3
|
const stack = [term];
|
|
11
4
|
const result = [];
|
|
@@ -13,37 +6,7 @@ export function findAll(term, predicate) {
|
|
|
13
6
|
const t = stack.pop();
|
|
14
7
|
if (predicate(t))
|
|
15
8
|
result.push(t);
|
|
16
|
-
|
|
17
|
-
stack.push(t.fn, t.arg);
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (t instanceof IRDelayed) {
|
|
21
|
-
stack.push(t.delayed);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (t instanceof IRForced) {
|
|
25
|
-
stack.push(t.forced);
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (t instanceof IRFunc) {
|
|
29
|
-
stack.push(t.body);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
if (t instanceof IRRecursive) {
|
|
33
|
-
stack.push(t.body);
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (t instanceof IRHoisted) {
|
|
37
|
-
stack.push(t.hoisted);
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (t instanceof IRLetted) {
|
|
41
|
-
// same stuff as the hoisted terms
|
|
42
|
-
// the only difference is that depth is then incremented
|
|
43
|
-
// once the letted term reaches its final position
|
|
44
|
-
stack.push(t.value);
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
9
|
+
stack.push(...t.children());
|
|
47
10
|
}
|
|
48
11
|
return result;
|
|
49
12
|
}
|
|
@@ -54,46 +17,12 @@ export function findAllNoHoisted(term, predicate) {
|
|
|
54
17
|
const t = stack.pop();
|
|
55
18
|
if (predicate(t))
|
|
56
19
|
result.push(t);
|
|
57
|
-
if (t instanceof IRApp) {
|
|
58
|
-
stack.push(t.fn, t.arg);
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (t instanceof IRCase) {
|
|
62
|
-
stack.push(t.constrTerm, ...t.continuations);
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (t instanceof IRConstr) {
|
|
66
|
-
stack.push(...t.fields);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (t instanceof IRDelayed) {
|
|
70
|
-
stack.push(t.delayed);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (t instanceof IRForced) {
|
|
74
|
-
stack.push(t.forced);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (t instanceof IRFunc) {
|
|
78
|
-
stack.push(t.body);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
if (t instanceof IRRecursive) {
|
|
82
|
-
stack.push(t.body);
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
20
|
if (t instanceof IRHoisted) {
|
|
86
21
|
// this is `findAllNoHoisted` remember?
|
|
87
22
|
// stack.push( t.hoisted );
|
|
88
23
|
continue;
|
|
89
24
|
}
|
|
90
|
-
|
|
91
|
-
// same stuff as the hoisted terms
|
|
92
|
-
// the only difference is that depth is then incremented
|
|
93
|
-
// once the letted term reaches its final position
|
|
94
|
-
stack.push(t.value);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
25
|
+
stack.push(...t.children());
|
|
97
26
|
}
|
|
98
27
|
return result;
|
|
99
28
|
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { equalIrHash } from "../../IRHash.js";
|
|
2
|
-
import {
|
|
3
|
-
import { IRApp } from "../../IRNodes/IRApp.js";
|
|
4
|
-
import { IRDelayed } from "../../IRNodes/IRDelayed.js";
|
|
5
|
-
import { IRForced } from "../../IRNodes/IRForced.js";
|
|
2
|
+
import { IRHoisted } from "../../IRNodes/index.js";
|
|
6
3
|
import { IRFunc } from "../../IRNodes/IRFunc.js";
|
|
7
|
-
import { IRLetted } from "../../IRNodes/IRLetted.js";
|
|
8
4
|
import { IRRecursive } from "../../IRNodes/IRRecursive.js";
|
|
9
|
-
import { mapArrayLike } from "../../IRNodes/utils/mapArrayLike.js";
|
|
10
5
|
export function getDebruijnInTerm(root, termToFind) {
|
|
11
6
|
const termTofindHash = termToFind.hash;
|
|
12
7
|
const stack = [{ term: root, dbn: 0 }];
|
|
@@ -14,38 +9,16 @@ export function getDebruijnInTerm(root, termToFind) {
|
|
|
14
9
|
const { term, dbn } = stack.pop();
|
|
15
10
|
if (term === termToFind || equalIrHash(term.hash, termTofindHash))
|
|
16
11
|
return dbn;
|
|
17
|
-
if (term instanceof
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
if (term instanceof IRCase) {
|
|
22
|
-
stack.push({ term: term.constrTerm, dbn }, ...mapArrayLike(term.continuations, (continuation) => ({ term: continuation, dbn })));
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (term instanceof IRConstr) {
|
|
26
|
-
stack.push(...mapArrayLike(term.fields, (field) => ({ term: field, dbn })));
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (term instanceof IRDelayed) {
|
|
30
|
-
stack.push({ term: term.delayed, dbn });
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (term instanceof IRForced) {
|
|
34
|
-
stack.push({ term: term.forced, dbn });
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (term instanceof IRFunc) {
|
|
12
|
+
if (term instanceof IRFunc
|
|
13
|
+
|| term instanceof IRRecursive) {
|
|
14
|
+
// new variable in scope
|
|
38
15
|
stack.push({ term: term.body, dbn: dbn + term.arity });
|
|
39
16
|
continue;
|
|
40
17
|
}
|
|
41
|
-
if (term instanceof
|
|
42
|
-
stack.push({ term: term.body, dbn: dbn + term.arity });
|
|
18
|
+
if (term instanceof IRHoisted) {
|
|
43
19
|
continue;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
stack.push({ term: term.value, dbn });
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
20
|
+
} // skip hoisted since closed
|
|
21
|
+
stack.push(...term.children().map(t => ({ term: t, dbn })));
|
|
49
22
|
}
|
|
50
23
|
return -1;
|
|
51
24
|
}
|
|
@@ -7,6 +7,7 @@ import { IRFunc } from "../../IRNodes/IRFunc.js";
|
|
|
7
7
|
import { IRHoisted } from "../../IRNodes/IRHoisted.js";
|
|
8
8
|
import { IRLetted } from "../../IRNodes/IRLetted.js";
|
|
9
9
|
import { IRRecursive } from "../../IRNodes/IRRecursive.js";
|
|
10
|
+
import { sanifyTree } from "../subRoutines/sanifyTree.js";
|
|
10
11
|
export function iterTree(_term, fn,
|
|
11
12
|
// necessary for letted hash calculation (exclude hoisted)
|
|
12
13
|
shouldSkipNode, shouldExit) {
|
|
@@ -32,31 +33,14 @@ shouldSkipNode, shouldExit) {
|
|
|
32
33
|
continue;
|
|
33
34
|
}
|
|
34
35
|
if (t instanceof IRApp) {
|
|
35
|
-
// sanifyTree as we go
|
|
36
|
-
if (t.fn.parent !== t)
|
|
37
|
-
t.fn = t.fn.clone();
|
|
38
|
-
if (t.arg.parent !== t)
|
|
39
|
-
t.arg = t.arg.clone();
|
|
40
36
|
stack.push({ term: t.fn, dbn }, { term: t.arg, dbn, shouldPopIfParentIsModified: true });
|
|
41
37
|
continue;
|
|
42
38
|
}
|
|
43
39
|
if (t instanceof IRCase) {
|
|
44
|
-
// sanifyTree as we go
|
|
45
|
-
if (t.constrTerm.parent !== t)
|
|
46
|
-
t.constrTerm = t.constrTerm.clone();
|
|
47
|
-
for (let i = 0; i < t.continuations.length; i++) {
|
|
48
|
-
if (t.continuations[i].parent !== t)
|
|
49
|
-
t.continuations[i] = t.continuations[i].clone();
|
|
50
|
-
}
|
|
51
40
|
stack.push({ term: t.constrTerm, dbn }, ...Array.from(t.continuations).map(cont => ({ term: cont, dbn, shouldPopIfParentIsModified: true })));
|
|
52
41
|
continue;
|
|
53
42
|
}
|
|
54
43
|
if (t instanceof IRConstr) {
|
|
55
|
-
// sanifyTree as we go
|
|
56
|
-
for (let i = 0; i < t.fields.length; i++) {
|
|
57
|
-
if (t.fields[i].parent !== t)
|
|
58
|
-
t.fields[i] = t.fields[i].clone();
|
|
59
|
-
}
|
|
60
44
|
stack.push(...Array.from(t.fields).map((f, i) => ({ term: f, dbn, shouldPopIfParentIsModified: i !== 0 })));
|
|
61
45
|
continue;
|
|
62
46
|
}
|
|
@@ -89,5 +73,7 @@ shouldSkipNode, shouldExit) {
|
|
|
89
73
|
stack.push({ term: t.value, dbn });
|
|
90
74
|
continue;
|
|
91
75
|
}
|
|
76
|
+
stack.push(...t.children().map(c => ({ term: c, dbn })));
|
|
92
77
|
}
|
|
78
|
+
sanifyTree(_term);
|
|
93
79
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type UPLCTerm } from "@harmoniclabs/uplc";
|
|
2
2
|
import type { IRTerm } from "../IRTerm.js";
|
|
3
3
|
import { CompilerOptions } from "./CompilerOptions.js";
|
|
4
4
|
export declare function compileIRToUPLC(term: IRTerm, paritalOptions?: Partial<CompilerOptions>): UPLCTerm;
|