@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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { _ir_apps } from "../../IRNodes/IRApp.js";
|
|
2
|
+
import { IRConst } from "../../IRNodes/IRConst.js";
|
|
3
|
+
import { IRFunc } from "../../IRNodes/IRFunc.js";
|
|
4
|
+
import { IRHoisted } from "../../IRNodes/IRHoisted.js";
|
|
5
|
+
import { IRLetted } from "../../IRNodes/IRLetted.js";
|
|
6
|
+
import { IRNative } from "../../IRNodes/IRNative/index.js";
|
|
7
|
+
import { IRNativeTag } from "../../IRNodes/IRNative/IRNativeTag.js";
|
|
8
|
+
import { IRVar } from "../../IRNodes/IRVar.js";
|
|
9
|
+
import { _modifyChildFromTo } from "../_internal/_modifyChildFromTo.js";
|
|
10
|
+
import { getApplicationTerms } from "../utils/getApplicationTerms.js";
|
|
11
|
+
import { _compTimeDropN } from "./_comptimeDropN.js";
|
|
12
|
+
export function rewriteNativesAppliedToConstantsAndReturnRoot(term) {
|
|
13
|
+
// traverse the tree, find applications of natives to constants
|
|
14
|
+
// and replace them with the optimized equivalent
|
|
15
|
+
const stack = [term];
|
|
16
|
+
while (stack.length > 0) {
|
|
17
|
+
const current = stack.pop();
|
|
18
|
+
const parent = current.parent;
|
|
19
|
+
const appTerms = getApplicationTerms(current);
|
|
20
|
+
if (!appTerms) {
|
|
21
|
+
stack.unshift(...current.children());
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const { func, args } = appTerms;
|
|
25
|
+
const [fstArg, ...restArgs] = args;
|
|
26
|
+
if (isId(func)
|
|
27
|
+
&& restArgs.length === 0) {
|
|
28
|
+
if (parent) {
|
|
29
|
+
_modifyChildFromTo(parent, current, fstArg);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
term = fstArg;
|
|
33
|
+
term.parent = undefined;
|
|
34
|
+
}
|
|
35
|
+
stack.unshift(fstArg);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (!(fstArg instanceof IRConst)) {
|
|
39
|
+
stack.unshift(...current.children());
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (isDropList(func)
|
|
43
|
+
&& (typeof fstArg.value === "bigint"
|
|
44
|
+
|| typeof fstArg.value === "number")) {
|
|
45
|
+
const newTerm = restArgs.length >= 1 ? _ir_apps(_compTimeDropN(fstArg.value), ...restArgs) : _compTimeDropN(fstArg.value);
|
|
46
|
+
if (parent) {
|
|
47
|
+
_modifyChildFromTo(parent, current, newTerm);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
term = newTerm;
|
|
51
|
+
term.parent = undefined;
|
|
52
|
+
}
|
|
53
|
+
stack.unshift(newTerm);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// const tsEnsureExhaustiveCheck: never = func;
|
|
57
|
+
stack.unshift(...current.children());
|
|
58
|
+
}
|
|
59
|
+
return term;
|
|
60
|
+
}
|
|
61
|
+
function isDropList(term) {
|
|
62
|
+
while (term instanceof IRHoisted
|
|
63
|
+
|| term instanceof IRLetted) {
|
|
64
|
+
if (term instanceof IRHoisted)
|
|
65
|
+
term = term.hoisted;
|
|
66
|
+
else if (term instanceof IRLetted)
|
|
67
|
+
term = term.value;
|
|
68
|
+
}
|
|
69
|
+
return (term instanceof IRNative
|
|
70
|
+
&& term.tag === IRNativeTag._dropList);
|
|
71
|
+
}
|
|
72
|
+
function isId(term) {
|
|
73
|
+
while (term instanceof IRHoisted
|
|
74
|
+
|| term instanceof IRLetted) {
|
|
75
|
+
if (term instanceof IRHoisted)
|
|
76
|
+
term = term.hoisted;
|
|
77
|
+
else if (term instanceof IRLetted)
|
|
78
|
+
term = term.value;
|
|
79
|
+
}
|
|
80
|
+
return ((term instanceof IRNative
|
|
81
|
+
&& term.tag === IRNativeTag._id) || (term instanceof IRFunc
|
|
82
|
+
&& term.params.length === 1
|
|
83
|
+
&& term.body instanceof IRVar
|
|
84
|
+
&& term.body.name === term.params[0]));
|
|
85
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IRApp } from "../../IRNodes/IRApp.js";
|
|
2
|
+
import { IRCase } from "../../IRNodes/IRCase.js";
|
|
3
|
+
import { IRConstr } from "../../IRNodes/IRConstr.js";
|
|
4
|
+
export function getApplicationTerms(term) {
|
|
5
|
+
const args = [];
|
|
6
|
+
while (term instanceof IRApp
|
|
7
|
+
|| (term instanceof IRCase
|
|
8
|
+
&& term.continuations.length === 1
|
|
9
|
+
&& term.constrTerm instanceof IRConstr
|
|
10
|
+
&& Number(term.constrTerm.index) === 0)
|
|
11
|
+
// go "through" letted and hoisted
|
|
12
|
+
// || term instanceof IRLetted
|
|
13
|
+
// || term instanceof IRHoisted
|
|
14
|
+
) {
|
|
15
|
+
if (term instanceof IRApp) {
|
|
16
|
+
args.unshift(term.arg);
|
|
17
|
+
term = term.fn;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (term instanceof IRCase
|
|
21
|
+
&& term.continuations.length === 1
|
|
22
|
+
&& term.constrTerm instanceof IRConstr
|
|
23
|
+
&& Number(term.constrTerm.index) === 0) {
|
|
24
|
+
args.push(...term.constrTerm.fields);
|
|
25
|
+
term = term.continuations[0];
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
// if( term instanceof IRLetted ) term = term.value;
|
|
29
|
+
// else if( term instanceof IRHoisted ) term = term.hoisted;
|
|
30
|
+
}
|
|
31
|
+
if (args.length === 0)
|
|
32
|
+
return undefined;
|
|
33
|
+
return {
|
|
34
|
+
func: term,
|
|
35
|
+
args,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IRForced } from "../IRNodes/
|
|
2
|
-
import { IRTerm } from "../IRTerm.js";
|
|
1
|
+
import { IRForced } from "../IRNodes/IRForced.js";
|
|
2
|
+
import type { IRTerm } from "../IRTerm.js";
|
|
3
3
|
export declare function _ir_lazyChooseList(listTerm: IRTerm, caseNil: IRTerm, caseCons: IRTerm): IRForced;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _ir_apps } from "../IRNodes/IRApp.js";
|
|
2
|
+
import { IRDelayed } from "../IRNodes/IRDelayed.js";
|
|
3
|
+
import { IRForced } from "../IRNodes/IRForced.js";
|
|
4
|
+
import { IRNative } from "../IRNodes/IRNative/index.js";
|
|
3
5
|
export function _ir_lazyChooseList(listTerm, caseNil, caseCons) {
|
|
4
6
|
return new IRForced(_ir_apps(IRNative.strictChooseList, listTerm, new IRDelayed(caseNil), new IRDelayed(caseCons)));
|
|
5
7
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _ir_apps } from "../IRNodes/IRApp.js";
|
|
2
|
+
import { IRDelayed } from "../IRNodes/IRDelayed.js";
|
|
3
|
+
import { IRForced } from "../IRNodes/IRForced.js";
|
|
4
|
+
import { IRNative } from "../IRNodes/IRNative/index.js";
|
|
3
5
|
export function _ir_lazyIfThenElse(condition, thenBranch, elseBranch) {
|
|
4
6
|
return new IRForced(_ir_apps(IRNative.strictIfThenElse, condition, new IRDelayed(thenBranch), new IRDelayed(elseBranch)));
|
|
5
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { IRApp } from "../IRNodes/index.js";
|
|
2
2
|
import { IRTerm } from "../IRTerm.js";
|
|
3
|
-
export declare function _ir_let(value: IRTerm,
|
|
3
|
+
export declare function _ir_let(value: IRTerm, mkBody: (varName: symbol) => IRTerm): IRApp;
|
|
4
|
+
export declare function _ir_let_sym(sym: symbol, value: IRTerm, body: IRTerm): IRApp;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { IRApp, IRFunc } from "../IRNodes/index.js";
|
|
2
|
-
export function _ir_let(value,
|
|
3
|
-
|
|
2
|
+
export function _ir_let(value, mkBody) {
|
|
3
|
+
const name = Symbol("lettedVar");
|
|
4
|
+
return new IRApp(new IRFunc([name], mkBody(name)), value);
|
|
5
|
+
}
|
|
6
|
+
export function _ir_let_sym(sym, value, body) {
|
|
7
|
+
return new IRApp(new IRFunc([sym], body), value);
|
|
4
8
|
}
|
|
@@ -2,7 +2,6 @@ import { IRConst } from "../IRNodes/IRConst.js";
|
|
|
2
2
|
import { IRFunc } from "../IRNodes/IRFunc.js";
|
|
3
3
|
import { IRApp } from "../IRNodes/IRApp.js";
|
|
4
4
|
import { IRError } from "../IRNodes/IRError.js";
|
|
5
|
-
import { IRNative } from "../IRNodes/IRNative/index.js";
|
|
6
5
|
import { IRHoisted } from "../IRNodes/IRHoisted.js";
|
|
7
6
|
import { IRLetted } from "../IRNodes/IRLetted.js";
|
|
8
7
|
import { IRVar } from "../IRNodes/IRVar.js";
|
|
@@ -12,29 +11,33 @@ import { IRConstr } from "../IRNodes/IRConstr.js";
|
|
|
12
11
|
import { IRCase } from "../IRNodes/IRCase.js";
|
|
13
12
|
import { IRRecursive } from "../IRNodes/IRRecursive.js";
|
|
14
13
|
import { IRSelfCall } from "../IRNodes/IRSelfCall.js";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (term instanceof
|
|
20
|
-
return term.
|
|
21
|
-
|
|
14
|
+
import { IRNative } from "../IRNodes/IRNative/index.js";
|
|
15
|
+
import { getUnboundedIRVars } from "../toUPLC/subRoutines/handleLetted/groupByScope.js";
|
|
16
|
+
import { prettyIRInline } from "./showIR.js";
|
|
17
|
+
function _isClosedIRTerm(term, boundedVars, parent) {
|
|
18
|
+
if (term instanceof IRVar)
|
|
19
|
+
return boundedVars.has(term.name);
|
|
20
|
+
if (term instanceof IRSelfCall)
|
|
21
|
+
return boundedVars.has(term.name);
|
|
22
22
|
if (term instanceof IRFunc) {
|
|
23
|
-
|
|
23
|
+
boundedVars = new Set(boundedVars);
|
|
24
|
+
for (const param of term.params)
|
|
25
|
+
boundedVars.add(param);
|
|
26
|
+
return _isClosedIRTerm(term.body, boundedVars, term);
|
|
24
27
|
}
|
|
25
28
|
if (term instanceof IRRecursive) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return _isClosedIRTerm(term.fn, dbn, term) && _isClosedIRTerm(term.arg, dbn, term);
|
|
30
|
-
}
|
|
31
|
-
if (term instanceof IRConstr) {
|
|
32
|
-
return Array.from(term.fields).every(f => _isClosedIRTerm(f, dbn, term));
|
|
33
|
-
}
|
|
34
|
-
if (term instanceof IRCase) {
|
|
35
|
-
return _isClosedIRTerm(term.constrTerm, dbn, term) &&
|
|
36
|
-
Array.from(term.continuations).every(cont => _isClosedIRTerm(cont, dbn, term));
|
|
29
|
+
boundedVars = new Set(boundedVars);
|
|
30
|
+
boundedVars.add(term.name);
|
|
31
|
+
return _isClosedIRTerm(term.body, boundedVars, term);
|
|
37
32
|
}
|
|
33
|
+
if (term instanceof IRApp)
|
|
34
|
+
return _isClosedIRTerm(term.fn, boundedVars, term) && _isClosedIRTerm(term.arg, boundedVars, term);
|
|
35
|
+
if (term instanceof IRConstr)
|
|
36
|
+
return Array.from(term.fields).every(f => _isClosedIRTerm(f, boundedVars, term));
|
|
37
|
+
if (term instanceof IRCase)
|
|
38
|
+
return (_isClosedIRTerm(term.constrTerm, boundedVars, term)
|
|
39
|
+
&& Array.from(term.continuations)
|
|
40
|
+
.every(cont => _isClosedIRTerm(cont, boundedVars, term)));
|
|
38
41
|
if (term instanceof IRConst)
|
|
39
42
|
return true;
|
|
40
43
|
if (term instanceof IRError)
|
|
@@ -42,17 +45,28 @@ function _isClosedIRTerm(term, dbn, parent) {
|
|
|
42
45
|
if (term instanceof IRNative)
|
|
43
46
|
return true;
|
|
44
47
|
if (term instanceof IRHoisted)
|
|
45
|
-
return
|
|
48
|
+
return _isClosedIRTerm(term.hoisted, boundedVars, term);
|
|
46
49
|
if (term instanceof IRLetted)
|
|
47
|
-
return _isClosedIRTerm(term.value,
|
|
50
|
+
return _isClosedIRTerm(term.value, boundedVars, term);
|
|
48
51
|
if (term instanceof IRForced)
|
|
49
|
-
return _isClosedIRTerm(term.forced,
|
|
52
|
+
return _isClosedIRTerm(term.forced, boundedVars, term);
|
|
50
53
|
if (term instanceof IRDelayed)
|
|
51
|
-
return _isClosedIRTerm(term.delayed,
|
|
54
|
+
return _isClosedIRTerm(term.delayed, boundedVars, term);
|
|
55
|
+
const tsEnsureExhaustiveCheck = term;
|
|
52
56
|
// not even an IRTerm
|
|
53
|
-
console.
|
|
57
|
+
console.error(parent);
|
|
54
58
|
throw new Error("`isClosedIRTerm` called on non-IR argument");
|
|
55
59
|
}
|
|
56
60
|
export function isClosedIRTerm(term) {
|
|
57
|
-
return _isClosedIRTerm(term,
|
|
61
|
+
return _isClosedIRTerm(term, new Set(), undefined);
|
|
62
|
+
}
|
|
63
|
+
export function _debug_assertClosedIR(term) {
|
|
64
|
+
if (!isClosedIRTerm(term)) {
|
|
65
|
+
const unboundedVars = getUnboundedIRVars(term);
|
|
66
|
+
console.error("unbounded vars:", unboundedVars.map(variab => variab.name));
|
|
67
|
+
console.error("term:", prettyIRInline(term));
|
|
68
|
+
console.error("unbounded parents:", unboundedVars.map(variab => prettyIRInline(variab.parent ?? variab)));
|
|
69
|
+
console.error("unbounded parents:", unboundedVars.map(variab => variab._creationStack));
|
|
70
|
+
throw new Error("Term is not closed");
|
|
71
|
+
}
|
|
58
72
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fromHex } from "@harmoniclabs/uint8array-utils";
|
|
2
|
+
import UPLCFlatUtils from "../../utils/UPLCFlatUtils/index.js";
|
|
2
3
|
/**
|
|
3
4
|
* writes the number in a new `Uint8Array` Big Endian
|
|
4
5
|
*/
|
|
@@ -7,8 +8,6 @@ export function positiveIntAsBytes(n) {
|
|
|
7
8
|
return positiveBigIntAsBytes(n);
|
|
8
9
|
}
|
|
9
10
|
if (!Number.isSafeInteger(n) || n < 0) {
|
|
10
|
-
console.log(n);
|
|
11
|
-
console.trace(); // some help
|
|
12
11
|
throw new Error("how did you end up here? the name of the function explicitly says 'positiveIntAsBytes'");
|
|
13
12
|
}
|
|
14
13
|
let str = n.toString(16);
|
|
@@ -17,11 +16,12 @@ export function positiveIntAsBytes(n) {
|
|
|
17
16
|
}
|
|
18
17
|
export function positiveBigIntAsBytes(n) {
|
|
19
18
|
if (n < 0 || typeof n !== "bigint") {
|
|
20
|
-
console.log(n);
|
|
21
|
-
console.trace(); // some help
|
|
22
19
|
throw new Error("how did you end up here? the name of the function explicitly says 'positiveBigIntAsBytes'");
|
|
23
20
|
}
|
|
24
21
|
let strHex = n.toString(16);
|
|
25
22
|
strHex = strHex.length % 2 === 0 ? strHex : "0" + strHex;
|
|
26
23
|
return fromHex(strHex);
|
|
27
24
|
}
|
|
25
|
+
export function zigzagBigintAsBytes(n) {
|
|
26
|
+
return positiveBigIntAsBytes(UPLCFlatUtils.zigzagBigint(BigInt(n)));
|
|
27
|
+
}
|
|
@@ -3,33 +3,20 @@ import { IRTerm } from "../IRTerm.js";
|
|
|
3
3
|
import { IRHoisted } from "../IRNodes/IRHoisted.js";
|
|
4
4
|
import { IRConst } from "../IRNodes/IRConst.js";
|
|
5
5
|
export declare function showIRText(_ir: IRTerm): string;
|
|
6
|
-
export declare function showIR(_ir: IRTerm):
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[hash: string]: string;
|
|
10
|
-
};
|
|
11
|
-
hoisted: {
|
|
12
|
-
[hash: string]: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare function prettyIRText(_ir: IRTerm, _indent?: number): string | {
|
|
16
|
-
text: string;
|
|
17
|
-
letted: {
|
|
18
|
-
[hash: string]: string;
|
|
19
|
-
};
|
|
20
|
-
hoisted: {
|
|
21
|
-
[hash: string]: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export type PrettiedIR = {
|
|
6
|
+
export declare function showIR(_ir: IRTerm): PrettiedIR;
|
|
7
|
+
export declare function prettyIRText(_ir: IRTerm, _indent?: number): string;
|
|
8
|
+
export interface PrettiedIR extends HoistedAndLetted {
|
|
25
9
|
text: string;
|
|
10
|
+
}
|
|
11
|
+
export type PrettiedLetted = string;
|
|
12
|
+
export interface HoistedAndLetted {
|
|
26
13
|
letted: {
|
|
27
|
-
[hash: string]:
|
|
14
|
+
[hash: string]: PrettiedLetted;
|
|
28
15
|
};
|
|
29
16
|
hoisted: {
|
|
30
17
|
[hash: string]: string;
|
|
31
18
|
};
|
|
32
|
-
}
|
|
19
|
+
}
|
|
33
20
|
export declare function prettyIR(_ir: IRTerm, _indent?: number): PrettiedIR;
|
|
34
21
|
export interface PrettyIRJsonStrOpts {
|
|
35
22
|
text: boolean;
|
|
@@ -41,3 +28,5 @@ export declare function hoistedToStr(ir: IRHoisted): string;
|
|
|
41
28
|
export declare function lettedToStr(ir: IRLetted): string;
|
|
42
29
|
export declare function constToString(ir: IRConst): string;
|
|
43
30
|
export declare function prettyIRInline(_ir: IRTerm, _indent?: number): string;
|
|
31
|
+
export declare function unfromatStr(str: string): string;
|
|
32
|
+
export declare function onlyHoistedAndLetted(prettied: PrettiedIR): HoistedAndLetted;
|
package/dist/IR/utils/showIR.js
CHANGED
|
@@ -42,9 +42,9 @@ export function showIRText(_ir) {
|
|
|
42
42
|
return hoistedToStr(ir);
|
|
43
43
|
}
|
|
44
44
|
if (ir instanceof IRVar)
|
|
45
|
-
return
|
|
45
|
+
return ir.name.description;
|
|
46
46
|
if (ir instanceof IRSelfCall)
|
|
47
|
-
return "self_" +
|
|
47
|
+
return "self_" + ir.name.description;
|
|
48
48
|
if (ir instanceof IRConst)
|
|
49
49
|
return constToString(ir);
|
|
50
50
|
if (ir instanceof IRDelayed)
|
|
@@ -54,11 +54,9 @@ export function showIRText(_ir) {
|
|
|
54
54
|
if (ir instanceof IRError)
|
|
55
55
|
return "(error)";
|
|
56
56
|
if (ir instanceof IRFunc) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn)})`;
|
|
57
|
+
const syms = ir.params;
|
|
58
|
+
const names = syms.map(s => s.description);
|
|
59
|
+
return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length)})`;
|
|
62
60
|
}
|
|
63
61
|
if (ir instanceof IRRecursive) {
|
|
64
62
|
const varName = "self_" + getVarNameForDbn(dbn++);
|
|
@@ -78,13 +76,8 @@ export function showIR(_ir) {
|
|
|
78
76
|
for (let i = 0; i < deps.length; i++) {
|
|
79
77
|
addHoisted(deps[i].hoisted);
|
|
80
78
|
}
|
|
81
|
-
hoistedHashes.push(hash
|
|
82
|
-
|
|
83
|
-
value: showIRText(h.hoisted),
|
|
84
|
-
writable: false,
|
|
85
|
-
enumerable: true,
|
|
86
|
-
configurable: false
|
|
87
|
-
});
|
|
79
|
+
hoistedHashes.push(hash);
|
|
80
|
+
hoisted[irHashToHex(hash)] = prettyIRText(h.hoisted);
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
83
|
const lettedHashes = [];
|
|
@@ -97,14 +90,9 @@ export function showIR(_ir) {
|
|
|
97
90
|
for (let i = 0; i < nDeps; i++) {
|
|
98
91
|
addLetted(deps[i].letted);
|
|
99
92
|
}
|
|
100
|
-
lettedHashes.push(hash
|
|
93
|
+
lettedHashes.push(hash);
|
|
101
94
|
getHoistedTerms(l.value).forEach(({ hoisted }) => addHoisted(hoisted));
|
|
102
|
-
|
|
103
|
-
value: showIRText(l.value),
|
|
104
|
-
writable: false,
|
|
105
|
-
enumerable: true,
|
|
106
|
-
configurable: false
|
|
107
|
-
});
|
|
95
|
+
letted[irHashToHex(hash)] = showIRText(l.value);
|
|
108
96
|
}
|
|
109
97
|
}
|
|
110
98
|
function _loop(ir, dbn) {
|
|
@@ -125,9 +113,9 @@ export function showIR(_ir) {
|
|
|
125
113
|
return hoistedToStr(ir);
|
|
126
114
|
}
|
|
127
115
|
if (ir instanceof IRVar)
|
|
128
|
-
return
|
|
116
|
+
return ir.name.description;
|
|
129
117
|
if (ir instanceof IRSelfCall)
|
|
130
|
-
return "self_" +
|
|
118
|
+
return "self_" + ir.name.description;
|
|
131
119
|
if (ir instanceof IRConst)
|
|
132
120
|
return constToString(ir);
|
|
133
121
|
if (ir instanceof IRDelayed)
|
|
@@ -137,11 +125,9 @@ export function showIR(_ir) {
|
|
|
137
125
|
if (ir instanceof IRError)
|
|
138
126
|
return "(error)";
|
|
139
127
|
if (ir instanceof IRFunc) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn)})`;
|
|
128
|
+
const syms = ir.params;
|
|
129
|
+
const names = syms.map(s => s.description);
|
|
130
|
+
return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length)})`;
|
|
145
131
|
}
|
|
146
132
|
if (ir instanceof IRRecursive) {
|
|
147
133
|
const varName = "self_" + getVarNameForDbn(dbn++);
|
|
@@ -158,7 +144,7 @@ export function showIR(_ir) {
|
|
|
158
144
|
}
|
|
159
145
|
export function prettyIRText(_ir, _indent = 2) {
|
|
160
146
|
if (!Number.isSafeInteger(_indent) || _indent < 1)
|
|
161
|
-
return showIR(_ir);
|
|
147
|
+
return showIR(_ir).text;
|
|
162
148
|
const indentStr = " ".repeat(_indent);
|
|
163
149
|
function _loop(ir, dbn, depth) {
|
|
164
150
|
const indent = `\n${indentStr.repeat(depth)}`;
|
|
@@ -178,9 +164,9 @@ export function prettyIRText(_ir, _indent = 2) {
|
|
|
178
164
|
return `${indent}${hoistedToStr(ir)}`;
|
|
179
165
|
}
|
|
180
166
|
if (ir instanceof IRVar)
|
|
181
|
-
return indent +
|
|
167
|
+
return indent + ir.name.description;
|
|
182
168
|
if (ir instanceof IRSelfCall)
|
|
183
|
-
return indent + "self_" +
|
|
169
|
+
return indent + "self_" + ir.name.description;
|
|
184
170
|
if (ir instanceof IRConst)
|
|
185
171
|
return `${indent}${constToString(ir)}`;
|
|
186
172
|
if (ir instanceof IRDelayed)
|
|
@@ -190,16 +176,15 @@ export function prettyIRText(_ir, _indent = 2) {
|
|
|
190
176
|
if (ir instanceof IRError)
|
|
191
177
|
return "(error)";
|
|
192
178
|
if (ir instanceof IRFunc) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
|
|
179
|
+
const syms = ir.params;
|
|
180
|
+
const names = syms.map(s => s.description);
|
|
181
|
+
return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length, depth + 1)}${indent})`;
|
|
198
182
|
}
|
|
199
183
|
if (ir instanceof IRRecursive) {
|
|
200
184
|
const varName = "self_" + getVarNameForDbn(dbn++);
|
|
201
185
|
return `${indent}(recursive ${varName} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
|
|
202
186
|
}
|
|
187
|
+
const tsEnsureExhaustiveCheck = ir;
|
|
203
188
|
return "";
|
|
204
189
|
}
|
|
205
190
|
return _loop(_ir, 0, 0);
|
|
@@ -217,9 +202,8 @@ export function prettyIR(_ir, _indent = 2) {
|
|
|
217
202
|
for (let i = 0; i < deps.length; i++) {
|
|
218
203
|
addHoisted(deps[i].hoisted);
|
|
219
204
|
}
|
|
220
|
-
hoistedHashes.push(hash
|
|
221
|
-
|
|
222
|
-
Object.defineProperty(hoisted, hashStr, { value: prettyIRText(h.hoisted, _indent), writable: true, enumerable: true });
|
|
205
|
+
hoistedHashes.push(hash);
|
|
206
|
+
hoisted[irHashToHex(hash)] = prettyIRText(h.hoisted, _indent);
|
|
223
207
|
}
|
|
224
208
|
}
|
|
225
209
|
const lettedHashes = [];
|
|
@@ -232,14 +216,10 @@ export function prettyIR(_ir, _indent = 2) {
|
|
|
232
216
|
for (let i = 0; i < nDeps; i++) {
|
|
233
217
|
addLetted(deps[i].letted);
|
|
234
218
|
}
|
|
235
|
-
lettedHashes.push(hash
|
|
219
|
+
lettedHashes.push(hash);
|
|
236
220
|
getHoistedTerms(l.value).forEach(({ hoisted }) => addHoisted(hoisted));
|
|
237
221
|
const hashStr = irHashToHex(hash);
|
|
238
|
-
|
|
239
|
-
value: prettyIRText(l.value, _indent),
|
|
240
|
-
writable: true,
|
|
241
|
-
enumerable: true
|
|
242
|
-
});
|
|
222
|
+
letted[hashStr] = prettyIRText(l.value, _indent);
|
|
243
223
|
}
|
|
244
224
|
}
|
|
245
225
|
function _loop(ir, dbn, depth) {
|
|
@@ -257,9 +237,9 @@ export function prettyIR(_ir, _indent = 2) {
|
|
|
257
237
|
return `${indent}${hoistedToStr(ir)}`;
|
|
258
238
|
}
|
|
259
239
|
if (ir instanceof IRVar)
|
|
260
|
-
return indent +
|
|
240
|
+
return indent + ir.name.description;
|
|
261
241
|
if (ir instanceof IRSelfCall)
|
|
262
|
-
return indent + "self_" +
|
|
242
|
+
return indent + "self_" + ir.name.description;
|
|
263
243
|
if (ir instanceof IRConst)
|
|
264
244
|
return `${indent}${constToString(ir)}`;
|
|
265
245
|
if (ir instanceof IRDelayed)
|
|
@@ -269,17 +249,21 @@ export function prettyIR(_ir, _indent = 2) {
|
|
|
269
249
|
if (ir instanceof IRError)
|
|
270
250
|
return "(error)";
|
|
271
251
|
if (ir instanceof IRFunc) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
|
|
252
|
+
const syms = ir.params;
|
|
253
|
+
const names = syms.map(s => s.description);
|
|
254
|
+
return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length, depth + 1)}${indent})`;
|
|
277
255
|
}
|
|
278
256
|
if (ir instanceof IRRecursive) {
|
|
279
257
|
const varName = "self_" + getVarNameForDbn(dbn++);
|
|
280
258
|
return `${indent}(recursive ${varName} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
|
|
281
259
|
}
|
|
282
|
-
|
|
260
|
+
if (ir instanceof IRConstr)
|
|
261
|
+
return `${indent}(constr ${ir.index.toString()} [${Array.from(ir.fields).map(f => _loop(f, dbn, depth + 1)).join(`, `)}${indent}])`;
|
|
262
|
+
if (ir instanceof IRCase)
|
|
263
|
+
return `${indent}(case ${_loop(ir.constrTerm, dbn, depth + 1)} ${indent}[${Array.from(ir.continuations).map(f => _loop(f, dbn, depth + 1)).join(", ")}${indent}])`;
|
|
264
|
+
const tsEnsureExhaustiveCheck = ir;
|
|
265
|
+
console.error(ir);
|
|
266
|
+
throw new Error("unknown IR node found");
|
|
283
267
|
}
|
|
284
268
|
const text = _loop(_ir, 0, 0);
|
|
285
269
|
return {
|
|
@@ -316,7 +300,7 @@ export function hoistedToStr(ir) {
|
|
|
316
300
|
return `(hoisted${(ir.meta.name ? " {" + ir.meta.name + "}" : "")} ${irHashToHex(ir.hash)})`;
|
|
317
301
|
}
|
|
318
302
|
export function lettedToStr(ir) {
|
|
319
|
-
return `(letted${
|
|
303
|
+
return `(letted ${ir.name.description} ${irHashToHex(ir.hash)})`;
|
|
320
304
|
}
|
|
321
305
|
export function constToString(ir) {
|
|
322
306
|
return `(const ${ir.type.toString()} ${showUPLCConstValue(ir.value)})`;
|
|
@@ -331,21 +315,25 @@ export function prettyIRInline(_ir, _indent = 2) {
|
|
|
331
315
|
return `${indent}(native ${nativeTagToString(ir.tag)})`;
|
|
332
316
|
if (ir instanceof IRLetted) {
|
|
333
317
|
// addLetted( ir );
|
|
334
|
-
return (`${indent}(letted${
|
|
335
|
-
`${
|
|
318
|
+
return (`${indent}(letted ${ir.name.description}` +
|
|
319
|
+
`${indent + indentStr}{` +
|
|
320
|
+
`${_loop(ir.value, dbn, depth + 2)}` +
|
|
321
|
+
`${indent + indentStr}}` +
|
|
336
322
|
`${indent})`);
|
|
337
323
|
}
|
|
338
324
|
if (ir instanceof IRHoisted) {
|
|
339
325
|
// addHoisted( ir )
|
|
340
326
|
// return `${indent}${hoistedToStr(ir)}`;
|
|
341
327
|
return (`${indent}(hoisted${(ir.meta.name ? " {" + ir.meta.name + "}" : "")} ${irHashToHex(ir.hash)}` +
|
|
342
|
-
`${
|
|
328
|
+
`${indent + indentStr}{` +
|
|
329
|
+
`${_loop(ir.hoisted, dbn, depth + 2)}` +
|
|
330
|
+
`${indent + indentStr}}` +
|
|
343
331
|
`${indent})`);
|
|
344
332
|
}
|
|
345
333
|
if (ir instanceof IRVar)
|
|
346
|
-
return indent +
|
|
334
|
+
return indent + ir.name.description;
|
|
347
335
|
if (ir instanceof IRSelfCall)
|
|
348
|
-
return indent + "self_" +
|
|
336
|
+
return indent + "self_" + ir.name.description;
|
|
349
337
|
if (ir instanceof IRConst)
|
|
350
338
|
return `${indent}${constToString(ir)}`;
|
|
351
339
|
if (ir instanceof IRDelayed)
|
|
@@ -355,11 +343,9 @@ export function prettyIRInline(_ir, _indent = 2) {
|
|
|
355
343
|
if (ir instanceof IRError)
|
|
356
344
|
return "(error)";
|
|
357
345
|
if (ir instanceof IRFunc) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
|
|
346
|
+
const syms = ir.params;
|
|
347
|
+
const names = syms.map(s => s.description);
|
|
348
|
+
return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length, depth + 1)}${indent})`;
|
|
363
349
|
}
|
|
364
350
|
if (ir instanceof IRRecursive) {
|
|
365
351
|
const varName = "self_" + getVarNameForDbn(dbn++);
|
|
@@ -370,3 +356,19 @@ export function prettyIRInline(_ir, _indent = 2) {
|
|
|
370
356
|
const text = _loop(_ir, 0, 0);
|
|
371
357
|
return text;
|
|
372
358
|
}
|
|
359
|
+
export function unfromatStr(str) {
|
|
360
|
+
return str
|
|
361
|
+
.replace("\n", " ")
|
|
362
|
+
.replace(/\s+/g, " ");
|
|
363
|
+
}
|
|
364
|
+
export function onlyHoistedAndLetted(prettied) {
|
|
365
|
+
const result = { letted: {}, hoisted: {} };
|
|
366
|
+
Object.keys(prettied.letted).forEach(k => {
|
|
367
|
+
const letted = prettied.letted[k];
|
|
368
|
+
result.letted[k] = unfromatStr(letted);
|
|
369
|
+
});
|
|
370
|
+
Object.keys(prettied.hoisted).forEach(k => {
|
|
371
|
+
result.hoisted[k] = unfromatStr(prettied.hoisted[k]);
|
|
372
|
+
});
|
|
373
|
+
return result;
|
|
374
|
+
}
|