@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.
Files changed (321) 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 +3 -3
  24. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +4 -4
  25. package/dist/IR/IRNodes/IRNative/index.d.ts +10 -8
  26. package/dist/IR/IRNodes/IRNative/index.js +56 -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/CompilerOptions.d.ts +5 -0
  42. package/dist/IR/toUPLC/CompilerOptions.js +10 -1
  43. package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +3 -0
  44. package/dist/IR/toUPLC/_internal/findAll.js +2 -73
  45. package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +7 -34
  46. package/dist/IR/toUPLC/_internal/iterTree.js +3 -17
  47. package/dist/IR/toUPLC/common_hoisted.d.ts +2 -0
  48. package/dist/IR/toUPLC/common_hoisted.js +4 -0
  49. package/dist/IR/toUPLC/compileIRToUPLC.d.ts +1 -1
  50. package/dist/IR/toUPLC/compileIRToUPLC.js +91 -14
  51. package/dist/IR/toUPLC/ctx/ToUplcCtx.d.ts +16 -0
  52. package/dist/IR/toUPLC/ctx/ToUplcCtx.js +67 -0
  53. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.d.ts +8 -0
  54. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.js +95 -0
  55. package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +7 -54
  56. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +6 -13
  57. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +65 -71
  58. package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +44 -170
  59. package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +7 -3
  60. package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +3 -2
  61. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.d.ts +22 -0
  62. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.js +59 -0
  63. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts +0 -0
  64. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.js +217 -0
  65. package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +12 -49
  66. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +1 -1
  67. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +11 -14
  68. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/{index.d.ts → performUplcOptimizationsAndReturnRoot.d.ts} +0 -2
  69. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +151 -0
  70. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.d.ts +11 -0
  71. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.js +46 -0
  72. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.d.ts +2 -0
  73. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js +80 -0
  74. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +18 -11
  75. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +45 -0
  76. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +277 -478
  77. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.d.ts +2 -0
  78. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +85 -0
  79. package/dist/IR/toUPLC/subRoutines/sanifyTree.js +1 -0
  80. package/dist/IR/toUPLC/utils/getApplicationTerms.d.ts +6 -0
  81. package/dist/IR/toUPLC/utils/getApplicationTerms.js +37 -0
  82. package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +2 -2
  83. package/dist/IR/tree_utils/_ir_lazyChooseList.js +4 -2
  84. package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +1 -1
  85. package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +4 -2
  86. package/dist/IR/tree_utils/_ir_let.d.ts +2 -1
  87. package/dist/IR/tree_utils/_ir_let.js +6 -2
  88. package/dist/IR/utils/isClosedIRTerm.d.ts +1 -0
  89. package/dist/IR/utils/isClosedIRTerm.js +40 -26
  90. package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
  91. package/dist/IR/utils/positiveIntAsBytes.js +4 -4
  92. package/dist/IR/utils/showIR.d.ts +10 -21
  93. package/dist/IR/utils/showIR.js +66 -64
  94. package/dist/ast/nodes/common/Identifier.d.ts +1 -0
  95. package/dist/ast/nodes/common/Identifier.js +3 -0
  96. package/dist/ast/nodes/expr/CaseExpr.d.ts +5 -5
  97. package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +2 -2
  98. package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +1 -1
  99. package/dist/ast/nodes/expr/PebbleExpr.d.ts +2 -1
  100. package/dist/ast/nodes/expr/PropAccessExpr.d.ts +3 -3
  101. package/dist/ast/nodes/expr/TernaryExpr.d.ts +3 -3
  102. package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +2 -1
  103. package/dist/ast/nodes/expr/TypeConversionExpr.js +2 -0
  104. package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +42 -42
  105. package/dist/ast/nodes/expr/functions/CallExpr.d.ts +1 -1
  106. package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +2 -1
  107. package/dist/ast/nodes/expr/functions/FuncExpr.js +6 -0
  108. package/dist/ast/nodes/expr/litteral/LitContextExpr.d.ts +6 -0
  109. package/dist/ast/nodes/expr/litteral/LitContextExpr.js +6 -0
  110. package/dist/ast/nodes/expr/litteral/LitFailExpr.d.ts +6 -0
  111. package/dist/ast/nodes/expr/litteral/LitFailExpr.js +6 -0
  112. package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +3 -1
  113. package/dist/ast/nodes/expr/litteral/LitteralExpr.js +5 -1
  114. package/dist/ast/nodes/statements/AssertStmt.d.ts +2 -2
  115. package/dist/ast/nodes/statements/AssignmentStmt.d.ts +1 -1
  116. package/dist/ast/nodes/statements/BlockStmt.d.ts +1 -1
  117. package/dist/ast/nodes/statements/FailStmt.d.ts +1 -1
  118. package/dist/ast/nodes/statements/ForOfStmt.d.ts +4 -2
  119. package/dist/ast/nodes/statements/ForOfStmt.js +6 -0
  120. package/dist/ast/nodes/statements/ForStmt.d.ts +6 -4
  121. package/dist/ast/nodes/statements/ForStmt.js +6 -0
  122. package/dist/ast/nodes/statements/IfStmt.d.ts +8 -5
  123. package/dist/ast/nodes/statements/IfStmt.js +13 -0
  124. package/dist/ast/nodes/statements/MatchStmt.d.ts +13 -4
  125. package/dist/ast/nodes/statements/MatchStmt.js +22 -1
  126. package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
  127. package/dist/ast/nodes/statements/PebbleStmt.js +3 -1
  128. package/dist/ast/nodes/statements/ReturnStmt.d.ts +1 -1
  129. package/dist/ast/nodes/statements/WhileStmt.d.ts +4 -2
  130. package/dist/ast/nodes/statements/WhileStmt.js +6 -0
  131. package/dist/ast/nodes/statements/declarations/ContractDecl.d.ts +17 -0
  132. package/dist/ast/nodes/statements/declarations/ContractDecl.js +22 -0
  133. package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +1 -1
  134. package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +1 -1
  135. package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +1 -1
  136. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +2 -1
  137. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +6 -0
  138. package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +1 -1
  139. package/dist/compiler/AstCompiler/AstCompiler.d.ts +7 -2
  140. package/dist/compiler/AstCompiler/AstCompiler.js +129 -25
  141. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.d.ts +10 -0
  142. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +777 -0
  143. package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +1 -1
  144. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +5 -1
  145. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +7 -4
  146. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +8 -2
  147. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +1 -1
  148. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +2 -1
  149. package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
  150. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
  151. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +8 -8
  152. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +2 -2
  153. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +48 -24
  154. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
  155. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +2 -1
  156. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +4 -3
  157. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +1 -1
  158. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +4 -1
  159. package/dist/compiler/AstCompiler/scope/AstScope.d.ts +1 -0
  160. package/dist/compiler/AstCompiler/scope/AstScope.js +9 -3
  161. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
  162. package/dist/compiler/Compiler.js +7 -1
  163. package/dist/compiler/TirCompiler/compileTirProgram.js +4 -1
  164. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +17 -5
  165. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +79 -49
  166. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +13 -2
  167. package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
  168. package/dist/compiler/TirCompiler/expressify/expressify.js +102 -41
  169. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
  170. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +77 -12
  171. package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
  172. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
  173. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +16 -9
  174. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -8
  175. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +146 -13
  176. package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
  177. package/dist/compiler/internalVar.d.ts +1 -1
  178. package/dist/compiler/internalVar.js +31 -24
  179. package/dist/compiler/io/CompilerIoApi.d.ts +1 -1
  180. package/dist/compiler/io/IOutputStream.d.ts +1 -0
  181. package/dist/compiler/io/IOutputStream.js +18 -3
  182. package/dist/compiler/path/getAbsolutePath.js +4 -6
  183. package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
  184. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
  185. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
  186. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
  187. package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
  188. package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
  189. package/dist/compiler/tir/expressions/TirCaseExpr.js +105 -60
  190. package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
  191. package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
  192. package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
  193. package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
  194. package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
  195. package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
  196. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
  197. package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
  198. package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
  199. package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
  200. package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
  201. package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
  202. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +6 -3
  203. package/dist/compiler/tir/expressions/TirLettedExpr.js +20 -7
  204. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +9 -5
  205. package/dist/compiler/tir/expressions/TirNativeFunc.js +58 -22
  206. package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
  207. package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
  208. package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
  209. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -1
  210. package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
  211. package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
  212. package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
  213. package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
  214. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
  215. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
  216. package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
  217. package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
  218. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +6 -3
  219. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +22 -8
  220. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +19 -20
  221. package/dist/compiler/tir/expressions/ToIRTermCtx.js +74 -50
  222. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +41 -0
  223. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +180 -4
  224. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
  225. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
  226. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
  227. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
  228. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
  229. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
  230. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
  231. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
  232. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
  233. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
  234. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
  235. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
  236. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
  237. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
  238. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
  239. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
  240. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
  241. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
  242. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
  243. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
  244. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
  245. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
  246. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
  247. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
  248. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
  249. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
  250. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
  251. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
  252. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
  253. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
  254. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
  255. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
  256. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
  257. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
  258. package/dist/compiler/tir/program/TypedProgram.d.ts +3 -2
  259. package/dist/compiler/tir/program/TypedProgram.js +9 -0
  260. package/dist/compiler/tir/program/stdScope/stdScope.js +135 -149
  261. package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
  262. package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
  263. package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
  264. package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
  265. package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
  266. package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
  267. package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
  268. package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
  269. package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
  270. package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
  271. package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
  272. package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
  273. package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
  274. package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
  275. package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
  276. package/dist/compiler/tir/statements/TirForStmt.js +21 -0
  277. package/dist/compiler/tir/statements/TirIfStmt.d.ts +2 -0
  278. package/dist/compiler/tir/statements/TirIfStmt.js +16 -0
  279. package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
  280. package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
  281. package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
  282. package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
  283. package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
  284. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
  285. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
  286. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
  287. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
  288. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
  289. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
  290. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
  291. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
  292. package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
  293. package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
  294. package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
  295. package/dist/diagnostics/DiagnosticEmitter.js +1 -1
  296. package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
  297. package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
  298. package/dist/parser/Parser.d.ts +8 -3
  299. package/dist/parser/Parser.js +180 -32
  300. package/dist/parser/Precedence.js +1 -0
  301. package/dist/tokenizer/Token.d.ts +81 -72
  302. package/dist/tokenizer/Token.js +82 -72
  303. package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
  304. package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
  305. package/dist/utils/BitUtils/index.js +1 -1
  306. package/dist/utils/UPLCFlatUtils/index.js +1 -1
  307. package/dist/utils/array/keepSortedArrInplace.js +1 -0
  308. package/package.json +3 -1
  309. package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
  310. package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
  311. package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
  312. package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
  313. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
  314. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
  315. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
  316. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
  317. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
  318. package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
  319. package/dist/IR/tree_utils/_ir_apps.js +0 -8
  320. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
  321. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -37
