@harmoniclabs/pebble 0.1.0-dev5 → 0.1.0-dev7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/IR/IRHash.d.ts +3 -3
- package/dist/IR/IRHash.js +47 -52
- package/dist/IR/IRNodes/IRApp.d.ts +12 -8
- package/dist/IR/IRNodes/IRApp.js +34 -20
- package/dist/IR/IRNodes/IRCase.d.ts +11 -7
- package/dist/IR/IRNodes/IRCase.js +33 -32
- package/dist/IR/IRNodes/IRConst.d.ts +7 -5
- package/dist/IR/IRNodes/IRConst.js +23 -13
- package/dist/IR/IRNodes/IRConstr.d.ts +11 -7
- package/dist/IR/IRNodes/IRConstr.js +34 -37
- package/dist/IR/IRNodes/IRDelayed.d.ts +12 -9
- package/dist/IR/IRNodes/IRDelayed.js +22 -18
- package/dist/IR/IRNodes/IRError.d.ts +9 -6
- package/dist/IR/IRNodes/IRError.js +12 -5
- package/dist/IR/IRNodes/IRForced.d.ts +9 -6
- package/dist/IR/IRNodes/IRForced.js +22 -18
- package/dist/IR/IRNodes/IRFunc.d.ts +14 -10
- package/dist/IR/IRNodes/IRFunc.js +35 -38
- package/dist/IR/IRNodes/IRHoisted.d.ts +16 -9
- package/dist/IR/IRNodes/IRHoisted.js +36 -18
- package/dist/IR/IRNodes/IRLetted.d.ts +14 -34
- package/dist/IR/IRNodes/IRLetted.js +65 -297
- package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +3 -3
- package/dist/IR/IRNodes/IRNative/IRNativeTag.js +4 -4
- package/dist/IR/IRNodes/IRNative/index.d.ts +10 -8
- package/dist/IR/IRNodes/IRNative/index.js +56 -18
- package/dist/IR/IRNodes/IRNative/isForcedNative.d.ts +2 -0
- package/dist/IR/IRNodes/IRNative/isForcedNative.js +1 -1
- package/dist/IR/IRNodes/IRRecursive.d.ts +18 -10
- package/dist/IR/IRNodes/IRRecursive.js +36 -44
- package/dist/IR/IRNodes/IRSelfCall.d.ts +10 -24
- package/dist/IR/IRNodes/IRSelfCall.js +25 -87
- package/dist/IR/IRNodes/IRVar.d.ts +11 -19
- package/dist/IR/IRNodes/IRVar.js +26 -54
- package/dist/IR/IRNodes/utils/dependsByDbns.d.ts +1 -1
- package/dist/IR/IRNodes/utils/dependsByDbns.js +5 -11
- package/dist/IR/IRNodes/utils/hashVarSym.d.ts +1 -0
- package/dist/IR/IRNodes/utils/hashVarSym.js +37 -0
- package/dist/IR/IRNodes/utils/makeArrayLikeProxy.d.ts +2 -1
- package/dist/IR/IRTerm.d.ts +7 -0
- package/dist/IR/toUPLC/CompilerOptions.d.ts +5 -0
- package/dist/IR/toUPLC/CompilerOptions.js +10 -1
- package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +3 -0
- package/dist/IR/toUPLC/_internal/findAll.js +2 -73
- package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +7 -34
- package/dist/IR/toUPLC/_internal/iterTree.js +3 -17
- package/dist/IR/toUPLC/common_hoisted.d.ts +2 -0
- package/dist/IR/toUPLC/common_hoisted.js +4 -0
- package/dist/IR/toUPLC/compileIRToUPLC.d.ts +1 -1
- package/dist/IR/toUPLC/compileIRToUPLC.js +91 -14
- package/dist/IR/toUPLC/ctx/ToUplcCtx.d.ts +16 -0
- package/dist/IR/toUPLC/ctx/ToUplcCtx.js +67 -0
- package/dist/IR/toUPLC/subRoutines/_comptimeDropN.d.ts +8 -0
- package/dist/IR/toUPLC/subRoutines/_comptimeDropN.js +95 -0
- package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +7 -54
- package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +6 -13
- package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +65 -71
- package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +44 -170
- package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +7 -3
- package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +3 -2
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.d.ts +22 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.js +59 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts +0 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.js +217 -0
- package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +12 -49
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +1 -1
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +11 -14
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/{index.d.ts → performUplcOptimizationsAndReturnRoot.d.ts} +0 -2
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +151 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.d.ts +11 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.js +46 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.d.ts +2 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js +80 -0
- package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +18 -11
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +45 -0
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +277 -478
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.d.ts +2 -0
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +85 -0
- package/dist/IR/toUPLC/subRoutines/sanifyTree.js +1 -0
- package/dist/IR/toUPLC/utils/getApplicationTerms.d.ts +6 -0
- package/dist/IR/toUPLC/utils/getApplicationTerms.js +37 -0
- package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +2 -2
- package/dist/IR/tree_utils/_ir_lazyChooseList.js +4 -2
- package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +1 -1
- package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +4 -2
- package/dist/IR/tree_utils/_ir_let.d.ts +2 -1
- package/dist/IR/tree_utils/_ir_let.js +6 -2
- package/dist/IR/utils/isClosedIRTerm.d.ts +1 -0
- package/dist/IR/utils/isClosedIRTerm.js +40 -26
- package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
- package/dist/IR/utils/positiveIntAsBytes.js +4 -4
- package/dist/IR/utils/showIR.d.ts +10 -21
- package/dist/IR/utils/showIR.js +66 -64
- package/dist/ast/nodes/common/Identifier.d.ts +1 -0
- package/dist/ast/nodes/common/Identifier.js +3 -0
- package/dist/ast/nodes/expr/CaseExpr.d.ts +5 -5
- package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +2 -2
- package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +1 -1
- package/dist/ast/nodes/expr/PebbleExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/PropAccessExpr.d.ts +3 -3
- package/dist/ast/nodes/expr/TernaryExpr.d.ts +3 -3
- package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/TypeConversionExpr.js +2 -0
- package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +42 -42
- package/dist/ast/nodes/expr/functions/CallExpr.d.ts +1 -1
- package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/functions/FuncExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitContextExpr.d.ts +6 -0
- package/dist/ast/nodes/expr/litteral/LitContextExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitFailExpr.d.ts +6 -0
- package/dist/ast/nodes/expr/litteral/LitFailExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +3 -1
- package/dist/ast/nodes/expr/litteral/LitteralExpr.js +5 -1
- package/dist/ast/nodes/statements/AssertStmt.d.ts +2 -2
- package/dist/ast/nodes/statements/AssignmentStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/BlockStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/FailStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/ForOfStmt.d.ts +4 -2
- package/dist/ast/nodes/statements/ForOfStmt.js +6 -0
- package/dist/ast/nodes/statements/ForStmt.d.ts +6 -4
- package/dist/ast/nodes/statements/ForStmt.js +6 -0
- package/dist/ast/nodes/statements/IfStmt.d.ts +8 -5
- package/dist/ast/nodes/statements/IfStmt.js +13 -0
- package/dist/ast/nodes/statements/MatchStmt.d.ts +13 -4
- package/dist/ast/nodes/statements/MatchStmt.js +22 -1
- package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
- package/dist/ast/nodes/statements/PebbleStmt.js +3 -1
- package/dist/ast/nodes/statements/ReturnStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/WhileStmt.d.ts +4 -2
- package/dist/ast/nodes/statements/WhileStmt.js +6 -0
- package/dist/ast/nodes/statements/declarations/ContractDecl.d.ts +17 -0
- package/dist/ast/nodes/statements/declarations/ContractDecl.js +22 -0
- package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +2 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +6 -0
- package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +1 -1
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +7 -2
- package/dist/compiler/AstCompiler/AstCompiler.js +129 -25
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.d.ts +10 -0
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +777 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +5 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +7 -4
- package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +8 -2
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +8 -8
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +2 -2
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +48 -24
- package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +2 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +4 -3
- package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +1 -1
- package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +4 -1
- package/dist/compiler/AstCompiler/scope/AstScope.d.ts +1 -0
- package/dist/compiler/AstCompiler/scope/AstScope.js +9 -3
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
- package/dist/compiler/Compiler.js +7 -1
- package/dist/compiler/TirCompiler/compileTirProgram.js +4 -1
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +17 -5
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +79 -49
- package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +13 -2
- package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressify.js +102 -41
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +77 -12
- package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +16 -9
- package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -8
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +146 -13
- package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
- package/dist/compiler/internalVar.d.ts +1 -1
- package/dist/compiler/internalVar.js +31 -24
- package/dist/compiler/io/CompilerIoApi.d.ts +1 -1
- package/dist/compiler/io/IOutputStream.d.ts +1 -0
- package/dist/compiler/io/IOutputStream.js +18 -3
- package/dist/compiler/path/getAbsolutePath.js +4 -6
- package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
- package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
- package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
- package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
- package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
- package/dist/compiler/tir/expressions/TirCaseExpr.js +105 -60
- package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
- package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
- package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
- package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
- package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
- package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
- package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
- package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +6 -3
- package/dist/compiler/tir/expressions/TirLettedExpr.js +20 -7
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +9 -5
- package/dist/compiler/tir/expressions/TirNativeFunc.js +58 -22
- package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
- package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
- package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
- package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +6 -3
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +22 -8
- package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +19 -20
- package/dist/compiler/tir/expressions/ToIRTermCtx.js +74 -50
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +41 -0
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +180 -4
- package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
- package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
- package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
- package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
- package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
- package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
- package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
- package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
- package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
- package/dist/compiler/tir/program/TypedProgram.d.ts +3 -2
- package/dist/compiler/tir/program/TypedProgram.js +9 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +135 -149
- package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
- package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
- package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
- package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
- package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
- package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
- package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
- package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirForStmt.js +21 -0
- package/dist/compiler/tir/statements/TirIfStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirIfStmt.js +16 -0
- package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
- package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
- package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
- package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
- package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
- package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
- package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
- package/dist/diagnostics/DiagnosticEmitter.js +1 -1
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
- package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
- package/dist/parser/Parser.d.ts +8 -3
- package/dist/parser/Parser.js +180 -32
- package/dist/parser/Precedence.js +1 -0
- package/dist/tokenizer/Token.d.ts +81 -72
- package/dist/tokenizer/Token.js +82 -72
- package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
- package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
- package/dist/utils/BitUtils/index.js +1 -1
- package/dist/utils/UPLCFlatUtils/index.js +1 -1
- package/dist/utils/array/keepSortedArrInplace.js +1 -0
- package/package.json +3 -1
- package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
- package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
- package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
- package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
- package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
- package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
- package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
- package/dist/IR/tree_utils/_ir_apps.js +0 -8
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -37
package/dist/parser/Parser.js
CHANGED
|
@@ -43,9 +43,9 @@ import { FuncDecl } from "../ast/nodes/statements/declarations/FuncDecl.js";
|
|
|
43
43
|
import { FailStmt } from "../ast/nodes/statements/FailStmt.js";
|
|
44
44
|
import { AssertStmt } from "../ast/nodes/statements/AssertStmt.js";
|
|
45
45
|
import { TestStmt } from "../ast/nodes/statements/TestStmt.js";
|
|
46
|
-
import { MatchStmt, MatchStmtCase } from "../ast/nodes/statements/MatchStmt.js";
|
|
46
|
+
import { MatchStmt, MatchStmtCase, MatchStmtElseCase } from "../ast/nodes/statements/MatchStmt.js";
|
|
47
47
|
import { WhileStmt } from "../ast/nodes/statements/WhileStmt.js";
|
|
48
|
-
import { CaseExpr, CaseExprMatcher } from "../ast/nodes/expr/CaseExpr.js";
|
|
48
|
+
import { CaseExpr, CaseExprMatcher, CaseWildcardMatcher } from "../ast/nodes/expr/CaseExpr.js";
|
|
49
49
|
import { StructConstrDecl, StructDecl, StructDeclAstFlags } from "../ast/nodes/statements/declarations/StructDecl.js";
|
|
50
50
|
import { InterfaceDecl, InterfaceDeclMethod } from "../ast/nodes/statements/declarations/InterfaceDecl.js";
|
|
51
51
|
import { ImportStarStmt } from "../ast/nodes/statements/ImportStarStmt.js";
|
|
@@ -69,6 +69,9 @@ import { DecrStmt } from "../ast/nodes/statements/DecrStmt.js";
|
|
|
69
69
|
import { ExportStmt } from "../ast/nodes/statements/ExportStmt.js";
|
|
70
70
|
import { defaultSymbolForge } from "../compiler/internalVar.js";
|
|
71
71
|
import { Precedence, determinePrecedence } from "./Precedence.js";
|
|
72
|
+
import { LitFailExpr } from "../ast/nodes/expr/litteral/LitFailExpr.js";
|
|
73
|
+
import { ContractDecl } from "../ast/nodes/statements/declarations/ContractDecl.js";
|
|
74
|
+
import { LitContextExpr } from "../ast/nodes/expr/litteral/LitContextExpr.js";
|
|
72
75
|
export class Parser extends DiagnosticEmitter {
|
|
73
76
|
tn;
|
|
74
77
|
constructor(tokenizer, diagnostics = undefined) {
|
|
@@ -120,6 +123,8 @@ export class Parser extends DiagnosticEmitter {
|
|
|
120
123
|
const stmt = this.parseTopLevelStatement();
|
|
121
124
|
if (!stmt)
|
|
122
125
|
return undefined;
|
|
126
|
+
if (stmt instanceof ContractDecl)
|
|
127
|
+
return this.error(DiagnosticCode.Contract_declarations_cannot_be_exported, stmt.range);
|
|
123
128
|
return new ExportStmt(stmt, tn.range(startPos, exportEnd));
|
|
124
129
|
}
|
|
125
130
|
const initialState = tn.mark();
|
|
@@ -158,19 +163,24 @@ export class Parser extends DiagnosticEmitter {
|
|
|
158
163
|
break;
|
|
159
164
|
}
|
|
160
165
|
case Token.Data: {
|
|
161
|
-
// skips `data` keyword
|
|
166
|
+
// `next()` skips `data` keyword
|
|
167
|
+
tn.next();
|
|
162
168
|
// positions on (expected) `struct` keyword
|
|
163
|
-
if (tn.
|
|
169
|
+
if (tn.peek() !== Token.Struct) {
|
|
170
|
+
console.error(Token[tn.peek()]);
|
|
164
171
|
return this.error(DiagnosticCode._0_expected, tn.range(), "struct");
|
|
172
|
+
}
|
|
165
173
|
tn.next(); // skip `struct`
|
|
166
174
|
statement = this.parseStruct(StructDeclAstFlags.onlyDataEncoding, flags, startPos);
|
|
167
175
|
break;
|
|
168
176
|
}
|
|
169
177
|
case Token.Runtime: {
|
|
170
|
-
// skips `runtime` keyword
|
|
178
|
+
// `next()` skips `runtime` keyword
|
|
179
|
+
tn.next();
|
|
171
180
|
// positions on (expected) `struct` keyword
|
|
172
|
-
if (tn.
|
|
181
|
+
if (tn.peek() !== Token.Struct) {
|
|
173
182
|
return this.error(DiagnosticCode._0_expected, tn.range(), "struct");
|
|
183
|
+
}
|
|
174
184
|
tn.next(); // skip `struct`
|
|
175
185
|
statement = this.parseStruct(StructDeclAstFlags.onlySopEncoding, flags, startPos);
|
|
176
186
|
break;
|
|
@@ -205,6 +215,11 @@ export class Parser extends DiagnosticEmitter {
|
|
|
205
215
|
statement = this.parseTypeStmt(flags, startPos);
|
|
206
216
|
break;
|
|
207
217
|
}
|
|
218
|
+
case Token.Contract: {
|
|
219
|
+
tn.next(); // skip `contract`
|
|
220
|
+
statement = this.parseContractDecl(startPos);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
208
223
|
default:
|
|
209
224
|
{
|
|
210
225
|
statement = this.parseStatement({ topLevel: true, isExport: false });
|
|
@@ -214,6 +229,75 @@ export class Parser extends DiagnosticEmitter {
|
|
|
214
229
|
tn.skip(Token.Semicolon); // if any
|
|
215
230
|
return statement;
|
|
216
231
|
}
|
|
232
|
+
parseContractDecl(startPos) {
|
|
233
|
+
const tn = this.tn;
|
|
234
|
+
startPos = typeof startPos === "number" ? startPos : tn.tokenPos;
|
|
235
|
+
// at 'contract': Identifier '{' ... '}'
|
|
236
|
+
const contractName = this.parseIdentifier();
|
|
237
|
+
if (!contractName)
|
|
238
|
+
return this.error(DiagnosticCode.Identifier_expected, tn.range());
|
|
239
|
+
if (!tn.skip(Token.OpenBrace))
|
|
240
|
+
return this.error(DiagnosticCode._0_expected, tn.range(), "{");
|
|
241
|
+
const params = [];
|
|
242
|
+
const spendMethods = [];
|
|
243
|
+
const mintMethods = [];
|
|
244
|
+
const certifyMethods = [];
|
|
245
|
+
const withdrawMethods = [];
|
|
246
|
+
const proposeMethods = [];
|
|
247
|
+
const voteMethods = [];
|
|
248
|
+
while (!tn.skip(Token.CloseBrace)) {
|
|
249
|
+
const thisStartPos = tn.tokenPos;
|
|
250
|
+
const prevState = tn.mark();
|
|
251
|
+
const nextToken = tn.next();
|
|
252
|
+
switch (nextToken) {
|
|
253
|
+
case Token.Param:
|
|
254
|
+
{
|
|
255
|
+
const varDecl = this._parseVarDecl(CommonFlags.Const);
|
|
256
|
+
if (!varDecl)
|
|
257
|
+
return undefined;
|
|
258
|
+
if (!(varDecl instanceof SimpleVarDecl))
|
|
259
|
+
return this.error(DiagnosticCode._0_expected, varDecl.range, "simple variable declaration");
|
|
260
|
+
if (!varDecl.type)
|
|
261
|
+
return this.error(DiagnosticCode._0_expected, varDecl.range, "Type annotation");
|
|
262
|
+
if (varDecl.initExpr)
|
|
263
|
+
return this.error(DiagnosticCode.Contract_parameters_cannot_have_an_initializer_expression, varDecl.range);
|
|
264
|
+
params.push(varDecl);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
268
|
+
// methods
|
|
269
|
+
case Token.Spend:
|
|
270
|
+
case Token.Mint:
|
|
271
|
+
case Token.Certify:
|
|
272
|
+
case Token.Withdraw:
|
|
273
|
+
case Token.Propose:
|
|
274
|
+
case Token.Vote:
|
|
275
|
+
{
|
|
276
|
+
const funcDecl = this.parseFuncDecl(CommonFlags.None, thisStartPos, new AstVoidType(tn.range()));
|
|
277
|
+
if (!funcDecl)
|
|
278
|
+
return undefined;
|
|
279
|
+
if (!(funcDecl.expr.signature.returnType instanceof AstVoidType))
|
|
280
|
+
return this.error(DiagnosticCode.Contract_methods_must_return_void_or_fail, funcDecl.expr.signature.returnType?.range ?? funcDecl.expr.signature.range);
|
|
281
|
+
(nextToken === Token.Spend ? spendMethods :
|
|
282
|
+
nextToken === Token.Mint ? mintMethods :
|
|
283
|
+
nextToken === Token.Certify ? certifyMethods :
|
|
284
|
+
nextToken === Token.Withdraw ? withdrawMethods :
|
|
285
|
+
nextToken === Token.Propose ? proposeMethods :
|
|
286
|
+
nextToken === Token.Vote ? voteMethods :
|
|
287
|
+
spendMethods // default to spendMethods, should never happen
|
|
288
|
+
).push(funcDecl);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
default: {
|
|
293
|
+
tn.reset(prevState);
|
|
294
|
+
return this.error(DiagnosticCode._0_expected, tn.range(), "contract member declaration");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
return new ContractDecl(contractName, params, spendMethods, mintMethods, certifyMethods, withdrawMethods, proposeMethods, voteMethods, tn.range(startPos, tn.pos));
|
|
300
|
+
}
|
|
217
301
|
parseUsingDecl() {
|
|
218
302
|
const tn = this.tn;
|
|
219
303
|
const startPos = tn.tokenPos;
|
|
@@ -509,7 +593,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
509
593
|
[
|
|
510
594
|
new StructConstrDecl(new Identifier(name.text, name.range), [], // fields
|
|
511
595
|
range)
|
|
512
|
-
], structDeclFlags
|
|
596
|
+
], structDeclFlags | StructDeclAstFlags.untaggedSingleConstructor, range.clone());
|
|
513
597
|
}
|
|
514
598
|
let constrIdentifier = undefined;
|
|
515
599
|
// in case of single constr shortcut
|
|
@@ -530,7 +614,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
530
614
|
tn.skip(Token.Semicolon); // if any
|
|
531
615
|
return new StructDecl(name, typeParams, [
|
|
532
616
|
new StructConstrDecl(new Identifier(name.text, name.range), fields, tn.range(startPos, tn.pos))
|
|
533
|
-
], structDeclFlags
|
|
617
|
+
], structDeclFlags | StructDeclAstFlags.untaggedSingleConstructor, tn.range(startPos, tn.pos));
|
|
534
618
|
}
|
|
535
619
|
const constrFields = this.parseStructConstrFields(flags);
|
|
536
620
|
if (!Array.isArray(constrFields))
|
|
@@ -580,7 +664,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
580
664
|
}
|
|
581
665
|
return fields;
|
|
582
666
|
}
|
|
583
|
-
parseNamedFuncSig(flags = CommonFlags.None, startPos) {
|
|
667
|
+
parseNamedFuncSig(flags = CommonFlags.None, startPos, defaultReturnType) {
|
|
584
668
|
const tn = this.tn;
|
|
585
669
|
startPos = startPos ?? tn.tokenPos;
|
|
586
670
|
if (!tn.skipIdentifier())
|
|
@@ -601,7 +685,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
601
685
|
const params = this.parseParameters();
|
|
602
686
|
if (!params)
|
|
603
687
|
return undefined;
|
|
604
|
-
let returnType =
|
|
688
|
+
let returnType = defaultReturnType;
|
|
605
689
|
if (tn.skip(Token.Colon)) {
|
|
606
690
|
returnType = this.parseTypeExpr();
|
|
607
691
|
if (!returnType)
|
|
@@ -613,10 +697,10 @@ export class Parser extends DiagnosticEmitter {
|
|
|
613
697
|
new AstFuncType(params, returnType, tn.range(sigStart, tn.pos))
|
|
614
698
|
];
|
|
615
699
|
}
|
|
616
|
-
parseFuncDecl(flags, startPos) {
|
|
700
|
+
parseFuncDecl(flags, startPos, defaultReturnType) {
|
|
617
701
|
const tn = this.tn;
|
|
618
702
|
startPos = startPos ?? tn.tokenPos;
|
|
619
|
-
const namedSig = this.parseNamedFuncSig(flags, startPos);
|
|
703
|
+
const namedSig = this.parseNamedFuncSig(flags, startPos, defaultReturnType);
|
|
620
704
|
if (!namedSig)
|
|
621
705
|
return undefined;
|
|
622
706
|
const [name, typeArgs, sig] = namedSig;
|
|
@@ -740,14 +824,17 @@ export class Parser extends DiagnosticEmitter {
|
|
|
740
824
|
*
|
|
741
825
|
* on the contrary in case we are parsing a field of a deconstructed variable declaration
|
|
742
826
|
* an initializer MUST NOT be present NOR a type
|
|
827
|
+
*
|
|
828
|
+
* EDIT:
|
|
829
|
+
* This method is also used while parsing contract `param`s;
|
|
743
830
|
*/
|
|
744
|
-
_parseVarDecl(flags) {
|
|
831
|
+
_parseVarDecl(flags, skipTypeAndInitializer = false) {
|
|
745
832
|
const tn = this.tn;
|
|
746
833
|
// ConstrName{ ... } || renamed
|
|
747
834
|
const renamedField = this.parseIdentifier();
|
|
748
835
|
if (tn.skip(Token.OpenBrace)) // ConstrName{ ... } || { ... }
|
|
749
836
|
{
|
|
750
|
-
const unnamed = this.parseSingleDeconstructVarDecl(flags);
|
|
837
|
+
const unnamed = this.parseSingleDeconstructVarDecl(flags, skipTypeAndInitializer);
|
|
751
838
|
if (!unnamed)
|
|
752
839
|
return undefined;
|
|
753
840
|
return renamedField instanceof Identifier ?
|
|
@@ -763,11 +850,15 @@ export class Parser extends DiagnosticEmitter {
|
|
|
763
850
|
this.error(DiagnosticCode.Unexpected_token, tn.range());
|
|
764
851
|
return undefined;
|
|
765
852
|
}
|
|
766
|
-
return this.parseArrayLikeDeconstr(flags);
|
|
853
|
+
return this.parseArrayLikeDeconstr(flags, skipTypeAndInitializer);
|
|
767
854
|
}
|
|
768
855
|
else if (renamedField instanceof Identifier) // renamed
|
|
769
856
|
{
|
|
770
|
-
|
|
857
|
+
let explicitType = undefined;
|
|
858
|
+
let initializer = undefined;
|
|
859
|
+
if (!skipTypeAndInitializer) {
|
|
860
|
+
[explicitType, initializer] = this._parseTypeAndInitializer();
|
|
861
|
+
}
|
|
771
862
|
let range = renamedField.range;
|
|
772
863
|
if (initializer)
|
|
773
864
|
range = SourceRange.join(range, initializer.range);
|
|
@@ -778,7 +869,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
778
869
|
else
|
|
779
870
|
return undefined;
|
|
780
871
|
}
|
|
781
|
-
parseSingleDeconstructVarDecl(flags) {
|
|
872
|
+
parseSingleDeconstructVarDecl(flags, skipTypeAndInitializer = false) {
|
|
782
873
|
const tn = this.tn;
|
|
783
874
|
const initRange = tn.range();
|
|
784
875
|
let elements = new Map();
|
|
@@ -849,10 +940,12 @@ export class Parser extends DiagnosticEmitter {
|
|
|
849
940
|
elements.set(fieldName, element);
|
|
850
941
|
tn.skip(Token.Comma); // skip comma if present
|
|
851
942
|
} // while( !tn.skip( Token.CloseBrace ) )
|
|
852
|
-
|
|
943
|
+
if (!skipTypeAndInitializer) {
|
|
944
|
+
[explicitType, initializer] = this._parseTypeAndInitializer();
|
|
945
|
+
}
|
|
853
946
|
return new SingleDeconstructVarDecl(elements, rest, explicitType, initializer, flags, SourceRange.join(initRange, tn.range()));
|
|
854
947
|
}
|
|
855
|
-
parseArrayLikeDeconstr(flags) {
|
|
948
|
+
parseArrayLikeDeconstr(flags, skipTypeAndInitializer = false) {
|
|
856
949
|
const tn = this.tn;
|
|
857
950
|
// at '[': ( VarDecl ','? )* ']' ( ':' AstTypeExpr )? ( '=' PebbleExpr )?
|
|
858
951
|
const startPos = tn.pos;
|
|
@@ -896,7 +989,11 @@ export class Parser extends DiagnosticEmitter {
|
|
|
896
989
|
return undefined;
|
|
897
990
|
}
|
|
898
991
|
}
|
|
899
|
-
|
|
992
|
+
let explicitType = undefined;
|
|
993
|
+
let initializer = undefined;
|
|
994
|
+
if (!skipTypeAndInitializer) {
|
|
995
|
+
[explicitType, initializer] = this._parseTypeAndInitializer();
|
|
996
|
+
}
|
|
900
997
|
let range = tn.range(startPos, tn.pos);
|
|
901
998
|
if (initializer)
|
|
902
999
|
range = SourceRange.join(range, initializer.range);
|
|
@@ -1029,8 +1126,9 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1029
1126
|
parseExpr(precedence = Precedence.Comma) {
|
|
1030
1127
|
const tn = this.tn;
|
|
1031
1128
|
let expr = this.parseExprStart();
|
|
1032
|
-
if (!expr)
|
|
1129
|
+
if (!expr) {
|
|
1033
1130
|
return undefined;
|
|
1131
|
+
}
|
|
1034
1132
|
const startPos = expr.range.start;
|
|
1035
1133
|
if (tn.skip(Token.HexBytesLiteral)) {
|
|
1036
1134
|
const hexBytes = tn.readHexBytes();
|
|
@@ -1041,8 +1139,13 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1041
1139
|
// precedence climbing
|
|
1042
1140
|
// see: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
|
|
1043
1141
|
let nextPrecedence;
|
|
1044
|
-
|
|
1142
|
+
let prevState;
|
|
1143
|
+
outer_while: while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
|
|
1144
|
+
prevState = tn.mark();
|
|
1045
1145
|
const token = tn.next();
|
|
1146
|
+
// DO NOT DIRECTLY RETURN FROM HERE
|
|
1147
|
+
// we need to loop to support right associative operators
|
|
1148
|
+
// and also to support constructs like a.b().c.d()[x]!.e().f.g
|
|
1046
1149
|
switch (token) {
|
|
1047
1150
|
case Token.As: {
|
|
1048
1151
|
if (tn.skip(Token.Const))
|
|
@@ -1219,6 +1322,11 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1219
1322
|
expr = makeBinaryExpr(token, expr, next, tn.range(startPos, tn.pos));
|
|
1220
1323
|
break;
|
|
1221
1324
|
}
|
|
1325
|
+
// comma operator handled in caller (only valid in for statements)
|
|
1326
|
+
case Token.Comma: {
|
|
1327
|
+
tn.reset(prevState);
|
|
1328
|
+
break outer_while;
|
|
1329
|
+
}
|
|
1222
1330
|
default: {
|
|
1223
1331
|
return this.error(DiagnosticCode.Expression_expected, tn.range());
|
|
1224
1332
|
}
|
|
@@ -1266,10 +1374,12 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1266
1374
|
}
|
|
1267
1375
|
// Special Identifier
|
|
1268
1376
|
case Token.Void: return new LitVoidExpr(tn.range());
|
|
1377
|
+
case Token.Fail: return new LitFailExpr(tn.range());
|
|
1269
1378
|
case Token.Undefined: return new LitUndefExpr(tn.range());
|
|
1270
1379
|
case Token.True: return new LitTrueExpr(tn.range());
|
|
1271
1380
|
case Token.False: return new LitFalseExpr(tn.range());
|
|
1272
1381
|
case Token.This: return new LitThisExpr(tn.range());
|
|
1382
|
+
case Token.Context: return new LitContextExpr(tn.range());
|
|
1273
1383
|
// ParenthesizedPebbleExpr or FunctionPebbleExpr
|
|
1274
1384
|
case Token.OpenParen: {
|
|
1275
1385
|
// determine whether this is a function expression
|
|
@@ -1350,8 +1460,15 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1350
1460
|
}
|
|
1351
1461
|
case Token.Identifier: {
|
|
1352
1462
|
const identifierText = tn.readIdentifier();
|
|
1353
|
-
|
|
1354
|
-
|
|
1463
|
+
// special expressions
|
|
1464
|
+
switch (identifierText) {
|
|
1465
|
+
case "undefined": return new LitUndefExpr(tn.range());
|
|
1466
|
+
case "true": return new LitTrueExpr(tn.range());
|
|
1467
|
+
case "false": return new LitFalseExpr(tn.range());
|
|
1468
|
+
case "this": return new LitThisExpr(tn.range());
|
|
1469
|
+
case "void": return new LitVoidExpr(tn.range());
|
|
1470
|
+
case "fail": return new LitFailExpr(tn.range());
|
|
1471
|
+
}
|
|
1355
1472
|
const identifier = new Identifier(identifierText, tn.range(startPos, tn.pos));
|
|
1356
1473
|
// LitNamedObjExpr
|
|
1357
1474
|
// eg: `Identifier{ a: 1, b: 2 }`
|
|
@@ -1422,6 +1539,9 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1422
1539
|
if (!expr)
|
|
1423
1540
|
return undefined;
|
|
1424
1541
|
}
|
|
1542
|
+
case Token.Fail: {
|
|
1543
|
+
return new LitFailExpr(tn.range());
|
|
1544
|
+
}
|
|
1425
1545
|
// case Token.Class: return this.parseClassPebbleExpr();
|
|
1426
1546
|
// case Token.Struct: return this.parseStructExpr();
|
|
1427
1547
|
default: {
|
|
@@ -1455,7 +1575,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1455
1575
|
}
|
|
1456
1576
|
parseCaseExpr() {
|
|
1457
1577
|
const tn = this.tn;
|
|
1458
|
-
// at 'case': Expression ('is' VarDecl '=>' Expression)+
|
|
1578
|
+
// at 'case': Expression ('is' VarDecl '=>' Expression)+ ('else' Expression)?
|
|
1459
1579
|
const startPos = tn.tokenPos;
|
|
1460
1580
|
const expr = this.parseExpr();
|
|
1461
1581
|
if (!expr)
|
|
@@ -1480,11 +1600,19 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1480
1600
|
return undefined;
|
|
1481
1601
|
cases.push(new CaseExprMatcher(matcher, body, tn.range(startPos, tn.pos)));
|
|
1482
1602
|
}
|
|
1603
|
+
let wildcardCase = undefined;
|
|
1604
|
+
if (tn.skip(Token.Else)) {
|
|
1605
|
+
const wildcardStart = tn.tokenPos;
|
|
1606
|
+
const body = this.parseExpr(Precedence.CaseExpr);
|
|
1607
|
+
if (!body)
|
|
1608
|
+
return undefined;
|
|
1609
|
+
wildcardCase = new CaseWildcardMatcher(body, tn.range(wildcardStart));
|
|
1610
|
+
}
|
|
1611
|
+
tn.skip(Token.Semicolon); // if any
|
|
1483
1612
|
const finalRange = tn.range(startPos, tn.pos);
|
|
1484
1613
|
if (cases.length < 1)
|
|
1485
1614
|
return this.error(DiagnosticCode.A_case_expression_must_have_at_least_one_clause, finalRange);
|
|
1486
|
-
return new CaseExpr(expr, cases,
|
|
1487
|
-
finalRange);
|
|
1615
|
+
return new CaseExpr(expr, cases, wildcardCase, finalRange);
|
|
1488
1616
|
}
|
|
1489
1617
|
parseFunctionExpr() {
|
|
1490
1618
|
const tn = this.tn;
|
|
@@ -1895,6 +2023,12 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1895
2023
|
case Token.Question_Question_Equals: {
|
|
1896
2024
|
return this.error(DiagnosticCode.Not_implemented_0, tn.range(), "??=");
|
|
1897
2025
|
}
|
|
2026
|
+
case Token.Plus_Plus: {
|
|
2027
|
+
return makeAssignmentStmt(varIdentifier, Token.Plus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
|
|
2028
|
+
}
|
|
2029
|
+
case Token.Minus_Minus: {
|
|
2030
|
+
return makeAssignmentStmt(varIdentifier, Token.Minus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
|
|
2031
|
+
}
|
|
1898
2032
|
default: {
|
|
1899
2033
|
return this.error(DiagnosticCode._0_expected, tn.range(), "=");
|
|
1900
2034
|
}
|
|
@@ -2059,8 +2193,11 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2059
2193
|
return this.error(DiagnosticCode.Invalid_for_statement_update, update.range);
|
|
2060
2194
|
updates.push(update);
|
|
2061
2195
|
} while (tn.skip(Token.Comma)); // comma expression (allowed only in for update part)
|
|
2062
|
-
if (!tn.skip(Token.CloseParen))
|
|
2196
|
+
if (!tn.skip(Token.CloseParen)) {
|
|
2197
|
+
const next = tn.peek();
|
|
2198
|
+
console.error('next token after for updates:', Token[next]);
|
|
2063
2199
|
return this.error(DiagnosticCode._0_expected, tn.range(), ")");
|
|
2200
|
+
}
|
|
2064
2201
|
}
|
|
2065
2202
|
const body = this.parseStatement();
|
|
2066
2203
|
if (!body)
|
|
@@ -2128,11 +2265,13 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2128
2265
|
return this.error(DiagnosticCode._0_expected, tn.range(), "{");
|
|
2129
2266
|
let noPatternCaseSeen = false;
|
|
2130
2267
|
const cases = new Array();
|
|
2131
|
-
while (!tn.skip(Token.CloseBrace)
|
|
2132
|
-
|
|
2268
|
+
while (!tn.skip(Token.CloseBrace)
|
|
2269
|
+
&& tn.peek() !== Token.Else) {
|
|
2270
|
+
if (!tn.skip(Token.When)) {
|
|
2133
2271
|
return this.error(DiagnosticCode._0_expected, tn.range(), "when");
|
|
2272
|
+
}
|
|
2134
2273
|
// const startPos = tn.pos;
|
|
2135
|
-
const pattern = this._parseVarDecl(CommonFlags.Const);
|
|
2274
|
+
const pattern = this._parseVarDecl(CommonFlags.Const, true);
|
|
2136
2275
|
if (!pattern)
|
|
2137
2276
|
return this.error(DiagnosticCode.Pattern_expected, tn.range());
|
|
2138
2277
|
if (noPatternCaseSeen)
|
|
@@ -2147,9 +2286,18 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2147
2286
|
return this.error(DiagnosticCode._0_expected, tn.range(statePreBody.tokenPos, statePreBody.pos), "{");
|
|
2148
2287
|
cases.push(new MatchStmtCase(pattern, body, tn.range()));
|
|
2149
2288
|
}
|
|
2289
|
+
let elseCase = undefined;
|
|
2290
|
+
if (tn.skip(Token.Else)) {
|
|
2291
|
+
const body = this.parseStatement({ topLevel: false, isExport: false });
|
|
2292
|
+
if (!body)
|
|
2293
|
+
return this.error(DiagnosticCode.Statement_expected, tn.range());
|
|
2294
|
+
elseCase = new MatchStmtElseCase(body, tn.range());
|
|
2295
|
+
if (!tn.skip(Token.CloseBrace))
|
|
2296
|
+
return this.error(DiagnosticCode._0_expected, tn.range(), "}");
|
|
2297
|
+
}
|
|
2150
2298
|
if (cases.length < 1)
|
|
2151
2299
|
return this.error(DiagnosticCode.A_match_statement_must_have_at_least_one_case, tn.range(startPos, tn.pos));
|
|
2152
|
-
return new MatchStmt(expr, cases, tn.range(startPos, tn.pos));
|
|
2300
|
+
return new MatchStmt(expr, cases, elseCase, tn.range(startPos, tn.pos));
|
|
2153
2301
|
}
|
|
2154
2302
|
parseFailStatement() {
|
|
2155
2303
|
const tn = this.tn;
|
|
@@ -89,6 +89,7 @@ export function determinePrecedence(kind) {
|
|
|
89
89
|
case Token.Plus_Plus:
|
|
90
90
|
case Token.Minus_Minus: return Precedence.UnaryPostfix;
|
|
91
91
|
case Token.Dot:
|
|
92
|
+
case Token.Exclamation_Dot:
|
|
92
93
|
case Token.Question_Dot:
|
|
93
94
|
case Token.OpenBracket:
|
|
94
95
|
case Token.Exclamation: return Precedence.MemberAccess;
|
|
@@ -41,120 +41,129 @@ export declare enum Token {
|
|
|
41
41
|
Test = 38,
|
|
42
42
|
Fail = 39,
|
|
43
43
|
Assert = 40,
|
|
44
|
+
Contract = 41,
|
|
45
|
+
Param = 42,
|
|
46
|
+
Spend = 43,
|
|
47
|
+
Mint = 44,
|
|
48
|
+
Certify = 45,
|
|
49
|
+
Withdraw = 46,
|
|
50
|
+
Propose = 47,
|
|
51
|
+
Vote = 48,
|
|
52
|
+
Context = 49,
|
|
44
53
|
/** `{` */
|
|
45
|
-
OpenBrace =
|
|
54
|
+
OpenBrace = 50,
|
|
46
55
|
/** `}` */
|
|
47
|
-
CloseBrace =
|
|
48
|
-
OpenParen =
|
|
49
|
-
CloseParen =
|
|
56
|
+
CloseBrace = 51,
|
|
57
|
+
OpenParen = 52,
|
|
58
|
+
CloseParen = 53,
|
|
50
59
|
/** `[` */
|
|
51
|
-
OpenBracket =
|
|
60
|
+
OpenBracket = 54,
|
|
52
61
|
/** `]` */
|
|
53
|
-
CloseBracket =
|
|
62
|
+
CloseBracket = 55,
|
|
54
63
|
/** `.` */
|
|
55
|
-
Dot =
|
|
64
|
+
Dot = 56,
|
|
56
65
|
/** `...` */
|
|
57
|
-
Dot_Dot_Dot =
|
|
66
|
+
Dot_Dot_Dot = 57,
|
|
58
67
|
/** `;` */
|
|
59
|
-
Semicolon =
|
|
68
|
+
Semicolon = 58,
|
|
60
69
|
/** `,` */
|
|
61
|
-
Comma =
|
|
70
|
+
Comma = 59,
|
|
62
71
|
/** `<` */
|
|
63
|
-
LessThan =
|
|
72
|
+
LessThan = 60,
|
|
64
73
|
/** `>` */
|
|
65
|
-
GreaterThan =
|
|
74
|
+
GreaterThan = 61,
|
|
66
75
|
/** `<=` */
|
|
67
|
-
LessThan_Equals =
|
|
76
|
+
LessThan_Equals = 62,
|
|
68
77
|
/** `>=` */
|
|
69
|
-
GreaterThan_Equals =
|
|
78
|
+
GreaterThan_Equals = 63,
|
|
70
79
|
/** `==` */
|
|
71
|
-
Equals_Equals =
|
|
80
|
+
Equals_Equals = 64,
|
|
72
81
|
/** `!=` */
|
|
73
|
-
Exclamation_Equals =
|
|
82
|
+
Exclamation_Equals = 65,
|
|
74
83
|
/** `===` */
|
|
75
|
-
Equals_Equals_Equals =
|
|
84
|
+
Equals_Equals_Equals = 66,
|
|
76
85
|
/** `!==` */
|
|
77
|
-
Exclamation_Equals_Equals =
|
|
86
|
+
Exclamation_Equals_Equals = 67,
|
|
78
87
|
/** `=>` */
|
|
79
|
-
FatArrow =
|
|
88
|
+
FatArrow = 68,
|
|
80
89
|
/** `+` */
|
|
81
|
-
Plus =
|
|
90
|
+
Plus = 69,
|
|
82
91
|
/** `-` */
|
|
83
|
-
Minus =
|
|
92
|
+
Minus = 70,
|
|
84
93
|
/** `**` */
|
|
85
|
-
Asterisk_Asterisk =
|
|
94
|
+
Asterisk_Asterisk = 71,
|
|
86
95
|
/** `*` */
|
|
87
|
-
Asterisk =
|
|
96
|
+
Asterisk = 72,
|
|
88
97
|
/** `/` */
|
|
89
|
-
Slash =
|
|
98
|
+
Slash = 73,
|
|
90
99
|
/** `%` */
|
|
91
|
-
Percent =
|
|
100
|
+
Percent = 74,
|
|
92
101
|
/** `++` */
|
|
93
|
-
Plus_Plus =
|
|
102
|
+
Plus_Plus = 75,
|
|
94
103
|
/** `--` */
|
|
95
|
-
Minus_Minus =
|
|
104
|
+
Minus_Minus = 76,
|
|
96
105
|
/** `<<` */
|
|
97
|
-
LessThan_LessThan =
|
|
106
|
+
LessThan_LessThan = 77,
|
|
98
107
|
/** `>>` */
|
|
99
|
-
GreaterThan_GreaterThan =
|
|
108
|
+
GreaterThan_GreaterThan = 78,
|
|
100
109
|
/** `>>>` */
|
|
101
|
-
GreaterThan_GreaterThan_GreaterThan =
|
|
110
|
+
GreaterThan_GreaterThan_GreaterThan = 79,
|
|
102
111
|
/** `+` */
|
|
103
|
-
Ampersand =
|
|
112
|
+
Ampersand = 80,
|
|
104
113
|
/** `|` */
|
|
105
|
-
Bar =
|
|
114
|
+
Bar = 81,
|
|
106
115
|
/** `^` */
|
|
107
|
-
Caret =
|
|
116
|
+
Caret = 82,
|
|
108
117
|
/** `!` */
|
|
109
|
-
Exclamation =
|
|
118
|
+
Exclamation = 83,
|
|
110
119
|
/** `~` */
|
|
111
|
-
Tilde =
|
|
120
|
+
Tilde = 84,
|
|
112
121
|
/** `&&` */
|
|
113
|
-
Ampersand_Ampersand =
|
|
122
|
+
Ampersand_Ampersand = 85,
|
|
114
123
|
/** `||` */
|
|
115
|
-
Bar_Bar =
|
|
124
|
+
Bar_Bar = 86,
|
|
116
125
|
/** `?` */
|
|
117
|
-
Question =
|
|
126
|
+
Question = 87,
|
|
118
127
|
/** `:` */
|
|
119
|
-
Colon =
|
|
128
|
+
Colon = 88,
|
|
120
129
|
/** `=` */
|
|
121
|
-
Equals =
|
|
122
|
-
Plus_Equals =
|
|
123
|
-
Minus_Equals =
|
|
124
|
-
Asterisk_Equals =
|
|
125
|
-
Asterisk_Asterisk_Equals =
|
|
126
|
-
Slash_Equals =
|
|
127
|
-
Percent_Equals =
|
|
128
|
-
LessThan_LessThan_Equals =
|
|
129
|
-
GreaterThan_GreaterThan_Equals =
|
|
130
|
-
GreaterThan_GreaterThan_GreaterThan_Equals =
|
|
131
|
-
Ampersand_Equals =
|
|
132
|
-
Bar_Equals =
|
|
133
|
-
Caret_Equals =
|
|
134
|
-
At =
|
|
130
|
+
Equals = 89,
|
|
131
|
+
Plus_Equals = 90,
|
|
132
|
+
Minus_Equals = 91,
|
|
133
|
+
Asterisk_Equals = 92,
|
|
134
|
+
Asterisk_Asterisk_Equals = 93,
|
|
135
|
+
Slash_Equals = 94,
|
|
136
|
+
Percent_Equals = 95,
|
|
137
|
+
LessThan_LessThan_Equals = 96,
|
|
138
|
+
GreaterThan_GreaterThan_Equals = 97,
|
|
139
|
+
GreaterThan_GreaterThan_GreaterThan_Equals = 98,
|
|
140
|
+
Ampersand_Equals = 99,
|
|
141
|
+
Bar_Equals = 100,
|
|
142
|
+
Caret_Equals = 101,
|
|
143
|
+
At = 102,
|
|
135
144
|
/** `??=` */
|
|
136
|
-
Question_Question_Equals =
|
|
145
|
+
Question_Question_Equals = 103,
|
|
137
146
|
/** `||=` */
|
|
138
|
-
Bar_Bar_Equals =
|
|
147
|
+
Bar_Bar_Equals = 104,
|
|
139
148
|
/** `&&=` */
|
|
140
|
-
Ampersand_Ampersand_Equals =
|
|
149
|
+
Ampersand_Ampersand_Equals = 105,
|
|
141
150
|
/** `??` */
|
|
142
|
-
Question_Question =
|
|
151
|
+
Question_Question = 106,
|
|
143
152
|
/** `?.` */
|
|
144
|
-
Question_Dot =
|
|
153
|
+
Question_Dot = 107,
|
|
145
154
|
/** `!.` */
|
|
146
|
-
Exclamation_Dot =
|
|
147
|
-
Data =
|
|
148
|
-
Bytes =
|
|
149
|
-
Optional =
|
|
150
|
-
List =
|
|
151
|
-
LinearMap =
|
|
152
|
-
Runtime =
|
|
153
|
-
Identifier =
|
|
154
|
-
StringLiteral =
|
|
155
|
-
HexBytesLiteral =
|
|
156
|
-
IntegerLiteral =
|
|
157
|
-
StringTemplateLiteralQuote =
|
|
158
|
-
Invalid =
|
|
159
|
-
EndOfFile =
|
|
155
|
+
Exclamation_Dot = 108,
|
|
156
|
+
Data = 109,
|
|
157
|
+
Bytes = 110,
|
|
158
|
+
Optional = 111,
|
|
159
|
+
List = 112,
|
|
160
|
+
LinearMap = 113,
|
|
161
|
+
Runtime = 114,
|
|
162
|
+
Identifier = 115,
|
|
163
|
+
StringLiteral = 116,
|
|
164
|
+
HexBytesLiteral = 117,
|
|
165
|
+
IntegerLiteral = 118,
|
|
166
|
+
StringTemplateLiteralQuote = 119,
|
|
167
|
+
Invalid = 120,
|
|
168
|
+
EndOfFile = 121
|
|
160
169
|
}
|