@harmoniclabs/pebble 0.1.0-dev5 → 0.1.0-dev6

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.
Files changed (307) hide show
  1. package/dist/IR/IRHash.d.ts +3 -3
  2. package/dist/IR/IRHash.js +47 -52
  3. package/dist/IR/IRNodes/IRApp.d.ts +12 -8
  4. package/dist/IR/IRNodes/IRApp.js +34 -20
  5. package/dist/IR/IRNodes/IRCase.d.ts +11 -7
  6. package/dist/IR/IRNodes/IRCase.js +33 -32
  7. package/dist/IR/IRNodes/IRConst.d.ts +7 -5
  8. package/dist/IR/IRNodes/IRConst.js +23 -13
  9. package/dist/IR/IRNodes/IRConstr.d.ts +11 -7
  10. package/dist/IR/IRNodes/IRConstr.js +34 -37
  11. package/dist/IR/IRNodes/IRDelayed.d.ts +12 -9
  12. package/dist/IR/IRNodes/IRDelayed.js +22 -18
  13. package/dist/IR/IRNodes/IRError.d.ts +9 -6
  14. package/dist/IR/IRNodes/IRError.js +12 -5
  15. package/dist/IR/IRNodes/IRForced.d.ts +9 -6
  16. package/dist/IR/IRNodes/IRForced.js +22 -18
  17. package/dist/IR/IRNodes/IRFunc.d.ts +14 -10
  18. package/dist/IR/IRNodes/IRFunc.js +35 -38
  19. package/dist/IR/IRNodes/IRHoisted.d.ts +16 -9
  20. package/dist/IR/IRNodes/IRHoisted.js +36 -18
  21. package/dist/IR/IRNodes/IRLetted.d.ts +14 -34
  22. package/dist/IR/IRNodes/IRLetted.js +65 -297
  23. package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +0 -2
  24. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +0 -4
  25. package/dist/IR/IRNodes/IRNative/index.d.ts +9 -8
  26. package/dist/IR/IRNodes/IRNative/index.js +55 -18
  27. package/dist/IR/IRNodes/IRNative/isForcedNative.d.ts +2 -0
  28. package/dist/IR/IRNodes/IRNative/isForcedNative.js +1 -1
  29. package/dist/IR/IRNodes/IRRecursive.d.ts +18 -10
  30. package/dist/IR/IRNodes/IRRecursive.js +36 -44
  31. package/dist/IR/IRNodes/IRSelfCall.d.ts +10 -24
  32. package/dist/IR/IRNodes/IRSelfCall.js +25 -87
  33. package/dist/IR/IRNodes/IRVar.d.ts +11 -19
  34. package/dist/IR/IRNodes/IRVar.js +26 -54
  35. package/dist/IR/IRNodes/utils/dependsByDbns.d.ts +1 -1
  36. package/dist/IR/IRNodes/utils/dependsByDbns.js +5 -11
  37. package/dist/IR/IRNodes/utils/hashVarSym.d.ts +1 -0
  38. package/dist/IR/IRNodes/utils/hashVarSym.js +37 -0
  39. package/dist/IR/IRNodes/utils/makeArrayLikeProxy.d.ts +2 -1
  40. package/dist/IR/IRTerm.d.ts +7 -0
  41. package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +3 -0
  42. package/dist/IR/toUPLC/_internal/findAll.js +2 -73
  43. package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +7 -34
  44. package/dist/IR/toUPLC/_internal/iterTree.js +3 -17
  45. package/dist/IR/toUPLC/common_hoisted.d.ts +2 -0
  46. package/dist/IR/toUPLC/common_hoisted.js +4 -0
  47. package/dist/IR/toUPLC/compileIRToUPLC.d.ts +1 -1
  48. package/dist/IR/toUPLC/compileIRToUPLC.js +91 -14
  49. package/dist/IR/toUPLC/ctx/ToUplcCtx.d.ts +16 -0
  50. package/dist/IR/toUPLC/ctx/ToUplcCtx.js +75 -0
  51. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.d.ts +8 -0
  52. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.js +95 -0
  53. package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +7 -54
  54. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +6 -13
  55. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +67 -71
  56. package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +44 -170
  57. package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +7 -3
  58. package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +3 -2
  59. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.d.ts +22 -0
  60. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.js +59 -0
  61. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts +0 -0
  62. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.js +217 -0
  63. package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +12 -49
  64. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +1 -1
  65. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +11 -14
  66. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/{index.d.ts → performUplcOptimizationsAndReturnRoot.d.ts} +0 -2
  67. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +151 -0
  68. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.d.ts +11 -0
  69. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.js +46 -0
  70. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.d.ts +2 -0
  71. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js +80 -0
  72. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +18 -11
  73. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +43 -0
  74. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +255 -478
  75. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.d.ts +2 -0
  76. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +85 -0
  77. package/dist/IR/toUPLC/subRoutines/sanifyTree.js +1 -0
  78. package/dist/IR/toUPLC/utils/getApplicationTerms.d.ts +6 -0
  79. package/dist/IR/toUPLC/utils/getApplicationTerms.js +37 -0
  80. package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +2 -2
  81. package/dist/IR/tree_utils/_ir_lazyChooseList.js +4 -2
  82. package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +1 -1
  83. package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +4 -2
  84. package/dist/IR/tree_utils/_ir_let.d.ts +2 -1
  85. package/dist/IR/tree_utils/_ir_let.js +6 -2
  86. package/dist/IR/utils/isClosedIRTerm.d.ts +1 -0
  87. package/dist/IR/utils/isClosedIRTerm.js +39 -25
  88. package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
  89. package/dist/IR/utils/positiveIntAsBytes.js +4 -0
  90. package/dist/IR/utils/showIR.d.ts +10 -21
  91. package/dist/IR/utils/showIR.js +66 -64
  92. package/dist/ast/nodes/common/Identifier.d.ts +1 -0
  93. package/dist/ast/nodes/common/Identifier.js +3 -0
  94. package/dist/ast/nodes/expr/CaseExpr.d.ts +5 -5
  95. package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +2 -2
  96. package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +1 -1
  97. package/dist/ast/nodes/expr/PebbleExpr.d.ts +2 -1
  98. package/dist/ast/nodes/expr/PropAccessExpr.d.ts +3 -3
  99. package/dist/ast/nodes/expr/TernaryExpr.d.ts +3 -3
  100. package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +2 -1
  101. package/dist/ast/nodes/expr/TypeConversionExpr.js +2 -0
  102. package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +42 -42
  103. package/dist/ast/nodes/expr/functions/CallExpr.d.ts +1 -1
  104. package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +2 -1
  105. package/dist/ast/nodes/expr/functions/FuncExpr.js +6 -0
  106. package/dist/ast/nodes/expr/litteral/LitContextExpr.d.ts +6 -0
  107. package/dist/ast/nodes/expr/litteral/LitContextExpr.js +6 -0
  108. package/dist/ast/nodes/expr/litteral/LitFailExpr.d.ts +6 -0
  109. package/dist/ast/nodes/expr/litteral/LitFailExpr.js +6 -0
  110. package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +3 -1
  111. package/dist/ast/nodes/expr/litteral/LitteralExpr.js +5 -1
  112. package/dist/ast/nodes/statements/AssertStmt.d.ts +2 -2
  113. package/dist/ast/nodes/statements/AssignmentStmt.d.ts +1 -1
  114. package/dist/ast/nodes/statements/BlockStmt.d.ts +1 -1
  115. package/dist/ast/nodes/statements/FailStmt.d.ts +1 -1
  116. package/dist/ast/nodes/statements/ForOfStmt.d.ts +4 -2
  117. package/dist/ast/nodes/statements/ForOfStmt.js +6 -0
  118. package/dist/ast/nodes/statements/ForStmt.d.ts +6 -4
  119. package/dist/ast/nodes/statements/ForStmt.js +6 -0
  120. package/dist/ast/nodes/statements/IfStmt.d.ts +8 -5
  121. package/dist/ast/nodes/statements/IfStmt.js +13 -0
  122. package/dist/ast/nodes/statements/MatchStmt.d.ts +13 -4
  123. package/dist/ast/nodes/statements/MatchStmt.js +22 -1
  124. package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
  125. package/dist/ast/nodes/statements/PebbleStmt.js +3 -1
  126. package/dist/ast/nodes/statements/ReturnStmt.d.ts +1 -1
  127. package/dist/ast/nodes/statements/WhileStmt.d.ts +4 -2
  128. package/dist/ast/nodes/statements/WhileStmt.js +6 -0
  129. package/dist/ast/nodes/statements/declarations/ContractDecl.d.ts +17 -0
  130. package/dist/ast/nodes/statements/declarations/ContractDecl.js +22 -0
  131. package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +1 -1
  132. package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +1 -1
  133. package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +1 -1
  134. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +2 -1
  135. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +6 -0
  136. package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +1 -1
  137. package/dist/compiler/AstCompiler/AstCompiler.d.ts +6 -2
  138. package/dist/compiler/AstCompiler/AstCompiler.js +91 -24
  139. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.d.ts +10 -0
  140. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +777 -0
  141. package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +1 -1
  142. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +1 -1
  143. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +8 -2
  144. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +1 -1
  145. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +3 -1
  146. package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
  147. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +2 -2
  148. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +2 -2
  149. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +48 -24
  150. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
  151. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +2 -2
  152. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +1 -1
  153. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +4 -1
  154. package/dist/compiler/AstCompiler/scope/AstScope.js +4 -3
  155. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
  156. package/dist/compiler/Compiler.js +3 -1
  157. package/dist/compiler/TirCompiler/compileTirProgram.js +3 -1
  158. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +13 -3
  159. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +41 -37
  160. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +11 -2
  161. package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
  162. package/dist/compiler/TirCompiler/expressify/expressify.js +82 -36
  163. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
  164. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +57 -8
  165. package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
  166. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +1 -1
  167. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +1 -0
  168. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +131 -9
  169. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +3 -1
  170. package/dist/compiler/io/IOutputStream.d.ts +1 -0
  171. package/dist/compiler/io/IOutputStream.js +18 -3
  172. package/dist/compiler/path/getAbsolutePath.js +4 -6
  173. package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
  174. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
  175. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
  176. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
  177. package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
  178. package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
  179. package/dist/compiler/tir/expressions/TirCaseExpr.js +103 -60
  180. package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
  181. package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
  182. package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
  183. package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
  184. package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
  185. package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
  186. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
  187. package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
  188. package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
  189. package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
  190. package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
  191. package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
  192. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +5 -2
  193. package/dist/compiler/tir/expressions/TirLettedExpr.js +19 -4
  194. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +8 -5
  195. package/dist/compiler/tir/expressions/TirNativeFunc.js +50 -22
  196. package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
  197. package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
  198. package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
  199. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -0
  200. package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
  201. package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
  202. package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
  203. package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
  204. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
  205. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
  206. package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
  207. package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
  208. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +7 -3
  209. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +17 -7
  210. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +16 -20
  211. package/dist/compiler/tir/expressions/ToIRTermCtx.js +67 -50
  212. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +40 -0
  213. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +174 -3
  214. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
  215. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
  216. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
  217. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
  218. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
  219. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
  220. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
  221. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
  222. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
  223. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
  224. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
  225. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
  226. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
  227. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
  228. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
  229. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
  230. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
  231. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
  232. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
  233. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
  234. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
  235. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
  236. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
  237. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
  238. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
  239. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
  240. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
  241. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
  242. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
  243. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
  244. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
  245. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
  246. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
  247. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
  248. package/dist/compiler/tir/program/TypedProgram.d.ts +1 -0
  249. package/dist/compiler/tir/program/TypedProgram.js +9 -0
  250. package/dist/compiler/tir/program/stdScope/stdScope.js +126 -126
  251. package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
  252. package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
  253. package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
  254. package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
  255. package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
  256. package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
  257. package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
  258. package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
  259. package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
  260. package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
  261. package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
  262. package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
  263. package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
  264. package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
  265. package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
  266. package/dist/compiler/tir/statements/TirForStmt.js +21 -0
  267. package/dist/compiler/tir/statements/TirIfStmt.d.ts +3 -0
  268. package/dist/compiler/tir/statements/TirIfStmt.js +19 -0
  269. package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
  270. package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
  271. package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
  272. package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
  273. package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
  274. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
  275. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
  276. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
  277. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
  278. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
  279. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
  280. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
  281. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
  282. package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
  283. package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
  284. package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
  285. package/dist/diagnostics/DiagnosticEmitter.js +1 -1
  286. package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
  287. package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
  288. package/dist/parser/Parser.d.ts +8 -3
  289. package/dist/parser/Parser.js +162 -30
  290. package/dist/tokenizer/Token.d.ts +81 -72
  291. package/dist/tokenizer/Token.js +82 -72
  292. package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
  293. package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
  294. package/dist/utils/BitUtils/index.js +1 -1
  295. package/dist/utils/UPLCFlatUtils/index.js +1 -1
  296. package/package.json +2 -1
  297. package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
  298. package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
  299. package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
  300. package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
  301. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
  302. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
  303. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
  304. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
  305. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
  306. package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
  307. package/dist/IR/tree_utils/_ir_apps.js +0 -8
