@harmoniclabs/pebble 0.1.0-dev4 → 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 (308) 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.d.ts +1 -0
  173. package/dist/compiler/path/getAbsolutePath.js +8 -5
  174. package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
  175. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
  176. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
  177. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
  178. package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
  179. package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
  180. package/dist/compiler/tir/expressions/TirCaseExpr.js +103 -60
  181. package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
  182. package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
  183. package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
  184. package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
  185. package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
  186. package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
  187. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
  188. package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
  189. package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
  190. package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
  191. package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
  192. package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
  193. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +5 -2
  194. package/dist/compiler/tir/expressions/TirLettedExpr.js +19 -4
  195. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +8 -5
  196. package/dist/compiler/tir/expressions/TirNativeFunc.js +50 -22
  197. package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
  198. package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
  199. package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
  200. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -0
  201. package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
  202. package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
  203. package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
  204. package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
  205. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
  206. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
  207. package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
  208. package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
  209. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +7 -3
  210. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +17 -7
  211. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +16 -20
  212. package/dist/compiler/tir/expressions/ToIRTermCtx.js +67 -50
  213. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +40 -0
  214. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +174 -3
  215. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
  216. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
  217. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
  218. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
  219. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
  220. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
  221. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
  222. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
  223. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
  224. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
  225. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
  226. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
  227. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
  228. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
  229. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
  230. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
  231. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
  232. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
  233. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
  234. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
  235. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
  236. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
  237. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
  238. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
  239. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
  240. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
  241. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
  242. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
  243. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
  244. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
  245. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
  246. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
  247. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
  248. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
  249. package/dist/compiler/tir/program/TypedProgram.d.ts +1 -0
  250. package/dist/compiler/tir/program/TypedProgram.js +9 -0
  251. package/dist/compiler/tir/program/stdScope/stdScope.js +126 -126
  252. package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
  253. package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
  254. package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
  255. package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
  256. package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
  257. package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
  258. package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
  259. package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
  260. package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
  261. package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
  262. package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
  263. package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
  264. package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
  265. package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
  266. package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
  267. package/dist/compiler/tir/statements/TirForStmt.js +21 -0
  268. package/dist/compiler/tir/statements/TirIfStmt.d.ts +3 -0
  269. package/dist/compiler/tir/statements/TirIfStmt.js +19 -0
  270. package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
  271. package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
  272. package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
  273. package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
  274. package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
  275. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
  276. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
  277. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
  278. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
  279. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
  280. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
  281. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
  282. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
  283. package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
  284. package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
  285. package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
  286. package/dist/diagnostics/DiagnosticEmitter.js +1 -1
  287. package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
  288. package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
  289. package/dist/parser/Parser.d.ts +8 -3
  290. package/dist/parser/Parser.js +162 -30
  291. package/dist/tokenizer/Token.d.ts +81 -72
  292. package/dist/tokenizer/Token.js +82 -72
  293. package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
  294. package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
  295. package/dist/utils/BitUtils/index.js +1 -1
  296. package/dist/utils/UPLCFlatUtils/index.js +1 -1
  297. package/package.json +2 -1
  298. package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
  299. package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
  300. package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
  301. package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
  302. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
  303. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
  304. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
  305. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
  306. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
  307. package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
  308. package/dist/IR/tree_utils/_ir_apps.js +0 -8
@@ -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
@@ -56,6 +58,7 @@ export declare class AstCompiler extends DiagnosticEmitter {
56
58
  private _collectInterfaceImplSigs;
57
59
  private _collectTopLevelFuncDeclSig;
58
60
  private _collectInterfaceDeclarations;
61
+ registerInternalTypeDecl(decl: StructDecl | TypeAliasDecl): void;
59
62
  private _collectTypeDeclarations;
60
63
  private _compileStructDecl;
61
64
  private _compileTypeAliasDecl;
@@ -67,7 +70,8 @@ export declare class AstCompiler extends DiagnosticEmitter {
67
70
  /**
68
71
  * @returns `true` if there were no errors. `false` otherwise.
69
72
  */
70
- compileAllDeps(_resolveStackNode: ResolveStackNode, isMain?: boolean): Promise<boolean>;
73
+ compileAllDeps(_resolveStackNode: ResolveStackNode, isEntryFile?: boolean): Promise<boolean>;
71
74
  private importPathsFromStmts;
72
75
  private _reportCircularDependency;
76
+ private _contractDeclToFuncDecl;
73
77
  }
@@ -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,9 @@ 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";
33
36
  /*
34
37
  Handling type expressions that depend on other types
35
38
  (such as generics, function return types, and inferred types from complex expressions)
@@ -96,17 +99,22 @@ export class AstCompiler extends DiagnosticEmitter {
96
99
  const entrySrc = await this.compileFile(filePath, true);
97
100
  if (this.diagnostics.length > 0 || !entrySrc) {
98
101
  let msg;
99
- globalThis.console && console.log(this.diagnostics);
100
102
  const fstErrorMsg = this.diagnostics[0].toString();
101
103
  const nDiags = this.diagnostics.length;
102
104
  while (msg = this.diagnostics.shift()) {
103
- this.io.stdout.write(msg.toString() + "\n");
105
+ /*
106
+ this.io.stdout.write( msg.toString() + "\n" );
107
+ /*/
108
+ console.log(msg);
109
+ console.log(msg.toString());
110
+ //*/
104
111
  }
