@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,777 @@
|
|
|
1
|
+
import { isObject } from "@harmoniclabs/obj-utils";
|
|
2
|
+
import { Identifier } from "../../../../ast/nodes/common/Identifier.js";
|
|
3
|
+
import { isBinaryExpr } from "../../../../ast/nodes/expr/binary/BinaryExpr.js";
|
|
4
|
+
import { CaseExpr } from "../../../../ast/nodes/expr/CaseExpr.js";
|
|
5
|
+
import { ElemAccessExpr } from "../../../../ast/nodes/expr/ElemAccessExpr.js";
|
|
6
|
+
import { CallExpr } from "../../../../ast/nodes/expr/functions/CallExpr.js";
|
|
7
|
+
import { FuncExpr } from "../../../../ast/nodes/expr/functions/FuncExpr.js";
|
|
8
|
+
import { LitArrExpr } from "../../../../ast/nodes/expr/litteral/LitArrExpr.js";
|
|
9
|
+
import { LitContextExpr } from "../../../../ast/nodes/expr/litteral/LitContextExpr.js";
|
|
10
|
+
import { LitFailExpr } from "../../../../ast/nodes/expr/litteral/LitFailExpr.js";
|
|
11
|
+
import { LitFalseExpr } from "../../../../ast/nodes/expr/litteral/LitFalseExpr.js";
|
|
12
|
+
import { LitHexBytesExpr } from "../../../../ast/nodes/expr/litteral/LitHexBytesExpr.js";
|
|
13
|
+
import { LitIntExpr } from "../../../../ast/nodes/expr/litteral/LitIntExpr.js";
|
|
14
|
+
import { LitNamedObjExpr } from "../../../../ast/nodes/expr/litteral/LitNamedObjExpr.js";
|
|
15
|
+
import { LitObjExpr } from "../../../../ast/nodes/expr/litteral/LitObjExpr.js";
|
|
16
|
+
import { LitStrExpr } from "../../../../ast/nodes/expr/litteral/LitStrExpr.js";
|
|
17
|
+
import { LitThisExpr } from "../../../../ast/nodes/expr/litteral/LitThisExpr.js";
|
|
18
|
+
import { LitTrueExpr } from "../../../../ast/nodes/expr/litteral/LitTrueExpr.js";
|
|
19
|
+
import { LitUndefExpr } from "../../../../ast/nodes/expr/litteral/LitUndefExpr.js";
|
|
20
|
+
import { LitVoidExpr } from "../../../../ast/nodes/expr/litteral/LitVoidExpr.js";
|
|
21
|
+
import { ParentesizedExpr } from "../../../../ast/nodes/expr/ParentesizedExpr.js";
|
|
22
|
+
import { isPropAccessExpr } from "../../../../ast/nodes/expr/PropAccessExpr.js";
|
|
23
|
+
import { TernaryExpr } from "../../../../ast/nodes/expr/TernaryExpr.js";
|
|
24
|
+
import { TypeConversionExpr } from "../../../../ast/nodes/expr/TypeConversionExpr.js";
|
|
25
|
+
import { isUnaryPrefixExpr } from "../../../../ast/nodes/expr/unary/UnaryPrefixExpr.js";
|
|
26
|
+
import { AssertStmt } from "../../../../ast/nodes/statements/AssertStmt.js";
|
|
27
|
+
import { isExplicitAssignmentStmt, isImplicitAssignmentStmt } from "../../../../ast/nodes/statements/AssignmentStmt.js";
|
|
28
|
+
import { BlockStmt } from "../../../../ast/nodes/statements/BlockStmt.js";
|
|
29
|
+
import { BreakStmt } from "../../../../ast/nodes/statements/BreakStmt.js";
|
|
30
|
+
import { ContinueStmt } from "../../../../ast/nodes/statements/ContinueStmt.js";
|
|
31
|
+
import { StructConstrDecl, StructDecl, StructDeclAstFlags } from "../../../../ast/nodes/statements/declarations/StructDecl.js";
|
|
32
|
+
import { NamedDeconstructVarDecl } from "../../../../ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.js";
|
|
33
|
+
import { SimpleVarDecl } from "../../../../ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js";
|
|
34
|
+
import { SingleDeconstructVarDecl } from "../../../../ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.js";
|
|
35
|
+
import { EmptyStmt } from "../../../../ast/nodes/statements/EmptyStmt.js";
|
|
36
|
+
import { FailStmt } from "../../../../ast/nodes/statements/FailStmt.js";
|
|
37
|
+
import { ForOfStmt } from "../../../../ast/nodes/statements/ForOfStmt.js";
|
|
38
|
+
import { ForStmt } from "../../../../ast/nodes/statements/ForStmt.js";
|
|
39
|
+
import { IfStmt } from "../../../../ast/nodes/statements/IfStmt.js";
|
|
40
|
+
import { MatchStmtCase, MatchStmt, MatchStmtElseCase } from "../../../../ast/nodes/statements/MatchStmt.js";
|
|
41
|
+
import { ReturnStmt } from "../../../../ast/nodes/statements/ReturnStmt.js";
|
|
42
|
+
import { UsingStmt } from "../../../../ast/nodes/statements/UsingStmt.js";
|
|
43
|
+
import { VarStmt } from "../../../../ast/nodes/statements/VarStmt.js";
|
|
44
|
+
import { WhileStmt } from "../../../../ast/nodes/statements/WhileStmt.js";
|
|
45
|
+
import { CommonFlags } from "../../../../common.js";
|
|
46
|
+
import { DiagnosticCode } from "../../../../diagnostics/diagnosticMessages.generated.js";
|
|
47
|
+
import { getUniqueInternalName } from "../../../internalVar.js";
|
|
48
|
+
import { AstNamedTypeExpr } from "../../../../ast/nodes/types/AstNamedTypeExpr.js";
|
|
49
|
+
import { NonNullExpr } from "../../../../ast/nodes/expr/unary/NonNullExpr.js";
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* only returns the body of the main function
|
|
53
|
+
*
|
|
54
|
+
* function arguments (parameters and script context) must be handled outside
|
|
55
|
+
*/
|
|
56
|
+
export function _deriveContractBody(compiler, contractDecl, paramsInternalNamesMap, scriptContextName) {
|
|
57
|
+
const contractRange = contractDecl.range;
|
|
58
|
+
// no methods is always fail
|
|
59
|
+
if (contractDecl.spendMethods.length === 0
|
|
60
|
+
&& contractDecl.mintMethods.length === 0
|
|
61
|
+
&& contractDecl.certifyMethods.length === 0
|
|
62
|
+
&& contractDecl.withdrawMethods.length === 0
|
|
63
|
+
&& contractDecl.proposeMethods.length === 0
|
|
64
|
+
&& contractDecl.voteMethods.length === 0)
|
|
65
|
+
return new BlockStmt([
|
|
66
|
+
new FailStmt(undefined, contractRange)
|
|
67
|
+
], contractRange);
|
|
68
|
+
// contract body alwyas looks like:
|
|
69
|
+
//
|
|
70
|
+
// ```
|
|
71
|
+
// func main( ...params, ctx: ScriptContext ) : void {
|
|
72
|
+
// const { tx, purpose, redeemer } = ctx;
|
|
73
|
+
//
|
|
74
|
+
// match( purpose ) {
|
|
75
|
+
// when Spend{}: { ... }
|
|
76
|
+
// when Mint{}: { ... }
|
|
77
|
+
// when Withdraw{}: { ... }
|
|
78
|
+
// when Certify{}: { ... }
|
|
79
|
+
// when Propose{}: { ... }
|
|
80
|
+
// when Vote{}: { ... }
|
|
81
|
+
// else fail;
|
|
82
|
+
// }
|
|
83
|
+
//
|
|
84
|
+
// fail; // unreachable
|
|
85
|
+
// }
|
|
86
|
+
// ```
|
|
87
|
+
//
|
|
88
|
+
// so we only have 3 statements in the body
|
|
89
|
+
const bodyStmts = [];
|
|
90
|
+
const txUniqueName = getUniqueInternalName("tx");
|
|
91
|
+
const purposeUniqueName = getUniqueInternalName("purpose");
|
|
92
|
+
const redeemerUniqueName = getUniqueInternalName("redeemer");
|
|
93
|
+
bodyStmts.push(new VarStmt([new SingleDeconstructVarDecl(
|
|
94
|
+
// fields
|
|
95
|
+
new Map([
|
|
96
|
+
[
|
|
97
|
+
new Identifier("tx", contractRange),
|
|
98
|
+
SimpleVarDecl.onlyNameConst(txUniqueName, contractRange)
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
new Identifier("purpose", contractRange),
|
|
102
|
+
SimpleVarDecl.onlyNameConst(purposeUniqueName, contractRange)
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
new Identifier("redeemer", contractRange),
|
|
106
|
+
SimpleVarDecl.onlyNameConst(redeemerUniqueName, contractRange)
|
|
107
|
+
],
|
|
108
|
+
]), undefined, // rest
|
|
109
|
+
undefined, // type (inferred from initExpr)
|
|
110
|
+
new Identifier(scriptContextName, contractRange), // initExpr
|
|
111
|
+
CommonFlags.Const, contractRange)], contractRange));
|
|
112
|
+
/*
|
|
113
|
+
const { data: scriptInfo_t } = defineMultiConstructorStruct(
|
|
114
|
+
"ScriptInfo", {
|
|
115
|
+
Mint: {
|
|
116
|
+
policy: policyId_t
|
|
117
|
+
},
|
|
118
|
+
Spend: {
|
|
119
|
+
ref: txOutRef_t,
|
|
120
|
+
optionalDatum: opt_data_t
|
|
121
|
+
},
|
|
122
|
+
Withdraw: {
|
|
123
|
+
credential: credential_t
|
|
124
|
+
},
|
|
125
|
+
Certificate: {
|
|
126
|
+
certificateIndex: int_t,
|
|
127
|
+
certificate: credential_t
|
|
128
|
+
},
|
|
129
|
+
Vote: {
|
|
130
|
+
voter: voter_t
|
|
131
|
+
},
|
|
132
|
+
Propose: {
|
|
133
|
+
proposalIndex: int_t,
|
|
134
|
+
proposal: proposalProcedure_t
|
|
135
|
+
}
|
|
136
|
+
}, onlyData
|
|
137
|
+
);
|
|
138
|
+
*/
|
|
139
|
+
const purposeMatchCases = [];
|
|
140
|
+
if (contractDecl.spendMethods.length > 0) {
|
|
141
|
+
const spendingRefUniqueName = getUniqueInternalName("spendingRef");
|
|
142
|
+
const optionalDatumUniqueName = getUniqueInternalName("optionalDatum");
|
|
143
|
+
const fields = new Map([
|
|
144
|
+
[
|
|
145
|
+
new Identifier("ref", contractRange),
|
|
146
|
+
SimpleVarDecl.onlyNameConst(spendingRefUniqueName, contractRange)
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
new Identifier("optionalDatum", contractRange),
|
|
150
|
+
SimpleVarDecl.onlyNameConst(optionalDatumUniqueName, contractRange)
|
|
151
|
+
],
|
|
152
|
+
]);
|
|
153
|
+
const bodyStmts = _getMatchedPurposeBlockStatements(compiler, contractDecl.spendMethods, paramsInternalNamesMap,
|
|
154
|
+
// contextVarsMapping
|
|
155
|
+
Object.freeze({
|
|
156
|
+
tx: txUniqueName,
|
|
157
|
+
purposeData: purposeUniqueName,
|
|
158
|
+
redeemerData: redeemerUniqueName,
|
|
159
|
+
spendingRef: spendingRefUniqueName,
|
|
160
|
+
optionalDatum: optionalDatumUniqueName,
|
|
161
|
+
}), "SpendRedeemer", contractRange);
|
|
162
|
+
if (!Array.isArray(bodyStmts))
|
|
163
|
+
return undefined;
|
|
164
|
+
purposeMatchCases.push(new MatchStmtCase(new NamedDeconstructVarDecl(new Identifier("Spend", contractRange), fields, undefined, // rest
|
|
165
|
+
undefined, // type (inferred from initExpr)
|
|
166
|
+
undefined, // initExpr
|
|
167
|
+
CommonFlags.Const, contractRange), new BlockStmt(bodyStmts, contractRange), contractRange));
|
|
168
|
+
}
|
|
169
|
+
if (contractDecl.mintMethods.length > 0) {
|
|
170
|
+
const policyUniqueName = getUniqueInternalName("policy");
|
|
171
|
+
const fields = new Map([
|
|
172
|
+
[
|
|
173
|
+
new Identifier("policy", contractRange),
|
|
174
|
+
SimpleVarDecl.onlyNameConst(policyUniqueName, contractRange)
|
|
175
|
+
],
|
|
176
|
+
]);
|
|
177
|
+
const bodyStmts = _getMatchedPurposeBlockStatements(compiler, contractDecl.mintMethods, paramsInternalNamesMap,
|
|
178
|
+
// contextVarsMapping
|
|
179
|
+
Object.freeze({
|
|
180
|
+
tx: txUniqueName,
|
|
181
|
+
purposeData: purposeUniqueName,
|
|
182
|
+
redeemerData: redeemerUniqueName,
|
|
183
|
+
policy: policyUniqueName,
|
|
184
|
+
}), "MintRedeemer", contractRange);
|
|
185
|
+
if (!Array.isArray(bodyStmts))
|
|
186
|
+
return undefined;
|
|
187
|
+
purposeMatchCases.push(new MatchStmtCase(new NamedDeconstructVarDecl(new Identifier("Mint", contractRange), fields, undefined, // rest
|
|
188
|
+
undefined, // type (inferred from initExpr)
|
|
189
|
+
undefined, // initExpr
|
|
190
|
+
CommonFlags.Const, contractRange), new BlockStmt(bodyStmts, contractRange), contractRange));
|
|
191
|
+
}
|
|
192
|
+
if (contractDecl.withdrawMethods.length > 0) {
|
|
193
|
+
const credentialUniqueName = getUniqueInternalName("credential");
|
|
194
|
+
const fields = new Map([
|
|
195
|
+
[
|
|
196
|
+
new Identifier("credential", contractRange),
|
|
197
|
+
SimpleVarDecl.onlyNameConst(credentialUniqueName, contractRange)
|
|
198
|
+
],
|
|
199
|
+
]);
|
|
200
|
+
const bodyStmts = _getMatchedPurposeBlockStatements(compiler, contractDecl.withdrawMethods, paramsInternalNamesMap,
|
|
201
|
+
// contextVarsMapping
|
|
202
|
+
Object.freeze({
|
|
203
|
+
tx: txUniqueName,
|
|
204
|
+
purposeData: purposeUniqueName,
|
|
205
|
+
redeemerData: redeemerUniqueName,
|
|
206
|
+
policy: credentialUniqueName,
|
|
207
|
+
}), "WithdrawRedeemer", contractRange);
|
|
208
|
+
if (!Array.isArray(bodyStmts))
|
|
209
|
+
return undefined;
|
|
210
|
+
purposeMatchCases.push(new MatchStmtCase(new NamedDeconstructVarDecl(new Identifier("Withdraw", contractRange), fields, undefined, // rest
|
|
211
|
+
undefined, // type (inferred from initExpr)
|
|
212
|
+
undefined, // initExpr
|
|
213
|
+
CommonFlags.Const, contractRange), new BlockStmt(bodyStmts, contractRange), contractRange));
|
|
214
|
+
}
|
|
215
|
+
if (contractDecl.certifyMethods.length > 0) {
|
|
216
|
+
const indexUniqueName = getUniqueInternalName("certificateIndex");
|
|
217
|
+
const certificateUniqueName = getUniqueInternalName("certificate");
|
|
218
|
+
const fields = new Map([
|
|
219
|
+
[
|
|
220
|
+
new Identifier("certificateIndex", contractRange),
|
|
221
|
+
SimpleVarDecl.onlyNameConst(indexUniqueName, contractRange)
|
|
222
|
+
],
|
|
223
|
+
[
|
|
224
|
+
new Identifier("certificate", contractRange),
|
|
225
|
+
SimpleVarDecl.onlyNameConst(certificateUniqueName, contractRange)
|
|
226
|
+
],
|
|
227
|
+
]);
|
|
228
|
+
const bodyStmts = _getMatchedPurposeBlockStatements(compiler, contractDecl.certifyMethods, paramsInternalNamesMap,
|
|
229
|
+
// contextVarsMapping
|
|
230
|
+
Object.freeze({
|
|
231
|
+
tx: txUniqueName,
|
|
232
|
+
purposeData: purposeUniqueName,
|
|
233
|
+
redeemerData: redeemerUniqueName,
|
|
234
|
+
certificateIndex: indexUniqueName,
|
|
235
|
+
certificate: certificateUniqueName,
|
|
236
|
+
}), "CertifyRedeemer", contractRange);
|
|
237
|
+
if (!Array.isArray(bodyStmts))
|
|
238
|
+
return undefined;
|
|
239
|
+
purposeMatchCases.push(new MatchStmtCase(new NamedDeconstructVarDecl(new Identifier("Certificate", contractRange), fields, undefined, // rest
|
|
240
|
+
undefined, // type (inferred from initExpr)
|
|
241
|
+
undefined, // initExpr
|
|
242
|
+
CommonFlags.Const, contractRange), new BlockStmt(bodyStmts, contractRange), contractRange));
|
|
243
|
+
}
|
|
244
|
+
if (contractDecl.proposeMethods.length > 0) {
|
|
245
|
+
const indexUniqueName = getUniqueInternalName("proposalIndex");
|
|
246
|
+
const proposalUniqueName = getUniqueInternalName("proposal");
|
|
247
|
+
const fields = new Map([
|
|
248
|
+
[
|
|
249
|
+
new Identifier("proposalIndex", contractRange),
|
|
250
|
+
SimpleVarDecl.onlyNameConst(indexUniqueName, contractRange)
|
|
251
|
+
],
|
|
252
|
+
[
|
|
253
|
+
new Identifier("proposal", contractRange),
|
|
254
|
+
SimpleVarDecl.onlyNameConst(proposalUniqueName, contractRange)
|
|
255
|
+
],
|
|
256
|
+
]);
|
|
257
|
+
const bodyStmts = _getMatchedPurposeBlockStatements(compiler, contractDecl.proposeMethods, paramsInternalNamesMap,
|
|
258
|
+
// contextVarsMapping
|
|
259
|
+
Object.freeze({
|
|
260
|
+
tx: txUniqueName,
|
|
261
|
+
purposeData: purposeUniqueName,
|
|
262
|
+
redeemerData: redeemerUniqueName,
|
|
263
|
+
proposalIndex: indexUniqueName,
|
|
264
|
+
proposal: proposalUniqueName,
|
|
265
|
+
}), "ProposeRedeemer", contractRange);
|
|
266
|
+
if (!Array.isArray(bodyStmts))
|
|
267
|
+
return undefined;
|
|
268
|
+
purposeMatchCases.push(new MatchStmtCase(new NamedDeconstructVarDecl(new Identifier("Propose", contractRange), fields, undefined, // rest
|
|
269
|
+
undefined, // type (inferred from initExpr)
|
|
270
|
+
undefined, // initExpr
|
|
271
|
+
CommonFlags.Const, contractRange), new BlockStmt(bodyStmts, contractRange), contractRange));
|
|
272
|
+
}
|
|
273
|
+
if (contractDecl.voteMethods.length > 0) {
|
|
274
|
+
const voterUniqueName = getUniqueInternalName("voter");
|
|
275
|
+
const fields = new Map([
|
|
276
|
+
[
|
|
277
|
+
new Identifier("voter", contractRange),
|
|
278
|
+
SimpleVarDecl.onlyNameConst(voterUniqueName, contractRange)
|
|
279
|
+
],
|
|
280
|
+
]);
|
|
281
|
+
const bodyStmts = _getMatchedPurposeBlockStatements(compiler, contractDecl.voteMethods, paramsInternalNamesMap,
|
|
282
|
+
// contextVarsMapping
|
|
283
|
+
Object.freeze({
|
|
284
|
+
tx: txUniqueName,
|
|
285
|
+
purposeData: purposeUniqueName,
|
|
286
|
+
redeemerData: redeemerUniqueName,
|
|
287
|
+
voter: voterUniqueName,
|
|
288
|
+
}), "VoteRedeemer", contractRange);
|
|
289
|
+
if (!Array.isArray(bodyStmts))
|
|
290
|
+
return undefined;
|
|
291
|
+
purposeMatchCases.push(new MatchStmtCase(new NamedDeconstructVarDecl(new Identifier("Vote", contractRange), fields, undefined, // rest
|
|
292
|
+
undefined, // type (inferred from initExpr)
|
|
293
|
+
undefined, // initExpr
|
|
294
|
+
CommonFlags.Const, contractRange), new BlockStmt(bodyStmts, contractRange), contractRange));
|
|
295
|
+
}
|
|
296
|
+
bodyStmts.push(new MatchStmt(new Identifier(purposeUniqueName, contractRange), purposeMatchCases, new MatchStmtElseCase(new FailStmt(undefined, contractRange), contractRange), contractRange));
|
|
297
|
+
bodyStmts.push(new FailStmt(undefined, contractRange)); // unreachable in theory (else case)
|
|
298
|
+
return new BlockStmt(bodyStmts, contractRange);
|
|
299
|
+
}
|
|
300
|
+
function _getMatchedPurposeBlockStatements(compiler, methods, paramsInternalNamesMap, contextVarsMapping, baseRedeemerName, contractRange) {
|
|
301
|
+
// usually 0 methods is checked before calling
|
|
302
|
+
// but just in case it is not, we handle it here
|
|
303
|
+
if (methods.length === 0)
|
|
304
|
+
return [
|
|
305
|
+
new FailStmt(undefined, contractRange)
|
|
306
|
+
];
|
|
307
|
+
const redeemerTypeDef = _deriveRedeemerTypeDef(baseRedeemerName, // "SpendRedeemer",
|
|
308
|
+
methods, contractRange);
|
|
309
|
+
compiler.registerInternalTypeDecl(redeemerTypeDef);
|
|
310
|
+
// if only one method, we can inline it
|
|
311
|
+
if (methods.length === 1) {
|
|
312
|
+
const method = methods[0];
|
|
313
|
+
const stmts = _getRedeemerMethodBlockStatemets(compiler, method, redeemerTypeDef, paramsInternalNamesMap, contextVarsMapping);
|
|
314
|
+
if (!Array.isArray(stmts))
|
|
315
|
+
return undefined;
|
|
316
|
+
return stmts;
|
|
317
|
+
}
|
|
318
|
+
// multiple methods, need to match redeemer
|
|
319
|
+
const redeemerMatchCases = [];
|
|
320
|
+
for (const method of methods) {
|
|
321
|
+
const stmts = _getRedeemerMethodBlockStatemets(compiler, method, redeemerTypeDef, paramsInternalNamesMap, contextVarsMapping);
|
|
322
|
+
if (!Array.isArray(stmts))
|
|
323
|
+
return undefined;
|
|
324
|
+
redeemerMatchCases.push(new MatchStmtCase(new NamedDeconstructVarDecl(new Identifier(method.expr.name.text, method.expr.name.range), new Map(redeemerTypeDef.constrs.find(c => c.name.text === method.expr.name.text).fields.map((fieldDef, i) => {
|
|
325
|
+
const param = method.expr.signature.params[i];
|
|
326
|
+
const range = param.range;
|
|
327
|
+
return [
|
|
328
|
+
new Identifier(fieldDef.name.text, range),
|
|
329
|
+
param
|
|
330
|
+
];
|
|
331
|
+
})), undefined, // rest
|
|
332
|
+
undefined, // type (inferred from initExpr)
|
|
333
|
+
undefined, // initExpr
|
|
334
|
+
CommonFlags.Const, method.expr.name.range), new BlockStmt(stmts, contractRange), method.expr.range));
|
|
335
|
+
}
|
|
336
|
+
return [
|
|
337
|
+
new MatchStmt(new TypeConversionExpr(new Identifier(contextVarsMapping.redeemerData, contractRange), new AstNamedTypeExpr(new Identifier(redeemerTypeDef.name.text, contractRange), [], // typeArgs
|
|
338
|
+
contractRange)), redeemerMatchCases, new MatchStmtElseCase(new FailStmt(undefined, contractRange), contractRange), contractRange),
|
|
339
|
+
new FailStmt(undefined, contractRange) // unreachable in theory (else case)
|
|
340
|
+
];
|
|
341
|
+
}
|
|
342
|
+
function _getRedeemerMethodBlockStatemets(compiler, method, redeemerTypeDef, paramsInternalNamesMap, contextVarsMapping,
|
|
343
|
+
/**
|
|
344
|
+
* remember destructured context fields that have been renamed
|
|
345
|
+
*/
|
|
346
|
+
renamedVariables = {}) {
|
|
347
|
+
const redeemerTypeName = redeemerTypeDef.name.text;
|
|
348
|
+
const methodExpr = method.expr;
|
|
349
|
+
const redeemerTypeConstr = redeemerTypeDef.constrs.find(constr => constr.name.text === method.expr.name.text);
|
|
350
|
+
if (!redeemerTypeConstr)
|
|
351
|
+
throw new Error(`unreachable Internal Error: missing redeemer constructor ${method.expr.name.text}`);
|
|
352
|
+
if (redeemerTypeConstr.fields.length !== methodExpr.signature.params.length)
|
|
353
|
+
throw new Error(`unreachable Internal Error: redeemer constructor ${method.expr.name.text} fields length missmatch with method parameters length`);
|
|
354
|
+
const result = _getMatchedRedeemerBlockStatements(compiler, methodExpr.bodyBlockStmt().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
355
|
+
if (!Array.isArray(result))
|
|
356
|
+
return undefined;
|
|
357
|
+
// prepend redeemer fields destructuring if single method for this purpose
|
|
358
|
+
if (redeemerTypeDef.constrs.length === 1
|
|
359
|
+
&& methodExpr.signature.params.length > 0) {
|
|
360
|
+
const fields = new Map(redeemerTypeConstr.fields.map((fieldDef, i) => {
|
|
361
|
+
const param = methodExpr.signature.params[i];
|
|
362
|
+
const range = param.range;
|
|
363
|
+
return [
|
|
364
|
+
new Identifier(fieldDef.name.text, range),
|
|
365
|
+
param
|
|
366
|
+
];
|
|
367
|
+
}));
|
|
368
|
+
result.unshift(new NamedDeconstructVarDecl(method.expr.name, fields, undefined, // rest
|
|
369
|
+
undefined, // type (inferred from initExpr)
|
|
370
|
+
new TypeConversionExpr(new Identifier(contextVarsMapping.redeemerData, method.range), new AstNamedTypeExpr(new Identifier(redeemerTypeName, method.range), [], // typeArgs
|
|
371
|
+
method.range)), // initExpr
|
|
372
|
+
CommonFlags.Const, method.range));
|
|
373
|
+
}
|
|
374
|
+
;
|
|
375
|
+
// always add implicit return void (unit) at the end of a method
|
|
376
|
+
result.push(new ReturnStmt(new LitVoidExpr(methodExpr.range.atEnd()), methodExpr.range.atEnd()));
|
|
377
|
+
return result;
|
|
378
|
+
}
|
|
379
|
+
function _getMatchedRedeemerBlockStatements(compiler, stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables) {
|
|
380
|
+
const result = stmts.slice();
|
|
381
|
+
for (let i = 0; i < result.length; i++) {
|
|
382
|
+
const stmt = result[i];
|
|
383
|
+
if (stmt instanceof VarStmt) {
|
|
384
|
+
if (stmt.declarations.length !== 1) {
|
|
385
|
+
for (const varDecl of stmt.declarations) {
|
|
386
|
+
if (varDecl.initExpr)
|
|
387
|
+
varDecl.initExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, varDecl.initExpr, paramsInternalNamesMap, renamedVariables);
|
|
388
|
+
}
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const varDecl = stmt.declarations[0];
|
|
392
|
+
if (!(varDecl.initExpr instanceof LitContextExpr)) {
|
|
393
|
+
// normal var decl
|
|
394
|
+
if (varDecl.initExpr)
|
|
395
|
+
varDecl.initExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, varDecl.initExpr, paramsInternalNamesMap, renamedVariables);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
// varDecl.initExpr is a LitContextExpr
|
|
399
|
+
// handle context destructuring
|
|
400
|
+
if (!(varDecl instanceof SingleDeconstructVarDecl))
|
|
401
|
+
return compiler.error(DiagnosticCode._context_can_only_be_destructured_as_an_unnamed_object, varDecl.range);
|
|
402
|
+
if (!varDecl.isConst())
|
|
403
|
+
return compiler.error(DiagnosticCode._context_can_only_be_destructured_in_a_constant_declaration, varDecl.range);
|
|
404
|
+
/**
|
|
405
|
+
* statements to push instead of the context destructuring
|
|
406
|
+
* (nested fields destructured)
|
|
407
|
+
**/
|
|
408
|
+
const newStmts = [];
|
|
409
|
+
const destructuredFieldsIds = [];
|
|
410
|
+
// introduce destructured variables as renamed variables
|
|
411
|
+
for (let [fieldIdentifier, fieldVarDecl] of varDecl.fields) {
|
|
412
|
+
if (!(contextVarsMapping && isObject(contextVarsMapping))) {
|
|
413
|
+
return compiler.error(DiagnosticCode._context_can_only_be_accessed_in_a_contract_method, fieldIdentifier.range);
|
|
414
|
+
}
|
|
415
|
+
const realVarName = contextVarsMapping[fieldIdentifier.text];
|
|
416
|
+
if (!realVarName && typeof realVarName !== "string") {
|
|
417
|
+
return compiler.error(DiagnosticCode._0_is_not_aviable_in_this_contract_method_context, fieldIdentifier.range, fieldIdentifier.text);
|
|
418
|
+
}
|
|
419
|
+
if (destructuredFieldsIds.includes(fieldIdentifier.text)) {
|
|
420
|
+
return compiler.error(DiagnosticCode.Duplicate_identifier_0, fieldVarDecl.range, fieldIdentifier.text);
|
|
421
|
+
}
|
|
422
|
+
destructuredFieldsIds.push(fieldIdentifier.text);
|
|
423
|
+
if (!(fieldVarDecl instanceof SimpleVarDecl)) {
|
|
424
|
+
const uniqueName = getUniqueInternalName(fieldIdentifier.text);
|
|
425
|
+
// move nested field destructuring outside of this destructuring
|
|
426
|
+
fieldVarDecl.initExpr = new Identifier(uniqueName, fieldIdentifier.range);
|
|
427
|
+
fieldVarDecl.flags |= CommonFlags.Const;
|
|
428
|
+
newStmts.push(fieldVarDecl);
|
|
429
|
+
// replace destructured field with a simple renaming of the field
|
|
430
|
+
fieldVarDecl = SimpleVarDecl.onlyNameConst(uniqueName, fieldIdentifier.range);
|
|
431
|
+
}
|
|
432
|
+
const introducedVarName = fieldVarDecl.name.text;
|
|
433
|
+
if (renamedVariables[introducedVarName])
|
|
434
|
+
return compiler.error(DiagnosticCode.Duplicate_identifier_0, fieldVarDecl.range, fieldIdentifier.text);
|
|
435
|
+
// when reading `introducedVarName`, it will be replaced with `realVarName`
|
|
436
|
+
renamedVariables[introducedVarName] = realVarName;
|
|
437
|
+
}
|
|
438
|
+
// remove the context destrucuturing statement from the result
|
|
439
|
+
// push new ones if any
|
|
440
|
+
result.splice(i, 1, ...newStmts);
|
|
441
|
+
i--;
|
|
442
|
+
continue;
|
|
443
|
+
} // if( stmt instanceof VarStmt )
|
|
444
|
+
if (stmt instanceof BreakStmt
|
|
445
|
+
|| stmt instanceof ContinueStmt
|
|
446
|
+
|| stmt instanceof EmptyStmt
|
|
447
|
+
|| stmt instanceof UsingStmt)
|
|
448
|
+
continue;
|
|
449
|
+
if (isImplicitAssignmentStmt(stmt))
|
|
450
|
+
continue;
|
|
451
|
+
if (isExplicitAssignmentStmt(stmt)) {
|
|
452
|
+
const newAssingedExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.assignedExpr, paramsInternalNamesMap, renamedVariables);
|
|
453
|
+
if (!newAssingedExpr)
|
|
454
|
+
return undefined;
|
|
455
|
+
stmt.assignedExpr = newAssingedExpr;
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
if (stmt instanceof BlockStmt) {
|
|
459
|
+
const nextBodyStmts = _getMatchedRedeemerBlockStatements(compiler, stmt.stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
460
|
+
if (!Array.isArray(nextBodyStmts))
|
|
461
|
+
return undefined;
|
|
462
|
+
stmt.stmts = nextBodyStmts;
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (stmt instanceof ReturnStmt) {
|
|
466
|
+
if (!stmt.value)
|
|
467
|
+
continue;
|
|
468
|
+
const newReturnExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.value, paramsInternalNamesMap, renamedVariables);
|
|
469
|
+
if (!newReturnExpr)
|
|
470
|
+
return undefined;
|
|
471
|
+
stmt.value = newReturnExpr;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (stmt instanceof IfStmt) {
|
|
475
|
+
const nextContidionExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.condition, paramsInternalNamesMap, renamedVariables);
|
|
476
|
+
if (!nextContidionExpr)
|
|
477
|
+
return undefined;
|
|
478
|
+
stmt.condition = nextContidionExpr;
|
|
479
|
+
const nextThenStmts = _getMatchedRedeemerBlockStatements(compiler, stmt.thenBranchBlock().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
480
|
+
if (!Array.isArray(nextThenStmts))
|
|
481
|
+
return undefined;
|
|
482
|
+
stmt.thenBranch = new BlockStmt(nextThenStmts, stmt.thenBranch.range);
|
|
483
|
+
if (stmt.elseBranch) {
|
|
484
|
+
const nextElseStmts = _getMatchedRedeemerBlockStatements(compiler, stmt.elseBranchBlock().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
485
|
+
if (!Array.isArray(nextElseStmts))
|
|
486
|
+
return undefined;
|
|
487
|
+
stmt.elseBranch = new BlockStmt(nextElseStmts, stmt.elseBranch.range);
|
|
488
|
+
}
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (stmt instanceof MatchStmt) {
|
|
492
|
+
const nextMatchExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.matchExpr, paramsInternalNamesMap, renamedVariables);
|
|
493
|
+
if (!nextMatchExpr)
|
|
494
|
+
return undefined;
|
|
495
|
+
stmt.matchExpr = nextMatchExpr;
|
|
496
|
+
for (let i = 0; i < stmt.cases.length; i++) {
|
|
497
|
+
const c = stmt.cases[i];
|
|
498
|
+
const nextCaseBody = _getMatchedRedeemerBlockStatements(compiler, c.bodyBlockStmt().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
499
|
+
if (!Array.isArray(nextCaseBody))
|
|
500
|
+
return undefined;
|
|
501
|
+
c.body = new BlockStmt(nextCaseBody, c.body.range);
|
|
502
|
+
}
|
|
503
|
+
if (stmt.elseCase) {
|
|
504
|
+
const nextElseBody = _getMatchedRedeemerBlockStatements(compiler, stmt.elseCase.bodyBlockStmt().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
505
|
+
if (!Array.isArray(nextElseBody))
|
|
506
|
+
return undefined;
|
|
507
|
+
stmt.elseCase.body = new BlockStmt(nextElseBody, stmt.elseCase.body.range);
|
|
508
|
+
}
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (stmt instanceof FailStmt) {
|
|
512
|
+
if (!stmt.value)
|
|
513
|
+
continue;
|
|
514
|
+
const newFailExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.value, paramsInternalNamesMap, renamedVariables);
|
|
515
|
+
if (!newFailExpr)
|
|
516
|
+
return undefined;
|
|
517
|
+
stmt.value = newFailExpr;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (stmt instanceof AssertStmt) {
|
|
521
|
+
const newConditionExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.condition, paramsInternalNamesMap, renamedVariables);
|
|
522
|
+
if (!newConditionExpr)
|
|
523
|
+
return undefined;
|
|
524
|
+
stmt.condition = newConditionExpr;
|
|
525
|
+
if (stmt.elseExpr) {
|
|
526
|
+
const newElseExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.elseExpr, paramsInternalNamesMap, renamedVariables);
|
|
527
|
+
if (!newElseExpr)
|
|
528
|
+
return undefined;
|
|
529
|
+
stmt.elseExpr = newElseExpr;
|
|
530
|
+
}
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (stmt instanceof ForStmt) {
|
|
534
|
+
if (stmt.init) {
|
|
535
|
+
const nextInitStmts = _getMatchedRedeemerBlockStatements(compiler, [stmt.init], paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
536
|
+
if (!(Array.isArray(nextInitStmts)
|
|
537
|
+
&& nextInitStmts.length === 1))
|
|
538
|
+
return undefined;
|
|
539
|
+
const nextInit = nextInitStmts[0];
|
|
540
|
+
if (!(nextInit instanceof VarStmt))
|
|
541
|
+
throw new Error("unreachable::_getMatchedRedeemerBlockStatements::ForStmt::init");
|
|
542
|
+
stmt.init = nextInit;
|
|
543
|
+
}
|
|
544
|
+
if (stmt.condition) {
|
|
545
|
+
const newConditionExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.condition, paramsInternalNamesMap, renamedVariables);
|
|
546
|
+
if (!newConditionExpr)
|
|
547
|
+
return undefined;
|
|
548
|
+
stmt.condition = newConditionExpr;
|
|
549
|
+
}
|
|
550
|
+
for (let i = 0; i < stmt.updates.length; i++) {
|
|
551
|
+
const updateStmt = stmt.updates[i];
|
|
552
|
+
const nextUpdateStmts = _getMatchedRedeemerBlockStatements(compiler, [updateStmt], paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
553
|
+
if (!(Array.isArray(nextUpdateStmts)
|
|
554
|
+
&& nextUpdateStmts.length === 1))
|
|
555
|
+
return undefined;
|
|
556
|
+
const nextUpdateStmt = nextUpdateStmts[0];
|
|
557
|
+
if (!(isImplicitAssignmentStmt(nextUpdateStmt) || isExplicitAssignmentStmt(nextUpdateStmt)))
|
|
558
|
+
throw new Error("unreachable::_getMatchedRedeemerBlockStatements::ForStmt::update");
|
|
559
|
+
stmt.updates[i] = nextUpdateStmt;
|
|
560
|
+
}
|
|
561
|
+
const nextBodyStmts = _getMatchedRedeemerBlockStatements(compiler, stmt.bodyBlock().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
562
|
+
if (!Array.isArray(nextBodyStmts))
|
|
563
|
+
return undefined;
|
|
564
|
+
stmt.body = new BlockStmt(nextBodyStmts, stmt.body.range);
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
if (stmt instanceof ForOfStmt) {
|
|
568
|
+
const newIterableExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.iterable, paramsInternalNamesMap, renamedVariables);
|
|
569
|
+
if (!newIterableExpr)
|
|
570
|
+
return undefined;
|
|
571
|
+
stmt.iterable = newIterableExpr;
|
|
572
|
+
const nextBodyStmts = _getMatchedRedeemerBlockStatements(compiler, stmt.bodyBlock().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
573
|
+
if (!Array.isArray(nextBodyStmts))
|
|
574
|
+
return undefined;
|
|
575
|
+
stmt.body = new BlockStmt(nextBodyStmts, stmt.body.range);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (stmt instanceof WhileStmt) {
|
|
579
|
+
const newConditionExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, stmt.condition, paramsInternalNamesMap, renamedVariables);
|
|
580
|
+
if (!newConditionExpr)
|
|
581
|
+
return undefined;
|
|
582
|
+
stmt.condition = newConditionExpr;
|
|
583
|
+
const nextBodyStmts = _getMatchedRedeemerBlockStatements(compiler, stmt.bodyBlock().stmts, paramsInternalNamesMap, contextVarsMapping, renamedVariables);
|
|
584
|
+
if (!Array.isArray(nextBodyStmts))
|
|
585
|
+
return undefined;
|
|
586
|
+
stmt.body = new BlockStmt(nextBodyStmts, stmt.body.range);
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
const tsEnsureExhaustiveCheck = stmt;
|
|
590
|
+
throw new Error("unreachable::_getMatchedRedeemerBlockStatements::stmt::");
|
|
591
|
+
}
|
|
592
|
+
return result;
|
|
593
|
+
}
|
|
594
|
+
function _exprReplaceParamsAndAssertNoLitContext(compiler, expr, paramsInternalNamesMap, renamedVariables) {
|
|
595
|
+
if (expr instanceof LitContextExpr)
|
|
596
|
+
return compiler.error(DiagnosticCode._context_can_only_be_destructured_as_an_unnamed_object, expr.range);
|
|
597
|
+
if (isPropAccessExpr(expr) && expr.object instanceof LitThisExpr) {
|
|
598
|
+
const paramName = expr.prop.text;
|
|
599
|
+
const internalName = paramsInternalNamesMap.get(paramName);
|
|
600
|
+
if (!internalName)
|
|
601
|
+
return compiler.error(DiagnosticCode._0_is_not_a_contract_parameter, expr.prop.range, paramName);
|
|
602
|
+
return new Identifier(internalName, expr.range);
|
|
603
|
+
}
|
|
604
|
+
if (expr instanceof LitThisExpr)
|
|
605
|
+
return compiler.error(DiagnosticCode._this_in_a_contract_context_can_only_be_used_to_read_parameters_in_a_contract_method, expr.range);
|
|
606
|
+
if (expr instanceof Identifier) {
|
|
607
|
+
const renamed = renamedVariables[expr.text];
|
|
608
|
+
if (renamed)
|
|
609
|
+
return new Identifier(renamed, expr.range);
|
|
610
|
+
return expr;
|
|
611
|
+
}
|
|
612
|
+
if (isUnaryPrefixExpr(expr)
|
|
613
|
+
|| expr instanceof NonNullExpr) {
|
|
614
|
+
const newOperand = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.operand, paramsInternalNamesMap, renamedVariables);
|
|
615
|
+
if (!newOperand)
|
|
616
|
+
return undefined;
|
|
617
|
+
expr.operand = newOperand;
|
|
618
|
+
return expr;
|
|
619
|
+
}
|
|
620
|
+
if (
|
|
621
|
+
// isLitteralExpr( expr )
|
|
622
|
+
expr instanceof LitVoidExpr
|
|
623
|
+
|| expr instanceof LitUndefExpr
|
|
624
|
+
|| expr instanceof LitTrueExpr
|
|
625
|
+
|| expr instanceof LitFalseExpr
|
|
626
|
+
|| expr instanceof LitThisExpr
|
|
627
|
+
|| expr instanceof LitContextExpr
|
|
628
|
+
|| expr instanceof LitArrExpr
|
|
629
|
+
|| expr instanceof LitObjExpr
|
|
630
|
+
|| expr instanceof LitNamedObjExpr
|
|
631
|
+
|| expr instanceof LitStrExpr
|
|
632
|
+
|| expr instanceof LitIntExpr
|
|
633
|
+
|| expr instanceof LitHexBytesExpr
|
|
634
|
+
|| expr instanceof LitFailExpr)
|
|
635
|
+
return expr;
|
|
636
|
+
if (isBinaryExpr(expr)) {
|
|
637
|
+
const newLeft = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.left, paramsInternalNamesMap, renamedVariables);
|
|
638
|
+
if (!newLeft)
|
|
639
|
+
return undefined;
|
|
640
|
+
expr.left = newLeft;
|
|
641
|
+
const newRight = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.right, paramsInternalNamesMap, renamedVariables);
|
|
642
|
+
if (!newRight)
|
|
643
|
+
return undefined;
|
|
644
|
+
expr.right = newRight;
|
|
645
|
+
return expr;
|
|
646
|
+
}
|
|
647
|
+
if (expr instanceof ParentesizedExpr) {
|
|
648
|
+
const newInner = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.expr, paramsInternalNamesMap, renamedVariables);
|
|
649
|
+
if (!newInner)
|
|
650
|
+
return undefined;
|
|
651
|
+
expr.expr = newInner;
|
|
652
|
+
return expr;
|
|
653
|
+
}
|
|
654
|
+
if (expr instanceof TypeConversionExpr) {
|
|
655
|
+
const newInner = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.expr, paramsInternalNamesMap, renamedVariables);
|
|
656
|
+
if (!newInner)
|
|
657
|
+
return undefined;
|
|
658
|
+
expr.expr = newInner;
|
|
659
|
+
return expr;
|
|
660
|
+
}
|
|
661
|
+
if (isPropAccessExpr(expr)) {
|
|
662
|
+
const newObject = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.object, paramsInternalNamesMap, renamedVariables);
|
|
663
|
+
if (!newObject)
|
|
664
|
+
return undefined;
|
|
665
|
+
expr.object = newObject;
|
|
666
|
+
return expr;
|
|
667
|
+
}
|
|
668
|
+
if (expr instanceof ElemAccessExpr) {
|
|
669
|
+
const newObj = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.arrLikeExpr, paramsInternalNamesMap, renamedVariables);
|
|
670
|
+
if (!newObj)
|
|
671
|
+
return undefined;
|
|
672
|
+
expr.arrLikeExpr = newObj;
|
|
673
|
+
const newIndex = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.indexExpr, paramsInternalNamesMap, renamedVariables);
|
|
674
|
+
if (!newIndex)
|
|
675
|
+
return undefined;
|
|
676
|
+
expr.indexExpr = newIndex;
|
|
677
|
+
return expr;
|
|
678
|
+
}
|
|
679
|
+
if (expr instanceof TernaryExpr) {
|
|
680
|
+
const newCondition = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.condition, paramsInternalNamesMap, renamedVariables);
|
|
681
|
+
if (!newCondition)
|
|
682
|
+
return undefined;
|
|
683
|
+
expr.condition = newCondition;
|
|
684
|
+
const newIfTrue = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.ifTrue, paramsInternalNamesMap, renamedVariables);
|
|
685
|
+
if (!newIfTrue)
|
|
686
|
+
return undefined;
|
|
687
|
+
expr.ifTrue = newIfTrue;
|
|
688
|
+
const newIfFalse = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.ifFalse, paramsInternalNamesMap, renamedVariables);
|
|
689
|
+
if (!newIfFalse)
|
|
690
|
+
return undefined;
|
|
691
|
+
expr.ifFalse = newIfFalse;
|
|
692
|
+
return expr;
|
|
693
|
+
}
|
|
694
|
+
if (expr instanceof CaseExpr) {
|
|
695
|
+
const newTestExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.matchExpr, paramsInternalNamesMap, renamedVariables);
|
|
696
|
+
if (!newTestExpr)
|
|
697
|
+
return undefined;
|
|
698
|
+
expr.matchExpr = newTestExpr;
|
|
699
|
+
for (let i = 0; i < expr.cases.length; i++) {
|
|
700
|
+
const c = expr.cases[i];
|
|
701
|
+
const newCaseBody = _exprReplaceParamsAndAssertNoLitContext(compiler, c.body, paramsInternalNamesMap, renamedVariables);
|
|
702
|
+
if (!newCaseBody)
|
|
703
|
+
return undefined;
|
|
704
|
+
c.body = newCaseBody;
|
|
705
|
+
}
|
|
706
|
+
if (expr.wildcardCase) {
|
|
707
|
+
const newWildcardBody = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.wildcardCase.body, paramsInternalNamesMap, renamedVariables);
|
|
708
|
+
if (!newWildcardBody)
|
|
709
|
+
return undefined;
|
|
710
|
+
expr.wildcardCase.body = newWildcardBody;
|
|
711
|
+
}
|
|
712
|
+
return expr;
|
|
713
|
+
}
|
|
714
|
+
if (expr instanceof CallExpr) {
|
|
715
|
+
const newCallee = _exprReplaceParamsAndAssertNoLitContext(compiler, expr.funcExpr, paramsInternalNamesMap, renamedVariables);
|
|
716
|
+
if (!newCallee)
|
|
717
|
+
return undefined;
|
|
718
|
+
expr.funcExpr = newCallee;
|
|
719
|
+
for (let i = 0; i < expr.args.length; i++) {
|
|
720
|
+
const arg = expr.args[i];
|
|
721
|
+
const newArg = _exprReplaceParamsAndAssertNoLitContext(compiler, arg, paramsInternalNamesMap, renamedVariables);
|
|
722
|
+
if (!newArg)
|
|
723
|
+
return undefined;
|
|
724
|
+
expr.args[i] = newArg;
|
|
725
|
+
}
|
|
726
|
+
return expr;
|
|
727
|
+
}
|
|
728
|
+
if (expr instanceof FuncExpr) {
|
|
729
|
+
const sigParams = expr.signature.params;
|
|
730
|
+
for (const param of sigParams) {
|
|
731
|
+
if (param.initExpr)
|
|
732
|
+
param.initExpr = _exprReplaceParamsAndAssertNoLitContext(compiler, param.initExpr, paramsInternalNamesMap, renamedVariables);
|
|
733
|
+
}
|
|
734
|
+
const nextBodyStmts = _getMatchedRedeemerBlockStatements(compiler, expr.bodyBlockStmt().stmts, paramsInternalNamesMap, undefined, // contextVarsMapping,
|
|
735
|
+
renamedVariables);
|
|
736
|
+
if (!Array.isArray(nextBodyStmts))
|
|
737
|
+
return undefined;
|
|
738
|
+
expr.body = new BlockStmt(nextBodyStmts, expr.body.range);
|
|
739
|
+
return expr;
|
|
740
|
+
}
|
|
741
|
+
const tsEnsureExhaustiveCheck = expr;
|
|
742
|
+
console.error(expr);
|
|
743
|
+
throw new Error("unreachable::_exprReplaceParamsAndAssertNoLitContext");
|
|
744
|
+
}
|
|
745
|
+
function _deriveRedeemerTypeDef(redeemerName, methods, contractRange) {
|
|
746
|
+
let defFlags = StructDeclAstFlags.onlyDataEncoding;
|
|
747
|
+
if (methods.length <= 1)
|
|
748
|
+
defFlags |= StructDeclAstFlags.untaggedSingleConstructor;
|
|
749
|
+
const uniqueName = getUniqueInternalName(redeemerName);
|
|
750
|
+
return new StructDecl(new Identifier(uniqueName, contractRange), [], // typeParams
|
|
751
|
+
methods.map(m => {
|
|
752
|
+
const methodParams = m.expr.signature.params;
|
|
753
|
+
if (!methodParams.every(p => p instanceof SimpleVarDecl && !p.initExpr && p.type))
|
|
754
|
+
throw new Error("Contract method parameters not simplified befor inferring redeemer definition.");
|
|
755
|
+
return new StructConstrDecl(new Identifier(m.expr.name.text, m.expr.name.range), methodParams, contractRange);
|
|
756
|
+
}), // contructors
|
|
757
|
+
defFlags, contractRange);
|
|
758
|
+
/*
|
|
759
|
+
return new TirDataStructType(
|
|
760
|
+
uniqueName,
|
|
761
|
+
"", // fileUid
|
|
762
|
+
methods.map( m =>
|
|
763
|
+
new TirStructConstr(
|
|
764
|
+
m.expr.name.text,
|
|
765
|
+
m.expr.signature.params.map( p =>
|
|
766
|
+
new TirStructField(
|
|
767
|
+
p.name.text,
|
|
768
|
+
p.type!,
|
|
769
|
+
)
|
|
770
|
+
)
|
|
771
|
+
)
|
|
772
|
+
),
|
|
773
|
+
new Map(), // no methods
|
|
774
|
+
methods.length <= 1, // untagged if there is only one method
|
|
775
|
+
);
|
|
776
|
+
//*/
|
|
777
|
+
}
|