@@ -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.next() !== Token.Struct)
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.next() !== Token.Struct)
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 & StructDeclAstFlags.untaggedSingleConstructor, range.clone());
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 & StructDeclAstFlags.untaggedSingleConstructor, tn.range(startPos, tn.pos));
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 = undefined;
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
- const [explicitType, initializer] = this._parseTypeAndInitializer();
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
- [explicitType, initializer] = this._parseTypeAndInitializer();
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
- const [explicitType, initializer] = this._parseTypeAndInitializer();
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();
@@ -1043,6 +1141,9 @@ export class Parser extends DiagnosticEmitter {
1043
1141
  let nextPrecedence;
1044
1142
  while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
1045
1143
  const token = tn.next();
1144
+ // DO NOT DIRECTLY RETURN FROM HERE
1145
+ // we need to loop to support right associative operators
1146
+ // and also to support constructs like a.b().c.d()[x]!.e().f.g
1046
1147
  switch (token) {
1047
1148
  case Token.As: {
1048
1149
  if (tn.skip(Token.Const))
@@ -1266,10 +1367,12 @@ export class Parser extends DiagnosticEmitter {
1266
1367
  }
1267
1368
  // Special Identifier
1268
1369
  case Token.Void: return new LitVoidExpr(tn.range());
1370
+ case Token.Fail: return new LitFailExpr(tn.range());
1269
1371
  case Token.Undefined: return new LitUndefExpr(tn.range());
1270
1372
  case Token.True: return new LitTrueExpr(tn.range());
1271
1373
  case Token.False: return new LitFalseExpr(tn.range());
1272
1374
  case Token.This: return new LitThisExpr(tn.range());
1375
+ case Token.Context: return new LitContextExpr(tn.range());
1273
1376
  // ParenthesizedPebbleExpr or FunctionPebbleExpr
1274
1377
  case Token.OpenParen: {
1275
1378
  // determine whether this is a function expression
@@ -1350,8 +1453,15 @@ export class Parser extends DiagnosticEmitter {
1350
1453
  }
1351
1454
  case Token.Identifier: {
1352
1455
  const identifierText = tn.readIdentifier();
1353
- if (identifierText === "undefined")
1354
- return new LitUndefExpr(tn.range()); // special
1456
+ // special expressions
1457
+ switch (identifierText) {
1458
+ case "undefined": return new LitUndefExpr(tn.range());
1459
+ case "true": return new LitTrueExpr(tn.range());
1460
+ case "false": return new LitFalseExpr(tn.range());
1461
+ case "this": return new LitThisExpr(tn.range());
1462
+ case "void": return new LitVoidExpr(tn.range());
1463
+ case "fail": return new LitFailExpr(tn.range());
1464
+ }
1355
1465
  const identifier = new Identifier(identifierText, tn.range(startPos, tn.pos));
1356
1466
  // LitNamedObjExpr
1357
1467
  // eg: `Identifier{ a: 1, b: 2 }`
@@ -1422,6 +1532,9 @@ export class Parser extends DiagnosticEmitter {
1422
1532
  if (!expr)
1423
1533
  return undefined;
1424
1534
  }
1535
+ case Token.Fail: {
1536
+ return new LitFailExpr(tn.range());
1537
+ }
1425
1538
  // case Token.Class: return this.parseClassPebbleExpr();
1426
1539
  // case Token.Struct: return this.parseStructExpr();
1427
1540
  default: {
@@ -1455,7 +1568,7 @@ export class Parser extends DiagnosticEmitter {
1455
1568
  }
1456
1569
  parseCaseExpr() {
1457
1570
  const tn = this.tn;
1458
- // at 'case': Expression ('is' VarDecl '=>' Expression)+
1571
+ // at 'case': Expression ('is' VarDecl '=>' Expression)+ ('else' Expression)?
1459
1572
  const startPos = tn.tokenPos;
1460
1573
  const expr = this.parseExpr();
1461
1574
  if (!expr)
@@ -1480,11 +1593,19 @@ export class Parser extends DiagnosticEmitter {
1480
1593
  return undefined;
1481
1594
  cases.push(new CaseExprMatcher(matcher, body, tn.range(startPos, tn.pos)));
1482
1595
  }
1596
+ let wildcardCase = undefined;
1597
+ if (tn.skip(Token.Else)) {
1598
+ const wildcardStart = tn.tokenPos;
1599
+ const body = this.parseExpr(Precedence.CaseExpr);
1600
+ if (!body)
1601
+ return undefined;
1602
+ wildcardCase = new CaseWildcardMatcher(body, tn.range(wildcardStart));
1603
+ }
1604
+ tn.skip(Token.Semicolon); // if any
1483
1605
  const finalRange = tn.range(startPos, tn.pos);
1484
1606
  if (cases.length < 1)
1485
1607
  return this.error(DiagnosticCode.A_case_expression_must_have_at_least_one_clause, finalRange);
1486
- return new CaseExpr(expr, cases, undefined, // wildcard case
1487
- finalRange);
1608
+ return new CaseExpr(expr, cases, wildcardCase, finalRange);
1488
1609
  }
1489
1610
  parseFunctionExpr() {
1490
1611
  const tn = this.tn;
@@ -2128,11 +2249,13 @@ export class Parser extends DiagnosticEmitter {
2128
2249
  return this.error(DiagnosticCode._0_expected, tn.range(), "{");
2129
2250
  let noPatternCaseSeen = false;
2130
2251
  const cases = new Array();
2131
- while (!tn.skip(Token.CloseBrace)) {
2132
- if (!tn.skip(Token.When))
2252
+ while (!tn.skip(Token.CloseBrace)
2253
+ && tn.peek() !== Token.Else) {
2254
+ if (!tn.skip(Token.When)) {
2133
2255
  return this.error(DiagnosticCode._0_expected, tn.range(), "when");
2256
+ }
2134
2257
  // const startPos = tn.pos;
2135
- const pattern = this._parseVarDecl(CommonFlags.Const);
2258
+ const pattern = this._parseVarDecl(CommonFlags.Const, true);
2136
2259
  if (!pattern)
2137
2260
  return this.error(DiagnosticCode.Pattern_expected, tn.range());
2138
2261
  if (noPatternCaseSeen)
@@ -2147,9 +2270,18 @@ export class Parser extends DiagnosticEmitter {
2147
2270
  return this.error(DiagnosticCode._0_expected, tn.range(statePreBody.tokenPos, statePreBody.pos), "{");
2148
2271
  cases.push(new MatchStmtCase(pattern, body, tn.range()));
2149
2272
  }
2273
+ let elseCase = undefined;
2274
+ if (tn.skip(Token.Else)) {
2275
+ const body = this.parseStatement({ topLevel: false, isExport: false });
2276
+ if (!body)
2277
+ return this.error(DiagnosticCode.Statement_expected, tn.range());
2278
+ elseCase = new MatchStmtElseCase(body, tn.range());
2279
+ if (!tn.skip(Token.CloseBrace))
2280
+ return this.error(DiagnosticCode._0_expected, tn.range(), "}");
2281
+ }
2150
2282
  if (cases.length < 1)
2151
2283
  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));
2284
+ return new MatchStmt(expr, cases, elseCase, tn.range(startPos, tn.pos));
2153
2285
  }
2154
2286
  parseFailStatement() {
2155
2287
  const tn = this.tn;
@@ -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 = 41,
54
+ OpenBrace = 50,
46
55
  /** `}` */
47
- CloseBrace = 42,
48
- OpenParen = 43,
49
- CloseParen = 44,
56
+ CloseBrace = 51,
57
+ OpenParen = 52,
58
+ CloseParen = 53,
50
59
  /** `[` */
51
- OpenBracket = 45,
60
+ OpenBracket = 54,
52
61
  /** `]` */
53
- CloseBracket = 46,
62
+ CloseBracket = 55,
54
63
  /** `.` */
55
- Dot = 47,
64
+ Dot = 56,
56
65
  /** `...` */
57
- Dot_Dot_Dot = 48,
66
+ Dot_Dot_Dot = 57,
58
67
  /** `;` */
59
- Semicolon = 49,
68
+ Semicolon = 58,
60
69
  /** `,` */
61
- Comma = 50,
70
+ Comma = 59,
62
71
  /** `<` */
63
- LessThan = 51,
72
+ LessThan = 60,
64
73
  /** `>` */
65
- GreaterThan = 52,
74
+ GreaterThan = 61,
66
75
  /** `<=` */
67
- LessThan_Equals = 53,
76
+ LessThan_Equals = 62,
68
77
  /** `>=` */
69
- GreaterThan_Equals = 54,
78
+ GreaterThan_Equals = 63,
70
79
  /** `==` */
71
- Equals_Equals = 55,
80
+ Equals_Equals = 64,
72
81
  /** `!=` */
73
- Exclamation_Equals = 56,
82
+ Exclamation_Equals = 65,
74
83
  /** `===` */
75
- Equals_Equals_Equals = 57,
84
+ Equals_Equals_Equals = 66,
76
85
  /** `!==` */
77
- Exclamation_Equals_Equals = 58,
86
+ Exclamation_Equals_Equals = 67,
78
87
  /** `=>` */
79
- FatArrow = 59,
88
+ FatArrow = 68,
80
89
  /** `+` */
81
- Plus = 60,
90
+ Plus = 69,
82
91
  /** `-` */
83
- Minus = 61,
92
+ Minus = 70,
84
93
  /** `**` */
85
- Asterisk_Asterisk = 62,
94
+ Asterisk_Asterisk = 71,
86
95
  /** `*` */
87
- Asterisk = 63,
96
+ Asterisk = 72,
88
97
  /** `/` */
89
- Slash = 64,
98
+ Slash = 73,
90
99
  /** `%` */
91
- Percent = 65,
100
+ Percent = 74,
92
101
  /** `++` */
93
- Plus_Plus = 66,
102
+ Plus_Plus = 75,
94
103
  /** `--` */
95
- Minus_Minus = 67,
104
+ Minus_Minus = 76,
96
105
  /** `<<` */
97
- LessThan_LessThan = 68,
106
+ LessThan_LessThan = 77,
98
107
  /** `>>` */
99
- GreaterThan_GreaterThan = 69,
108
+ GreaterThan_GreaterThan = 78,
100
109
  /** `>>>` */
101
- GreaterThan_GreaterThan_GreaterThan = 70,
110
+ GreaterThan_GreaterThan_GreaterThan = 79,
102
111
  /** `+` */
103
- Ampersand = 71,
112
+ Ampersand = 80,
104
113
  /** `|` */
105
- Bar = 72,
114
+ Bar = 81,
106
115
  /** `^` */
107
- Caret = 73,
116
+ Caret = 82,
108
117
  /** `!` */
109
- Exclamation = 74,
118
+ Exclamation = 83,
110
119
  /** `~` */
111
- Tilde = 75,
120
+ Tilde = 84,
112
121
  /** `&&` */
113
- Ampersand_Ampersand = 76,
122
+ Ampersand_Ampersand = 85,
114
123
  /** `||` */
115
- Bar_Bar = 77,
124
+ Bar_Bar = 86,
116
125
  /** `?` */
117
- Question = 78,
126
+ Question = 87,
118
127
  /** `:` */
119
- Colon = 79,
128
+ Colon = 88,
120
129
  /** `=` */
121
- Equals = 80,
122
- Plus_Equals = 81,
123
- Minus_Equals = 82,
124
- Asterisk_Equals = 83,
125
- Asterisk_Asterisk_Equals = 84,
126
- Slash_Equals = 85,
127
- Percent_Equals = 86,
128
- LessThan_LessThan_Equals = 87,
129
- GreaterThan_GreaterThan_Equals = 88,
130
- GreaterThan_GreaterThan_GreaterThan_Equals = 89,
131
- Ampersand_Equals = 90,
132
- Bar_Equals = 91,
133
- Caret_Equals = 92,
134
- At = 93,
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 = 94,
145
+ Question_Question_Equals = 103,
137
146
  /** `||=` */
138
- Bar_Bar_Equals = 95,
147
+ Bar_Bar_Equals = 104,
139
148
  /** `&&=` */
140
- Ampersand_Ampersand_Equals = 96,
149
+ Ampersand_Ampersand_Equals = 105,
141
150
  /** `??` */
142
- Question_Question = 97,
151
+ Question_Question = 106,
143
152
  /** `?.` */
144
- Question_Dot = 98,
153
+ Question_Dot = 107,
145
154
  /** `!.` */
146
- Exclamation_Dot = 99,
147
- Data = 100,
148
- Bytes = 101,
149
- Optional = 102,
150
- List = 103,
151
- LinearMap = 104,
152
- Runtime = 105,
153
- Identifier = 106,
154
- StringLiteral = 107,
155
- HexBytesLiteral = 108,
156
- IntegerLiteral = 109,
157
- StringTemplateLiteralQuote = 110,
158
- Invalid = 111,
159
- EndOfFile = 112
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
  }