105
112
  throw new Error("AstCompiler.compile: failed with " + nDiags + " diagnostic messages; first message: " + fstErrorMsg);
106
113
  }
107
114
  const mainFuncExpr = this.program.functions.get(this.program.contractTirFuncName);
108
115
  if (this.program.contractTirFuncName === "" || !mainFuncExpr) {
109
- this.error(DiagnosticCode.Main_function_is_missing, undefined);
116
+ console.error(mainFuncExpr, `"${this.program.contractTirFuncName}"`);
117
+ this.error(DiagnosticCode.Contract_is_missing, undefined);
110
118
  return this.program;
111
119
  }
112
120
  if (!mainFuncExpr)
@@ -114,16 +122,16 @@ export class AstCompiler extends DiagnosticEmitter {
114
122
  return this.program;
115
123
  }
116
124
  // mutually recursive
117
- async compileFile(path, isMain = false) {
125
+ async compileFile(path, isEntryFile = false) {
118
126
  const src = await this.getAbsoulteProjPathSource(path);
119
127
  if (!src)
120
128
  return;
121
129
  // parse imports first
122
- await this.compileAllDeps(ResolveStackNode.entry(src), isMain);
130
+ await this.compileAllDeps(ResolveStackNode.entry(src), isEntryFile);
123
131
  // if there were errors
124
- if (this.diagnostics.length > 0)
132
+ if (this.diagnostics.some(d => d.category === DiagnosticCategory.Error))
125
133
  return;
126
- await this._compileParsedSource(src, isMain);
134
+ await this._compileParsedSource(src, isEntryFile);
127
135
  return src;
128
136
  }
129
137
  _srcDonelogUids = new Set();
@@ -131,7 +139,7 @@ export class AstCompiler extends DiagnosticEmitter {
131
139
  * translates the source AST statements
132
140
  * to TIR statements; and saves the result in `this.program`
133
141
  */
134
- async _compileParsedSource(src, isMain = false) {
142
+ async _compileParsedSource(src, isEntryFile = false) {
135
143
  if (this._srcDonelogUids.has(src.uid))
136
144
  return;
137
145
  // clone array so we don't remove stmts from the original AST
@@ -146,7 +154,7 @@ export class AstCompiler extends DiagnosticEmitter {
146
154
  // collect top level **interface** declarations (NOT implementations)
147
155
  this._collectInterfaceDeclarations(stmts, topLevelScope, srcExports);
148
156
  // collects top level functions, methods (interface impls), and consts types
149
- this._collectAllTopLevelSignatures(stmts, src.uid, topLevelScope, srcExports, isMain);
157
+ this._collectAllTopLevelSignatures(stmts, src.uid, topLevelScope, srcExports, isEntryFile);
150
158
  /*
151
159
  this._compileTopLevelFunctionsAndConsts(
152
160
  stmts,
@@ -158,7 +166,7 @@ export class AstCompiler extends DiagnosticEmitter {
158
166
  this.program.setExportedSymbols(src.absoluteProjPath, srcExports);
159
167
  this._srcDonelogUids.add(src.uid);
160
168
  }
161
- _collectAllTopLevelSignatures(stmts, srcUid, topLevelScope, srcExports, isMain = false) {
169
+ _collectAllTopLevelSignatures(stmts, srcUid, topLevelScope, srcExports, isEntryFile = false) {
162
170
  for (let i = 0; i < stmts.length; i++) {
163
171
  let stmt = stmts[i];
164
172
  let exported = false;
@@ -169,12 +177,40 @@ export class AstCompiler extends DiagnosticEmitter {
169
177
  stmt = stmt.stmt;
170
178
  }
171
179
  if (!(stmt instanceof FuncDecl
172
- || stmt instanceof TypeImplementsStmt))
180
+ || stmt instanceof TypeImplementsStmt
181
+ || stmt instanceof ContractDecl))
173
182
  continue;
174
183
  if (exported && stmt instanceof TypeImplementsStmt)
175
184
  this.error(DiagnosticCode.Interface_implementations_cannot_be_exported, exportRange ?? stmt.range);
185
+ if (stmt instanceof ContractDecl) {
186
+ // ignore contract declarations if not in the entry file
187
+ if (!isEntryFile) {
188
+ // remove from array so we don't process it again
189
+ void stmts.splice(i, 1);
190
+ i--;
191
+ continue;
192
+ }
193
+ const funcDeclContract = this._contractDeclToFuncDecl(stmt);
194
+ if (!funcDeclContract) {
195
+ // remove from array so we don't process it again
196
+ void stmts.splice(i, 1);
197
+ i--;
198
+ continue;
199
+ }
200
+ this._collectTopLevelFuncDeclSig(funcDeclContract, srcUid, topLevelScope, srcExports, exportRange,
201
+ // set main
202
+ true // isEntryFile
203
+ );
204
+ // remove from array so we don't process it again
205
+ void stmts.splice(i, 1);
206
+ i--;
207
+ continue;
208
+ }
176
209
  if (stmt instanceof FuncDecl)
177
- this._collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports, exportRange, isMain);
210
+ this._collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports, exportRange,
211
+ // don't set main
212
+ false // isEntryFile
213
+ );
178
214
  else
179
215
  this._collectInterfaceImplSigs(stmt, srcUid, topLevelScope);
180
216
  // remove from array so we don't process it again
@@ -223,7 +259,7 @@ export class AstCompiler extends DiagnosticEmitter {
223
259
  this.program.functions.set(tirMethodName, funcExpr);
224
260
  }
225
261
  }
226
- _collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports = undefined, exportRange = undefined, isMain = false) {
262
+ _collectTopLevelFuncDeclSig(stmt, srcUid, topLevelScope, srcExports = undefined, exportRange = undefined, isEntryFile = false) {
227
263
  const astFuncExpr = stmt.expr;
228
264
  const astFuncName = astFuncExpr.name.text;
229
265
  const tirFuncName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + astFuncName + "_" + srcUid;
@@ -245,9 +281,8 @@ export class AstCompiler extends DiagnosticEmitter {
245
281
  srcExports.functions.set(astFuncName, tirFuncName);
246
282
  }
247
283
  }
248
- if (isMain
249
- && this.program.contractTirFuncName === ""
250
- && astFuncExpr.name.text === "main")
284
+ if (isEntryFile
285
+ && this.program.contractTirFuncName === "")
251
286
  this.program.contractTirFuncName = tirFuncName;
252
287
  }
253
288
  _collectInterfaceDeclarations(stmts, topLevelScope, srcExports) {
@@ -277,6 +312,9 @@ export class AstCompiler extends DiagnosticEmitter {
277
312
  i--;
278
313
  }
279
314
  }
315
+ registerInternalTypeDecl(decl) {
316
+ this._collectTypeDeclarations([decl], "", this.preludeScope, this.preludeScope);
317
+ }
280
318
  _collectTypeDeclarations(stmts, srcUid, topLevelScope, srcExports) {
281
319
  for (let i = 0; i < stmts.length; i++) {
282
320
  let stmt = stmts[i];
@@ -298,9 +336,9 @@ export class AstCompiler extends DiagnosticEmitter {
298
336
  continue; // ignore type decl
299
337
  // define on program
300
338
  if (tirTypes.sop)
301
- this.program.types.set(tirTypes.sop.toConcreteTirTypeName(), tirTypes.sop);
339
+ this.program.registerType(tirTypes.sop);
302
340
  if (tirTypes.data)
303
- this.program.types.set(tirTypes.data.toConcreteTirTypeName(), tirTypes.data);
341
+ this.program.registerType(tirTypes.data);
304
342
  const sopTirName = tirTypes.sop?.toTirTypeKey() ?? tirTypes.data.toTirTypeKey();
305
343
  const dataTirName = tirTypes.data?.toTirTypeKey();
306
344
  const possibleTirTypes = Object.freeze({
@@ -375,7 +413,7 @@ export class AstCompiler extends DiagnosticEmitter {
375
413
  else
376
414
  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
415
  }
378
- return sop || data ? { sop, data, methodsNames } : undefined;
416
+ return (sop || data) ? { sop, data, methodsNames } : undefined;
379
417
  }
380
418
  _compileTypeAliasDecl(stmt, srcUid, topLevelScope) {
381
419
  if (stmt.typeParams.length > 0)
@@ -400,7 +438,6 @@ export class AstCompiler extends DiagnosticEmitter {
400
438
  if (!(stmt instanceof ImportStmt))
401
439
  continue;
402
440
  const importAbsPath = getAbsolutePath(stmt.fromPath.string, srcAbsPath) ?? "";
403
- // console.log(projAbsoultePath, [ ...this.program.files.keys() ]);
404
441
  const importedSymbols = this.program.getExportedSymbols(importAbsPath);
405
442
  if (!importedSymbols) {
406
443
  return this.error(DiagnosticCode.File_0_not_found, stmt.fromPath.range, importAbsPath // stmt.fromPath.string
@@ -456,7 +493,7 @@ export class AstCompiler extends DiagnosticEmitter {
456
493
  /**
457
494
  * @returns `true` if there were no errors. `false` otherwise.
458
495
  */
459
- async compileAllDeps(_resolveStackNode, isMain = false) {
496
+ async compileAllDeps(_resolveStackNode, isEntryFile = false) {
460
497
  const src = _resolveStackNode.dependent; // resolveStackNode instanceof ResolveStackNode ? source.dependent : source;
461
498
  const resolveStack = _resolveStackNode; // source instanceof ResolveStackNode ? source : new ResolveStackNode( undefined, src );
462
499
  const isCycle = resolveStack.parent?.includesInternalPath(src.absoluteProjPath) ?? false;
@@ -484,7 +521,7 @@ export class AstCompiler extends DiagnosticEmitter {
484
521
  if (!await this.compileAllDeps(nextStack))
485
522
  return false;
486
523
  }
487
- this._compileParsedSource(src, isMain);
524
+ this._compileParsedSource(src, isEntryFile);
488
525
  return true;
489
526
  }
490
527
  importPathsFromStmts(stmts, requestingPath) {
@@ -534,6 +571,36 @@ export class AstCompiler extends DiagnosticEmitter {
534
571
  }
535
572
  ;
536
573
  }
574
+ _contractDeclToFuncDecl(contractDecl) {
575
+ const funcName = getUniqueInternalName(contractDecl.name.text);
576
+ const paramsInternalNamesMap = new Map();
577
+ const funcParams = new Array(contractDecl.params.length + 1);
578
+ for (const [i, param] of contractDecl.params.entries()) {
579
+ if (!param.type) {
580
+ this.error(DiagnosticCode.Type_expected, param.name.range.atEnd());
581
+ return undefined;
582
+ }
583
+ const astType = param.type;
584
+ const astName = param.name.text;
585
+ if (paramsInternalNamesMap.has(astName)) {
586
+ this.error(DiagnosticCode.Duplicate_identifier_0, param.name.range, param.name.text);
587
+ return undefined;
588
+ }
589
+ const internalName = getUniqueInternalName(param.name.text);
590
+ paramsInternalNamesMap.set(astName, internalName);
591
+ funcParams[i] = new SimpleVarDecl(new Identifier(internalName, param.name.range), astType, undefined, // initExpr
592
+ CommonFlags.Const, param.range);
593
+ }
594
+ const scriptContextName = getUniqueInternalName("ctx");
595
+ 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
596
+ CommonFlags.Const, contractDecl.name.range);
597
+ const funcSig = new AstFuncType(funcParams, new AstVoidType(contractDecl.name.range), contractDecl.name.range);
598
+ const contractBody = _deriveContractBody(this, contractDecl, paramsInternalNamesMap, scriptContextName);
599
+ if (!contractBody)
600
+ return undefined;
601
+ return new FuncDecl(new FuncExpr(new Identifier(funcName, contractDecl.name.range), CommonFlags.None, [], // typeParameters
602
+ funcSig, contractBody, ArrowKind.None, contractDecl.range));
603
+ }
537
604
  }
538
605
  function isImportStmtLike(stmt) {
539
606
  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;