@@ -23,7 +23,8 @@ import { UsingStmt } from "./UsingStmt.js";
23
23
  import { FuncDecl } from "./declarations/FuncDecl.js";
24
24
  import { ExportStmt } from "./ExportStmt.js";
25
25
  import { InterfaceDecl } from "./declarations/InterfaceDecl.js";
26
- export type TopLevelStmt = EmptyStmt | VarStmt | PebbleTypeDecl | InterfaceDecl | FuncDecl | TestStmt | ExportStmt | ExportStarStmt | ExportImportStmt | ImportStmt | ImportStarStmt | TypeImplementsStmt | UsingStmt;
26
+ import { ContractDecl } from "./declarations/ContractDecl.js";
27
+ export type TopLevelStmt = EmptyStmt | VarStmt | PebbleTypeDecl | InterfaceDecl | FuncDecl | TestStmt | ExportStmt | ExportStarStmt | ExportImportStmt | ImportStmt | ImportStarStmt | TypeImplementsStmt | UsingStmt | ContractDecl;
27
28
  export declare function isTopLevelStmt(stmt: any): stmt is TopLevelStmt;
28
29
  export type BodyStmt = IfStmt | VarStmt | ForStmt | ForOfStmt | WhileStmt | ReturnStmt | BlockStmt | BreakStmt | ContinueStmt | EmptyStmt | FailStmt | AssertStmt | MatchStmt | AssignmentStmt | UsingStmt;
