@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,7 +1,8 @@
|
|
|
1
|
+
import { isClosedTerm, prettyUPLC } from "@harmoniclabs/uplc";
|
|
1
2
|
import { IRLetted } from "../IRNodes/IRLetted.js";
|
|
2
3
|
import { IRHoisted } from "../IRNodes/IRHoisted.js";
|
|
3
4
|
import { IRConst } from "../IRNodes/IRConst.js";
|
|
4
|
-
import {
|
|
5
|
+
import { _makeAllNegativeNativesHoisted } from "./_internal/_makeAllNegativeNativesHoisted.js";
|
|
5
6
|
import { includesNode } from "./_internal/includesNode.js";
|
|
6
7
|
import { handleLettedAndReturnRoot } from "./subRoutines/handleLetted/index.js";
|
|
7
8
|
import { handleHoistedAndReturnRoot } from "./subRoutines/handleHoistedAndReturnRoot/index.js";
|
|
@@ -11,20 +12,26 @@ import { hoistForcedNatives } from "./subRoutines/hoistForcedNatives.js";
|
|
|
11
12
|
import { handleRootRecursiveTerm } from "./subRoutines/handleRecursiveTerms.js";
|
|
12
13
|
import { completeCompilerOptions, defaultOptions } from "./CompilerOptions.js";
|
|
13
14
|
import { replaceHoistedWithLetted } from "./subRoutines/replaceHoistedWithLetted.js";
|
|
14
|
-
import { IRCase, IRConstr, IRNative } from "../IRNodes/index.js";
|
|
15
|
+
import { IRCase, IRConstr, IRFunc, IRNative } from "../IRNodes/index.js";
|
|
15
16
|
import { replaceForcedNativesWithHoisted } from "./subRoutines/replaceForcedNativesWithHoisted.js";
|
|
16
|
-
import { performUplcOptimizationsAndReturnRoot } from "./subRoutines/performUplcOptimizationsAndReturnRoot/
|
|
17
|
+
import { performUplcOptimizationsAndReturnRoot } from "./subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js";
|
|
18
|
+
import { rewriteNativesAppliedToConstantsAndReturnRoot } from "./subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js";
|
|
19
|
+
import { _debug_assertClosedIR } from "../utils/index.js";
|
|
20
|
+
import { ToUplcCtx } from "./ctx/ToUplcCtx.js";
|
|
21
|
+
import { removeUnusedVarsAndReturnRoot } from "./subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js";
|
|
22
|
+
import { IRRecursive } from "../IRNodes/IRRecursive.js";
|
|
17
23
|
export function compileIRToUPLC(term, paritalOptions = defaultOptions) {
|
|
18
24
|
// most of the time we are just compiling small
|
|
19
25
|
// pre-execuded terms (hence constants)
|
|
20
26
|
if (term instanceof IRConst)
|
|
21
|
-
return
|
|
27
|
+
return term.toUPLC();
|
|
22
28
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
29
|
// ------------------------------------------------------------------------- //
|
|
24
30
|
// --------------------------------- init --------------------------------- //
|
|
25
31
|
// ------------------------------------------------------------------------- //
|
|
26
32
|
///////////////////////////////////////////////////////////////////////////////
|
|
27
33
|
const options = completeCompilerOptions(paritalOptions);
|
|
34
|
+
const debugAsserts = options.debugAsserts ?? false;
|
|
28
35
|
// unwrap top level letted and hoisted;
|
|
29
36
|
while (term instanceof IRLetted || term instanceof IRHoisted) {
|
|
30
37
|
// replace with value
|
|
@@ -32,14 +39,20 @@ export function compileIRToUPLC(term, paritalOptions = defaultOptions) {
|
|
|
32
39
|
// forget the parent; this is the new root
|
|
33
40
|
term.parent = undefined;
|
|
34
41
|
}
|
|
35
|
-
|
|
42
|
+
debugAsserts && _debug_assertions(term);
|
|
43
|
+
// term = preEvaluateDefinedTermsAndReturnRoot( term );
|
|
44
|
+
term = rewriteNativesAppliedToConstantsAndReturnRoot(term);
|
|
45
|
+
debugAsserts && _debug_assertions(term);
|
|
46
|
+
// removing unused variables BEFORE going into the rest of the compilation
|
|
47
|
+
// helps letted terms to find a better spot (and possibly be inlined instead of hoisted)
|
|
48
|
+
term = removeUnusedVarsAndReturnRoot(term);
|
|
49
|
+
debugAsserts && _debug_assertions(term);
|
|
50
|
+
_makeAllNegativeNativesHoisted(term);
|
|
36
51
|
///////////////////////////////////////////////////////////////////////////////
|
|
37
52
|
// ------------------------------------------------------------------------- //
|
|
38
53
|
// ----------------------------- optimizations ----------------------------- //
|
|
39
54
|
// ------------------------------------------------------------------------- //
|
|
40
55
|
///////////////////////////////////////////////////////////////////////////////
|
|
41
|
-
// --------------------------- optimize natives --------------------------- //
|
|
42
|
-
// at constant -> head and tails
|
|
43
56
|
// --------------------- optimize recursive functions --------------------- //
|
|
44
57
|
// avoid passing whole structs
|
|
45
58
|
// take letted terms outside
|
|
@@ -52,6 +65,7 @@ export function compileIRToUPLC(term, paritalOptions = defaultOptions) {
|
|
|
52
65
|
// ------------------------------------------------------------------------- //
|
|
53
66
|
///////////////////////////////////////////////////////////////////////////////
|
|
54
67
|
term = replaceNativesAndReturnRoot(term);
|
|
68
|
+
debugAsserts && _debug_assertions(term);
|
|
55
69
|
// unwrap top level letted and hoisted;
|
|
56
70
|
// some natives may be converted to hoisted;
|
|
57
71
|
// this is really just an edge case
|
|
@@ -64,23 +78,32 @@ export function compileIRToUPLC(term, paritalOptions = defaultOptions) {
|
|
|
64
78
|
if (term instanceof IRNative ||
|
|
65
79
|
term instanceof IRConst // while we are at it
|
|
66
80
|
)
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
return term.toUPLC();
|
|
82
|
+
replaceForcedNativesWithHoisted(term);
|
|
83
|
+
debugAsserts && _debug_assertions(term);
|
|
70
84
|
if (options.delayHoists)
|
|
71
85
|
replaceHoistedWithLetted(term);
|
|
72
86
|
else
|
|
73
87
|
replaceClosedLettedWithHoisted(term);
|
|
88
|
+
debugAsserts && _debug_assertions(term);
|
|
89
|
+
if (debugAsserts
|
|
90
|
+
&& options.delayHoists
|
|
91
|
+
&& includesNode(term, node => node instanceof IRHoisted)) {
|
|
92
|
+
throw new Error("debug assertion failed: hoisted nodes found while delayHoists is true");
|
|
93
|
+
}
|
|
74
94
|
// handle letted before hoisted because the tree is smaller
|
|
75
95
|
// and we also have less letted dependecies to handle
|
|
76
96
|
term = handleLettedAndReturnRoot(term);
|
|
97
|
+
debugAsserts && _debug_assertions(term);
|
|
77
98
|
term = handleHoistedAndReturnRoot(term);
|
|
99
|
+
debugAsserts && _debug_assertions(term);
|
|
78
100
|
// replaced hoisted terms might include new letted terms
|
|
79
|
-
while (includesNode(term, node => node instanceof IRLetted
|
|
80
|
-
node instanceof IRHoisted)) {
|
|
101
|
+
while (includesNode(term, node => node instanceof IRLetted
|
|
102
|
+
|| node instanceof IRHoisted)) {
|
|
81
103
|
term = handleLettedAndReturnRoot(term);
|
|
82
104
|
term = handleHoistedAndReturnRoot(term);
|
|
83
105
|
}
|
|
106
|
+
debugAsserts && _debug_assertions(term);
|
|
84
107
|
///////////////////////////////////////////////////////////////////////////////
|
|
85
108
|
// ------------------------------------------------------------------------- //
|
|
86
109
|
// --------------------------- translate to UPLC --------------------------- //
|
|
@@ -94,12 +117,33 @@ export function compileIRToUPLC(term, paritalOptions = defaultOptions) {
|
|
|
94
117
|
// if( options.delayHoists ) replaceHoistedWithLetted( term );
|
|
95
118
|
// handle new hoisted terms
|
|
96
119
|
term = handleHoistedAndReturnRoot(term);
|
|
120
|
+
debugAsserts && _debug_assertions(term);
|
|
97
121
|
// strictly necessary to check the options
|
|
98
122
|
// otherwise forced natives where already hoisted
|
|
99
123
|
// will be re-hosited; causeing uselsess evaluations
|
|
100
124
|
if (!options.delayHoists)
|
|
101
125
|
term = hoistForcedNatives(term);
|
|
126
|
+
debugAsserts && _debug_assertions(term);
|
|
102
127
|
// at this point we expect the IR to be translable 1:1 to UPLC
|
|
128
|
+
// The loop is needed because after inlining some params,
|
|
129
|
+
// new params in outer (or sibling) functions can become
|
|
130
|
+
// single‑use; a single bottom‑up pass doesn’t
|
|
131
|
+
// “see” those future states.
|
|
132
|
+
//
|
|
133
|
+
// ALWAYS AT LEAST 1 ITERATION
|
|
134
|
+
// const maxInlineIterations = Math.max( 3, 1 );
|
|
135
|
+
// for(
|
|
136
|
+
// let somethingWasInlined = true,
|
|
137
|
+
// inlineIterations = 0;
|
|
138
|
+
// somethingWasInlined
|
|
139
|
+
// && inlineIterations < maxInlineIterations;
|
|
140
|
+
// inlineIterations++
|
|
141
|
+
// ) {
|
|
142
|
+
// const inlineResult = inlineSingleUseAndReturnRoot( term );
|
|
143
|
+
// term = inlineResult.term;
|
|
144
|
+
// somethingWasInlined = inlineResult.somethingWasInlined;
|
|
145
|
+
// }
|
|
146
|
+
term = removeUnusedVarsAndReturnRoot(term);
|
|
103
147
|
term = performUplcOptimizationsAndReturnRoot(term, options);
|
|
104
148
|
if (options.addMarker &&
|
|
105
149
|
options.targetUplcVersion.major >= 1 &&
|
|
@@ -111,8 +155,41 @@ export function compileIRToUPLC(term, paritalOptions = defaultOptions) {
|
|
|
111
155
|
IRConst.int(42)
|
|
112
156
|
]);
|
|
113
157
|
}
|
|
114
|
-
|
|
115
|
-
|
|
158
|
+
// let irJson = prettyIR( term );
|
|
159
|
+
// console.log(
|
|
160
|
+
// "final IR before UPLC translation:\n",
|
|
161
|
+
// irJson.text,
|
|
162
|
+
// JSON.stringify( onlyHoistedAndLetted( irJson ) )
|
|
163
|
+
// );
|
|
164
|
+
debugAsserts && _debug_assertions(term);
|
|
165
|
+
// const srcmap = {};
|
|
166
|
+
const uplc = term.toUPLC(ToUplcCtx.root());
|
|
167
|
+
if (!isClosedTerm(uplc)) {
|
|
168
|
+
console.error(prettyUPLC(uplc));
|
|
169
|
+
throw new Error("compileIRToUPLC: final UPLC term is not closed:\n" +
|
|
170
|
+
"This is a compiler internal error; please open an issue on github so we can fix this.");
|
|
171
|
+
}
|
|
116
172
|
// console.log( "srcmap", srcmap );
|
|
117
173
|
return uplc;
|
|
118
174
|
}
|
|
175
|
+
function _debug_assertions(term) {
|
|
176
|
+
_debug_assertClosedIR(term);
|
|
177
|
+
_debug_assertNoDoubleVars(term);
|
|
178
|
+
}
|
|
179
|
+
function _debug_assertNoDoubleVars(term) {
|
|
180
|
+
const seen = new Set();
|
|
181
|
+
const stack = [term];
|
|
182
|
+
let current = term;
|
|
183
|
+
while (current = stack.pop()) {
|
|
184
|
+
if (current instanceof IRFunc
|
|
185
|
+
|| current instanceof IRRecursive) {
|
|
186
|
+
for (const p of current.params) {
|
|
187
|
+
if (seen.has(p)) {
|
|
188
|
+
throw new Error("debug assertion failed: double variable detected");
|
|
189
|
+
}
|
|
190
|
+
seen.add(p);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
stack.push(...current.children());
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class ToUplcCtx {
|
|
2
|
+
readonly parent: ToUplcCtx | undefined;
|
|
3
|
+
readonly ctxMap: Map<symbol, ToUplcCtx>;
|
|
4
|
+
private readonly _variables;
|
|
5
|
+
private get _parentDbn();
|
|
6
|
+
get dbn(): number;
|
|
7
|
+
private _frozen;
|
|
8
|
+
constructor(parent: ToUplcCtx | undefined, variables: symbol[]);
|
|
9
|
+
static root(): ToUplcCtx;
|
|
10
|
+
newChild(variables: symbol[]): ToUplcCtx;
|
|
11
|
+
getVarDeclDbn(sym: symbol): number;
|
|
12
|
+
getVarAccessDbn(sym: symbol): number;
|
|
13
|
+
toJson(): any;
|
|
14
|
+
allVars(): symbol[];
|
|
15
|
+
expectedDbn(sym: symbol): number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export class ToUplcCtx {
|
|
2
|
+
parent;
|
|
3
|
+
ctxMap;
|
|
4
|
+
_variables;
|
|
5
|
+
get _parentDbn() {
|
|
6
|
+
return this.parent?.dbn ?? 0;
|
|
7
|
+
}
|
|
8
|
+
get dbn() {
|
|
9
|
+
return this._variables.length + this._parentDbn;
|
|
10
|
+
}
|
|
11
|
+
_frozen;
|
|
12
|
+
constructor(parent, variables) {
|
|
13
|
+
this.parent = parent;
|
|
14
|
+
this.ctxMap = this.parent?.ctxMap ?? new Map();
|
|
15
|
+
this._variables = variables;
|
|
16
|
+
for (const v of variables)
|
|
17
|
+
this.ctxMap.set(v, this);
|
|
18
|
+
}
|
|
19
|
+
static root() {
|
|
20
|
+
return new ToUplcCtx(undefined, []);
|
|
21
|
+
}
|
|
22
|
+
newChild(variables) {
|
|
23
|
+
return new ToUplcCtx(this, variables);
|
|
24
|
+
}
|
|
25
|
+
getVarDeclDbn(sym) {
|
|
26
|
+
const ctx = this.ctxMap.get(sym);
|
|
27
|
+
const idx = ctx?._variables.indexOf(sym) ?? -1;
|
|
28
|
+
if (idx <= -1) {
|
|
29
|
+
console.error(sym, ctx?.allVars());
|
|
30
|
+
throw new Error("Variable not found in its defining context");
|
|
31
|
+
}
|
|
32
|
+
return ctx._parentDbn + idx + 1;
|
|
33
|
+
}
|
|
34
|
+
getVarAccessDbn(sym) {
|
|
35
|
+
const declDbn = this.getVarDeclDbn(sym);
|
|
36
|
+
return this.dbn - declDbn;
|
|
37
|
+
}
|
|
38
|
+
toJson() {
|
|
39
|
+
let obj = {};
|
|
40
|
+
let prevCtx = null;
|
|
41
|
+
let ctx = this;
|
|
42
|
+
do {
|
|
43
|
+
obj["parentDbn"] = ctx._parentDbn;
|
|
44
|
+
obj["dbn"] = ctx.dbn;
|
|
45
|
+
obj["vars"] = ctx._variables.slice();
|
|
46
|
+
obj["next"] = prevCtx;
|
|
47
|
+
prevCtx = obj;
|
|
48
|
+
obj = {};
|
|
49
|
+
ctx = ctx.parent;
|
|
50
|
+
} while (ctx);
|
|
51
|
+
return prevCtx;
|
|
52
|
+
}
|
|
53
|
+
allVars() {
|
|
54
|
+
let vars = [];
|
|
55
|
+
let ctx = this;
|
|
56
|
+
while (ctx = ctx.parent) {
|
|
57
|
+
vars = ctx._variables.concat(vars);
|
|
58
|
+
}
|
|
59
|
+
return vars;
|
|
60
|
+
}
|
|
61
|
+
// for debugging purposes
|
|
62
|
+
// "inefficient" but correct way to get expected de bruijn index
|
|
63
|
+
expectedDbn(sym) {
|
|
64
|
+
const vars = this.allVars();
|
|
65
|
+
return vars.length - 1 - vars.lastIndexOf(sym);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IRHoisted, IRNative } from "../../IRNodes/index.js";
|
|
2
|
+
export declare const hoisted_drop2: IRHoisted;
|
|
3
|
+
export declare const hoisted_drop3: IRHoisted;
|
|
4
|
+
export declare const hoisted_drop4: IRHoisted;
|
|
5
|
+
export declare const hoisted_drop8: IRHoisted;
|
|
6
|
+
export declare const hoisted_drop16: IRHoisted;
|
|
7
|
+
export declare const hoisted_drop32: IRHoisted;
|
|
8
|
+
export declare function _compTimeDropN(bigN: bigint): IRHoisted | IRNative;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { IRHoisted, IRFunc, IRNative, IRVar, _ir_apps } from "../../IRNodes/index.js";
|
|
2
|
+
const tailList = new IRHoisted(IRNative.tailList);
|
|
3
|
+
tailList.hash;
|
|
4
|
+
const drop2_lst = Symbol("lst");
|
|
5
|
+
export const hoisted_drop2 = new IRHoisted(new IRFunc([drop2_lst], // lst
|
|
6
|
+
_ir_apps(tailList.clone(), _ir_apps(tailList.clone(), new IRVar(drop2_lst) // lst
|
|
7
|
+
))));
|
|
8
|
+
hoisted_drop2.hash;
|
|
9
|
+
const drop3_lst = Symbol("lst");
|
|
10
|
+
export const hoisted_drop3 = new IRHoisted(new IRFunc([drop3_lst], // lst
|
|
11
|
+
_ir_apps(tailList.clone(), _ir_apps(tailList.clone(), _ir_apps(tailList.clone(), new IRVar(drop3_lst) // lst
|
|
12
|
+
)))));
|
|
13
|
+
hoisted_drop3.hash;
|
|
14
|
+
const drop4_lst = Symbol("lst");
|
|
15
|
+
export const hoisted_drop4 = new IRHoisted(new IRFunc([drop4_lst], // lst
|
|
16
|
+
_ir_apps(tailList.clone(), _ir_apps(tailList.clone(), _ir_apps(tailList.clone(), _ir_apps(tailList.clone(), new IRVar(drop4_lst) // lst
|
|
17
|
+
))))));
|
|
18
|
+
hoisted_drop4.hash;
|
|
19
|
+
const drop8_lst = Symbol("lst");
|
|
20
|
+
export const hoisted_drop8 = new IRHoisted(new IRFunc([drop8_lst], // lst
|
|
21
|
+
_ir_apps(hoisted_drop4.clone(), _ir_apps(hoisted_drop4.clone(), new IRVar(drop8_lst) // lst
|
|
22
|
+
))));
|
|
23
|
+
hoisted_drop8.hash;
|
|
24
|
+
// replace numeric arity version of drop16 with symbol param
|
|
25
|
+
const drop16_lst = Symbol("lst");
|
|
26
|
+
export const hoisted_drop16 = new IRHoisted(new IRFunc([drop16_lst], _ir_apps(hoisted_drop8.clone(), _ir_apps(hoisted_drop8.clone(), new IRVar(drop16_lst)))));
|
|
27
|
+
hoisted_drop16.hash;
|
|
28
|
+
// replace numeric arity version of drop32 with symbol param
|
|
29
|
+
const drop32_lst = Symbol("lst");
|
|
30
|
+
export const hoisted_drop32 = new IRHoisted(new IRFunc([drop32_lst], _ir_apps(hoisted_drop16.clone(), _ir_apps(hoisted_drop16.clone(), new IRVar(drop32_lst)))));
|
|
31
|
+
hoisted_drop32.hash;
|
|
32
|
+
export function _compTimeDropN(bigN) {
|
|
33
|
+
const n = Number(bigN);
|
|
34
|
+
if (n < 0)
|
|
35
|
+
throw new Error(`Cannot drop a negative number of elements from a list`);
|
|
36
|
+
if (n === 0)
|
|
37
|
+
return IRNative._id;
|
|
38
|
+
if (n === 1)
|
|
39
|
+
return tailList.clone();
|
|
40
|
+
if (n === 2)
|
|
41
|
+
return hoisted_drop2;
|
|
42
|
+
if (n === 3)
|
|
43
|
+
return hoisted_drop3;
|
|
44
|
+
if (n === 4)
|
|
45
|
+
return hoisted_drop4;
|
|
46
|
+
if (n === 8)
|
|
47
|
+
return hoisted_drop8;
|
|
48
|
+
if (n === 16)
|
|
49
|
+
return hoisted_drop16;
|
|
50
|
+
if (n === 32)
|
|
51
|
+
return hoisted_drop32;
|
|
52
|
+
// Greedy decomposition into available drop sizes (largest first)
|
|
53
|
+
let remaining = n;
|
|
54
|
+
const parts = [];
|
|
55
|
+
const sizes = [32, 16, 8, 4, 3, 2, 1];
|
|
56
|
+
for (const s of sizes) {
|
|
57
|
+
while (remaining >= s) {
|
|
58
|
+
parts.push(s);
|
|
59
|
+
remaining -= s;
|
|
60
|
+
}
|
|
61
|
+
if (remaining === 0)
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
// Build the composed drop function body by sequential application
|
|
65
|
+
const lst = Symbol("lst"); // symbol param for composed function
|
|
66
|
+
let body = new IRVar(lst);
|
|
67
|
+
for (const p of parts) {
|
|
68
|
+
switch (p) {
|
|
69
|
+
case 32:
|
|
70
|
+
body = _ir_apps(hoisted_drop32.clone(), body);
|
|
71
|
+
break;
|
|
72
|
+
case 16:
|
|
73
|
+
body = _ir_apps(hoisted_drop16.clone(), body);
|
|
74
|
+
break;
|
|
75
|
+
case 8:
|
|
76
|
+
body = _ir_apps(hoisted_drop8.clone(), body);
|
|
77
|
+
break;
|
|
78
|
+
case 4:
|
|
79
|
+
body = _ir_apps(hoisted_drop4.clone(), body);
|
|
80
|
+
break;
|
|
81
|
+
case 3:
|
|
82
|
+
body = _ir_apps(hoisted_drop3.clone(), body);
|
|
83
|
+
break;
|
|
84
|
+
case 2:
|
|
85
|
+
body = _ir_apps(hoisted_drop2.clone(), body);
|
|
86
|
+
break;
|
|
87
|
+
case 1:
|
|
88
|
+
body = _ir_apps(tailList.clone(), body);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const hoisted = new IRHoisted(new IRFunc([lst], body));
|
|
93
|
+
hoisted.hash;
|
|
94
|
+
return hoisted;
|
|
95
|
+
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { IRApp } from "../../../IRNodes/IRApp.js";
|
|
2
|
-
import { IRDelayed } from "../../../IRNodes/IRDelayed.js";
|
|
3
|
-
import { IRForced } from "../../../IRNodes/IRForced.js";
|
|
4
2
|
import { IRFunc } from "../../../IRNodes/IRFunc.js";
|
|
5
3
|
import { getSortedHoistedSet, getHoistedTerms, IRHoisted } from "../../../IRNodes/IRHoisted.js";
|
|
6
|
-
import { IRLetted } from "../../../IRNodes/IRLetted.js";
|
|
7
4
|
import { IRVar } from "../../../IRNodes/IRVar.js";
|
|
8
5
|
import { _modifyChildFromTo } from "../../_internal/_modifyChildFromTo.js";
|
|
9
6
|
import { showIR } from "../../../utils/showIR.js";
|
|
10
7
|
import { markRecursiveHoistsAsForced } from "../markRecursiveHoistsAsForced.js";
|
|
11
8
|
import { equalIrHash, irHashToHex } from "../../../IRHash.js";
|
|
12
|
-
import { mapArrayLike } from "../../../IRNodes/utils/mapArrayLike.js";
|
|
13
|
-
import { IRCase } from "../../../IRNodes/IRCase.js";
|
|
14
|
-
import { IRConstr } from "../../../IRNodes/IRConstr.js";
|
|
15
9
|
import { stringify } from "../../../../utils/stringify.js";
|
|
16
10
|
import { IRRecursive } from "../../../IRNodes/IRRecursive.js";
|
|
17
11
|
export function handleHoistedAndReturnRoot(term) {
|
|
@@ -68,19 +62,11 @@ export function handleHoistedAndReturnRoot(term) {
|
|
|
68
62
|
let root = term;
|
|
69
63
|
while (root.parent !== undefined)
|
|
70
64
|
root = root.parent;
|
|
71
|
-
function getIRVarForHoistedAtLevel(_hoistedHash, level) {
|
|
72
|
-
let levelOfTerm = toHoist.findIndex(sortedH => equalIrHash(sortedH.hash, _hoistedHash));
|
|
73
|
-
if (levelOfTerm < 0) {
|
|
74
|
-
throw new Error(`missing hoisted with hash ${irHashToHex(_hoistedHash)} between toHoist [\n\t${toHoist.map(h => irHashToHex(h.hash))
|
|
75
|
-
.join(",\n\t")}\n]; can't replace with IRVar`);
|
|
76
|
-
}
|
|
77
|
-
return new IRVar(level - (levelOfTerm + 1));
|
|
78
|
-
}
|
|
79
65
|
// adds the actual terms
|
|
80
66
|
// from last to first
|
|
81
67
|
for (let i = toHoist.length - 1; i >= 0; i--) {
|
|
82
68
|
const thisHoisted = toHoist[i];
|
|
83
|
-
root = new IRApp(new IRFunc(
|
|
69
|
+
root = new IRApp(new IRFunc([thisHoisted.name], root), thisHoisted.hoisted.clone());
|
|
84
70
|
}
|
|
85
71
|
// replace hoisted references with variables
|
|
86
72
|
const stack = [{ irTerm: root, dbn: 0 }];
|
|
@@ -93,22 +79,14 @@ export function handleHoistedAndReturnRoot(term) {
|
|
|
93
79
|
irTerm instanceof IRHoisted &&
|
|
94
80
|
// is not one to be inlined
|
|
95
81
|
!isHoistedToinline) {
|
|
96
|
-
const irvar = getIRVarForHoistedAtLevel(irTermHash, dbn);
|
|
97
|
-
if (irvar.dbn >= dbn) {
|
|
98
|
-
throw new Error(`out of bound hoisted term; hash: ${irHashToHex(irTerm.hash)}; var's DeBruijn: ${irvar.dbn} (starts from 0); tot hoisted in scope: ${dbn}`);
|
|
99
|
-
}
|
|
82
|
+
const irvar = new IRVar(irTerm.name); // getIRVarForHoistedAtLevel( irTermHash, dbn );
|
|
100
83
|
// console.log(
|
|
101
84
|
// showIRText( irTerm.parent as IRTerm ),
|
|
102
85
|
// "\n\n",
|
|
103
86
|
// showIRText( irTerm ),
|
|
104
87
|
// )
|
|
105
88
|
_modifyChildFromTo(irTerm.parent, irTerm, irvar);
|
|
106
|
-
|
|
107
|
-
value: true,
|
|
108
|
-
writable: true,
|
|
109
|
-
enumerable: true,
|
|
110
|
-
configurable: true
|
|
111
|
-
});
|
|
89
|
+
irTerm.meta.handled = true;
|
|
112
90
|
// don't push anything
|
|
113
91
|
// because we just replaced with a variable
|
|
114
92
|
// so we know there's not a tree to explore
|
|
@@ -124,38 +102,13 @@ export function handleHoistedAndReturnRoot(term) {
|
|
|
124
102
|
stack.push({ irTerm: toInline, dbn });
|
|
125
103
|
continue;
|
|
126
104
|
}
|
|
127
|
-
if (irTerm instanceof
|
|
128
|
-
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (irTerm instanceof IRCase) {
|
|
132
|
-
stack.push({ irTerm: irTerm.constrTerm, dbn }, ...mapArrayLike(irTerm.continuations, (continuation) => ({ irTerm: continuation, dbn })));
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (irTerm instanceof IRConstr) {
|
|
136
|
-
stack.push(...mapArrayLike(irTerm.fields, (field) => ({ irTerm: field, dbn })));
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (irTerm instanceof IRDelayed) {
|
|
140
|
-
stack.push({ irTerm: irTerm.delayed, dbn });
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (irTerm instanceof IRForced) {
|
|
144
|
-
stack.push({ irTerm: irTerm.forced, dbn });
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
if (irTerm instanceof IRFunc) {
|
|
105
|
+
if (irTerm instanceof IRFunc
|
|
106
|
+
|| irTerm instanceof IRRecursive) {
|
|
148
107
|
stack.push({ irTerm: irTerm.body, dbn: dbn + irTerm.arity });
|
|
149
108
|
continue;
|
|
150
109
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
if (irTerm instanceof IRLetted) {
|
|
156
|
-
stack.push({ irTerm: irTerm.value, dbn });
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
110
|
+
stack.push(...irTerm.children()
|
|
111
|
+
.map(child => ({ irTerm: child, dbn })));
|
|
159
112
|
}
|
|
160
113
|
return root;
|
|
161
114
|
}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import { IRFunc } from "../../../IRNodes/IRFunc.js";
|
|
2
1
|
import { LettedSetEntry } from "../../../IRNodes/IRLetted.js";
|
|
2
|
+
import { IRSelfCall } from "../../../IRNodes/IRSelfCall.js";
|
|
3
|
+
import { IRVar } from "../../../IRNodes/IRVar.js";
|
|
3
4
|
import { IRTerm } from "../../../IRTerm.js";
|
|
4
5
|
type ScopedLettedTerms = {
|
|
5
|
-
maxScope:
|
|
6
|
+
maxScope: IRTerm | undefined;
|
|
6
7
|
group: LettedSetEntry[];
|
|
7
8
|
};
|
|
8
9
|
export declare function groupByScope(letteds: LettedSetEntry[]): ScopedLettedTerms[];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @returns {number | undefined}
|
|
13
|
-
* a `number` if the `_term` param is open;
|
|
14
|
-
* represents the debuijn index an `IRVar` would have
|
|
15
|
-
* in order to point to the smallest scope that fulfills the term;
|
|
16
|
-
*
|
|
17
|
-
* `undefined` if the term is closed
|
|
18
|
-
*/
|
|
19
|
-
export declare function _getMinUnboundDbn(_term: IRTerm): number | undefined;
|
|
10
|
+
export declare function getMaxScope(term: IRTerm): IRTerm | undefined;
|
|
11
|
+
export declare function getUnboundedIRVars(term: IRTerm): (IRVar | IRSelfCall)[];
|
|
12
|
+
export declare function getUnboundedVars(term: IRTerm, knownVars?: Set<symbol> | undefined): Set<symbol>;
|
|
20
13
|
export {};
|