29
30
  export declare function isBodyStmt(stmt: any): stmt is BodyStmt;
@@ -25,6 +25,7 @@ import { DecrStmt } from "./DecrStmt.js";
25
25
  import { UsingStmt } from "./UsingStmt.js";
26
26
  import { FuncDecl } from "./declarations/FuncDecl.js";
27
27
  import { ExportStmt } from "./ExportStmt.js";
28
+ import { ContractDecl } from "./declarations/ContractDecl.js";
28
29
  export function isTopLevelStmt(stmt) {
29
30
  return (stmt instanceof EmptyStmt
30
31
  || stmt instanceof VarStmt
@@ -37,7 +38,8 @@ export function isTopLevelStmt(stmt) {
37
38
  || stmt instanceof ImportStmt
38
39
  || stmt instanceof ImportStarStmt
39
40
  || stmt instanceof TypeImplementsStmt
40
- || stmt instanceof UsingStmt);
41
+ || stmt instanceof UsingStmt
42
+ || stmt instanceof ContractDecl);
41
43
  }
42
44
  export function isBodyStmt(stmt) {
43
45
  return (stmt instanceof IfStmt
@@ -2,7 +2,7 @@ import { SourceRange } from "../../Source/SourceRange.js";
2
2
  import { PebbleExpr } from "../expr/PebbleExpr.js";
3
3
  import { HasSourceRange } from "../HasSourceRange.js";
4
4
  export declare class ReturnStmt implements HasSourceRange {
5
- readonly value: PebbleExpr | undefined;
5
+ value: PebbleExpr | undefined;
6
6
  readonly range: SourceRange;
7
7
  constructor(value: PebbleExpr | undefined, range: SourceRange);
8
8
  }
@@ -1,10 +1,12 @@
1
1
  import { SourceRange } from "../../Source/SourceRange.js";
2
2
  import { PebbleExpr } from "../expr/PebbleExpr.js";
3
3
  import { HasSourceRange } from "../HasSourceRange.js";
4
+ import { BlockStmt } from "./BlockStmt.js";
4
5
  import { BodyStmt } from "./PebbleStmt.js";
5
6
  export declare class WhileStmt implements HasSourceRange {
6
- readonly condition: PebbleExpr;
7
- readonly body: BodyStmt;
7
+ condition: PebbleExpr;
8
+ body: BodyStmt;
8
9
  readonly range: SourceRange;
9
10
  constructor(condition: PebbleExpr, body: BodyStmt, range: SourceRange);
11
+ bodyBlock(): BlockStmt;
10
12
  }
@@ -1,3 +1,4 @@
1
+ import { BlockStmt } from "./BlockStmt.js";
1
2
  export class WhileStmt {
2
3
  condition;
3
4
  body;
@@ -7,4 +8,9 @@ export class WhileStmt {
7
8
  this.body = body;
8
9
  this.range = range;
9
10
  }
11
+ bodyBlock() {
12
+ if (this.body instanceof BlockStmt)
13
+ return this.body;
14
+ return new BlockStmt([this.body], this.body.range);
15
+ }
10
16
  }
@@ -0,0 +1,17 @@
1
+ import { SourceRange } from "../../../Source/SourceRange.js";
2
+ import { Identifier } from "../../common/Identifier.js";
3
+ import { HasSourceRange } from "../../HasSourceRange.js";
4
+ import { FuncDecl } from "./FuncDecl.js";
5
+ import { SimpleVarDecl } from "./VarDecl/SimpleVarDecl.js";
6
+ export declare class ContractDecl implements HasSourceRange {
7
+ readonly name: Identifier;
8
+ readonly params: SimpleVarDecl[];
9
+ readonly spendMethods: FuncDecl[];
10
+ readonly mintMethods: FuncDecl[];
11
+ readonly certifyMethods: FuncDecl[];
12
+ readonly withdrawMethods: FuncDecl[];
13
+ readonly proposeMethods: FuncDecl[];
14
+ readonly voteMethods: FuncDecl[];
15
+ readonly range: SourceRange;
16
+ constructor(name: Identifier, params: SimpleVarDecl[], spendMethods: FuncDecl[], mintMethods: FuncDecl[], certifyMethods: FuncDecl[], withdrawMethods: FuncDecl[], proposeMethods: FuncDecl[], voteMethods: FuncDecl[], range: SourceRange);
17
+ }
@@ -0,0 +1,22 @@
1
+ export class ContractDecl {
2
+ name;
3
+ params;
4
+ spendMethods;
5
+ mintMethods;
6
+ certifyMethods;
7
+ withdrawMethods;
8
+ proposeMethods;
9
+ voteMethods;
10
+ range;
11
+ constructor(name, params, spendMethods, mintMethods, certifyMethods, withdrawMethods, proposeMethods, voteMethods, range) {
12
+ this.name = name;
13
+ this.params = params;
14
+ this.spendMethods = spendMethods;
15
+ this.mintMethods = mintMethods;
16
+ this.certifyMethods = certifyMethods;
17
+ this.withdrawMethods = withdrawMethods;
18
+ this.proposeMethods = proposeMethods;
19
+ this.voteMethods = voteMethods;
20
+ this.range = range;
21
+ }
22
+ }
@@ -10,7 +10,7 @@ export declare class ArrayLikeDeconstr implements HasSourceRange, HasInitExpr {
10
10
  readonly elements: VarDecl[];
11
11
  readonly rest: Identifier | undefined;
12
12
  type: AstTypeExpr | undefined;
13
- readonly initExpr: PebbleExpr | undefined;
13
+ initExpr: PebbleExpr | undefined;
14
14
  flags: CommonFlags;
15
15
  readonly range: SourceRange;
16
16
  constructor(elements: VarDecl[], rest: Identifier | undefined, type: AstTypeExpr | undefined, // just for the type checker, or func params, usually this is inferred
@@ -1,5 +1,5 @@
1
1
  import { PebbleExpr } from "../../../expr/PebbleExpr.js";
2
2
  export interface HasInitExpr {
3
- readonly initExpr: PebbleExpr | undefined;
3
+ initExpr: PebbleExpr | undefined;
4
4
  }
5
5
  export declare function hasInitExpr(thing: any): thing is HasInitExpr;
@@ -12,7 +12,7 @@ export declare class NamedDeconstructVarDecl implements HasSourceRange, ISingleD
12
12
  readonly fields: Map<Identifier, VarDecl>;
13
13
  readonly rest: Identifier | undefined;
14
14
  type: AstTypeExpr | undefined;
15
- readonly initExpr: PebbleExpr | undefined;
15
+ initExpr: PebbleExpr | undefined;
16
16
  flags: CommonFlags;
17
17
  readonly range: SourceRange;
18
18
  constructor(
@@ -8,10 +8,11 @@ import { HasInitExpr } from "./HasInit.js";
8
8
  export declare class SimpleVarDecl implements HasSourceRange, HasInitExpr {
9
9
  readonly name: Identifier;
10
10
  type: AstTypeExpr | undefined;
11
- readonly initExpr: PebbleExpr | undefined;
11
+ initExpr: PebbleExpr | undefined;
12
12
  flags: CommonFlags;
13
13
  readonly range: SourceRange;
14
14
  constructor(name: Identifier, type: AstTypeExpr | undefined, initExpr: PebbleExpr | undefined, flags: CommonFlags, range: SourceRange);
15
15
  isConst(): boolean;
16
16
  static onlyIdentifier(identifier: Identifier, flags: CommonFlags): SimpleVarDecl;
17
+ static onlyNameConst(name: string, range: SourceRange): SimpleVarDecl;
17
18
  }
@@ -1,4 +1,5 @@
1
1
  import { CommonFlags } from "../../../../../common.js";
2
+ import { Identifier } from "../../../common/Identifier.js";
2
3
  export class SimpleVarDecl {
3
4
  name;
4
5
  type;
@@ -18,4 +19,9 @@ export class SimpleVarDecl {
18
19
  static onlyIdentifier(identifier, flags) {
19
20
  return new SimpleVarDecl(identifier, undefined, undefined, flags, identifier.range);
20
21
  }
22
+ static onlyNameConst(name, range) {
23
+ return new SimpleVarDecl(new Identifier(name, range), undefined, // type
24
+ undefined, // initExpr
25
+ CommonFlags.Const, range);
26
+ }
21
27
  }
@@ -16,7 +16,7 @@ export declare class SingleDeconstructVarDecl implements HasSourceRange, ISingle
16
16
  readonly fields: Map<Identifier, VarDecl>;
17
17
  readonly rest: Identifier | undefined;
18
18
  type: AstTypeExpr | undefined;
19
- readonly initExpr: PebbleExpr | undefined;
19
+ initExpr: PebbleExpr | undefined;
20
20
  flags: CommonFlags;
21
21
  readonly range: SourceRange;
22
22
  constructor(fields: Map<Identifier, VarDecl>, rest: Identifier | undefined, type: AstTypeExpr | undefined, initExpr: PebbleExpr | undefined, flags: CommonFlags, range: SourceRange);
@@ -1,3 +1,5 @@
1
+ import { StructDecl } from "../../ast/nodes/statements/declarations/StructDecl.js";
2
+ import { TypeAliasDecl } from "../../ast/nodes/statements/declarations/TypeAliasDecl.js";
1
3
  import { Source } from "../../ast/Source/Source.js";
2
4
  import { DiagnosticEmitter } from "../../diagnostics/DiagnosticEmitter.js";
3
5
  import { DiagnosticMessage } from "../../diagnostics/DiagnosticMessage.js";
@@ -45,7 +47,7 @@ export declare class AstCompiler extends DiagnosticEmitter {
45
47
  * the result is store in `this.program`
46
48
  */
47
49
  compile(): Promise<TypedProgram>;
48
- compileFile(path: string, isMain?: boolean): Promise<Source | undefined>;
50
+ compileFile(path: string, isEntryFile?: boolean): Promise<Source | undefined>;
49
51
  private readonly _srcDonelogUids;
50
52
  /**
51
53
  * translates the source AST statements
@@ -54,8 +56,10 @@ export declare class AstCompiler extends DiagnosticEmitter {
54
56
  private _compileParsedSource;
55
57
  private _collectAllTopLevelSignatures;
56
58
  private _collectInterfaceImplSigs;
59
+ private _collectTopLevelConst;
57
60
  private _collectTopLevelFuncDeclSig;
58
61
  private _collectInterfaceDeclarations;
62
+ registerInternalTypeDecl(decl: StructDecl | TypeAliasDecl): void;
59
63
  private _collectTypeDeclarations;
60
64
  private _compileStructDecl;
61
65
  private _compileTypeAliasDecl;
@@ -67,7 +71,8 @@ export declare class AstCompiler extends DiagnosticEmitter {
67
71
  /**
68
72
  * @returns `true` if there were no errors. `false` otherwise.
69
73
  */
70
- compileAllDeps(_resolveStackNode: ResolveStackNode, isMain?: boolean): Promise<boolean>;
74
+ compileAllDeps(_resolveStackNode: ResolveStackNode, isEntryFile?: boolean): Promise<boolean>;
71
75
  private importPathsFromStmts;
72
76
  private _reportCircularDependency;
77
+ private _contractDeclToFuncDecl;
73
78
  }
@@ -19,10 +19,10 @@ import { _compileDataEncodedConcreteType } from "./internal/types/_compileDataEn
19
19
  import { getAbsolutePath, getEnvRelativePath } from "../path/getAbsolutePath.js";
20
20
  import { _compileSopEncodedConcreteType } from "./internal/types/_compileSopEncodedConcreteType.js";
21
21
  import { InterfaceDecl } from "../../ast/nodes/statements/declarations/InterfaceDecl.js";
22
- import { AstFuncType } from "../../ast/nodes/types/AstNativeTypeExpr.js";
22
+ import { AstFuncType, AstVoidType } from "../../ast/nodes/types/AstNativeTypeExpr.js";
23
23
  import { FuncDecl } from "../../ast/nodes/statements/declarations/FuncDecl.js";
24
24
  import { InterfaceMethodImpl, TypeImplementsStmt } from "../../ast/nodes/statements/TypeImplementsStmt.js";
25
- import { PEBBLE_INTERNAL_IDENTIFIER_PREFIX } from "../internalVar.js";
25
+ import { getUniqueInternalName, PEBBLE_INTERNAL_IDENTIFIER_PREFIX } from "../internalVar.js";
26
26
  import { AstNamedTypeExpr } from "../../ast/nodes/types/AstNamedTypeExpr.js";
27
27
  import { FuncExpr } from "../../ast/nodes/expr/functions/FuncExpr.js";
28
28
  import { CommonFlags } from "../../common.js";
@@ -30,6 +30,11 @@ import { SimpleVarDecl } from "../../ast/nodes/statements/declarations/VarDecl/S
30
30
  import { Identifier } from "../../ast/nodes/common/Identifier.js";
31
31
  import { ArrowKind } from "../../ast/nodes/expr/functions/ArrowKind.js";
32
32
  import { _compileFuncExpr } from "./internal/exprs/_compileFuncExpr.js";
33
+ import { ContractDecl } from "../../ast/nodes/statements/declarations/ContractDecl.js";
34
+ import { _deriveContractBody } from "./internal/_deriveContractBody/_deriveContractBody.js";
35
+ import { DiagnosticCategory } from "../../diagnostics/DiagnosticCategory.js";
36
+ import { VarStmt } from "../../ast/nodes/statements/VarStmt.js";
37
+ import { _compileSimpleVarDecl } from "./internal/statements/_compileVarStmt.js";
33
38
  /*
34
39
  Handling type expressions that depend on other types
35
40
  (such as generics, function return types, and inferred types from complex expressions)
@@ -96,17 +101,22 @@ export class AstCompiler extends DiagnosticEmitter {
96
101
  const entrySrc = await this.compileFile(filePath, true);
97
102
  if (this.diagnostics.length > 0 || !entrySrc) {
98
103
  let msg;
99
- globalThis.console && console.log(this.diagnostics);
100
104
  const fstErrorMsg = this.diagnostics[0].toString();
101
105
  const nDiags = this.diagnostics.length;
102
106
  while (msg = this.diagnostics.shift()) {
103
- this.io.stdout.write(msg.toString() + "\n");
107
+ /*
108
+ this.io.stdout.write( msg.toString() + "\n" );
109
+ /*/
110
+ console.log(msg);
111
+ console.log(msg.toString());
112
+ //*/
104
113
  }
105
114
  throw new Error("AstCompiler.compile: failed with " + nDiags + " diagnostic messages; first message: " + fstErrorMsg);
106
115
  }
107
116
  const mainFuncExpr = this.program.functions.get(this.program.contractTirFuncName);
108
117
  if (this.program.contractTirFuncName === "" || !mainFuncExpr) {
109
- this.error(DiagnosticCode.Main_function_is_missing, undefined);
118
+ console.error(mainFuncExpr, `"${this.program.contractTirFuncName}"`);
119
+ this.error(DiagnosticCode.Contract_is_missing, undefined);
110
120
  return this.program;
111
121
  }
112
122
  if (!mainFuncExpr)
@@ -114,16 +124,16 @@ export class AstCompiler extends DiagnosticEmitter {
114
124
  return this.program;
115
125
  }
116
126
  // mutually recursive
117
- async compileFile(path, isMain = false) {
127
+ async compileFile(path, isEntryFile = false) {
118
128
  const src = await this.getAbsoulteProjPathSource(path);
119
129
  if (!src)
120
130
  return;
121
131
  // parse imports first
122
- await this.compileAllDeps(ResolveStackNode.entry(src), isMain);
132
+ await this.compileAllDeps(ResolveStackNode.entry(src), isEntryFile);
123
133
  // if there were errors
124
- if (this.diagnostics.length > 0)
134
+ if (this.diagnostics.some(d => d.category === DiagnosticCategory.Error))
125
135
  return;
126
- await this._compileParsedSource(src, isMain);
136
+ await this._compileParsedSource(src, isEntryFile);
127
137
  return src;
128
138
  }
129
139
  _srcDonelogUids = new Set();
@@ -131,7 +141,7 @@ export class AstCompiler extends DiagnosticEmitter {
131
141
  * translates the source AST statements
132
142
  * to TIR statements; and saves the result in `this.program`
133
143
  */
134
- async _compileParsedSource(src, isMain = false) {
144
+ async _compileParsedSource(src, isEntryFile = false) {
135
145
  if (this._srcDonelogUids.has(src.uid))
136
146
  return;
137
147
  // clone array so we don't remove stmts from the original AST
@@ -146,7 +156,7 @@ export class AstCompiler extends DiagnosticEmitter {
146
156
  // collect top level **interface** declarations (NOT implementations)
147
157
  this._collectInterfaceDeclarations(stmts, topLevelScope, srcExports);
148
158
  // collects top level functions, methods (interface impls), and consts types
149
- this._collectAllTopLevelSignatures(stmts, src.uid, topLevelScope, srcExports, isMain);
159
+ this._collectAllTopLevelSignatures(stmts, src.uid, topLevelScope, srcExports, isEntryFile);
150
160
  /*
151
161
  this._compileTopLevelFunctionsAndConsts(
152
162
  stmts,
@@ -158,8 +168,8 @@ export class AstCompiler extends DiagnosticEmitter {
158
168
  this.program.setExportedSymbols(src.absoluteProjPath, srcExports);
159
169
  this._srcDonelogUids.add(src.uid);
160
170
  }
161
- _collectAllTopLevelSignatures(stmts, srcUid, topLevelScope, srcExports, isMain = false) {
162
- for (let i = 0; i < stmts.length; i++) {
171
+ _collectAllTopLevelSignatures(stmts, srcUid, topLevelScope, srcExports, isEntryFile = false) {
172
+ top_level_stmts_iter: for (let i = 0; i < stmts.length; i++) {
163
173
  let stmt = stmts[i];
164
174
  let exported = false;
165
175
  let exportRange = undefined;
@@ -169,12 +179,60 @@ export class AstCompiler extends DiagnosticEmitter {
169
179
  stmt = stmt.stmt;
170
180
  }
171
181
  if (!(stmt instanceof FuncDecl
172
- || stmt instanceof TypeImplementsStmt))
182
+ || stmt instanceof TypeImplementsStmt
183
+ || stmt instanceof ContractDecl
184
+ || stmt instanceof VarStmt))
185
+ continue;
186
+ if (stmt instanceof VarStmt) {
187
+ const nDecl = stmt.declarations.length;
188
+ for (let dI = 0; dI < nDecl; dI++) {
189
+ const decl = stmt.declarations[dI];
190
+ if (!(decl.isConst()
191
+ && decl instanceof SimpleVarDecl)) {
192
+ this.error(DiagnosticCode.Only_constants_can_be_declared_outside_of_a_function, stmt.range);
193
+ // remove from array so we don't process it again
194
+ void stmts.splice(i, 1);
195
+ i--;
196
+ continue top_level_stmts_iter;
197
+ }
198
+ this._collectTopLevelConst(decl, srcUid, topLevelScope, srcExports, exportRange, isEntryFile);
199
+ }
200
+ // remove from array so we don't process it again
201
+ void stmts.splice(i, 1);
202
+ i--;
173
203
  continue;
204
+ }
174
205
  if (exported && stmt instanceof TypeImplementsStmt)
175
206
  this.error(DiagnosticCode.Interface_implementations_cannot_be_exported, exportRange ?? stmt.range);
207
+ if (stmt instanceof ContractDecl) {
208
+ // ignore contract declarations if not in the entry file
209
+ if (!isEntryFile) {
210
+ // remove from array so we don't process it again
211
+ void stmts.splice(i, 1);
212
+ i--;
213
+ continue;
214
+ }
215
+ const funcDeclContract = this._contractDeclToFuncDecl(stmt);
216
+ if (!funcDeclContract) {
217
+ // remove from array so we don't process it again
218
+ void stmts.splice(i, 1);
219
+ i--;
220
+ continue;
221
+ }
222
+ this._collectTopLevelFuncDeclSig(funcDeclContract, srcUid, topLevelScope, srcExports, exportRange,
223
+ // set main
224
+ true // isEntryFile
225
+ );
226
+ // remove from array so we don't process it again
227
+ void stmts.splice(i, 1);
228
+ i--;
229
+ continue;
230
+ }
176
231
  if (stmt instanceof FuncDecl)
177
- this._collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports, exportRange, isMain);
232
+ this._collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports, exportRange,
233
+ // don't set main
234
+ false // isEntryFile
235
+ );
178
236
  else
179
237
  this._collectInterfaceImplSigs(stmt, srcUid, topLevelScope);
180
238
  // remove from array so we don't process it again
@@ -223,7 +281,22 @@ export class AstCompiler extends DiagnosticEmitter {
223
281
  this.program.functions.set(tirMethodName, funcExpr);
224
282
  }
225
283
  }
226
- _collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports = undefined, exportRange = undefined, isMain = false) {
284
+ _collectTopLevelConst(decl, srcUid, topLevelScope, srcExports = undefined, exportRange = undefined, isEntryFile = false) {
285
+ const astName = decl.name.text;
286
+ // const tirConstName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + astName + "_" + srcUid;
287
+ const declContext = AstCompilationCtx.fromScope(this.program, topLevelScope);
288
+ const tirVarDecl = _compileSimpleVarDecl(declContext, decl, undefined // type hint (extracted from init expr if explicit, or inferred from expression)
289
+ );
290
+ if (!tirVarDecl)
291
+ return undefined;
292
+ if (!tirVarDecl.initExpr)
293
+ return this.error(DiagnosticCode._const_declarations_must_be_initialized, tirVarDecl.range);
294
+ if (this.program.constants.has(astName)) {
295
+ throw new Error("not_implemented::AstCompiler::_collectTopLevelConst::const_redefinition_check");
296
+ }
297
+ this.program.constants.set(astName, tirVarDecl);
298
+ }
299
+ _collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports = undefined, exportRange = undefined, isEntryFile = false) {
227
300
  const astFuncExpr = stmt.expr;
228
301
  const astFuncName = astFuncExpr.name.text;
229
302
  const tirFuncName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + astFuncName + "_" + srcUid;
@@ -245,9 +318,8 @@ export class AstCompiler extends DiagnosticEmitter {
245
318
  srcExports.functions.set(astFuncName, tirFuncName);
246
319
  }
247
320
  }
248
- if (isMain
249
- && this.program.contractTirFuncName === ""
250
- && astFuncExpr.name.text === "main")
321
+ if (isEntryFile
322
+ && this.program.contractTirFuncName === "")
251
323
  this.program.contractTirFuncName = tirFuncName;
252
324
  }
253
325
  _collectInterfaceDeclarations(stmts, topLevelScope, srcExports) {
@@ -277,6 +349,9 @@ export class AstCompiler extends DiagnosticEmitter {
277
349
  i--;
278
350
  }
279
351
  }
352
+ registerInternalTypeDecl(decl) {
353
+ this._collectTypeDeclarations([decl], "", this.preludeScope, this.preludeScope);
354
+ }
280
355
  _collectTypeDeclarations(stmts, srcUid, topLevelScope, srcExports) {
281
356
  for (let i = 0; i < stmts.length; i++) {
282
357
  let stmt = stmts[i];
@@ -298,9 +373,9 @@ export class AstCompiler extends DiagnosticEmitter {
298
373
  continue; // ignore type decl
299
374
  // define on program
300
375
  if (tirTypes.sop)
301
- this.program.types.set(tirTypes.sop.toConcreteTirTypeName(), tirTypes.sop);
376
+ this.program.registerType(tirTypes.sop);
302
377
  if (tirTypes.data)
303
- this.program.types.set(tirTypes.data.toConcreteTirTypeName(), tirTypes.data);
378
+ this.program.registerType(tirTypes.data);
304
379
  const sopTirName = tirTypes.sop?.toTirTypeKey() ?? tirTypes.data.toTirTypeKey();
305
380
  const dataTirName = tirTypes.data?.toTirTypeKey();
306
381
  const possibleTirTypes = Object.freeze({
@@ -375,7 +450,7 @@ export class AstCompiler extends DiagnosticEmitter {
375
450
  else
376
451
  this.warning(DiagnosticCode.Type_0_cannot_be_encoded_as_data_but_it_has_a_runtime_encoding_Use_runtime_keyword_modifier_for_the_declaration, stmt.range, stmt.name.text);
377
452
  }
378
- return sop || data ? { sop, data, methodsNames } : undefined;
453
+ return (sop || data) ? { sop, data, methodsNames } : undefined;
379
454
  }
380
455
  _compileTypeAliasDecl(stmt, srcUid, topLevelScope) {
381
456
  if (stmt.typeParams.length > 0)
@@ -400,7 +475,6 @@ export class AstCompiler extends DiagnosticEmitter {
400
475
  if (!(stmt instanceof ImportStmt))
401
476
  continue;
402
477
  const importAbsPath = getAbsolutePath(stmt.fromPath.string, srcAbsPath) ?? "";
403
- // console.log(projAbsoultePath, [ ...this.program.files.keys() ]);
404
478
  const importedSymbols = this.program.getExportedSymbols(importAbsPath);
405
479
  if (!importedSymbols) {
406
480
  return this.error(DiagnosticCode.File_0_not_found, stmt.fromPath.range, importAbsPath // stmt.fromPath.string
@@ -456,7 +530,7 @@ export class AstCompiler extends DiagnosticEmitter {
456
530
  /**
457
531
  * @returns `true` if there were no errors. `false` otherwise.
458
532
  */
459
- async compileAllDeps(_resolveStackNode, isMain = false) {
533
+ async compileAllDeps(_resolveStackNode, isEntryFile = false) {
460
534
  const src = _resolveStackNode.dependent; // resolveStackNode instanceof ResolveStackNode ? source.dependent : source;
461
535
  const resolveStack = _resolveStackNode; // source instanceof ResolveStackNode ? source : new ResolveStackNode( undefined, src );
462
536
  const isCycle = resolveStack.parent?.includesInternalPath(src.absoluteProjPath) ?? false;
@@ -484,7 +558,7 @@ export class AstCompiler extends DiagnosticEmitter {
484
558
  if (!await this.compileAllDeps(nextStack))
485
559
  return false;
486
560
  }
487
- this._compileParsedSource(src, isMain);
561
+ this._compileParsedSource(src, isEntryFile);
488
562
  return true;
489
563
  }
490
564
  importPathsFromStmts(stmts, requestingPath) {
@@ -534,6 +608,36 @@ export class AstCompiler extends DiagnosticEmitter {
534
608
  }
535
609
  ;
536
610
  }
611
+ _contractDeclToFuncDecl(contractDecl) {
612
+ const funcName = getUniqueInternalName(contractDecl.name.text);
613
+ const paramsInternalNamesMap = new Map();
614
+ const funcParams = new Array(contractDecl.params.length + 1);
615
+ for (const [i, param] of contractDecl.params.entries()) {
616
+ if (!param.type) {
617
+ this.error(DiagnosticCode.Type_expected, param.name.range.atEnd());
618
+ return undefined;
619
+ }
620
+ const astType = param.type;
621
+ const astName = param.name.text;
622
+ if (paramsInternalNamesMap.has(astName)) {
623
+ this.error(DiagnosticCode.Duplicate_identifier_0, param.name.range, param.name.text);
624
+ return undefined;
625
+ }
626
+ const internalName = getUniqueInternalName(param.name.text);
627
+ paramsInternalNamesMap.set(astName, internalName);
628
+ funcParams[i] = new SimpleVarDecl(new Identifier(internalName, param.name.range), astType, undefined, // initExpr
629
+ CommonFlags.Const, param.range);
630
+ }
631
+ const scriptContextName = getUniqueInternalName("ctx");
632
+ funcParams[contractDecl.params.length] = new SimpleVarDecl(new Identifier(scriptContextName, contractDecl.name.range), new AstNamedTypeExpr(new Identifier("ScriptContext", contractDecl.name.range), [], contractDecl.name.range), undefined, // initExpr
633
+ CommonFlags.Const, contractDecl.name.range);
634
+ const funcSig = new AstFuncType(funcParams, new AstVoidType(contractDecl.name.range), contractDecl.name.range);
635
+ const contractBody = _deriveContractBody(this, contractDecl, paramsInternalNamesMap, scriptContextName);
636
+ if (!contractBody)
637
+ return undefined;
638
+ return new FuncDecl(new FuncExpr(new Identifier(funcName, contractDecl.name.range), CommonFlags.None, [], // typeParameters
639
+ funcSig, contractBody, ArrowKind.None, contractDecl.range));
640
+ }
537
641
  }
538
642
  function isImportStmtLike(stmt) {
539
643
  return (stmt instanceof ImportStmt
@@ -0,0 +1,10 @@
1
+ import { BlockStmt } from "../../../../ast/nodes/statements/BlockStmt.js";
2
+ import { ContractDecl } from "../../../../ast/nodes/statements/declarations/ContractDecl.js";
3
+ import { AstCompiler } from "../../AstCompiler.js";
4
+ /**
5
+ *
6
+ * only returns the body of the main function
7
+ *
8
+ * function arguments (parameters and script context) must be handled outside
9
+ */
10
+ export declare function _deriveContractBody(compiler: AstCompiler, contractDecl: ContractDecl, paramsInternalNamesMap: Map<string, string>, scriptContextName: string): BlockStmt | undefined;