@harmoniclabs/pebble 0.1.0-dev5 → 0.1.0-dev6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (307) hide show
  1. package/dist/IR/IRHash.d.ts +3 -3
  2. package/dist/IR/IRHash.js +47 -52
  3. package/dist/IR/IRNodes/IRApp.d.ts +12 -8
  4. package/dist/IR/IRNodes/IRApp.js +34 -20
  5. package/dist/IR/IRNodes/IRCase.d.ts +11 -7
  6. package/dist/IR/IRNodes/IRCase.js +33 -32
  7. package/dist/IR/IRNodes/IRConst.d.ts +7 -5
  8. package/dist/IR/IRNodes/IRConst.js +23 -13
  9. package/dist/IR/IRNodes/IRConstr.d.ts +11 -7
  10. package/dist/IR/IRNodes/IRConstr.js +34 -37
  11. package/dist/IR/IRNodes/IRDelayed.d.ts +12 -9
  12. package/dist/IR/IRNodes/IRDelayed.js +22 -18
  13. package/dist/IR/IRNodes/IRError.d.ts +9 -6
  14. package/dist/IR/IRNodes/IRError.js +12 -5
  15. package/dist/IR/IRNodes/IRForced.d.ts +9 -6
  16. package/dist/IR/IRNodes/IRForced.js +22 -18
  17. package/dist/IR/IRNodes/IRFunc.d.ts +14 -10
  18. package/dist/IR/IRNodes/IRFunc.js +35 -38
  19. package/dist/IR/IRNodes/IRHoisted.d.ts +16 -9
  20. package/dist/IR/IRNodes/IRHoisted.js +36 -18
  21. package/dist/IR/IRNodes/IRLetted.d.ts +14 -34
  22. package/dist/IR/IRNodes/IRLetted.js +65 -297
  23. package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +0 -2
  24. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +0 -4
  25. package/dist/IR/IRNodes/IRNative/index.d.ts +9 -8
  26. package/dist/IR/IRNodes/IRNative/index.js +55 -18
  27. package/dist/IR/IRNodes/IRNative/isForcedNative.d.ts +2 -0
  28. package/dist/IR/IRNodes/IRNative/isForcedNative.js +1 -1
  29. package/dist/IR/IRNodes/IRRecursive.d.ts +18 -10
  30. package/dist/IR/IRNodes/IRRecursive.js +36 -44
  31. package/dist/IR/IRNodes/IRSelfCall.d.ts +10 -24
  32. package/dist/IR/IRNodes/IRSelfCall.js +25 -87
  33. package/dist/IR/IRNodes/IRVar.d.ts +11 -19
  34. package/dist/IR/IRNodes/IRVar.js +26 -54
  35. package/dist/IR/IRNodes/utils/dependsByDbns.d.ts +1 -1
  36. package/dist/IR/IRNodes/utils/dependsByDbns.js +5 -11
  37. package/dist/IR/IRNodes/utils/hashVarSym.d.ts +1 -0
  38. package/dist/IR/IRNodes/utils/hashVarSym.js +37 -0
  39. package/dist/IR/IRNodes/utils/makeArrayLikeProxy.d.ts +2 -1
  40. package/dist/IR/IRTerm.d.ts +7 -0
  41. package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +3 -0
  42. package/dist/IR/toUPLC/_internal/findAll.js +2 -73
  43. package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +7 -34
  44. package/dist/IR/toUPLC/_internal/iterTree.js +3 -17
  45. package/dist/IR/toUPLC/common_hoisted.d.ts +2 -0
  46. package/dist/IR/toUPLC/common_hoisted.js +4 -0
  47. package/dist/IR/toUPLC/compileIRToUPLC.d.ts +1 -1
  48. package/dist/IR/toUPLC/compileIRToUPLC.js +91 -14
  49. package/dist/IR/toUPLC/ctx/ToUplcCtx.d.ts +16 -0
  50. package/dist/IR/toUPLC/ctx/ToUplcCtx.js +75 -0
  51. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.d.ts +8 -0
  52. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.js +95 -0
  53. package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +7 -54
  54. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +6 -13
  55. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +67 -71
  56. package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +44 -170
  57. package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +7 -3
  58. package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +3 -2
  59. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.d.ts +22 -0
  60. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.js +59 -0
  61. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts +0 -0
  62. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.js +217 -0
  63. package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +12 -49
  64. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +1 -1
  65. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +11 -14
  66. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/{index.d.ts → performUplcOptimizationsAndReturnRoot.d.ts} +0 -2
  67. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +151 -0
  68. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.d.ts +11 -0
  69. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.js +46 -0
  70. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.d.ts +2 -0
  71. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js +80 -0
  72. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +18 -11
  73. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +43 -0
  74. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +255 -478
  75. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.d.ts +2 -0
  76. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +85 -0
  77. package/dist/IR/toUPLC/subRoutines/sanifyTree.js +1 -0
  78. package/dist/IR/toUPLC/utils/getApplicationTerms.d.ts +6 -0
  79. package/dist/IR/toUPLC/utils/getApplicationTerms.js +37 -0
  80. package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +2 -2
  81. package/dist/IR/tree_utils/_ir_lazyChooseList.js +4 -2
  82. package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +1 -1
  83. package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +4 -2
  84. package/dist/IR/tree_utils/_ir_let.d.ts +2 -1
  85. package/dist/IR/tree_utils/_ir_let.js +6 -2
  86. package/dist/IR/utils/isClosedIRTerm.d.ts +1 -0
  87. package/dist/IR/utils/isClosedIRTerm.js +39 -25
  88. package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
  89. package/dist/IR/utils/positiveIntAsBytes.js +4 -0
  90. package/dist/IR/utils/showIR.d.ts +10 -21
  91. package/dist/IR/utils/showIR.js +66 -64
  92. package/dist/ast/nodes/common/Identifier.d.ts +1 -0
  93. package/dist/ast/nodes/common/Identifier.js +3 -0
  94. package/dist/ast/nodes/expr/CaseExpr.d.ts +5 -5
  95. package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +2 -2
  96. package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +1 -1
  97. package/dist/ast/nodes/expr/PebbleExpr.d.ts +2 -1
  98. package/dist/ast/nodes/expr/PropAccessExpr.d.ts +3 -3
  99. package/dist/ast/nodes/expr/TernaryExpr.d.ts +3 -3
  100. package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +2 -1
  101. package/dist/ast/nodes/expr/TypeConversionExpr.js +2 -0
  102. package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +42 -42
  103. package/dist/ast/nodes/expr/functions/CallExpr.d.ts +1 -1
  104. package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +2 -1
  105. package/dist/ast/nodes/expr/functions/FuncExpr.js +6 -0
  106. package/dist/ast/nodes/expr/litteral/LitContextExpr.d.ts +6 -0
  107. package/dist/ast/nodes/expr/litteral/LitContextExpr.js +6 -0
  108. package/dist/ast/nodes/expr/litteral/LitFailExpr.d.ts +6 -0
  109. package/dist/ast/nodes/expr/litteral/LitFailExpr.js +6 -0
  110. package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +3 -1
  111. package/dist/ast/nodes/expr/litteral/LitteralExpr.js +5 -1
  112. package/dist/ast/nodes/statements/AssertStmt.d.ts +2 -2
  113. package/dist/ast/nodes/statements/AssignmentStmt.d.ts +1 -1
  114. package/dist/ast/nodes/statements/BlockStmt.d.ts +1 -1
  115. package/dist/ast/nodes/statements/FailStmt.d.ts +1 -1
  116. package/dist/ast/nodes/statements/ForOfStmt.d.ts +4 -2
  117. package/dist/ast/nodes/statements/ForOfStmt.js +6 -0
  118. package/dist/ast/nodes/statements/ForStmt.d.ts +6 -4
  119. package/dist/ast/nodes/statements/ForStmt.js +6 -0
  120. package/dist/ast/nodes/statements/IfStmt.d.ts +8 -5
  121. package/dist/ast/nodes/statements/IfStmt.js +13 -0
  122. package/dist/ast/nodes/statements/MatchStmt.d.ts +13 -4
  123. package/dist/ast/nodes/statements/MatchStmt.js +22 -1
  124. package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
  125. package/dist/ast/nodes/statements/PebbleStmt.js +3 -1
  126. package/dist/ast/nodes/statements/ReturnStmt.d.ts +1 -1
  127. package/dist/ast/nodes/statements/WhileStmt.d.ts +4 -2
  128. package/dist/ast/nodes/statements/WhileStmt.js +6 -0
  129. package/dist/ast/nodes/statements/declarations/ContractDecl.d.ts +17 -0
  130. package/dist/ast/nodes/statements/declarations/ContractDecl.js +22 -0
  131. package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +1 -1
  132. package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +1 -1
  133. package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +1 -1
  134. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +2 -1
  135. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +6 -0
  136. package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +1 -1
  137. package/dist/compiler/AstCompiler/AstCompiler.d.ts +6 -2
  138. package/dist/compiler/AstCompiler/AstCompiler.js +91 -24
  139. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.d.ts +10 -0
  140. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +777 -0
  141. package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +1 -1
  142. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +1 -1
  143. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +8 -2
  144. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +1 -1
  145. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +3 -1
  146. package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
  147. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +2 -2
  148. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +2 -2
  149. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +48 -24
  150. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
  151. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +2 -2
  152. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +1 -1
  153. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +4 -1
  154. package/dist/compiler/AstCompiler/scope/AstScope.js +4 -3
  155. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
  156. package/dist/compiler/Compiler.js +3 -1
  157. package/dist/compiler/TirCompiler/compileTirProgram.js +3 -1
  158. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +13 -3
  159. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +41 -37
  160. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +11 -2
  161. package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
  162. package/dist/compiler/TirCompiler/expressify/expressify.js +82 -36
  163. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
  164. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +57 -8
  165. package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
  166. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +1 -1
  167. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +1 -0
  168. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +131 -9
  169. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +3 -1
  170. package/dist/compiler/io/IOutputStream.d.ts +1 -0
  171. package/dist/compiler/io/IOutputStream.js +18 -3
  172. package/dist/compiler/path/getAbsolutePath.js +4 -6
  173. package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
  174. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
  175. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
  176. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
  177. package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
  178. package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
  179. package/dist/compiler/tir/expressions/TirCaseExpr.js +103 -60
  180. package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
  181. package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
  182. package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
  183. package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
  184. package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
  185. package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
  186. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
  187. package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
  188. package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
  189. package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
  190. package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
  191. package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
  192. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +5 -2
  193. package/dist/compiler/tir/expressions/TirLettedExpr.js +19 -4
  194. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +8 -5
  195. package/dist/compiler/tir/expressions/TirNativeFunc.js +50 -22
  196. package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
  197. package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
  198. package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
  199. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -0
  200. package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
  201. package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
  202. package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
  203. package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
  204. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
  205. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
  206. package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
  207. package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
  208. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +7 -3
  209. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +17 -7
  210. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +16 -20
  211. package/dist/compiler/tir/expressions/ToIRTermCtx.js +67 -50
  212. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +40 -0
  213. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +174 -3
  214. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
  215. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
  216. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
  217. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
  218. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
  219. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
  220. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
  221. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
  222. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
  223. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
  224. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
  225. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
  226. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
  227. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
  228. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
  229. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
  230. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
  231. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
  232. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
  233. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
  234. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
  235. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
  236. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
  237. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
  238. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
  239. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
  240. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
  241. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
  242. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
  243. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
  244. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
  245. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
  246. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
  247. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
  248. package/dist/compiler/tir/program/TypedProgram.d.ts +1 -0
  249. package/dist/compiler/tir/program/TypedProgram.js +9 -0
  250. package/dist/compiler/tir/program/stdScope/stdScope.js +126 -126
  251. package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
  252. package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
  253. package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
  254. package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
  255. package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
  256. package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
  257. package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
  258. package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
  259. package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
  260. package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
  261. package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
  262. package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
  263. package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
  264. package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
  265. package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
  266. package/dist/compiler/tir/statements/TirForStmt.js +21 -0
  267. package/dist/compiler/tir/statements/TirIfStmt.d.ts +3 -0
  268. package/dist/compiler/tir/statements/TirIfStmt.js +19 -0
  269. package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
  270. package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
  271. package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
  272. package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
  273. package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
  274. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
  275. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
  276. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
  277. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
  278. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
  279. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
  280. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
  281. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
  282. package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
  283. package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
  284. package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
  285. package/dist/diagnostics/DiagnosticEmitter.js +1 -1
  286. package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
  287. package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
  288. package/dist/parser/Parser.d.ts +8 -3
  289. package/dist/parser/Parser.js +162 -30
  290. package/dist/tokenizer/Token.d.ts +81 -72
  291. package/dist/tokenizer/Token.js +82 -72
  292. package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
  293. package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
  294. package/dist/utils/BitUtils/index.js +1 -1
  295. package/dist/utils/UPLCFlatUtils/index.js +1 -1
  296. package/package.json +2 -1
  297. package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
  298. package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
  299. package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
  300. package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
  301. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
  302. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
  303. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
  304. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
  305. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
  306. package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
  307. package/dist/IR/tree_utils/_ir_apps.js +0 -8
@@ -60,7 +60,7 @@ export function _compileBinaryExpr(ctx, expr, typeHint) {
60
60
  return _compileLogicalOrExpr(ctx, expr, typeHint);
61
61
  if (expr instanceof OptionalDefaultExpr)
62
62
  return _compileOptionalDefaultExpr(ctx, expr, typeHint);
63
- const tsEnsureExsautstiveCheck = expr;
63
+ const tsEnsureExhautstiveCheck = expr;
64
64
  console.error(expr);
65
65
  throw new Error("unreachable::AstCompiler::_compileBinaryExpr");
66
66
  }
@@ -71,7 +71,7 @@ typeHint) {
71
71
  //*/
72
72
  if (isLitteralExpr(expr))
73
73
  return _compileLitteralExpr(ctx, expr, typeHint);
74
- const tsEnsureExsautstiveCheck = expr;
74
+ const tsEnsureExhautstiveCheck = expr;
75
75
  console.error(expr);
76
76
  throw new Error("unreachable::AstCompiler::_compileExpr");
77
77
  }
@@ -1,4 +1,6 @@
1
1
  import { LitArrExpr } from "../../../../ast/nodes/expr/litteral/LitArrExpr.js";
2
+ import { LitContextExpr } from "../../../../ast/nodes/expr/litteral/LitContextExpr.js";
3
+ import { LitFailExpr } from "../../../../ast/nodes/expr/litteral/LitFailExpr.js";
2
4
  import { LitFalseExpr } from "../../../../ast/nodes/expr/litteral/LitFalseExpr.js";
3
5
  import { LitHexBytesExpr } from "../../../../ast/nodes/expr/litteral/LitHexBytesExpr.js";
4
6
  import { LitIntExpr } from "../../../../ast/nodes/expr/litteral/LitIntExpr.js";
@@ -11,6 +13,7 @@ import { LitUndefExpr } from "../../../../ast/nodes/expr/litteral/LitUndefExpr.j
11
13
  import { LitVoidExpr } from "../../../../ast/nodes/expr/litteral/LitVoidExpr.js";
12
14
  import { DiagnosticCode } from "../../../../diagnostics/diagnosticMessages.generated.js";
13
15
  import { TirLitArrExpr } from "../../../tir/expressions/litteral/TirLitArrExpr.js";
16
+ import { TirLitFailExpr } from "../../../tir/expressions/litteral/TirLitFailExpr.js";
14
17
  import { TirLitFalseExpr } from "../../../tir/expressions/litteral/TirLitFalseExpr.js";
15
18
  import { TirLitHexBytesExpr } from "../../../tir/expressions/litteral/TirLitHexBytesExpr.js";
16
19
  import { TirLitIntExpr } from "../../../tir/expressions/litteral/TirLitIntExpr.js";
@@ -61,8 +64,11 @@ export function _compileLitteralExpr(ctx, expr, typeHint) {
61
64
  return _compileLitteralObjExpr(ctx, expr, typeHint);
62
65
  if (expr instanceof LitNamedObjExpr)
63
66
  return _compileLitteralNamedObjExpr(ctx, expr, typeHint);
64
- // never
65
- // expr;
67
+ if (expr instanceof LitFailExpr)
68
+ return new TirLitFailExpr(expr.range);
69
+ if (expr instanceof LitContextExpr)
70
+ throw new Error("Litteral `context` should have been handled while desugaring.");
71
+ const tsEnsureExhautstiveCheck = expr;
66
72
  throw new Error("unreachable::AstCompiler::_compileLitteralExpr");
67
73
  }
68
74
  export function _compileLitteralUndefExpr(ctx, expr, typeHint) {
@@ -20,7 +20,7 @@ export function _compilePropAccessExpr(ctx, expr, typeHint) {
20
20
  return _compileNonNullPropAccessExpr(ctx, expr, typeHint);
21
21
  if (expr instanceof DotPropAccessExpr)
22
22
  return _compileDotPropAccessExpr(ctx, expr, typeHint);
23
- const tsEnsureExsautstiveCheck = expr;
23
+ const tsEnsureExhautstiveCheck = expr;
24
24
  console.error(expr);
25
25
  throw new Error("unreachable::AstCompiler::_compilePropAccessExpr");
26
26
  }
@@ -6,8 +6,10 @@ import { _compileExpr } from "./_compileExpr.js";
6
6
  export function _compileTypeConversionExpr(ctx, ast, typeHint) {
7
7
  const data_t = ctx.program.stdTypes.data;
8
8
  const possibleTargetTypeTirNames = ctx.scope.resolveType(ast.asType.toAstName());
9
- if (!possibleTargetTypeTirNames)
9
+ if (!possibleTargetTypeTirNames) {
10
+ console.log(ctx.scope);
10
11
  return ctx.error(DiagnosticCode._0_is_not_defined, ast.asType.range, ast.asType.toAstName());
12
+ }
11
13
  const sopTargetType = ctx.program.types.get(possibleTargetTypeTirNames.sopTirName);
12
14
  if (!sopTargetType)
13
15
  return ctx.error(DiagnosticCode._0_is_not_defined, ast.asType.range, ast.asType.toAstName());
@@ -48,7 +48,7 @@ export function _compileUnaryPrefixExpr(ctx, expr, _typeHint) {
48
48
  }
49
49
  return new TirUnaryTilde(operand, int_t, expr.range);
50
50
  }
51
- const tsEnsureExsautstiveCheck = expr;
51
+ const tsEnsureExhautstiveCheck = expr;
52
52
  console.error(expr);
53
53
  throw new Error("unreachable::AstCompiler::_compileUnaryPrefixExpr");
54
54
  }
@@ -31,7 +31,7 @@ export function _compileAssignmentStmt(ctx, stmt) {
31
31
  return [tirStmt];
32
32
  }
33
33
  else {
34
- const tsEnsureExsautstiveCheck = stmt;
34
+ const tsEnsureExhautstiveCheck = stmt;
35
35
  console.error(stmt);
36
36
  throw new Error("unreachable::AstCompiler::_compileForUpdateStmts");
37
37
  }
@@ -136,7 +136,7 @@ export function _compileExplicitAssignmentStmt(ctx, stmt) {
136
136
  expr = new TirLogicalOrExpr(varAccessExpr, expr, stmt.range);
137
137
  }
138
138
  else {
139
- const tsEnsureExsautstiveCheck = stmt;
139
+ const tsEnsureExhautstiveCheck = stmt;
140
140
  console.error(stmt);
141
141
  throw new Error("unreachable::AstCompiler::_compileExplicitAssignmentStmt");
142
142
  }
@@ -1,6 +1,6 @@
1
1
  import { MatchStmt, MatchStmtCase } from "../../../../ast/nodes/statements/MatchStmt.js";
2
- import { TirMatchStmt, TirMatchStmtCase, TirMatchStmtWildcardCase } from "../../../tir/statements/TirMatchStmt.js";
2
+ import { TirMatchStmt, TirMatchStmtCase } from "../../../tir/statements/TirMatchStmt.js";
3
3
  import { DeconstructableTirType } from "../../../tir/types/utils/getDeconstructableType.js";
4
4
  import { AstCompilationCtx } from "../../AstCompilationCtx.js";
5
5
  export declare function _compileMatchStmt(ctx: AstCompilationCtx, stmt: MatchStmt): [TirMatchStmt] | undefined;
6
- export declare function _compileTirMatchStmtCase(ctx: AstCompilationCtx, matchCase: MatchStmtCase, deconstructableType: DeconstructableTirType, constrNamesAlreadySpecified: string[]): TirMatchStmtCase | TirMatchStmtWildcardCase | undefined;
6
+ export declare function _compileTirMatchStmtCase(ctx: AstCompilationCtx, matchCase: MatchStmtCase, deconstructableType: DeconstructableTirType, constrNamesAlreadySpecified: string[]): TirMatchStmtCase | undefined;
@@ -13,7 +13,7 @@ import { getDeconstructableType } from "../../../tir/types/utils/getDeconstructa
13
13
  import { wrapManyStatements } from "../../utils/wrapManyStatementsOrReturnSame.js";
14
14
  import { _compileExpr } from "../exprs/_compileExpr.js";
15
15
  import { _compileStatement } from "./_compileStatement.js";
16
- import { _compileNamedDeconstructVarDecl, _compileSingleDeconstructVarDecl, _compileVarDecl } from "./_compileVarStmt.js";
16
+ import { _compileNamedDeconstructVarDecl, _compileSingleDeconstructVarDecl } from "./_compileVarStmt.js";
17
17
  export function _compileMatchStmt(ctx, stmt) {
18
18
  if (!ctx.functionCtx)
19
19
  return ctx.error(DiagnosticCode.A_match_statement_can_only_be_used_within_a_function_body, stmt.range);
@@ -34,16 +34,18 @@ export function _compileMatchStmt(ctx, stmt) {
34
34
  if (stmt.cases.length === 0)
35
35
  return ctx.error(DiagnosticCode.A_match_statement_must_have_at_least_one_case, stmt.range);
36
36
  const cases = [];
37
- let wildcardCase = undefined;
38
37
  const constrNamesAlreadySpecified = [];
39
38
  for (const matchCase of stmt.cases) {
40
39
  const branch = _compileTirMatchStmtCase(ctx, matchCase, deconstructableType, constrNamesAlreadySpecified);
41
40
  if (!branch)
42
41
  return undefined;
43
- if (branch instanceof TirMatchStmtWildcardCase) {
42
+ /*
43
+ if( branch instanceof TirMatchStmtWildcardCase )
44
+ {
44
45
  wildcardCase = branch;
45
46
  break; // wildcard case catches any branch specified after it
46
47
  }
48
+ //*/
47
49
  const indexOfCtor = missingCtors.indexOf(branch.pattern.constrName);
48
50
  if (indexOfCtor === -1) {
49
51
  return ctx.error(DiagnosticCode.Unknown_0_constructor_1, branch.pattern.range, deconstructableType.toString(), branch.pattern.constrName);
@@ -51,23 +53,44 @@ export function _compileMatchStmt(ctx, stmt) {
51
53
  missingCtors.splice(indexOfCtor, 1);
52
54
  cases.push(branch);
53
55
  }
56
+ let wildcardCase = undefined;
57
+ if (stmt.elseCase) {
58
+ const matchCase = stmt.elseCase;
59
+ const branchCtx = ctx.newBranchChildScope();
60
+ const branchBody = wrapManyStatements(_compileStatement(branchCtx, matchCase.body), matchCase.body.range);
61
+ if (!branchBody)
62
+ return undefined;
63
+ wildcardCase = new TirMatchStmtWildcardCase(branchBody, matchCase.range);
64
+ }
54
65
  if (!wildcardCase && cases.length < ctors.length) {
55
66
  return ctx.error(DiagnosticCode.Match_cases_are_not_exhaustive, stmt.range);
56
67
  }
57
68
  return [new TirMatchStmt(matchExpr, cases, wildcardCase, stmt.range)];
58
69
  }
59
70
  export function _compileTirMatchStmtCase(ctx, matchCase, deconstructableType, constrNamesAlreadySpecified) {
60
- const pattern = _compileVarDecl(ctx, matchCase.pattern, deconstructableType);
61
- if (!pattern)
62
- return undefined;
71
+ /*
72
+ const pattern = _compileVarDecl( ctx, matchCase.pattern, deconstructableType );
73
+ if( !pattern ) return undefined;
74
+ //*/
75
+ const pattern = matchCase.pattern;
63
76
  if (pattern instanceof SimpleVarDecl) {
64
- if (pattern.name.text === "_") {
77
+ /*
78
+ if( pattern.name.text === "_" ) {
65
79
  const branchCtx = ctx.newBranchChildScope();
66
- const branchBody = wrapManyStatements(_compileStatement(branchCtx, matchCase.body), matchCase.body.range);
67
- if (!branchBody)
68
- return undefined;
69
- return new TirMatchStmtWildcardCase(branchBody, matchCase.range);
80
+ const branchBody = wrapManyStatements(
81
+ _compileStatement(
82
+ branchCtx,
83
+ matchCase.body
84
+ ),
85
+ matchCase.body.range
86
+ );
87
+ if( !branchBody ) return undefined;
88
+ return new TirMatchStmtWildcardCase(
89
+ branchBody,
90
+ matchCase.range
91
+ );
70
92
  }
93
+ //*/
71
94
  return ctx.error(DiagnosticCode.The_argument_of_a_match_statement_branch_must_be_deconstructed, matchCase.pattern.range);
72
95
  }
73
96
  else if (pattern instanceof NamedDeconstructVarDecl) {
@@ -76,14 +99,11 @@ export function _compileTirMatchStmtCase(ctx, matchCase, deconstructableType, co
76
99
  if (constrNamesAlreadySpecified.includes(deconstructedCtorName))
77
100
  return ctx.error(DiagnosticCode.Constructor_0_was_already_specified, deconstructedCtorIdentifier.range, deconstructedCtorName);
78
101
  constrNamesAlreadySpecified.push(deconstructedCtorName);
79
- if (deconstructableType instanceof TirDataT) {
80
- if (!(deconstructedCtorName === "Constr" // { index, fields, ...rest }
81
- || deconstructedCtorName === "Map" // { map, ...rest }
82
- || deconstructedCtorName === "List" // { list, ...rest }
83
- || deconstructedCtorName === "B" // { bytes, ...rest }
84
- || deconstructedCtorName === "I" // { int, ...rest }
85
- ))
86
- return ctx.error(DiagnosticCode.Unknown_0_constructor_1, pattern.name.range, "data", deconstructedCtorName);
102
+ if (deconstructableType instanceof TirSoPStructType
103
+ || deconstructableType instanceof TirDataStructType) {
104
+ const ctorDef = deconstructableType.constructors.find(c => c.name === deconstructedCtorName);
105
+ if (!ctorDef)
106
+ return ctx.error(DiagnosticCode.Unknown_0_constructor_1, pattern.name.range, deconstructableType.toString(), deconstructedCtorName);
87
107
  const branchCtx = ctx.newBranchChildScope();
88
108
  const branchArg = _compileNamedDeconstructVarDecl(branchCtx, pattern, deconstructableType);
89
109
  if (!branchArg)
@@ -108,11 +128,14 @@ export function _compileTirMatchStmtCase(ctx, matchCase, deconstructableType, co
108
128
  return undefined;
109
129
  return new TirMatchStmtCase(branchArg, branchBody, matchCase.range);
110
130
  }
111
- else if (deconstructableType instanceof TirSoPStructType
112
- || deconstructableType instanceof TirDataStructType) {
113
- const ctorDef = deconstructableType.constructors.find(c => c.name === deconstructedCtorName);
114
- if (!ctorDef)
115
- return ctx.error(DiagnosticCode.Unknown_0_constructor_1, pattern.name.range, deconstructableType.toString(), deconstructedCtorName);
131
+ else if (deconstructableType instanceof TirDataT) {
132
+ if (!(deconstructedCtorName === "Constr" // { index, fields, ...rest }
133
+ || deconstructedCtorName === "Map" // { map, ...rest }
134
+ || deconstructedCtorName === "List" // { list, ...rest }
135
+ || deconstructedCtorName === "B" // { bytes, ...rest }
136
+ || deconstructedCtorName === "I" // { int, ...rest }
137
+ ))
138
+ return ctx.error(DiagnosticCode.Unknown_0_constructor_1, pattern.name.range, "data", deconstructedCtorName);
116
139
  const branchCtx = ctx.newBranchChildScope();
117
140
  const branchArg = _compileNamedDeconstructVarDecl(branchCtx, pattern, deconstructableType);
118
141
  if (!branchArg)
@@ -179,4 +202,5 @@ export function _compileTirMatchStmtCase(ctx, matchCase, deconstructableType, co
179
202
  );
180
203
  //*/
181
204
  }
205
+ throw new Error("unreachable::AstCompiler::_compileTirMatchStmtCase");
182
206
  }
@@ -3,6 +3,7 @@ import { isAssignmentStmt } from "../../../../ast/nodes/statements/AssignmentStm
3
3
  import { BlockStmt } from "../../../../ast/nodes/statements/BlockStmt.js";
4
4
  import { BreakStmt } from "../../../../ast/nodes/statements/BreakStmt.js";
5
5
  import { ContinueStmt } from "../../../../ast/nodes/statements/ContinueStmt.js";
6
+ import { isVarDecl } from "../../../../ast/nodes/statements/declarations/VarDecl/VarDecl.js";
6
7
  import { EmptyStmt } from "../../../../ast/nodes/statements/EmptyStmt.js";
7
8
  import { FailStmt } from "../../../../ast/nodes/statements/FailStmt.js";
8
9
  import { ForOfStmt } from "../../../../ast/nodes/statements/ForOfStmt.js";
@@ -37,6 +38,8 @@ import { _compileWhileStmt } from "./_compileWhileStmt.js";
37
38
  export function _compileStatement(ctx, stmt) {
38
39
  if (stmt instanceof IfStmt)
39
40
  return _compileIfStmt(ctx, stmt);
41
+ if (isVarDecl(stmt))
42
+ stmt = new VarStmt([stmt], stmt.range); // sometime these slip through
40
43
  if (stmt instanceof VarStmt)
41
44
  return _compileVarStmt(ctx, stmt);
42
45
  if (stmt instanceof ForStmt)
@@ -67,7 +70,7 @@ export function _compileStatement(ctx, stmt) {
67
70
  // if( stmt instanceof ExprStmt ) return _compileExprStmt( ctx, stmt );
68
71
  if (stmt instanceof UsingStmt)
69
72
  return _compileUsingStmt(ctx, stmt);
70
- const tsEnsureExsautstiveCheck = stmt;
73
+ const tsEnsureExhautstiveCheck = stmt;
71
74
  console.error(stmt);
72
75
  throw new Error("unreachable::AstCompiler::_compileStatement");
73
76
  }
@@ -35,7 +35,7 @@ export function _compileVarDecl(ctx, decl, typeHint) {
35
35
  return _compileSingleDeconstructVarDecl(ctx, decl, typeHint);
36
36
  if (decl instanceof ArrayLikeDeconstr)
37
37
  return _compileArrayLikeDeconstr(ctx, decl, typeHint);
38
- const tsEnsureExsautstiveCheck = decl;
38
+ const tsEnsureExhautstiveCheck = decl;
39
39
  console.error(decl);
40
40
  throw new Error("unreachable::AstCompiler::_compileVarDecl");
41
41
  }
@@ -176,7 +176,7 @@ export function _getVarDeclTypeAndExpr(ctx, decl, deconstructTypeHint) {
176
176
  // // stmtIdx
177
177
  // // )
178
178
  // );
179
- const typeHint = deconstructTypeHint ?? declarationType;
179
+ const typeHint = declarationType ?? deconstructTypeHint;
180
180
  // even in deconstructions
181
181
  // we allow for `as` type assertions
182
182
  // and we store the type to be converted to in the var decl type
@@ -55,7 +55,7 @@ export function _compileDataEncodedConcreteType(ctx, typeExpr, optionalsAsSop =
55
55
  return undefined;
56
56
  return ctx.program.types.get(possibleTirNames.dataTirName);
57
57
  }
58
- const tsEnsureExsautstiveCheck = typeExpr;
58
+ const tsEnsureExhautstiveCheck = typeExpr;
59
59
  console.error(typeExpr);
60
60
  throw new Error("unreachable::AstCompiler::_compileDataEncodedConcreteType");
61
61
  }
@@ -52,8 +52,11 @@ export function _compileSopEncodedConcreteType(ctx, typeExpr) {
52
52
  if (typeof possibleTirNames.dataTirName !== "string")
53
53
  return undefined;
54
54
  return ctx.program.types.get(possibleTirNames.dataTirName);
55
+ // const result = ctx.program.types.get( possibleTirNames.dataTirName );
56
+ // console.log( "possibleTirNames", possibleTirNames, result );
57
+ // return result;
55
58
  }
56
- const tsEnsureExsautstiveCheck = typeExpr;
59
+ const tsEnsureExhautstiveCheck = typeExpr;
57
60
  console.error(typeExpr);
58
61
  throw new Error("unreachable::AstCompiler::_compileSopEncodedConcreteType");
59
62
  }
@@ -99,7 +99,7 @@ export class AstScope {
99
99
  return false; // already defined
100
100
  this.types.set(name, {
101
101
  sopTirName: tirTypeKey,
102
- dataTirName: allowsDataEncoding ? undefined : tirTypeKey,
102
+ dataTirName: allowsDataEncoding ? tirTypeKey : undefined,
103
103
  allTirNames: new Set([tirTypeKey]),
104
104
  methodsNames,
105
105
  isGeneric: false
@@ -107,8 +107,9 @@ export class AstScope {
107
107
  return true;
108
108
  }
109
109
  defineType(name, possibleTirTypes) {
110
- if (this._isReadonly)
111
- return false;
110
+ if (this._isReadonly) {
111
+ throw new Error("Cannot define type on readonly scope");
112
+ }
112
113
  if (invalidSymbolNames.has(name))
113
114
  return false;
114
115
  if (this.types.has(name))
@@ -60,6 +60,7 @@ function getListMethods(elemsType) {
60
60
  const mapReturnT = new TirTypeParam("T");
61
61
  return {
62
62
  length: new TirFuncT([], int_t),
63
+ isEmpty: new TirFuncT([], bool_t),
63
64
  show: new TirFuncT([], bytes_t),
64
65
  head: new TirFuncT([], elemsType),
65
66
  tail: new TirFuncT([], new TirListT(elemsType)),
@@ -79,7 +80,8 @@ function getListMethods(elemsType) {
79
80
  ], bool_t),
80
81
  some: new TirFuncT([
81
82
  new TirFuncT([elemsType], bool_t)
82
- ], bool_t)
83
+ ], bool_t),
84
+ includes: new TirFuncT([elemsType], bool_t),
83
85
  };
84
86
  }
85
87
  function getLinearMapMethods(kT, vT) {
@@ -112,10 +114,10 @@ function findPropInImpls(ctx, methodsNamesPtr, propName) {
112
114
  const tirFuncName = methodsNamesPtr.get(propName);
113
115
  if (!tirFuncName)
114
116
  return undefined;
115
- const funcInfos = ctx.program.functions.get(tirFuncName);
116
- if (!funcInfos)
117
+ const funcExpr = ctx.program.functions.get(tirFuncName);
118
+ if (!funcExpr)
117
119
  return undefined;
118
- const fullSig = funcInfos.sig();
120
+ const fullSig = funcExpr.sig();
119
121
  const methodSig = new TirFuncT(fullSig.argTypes.slice(1), fullSig.returnType);
120
122
  return methodSig;
121
123
  }
@@ -1,10 +1,11 @@
1
1
  import { compileUPLC, UPLCProgram } from "@harmoniclabs/uplc";
2
2
  import { DiagnosticEmitter } from "../diagnostics/DiagnosticEmitter.js";
3
- import { compileIRToUPLC } from "../IR/index.js";
4
3
  import { defaultOptions } from "../IR/toUPLC/CompilerOptions.js";
5
4
  import { AstCompiler } from "./AstCompiler/AstCompiler.js";
6
5
  import { createMemoryCompilerIoApi } from "./io/CompilerIoApi.js";
7
6
  import { compileTypedProgram } from "./TirCompiler/compileTirProgram.js";
7
+ import { __VERY_UNSAFE_FORGET_IRHASH_ONLY_USE_AT_END_OF_UPLC_COMPILATION } from "../IR/IRHash.js";
8
+ import { compileIRToUPLC } from "../IR/toUPLC/compileIRToUPLC.js";
8
9
  export class Compiler extends DiagnosticEmitter {
9
10
  io;
10
11
  cfg;
@@ -37,6 +38,7 @@ export class Compiler extends DiagnosticEmitter {
37
38
  const outPath = outDir + (outDir.endsWith("/") ? "" : "/") + "out.flat";
38
39
  this.io.writeFile(outPath, serialized, cfg.root);
39
40
  this.io.stdout.write(`compiled program written to ${outPath}\n`);
41
+ __VERY_UNSAFE_FORGET_IRHASH_ONLY_USE_AT_END_OF_UPLC_COMPILATION();
40
42
  return;
41
43
  }
42
44
  }
@@ -13,6 +13,8 @@ export function compileTypedProgram(cfg, tirProgram) {
13
13
  );
14
14
  //*/
15
15
  const mainFuncExpr = tirProgram.getMainOrThrow();
16
- void expressify(mainFuncExpr, undefined);
16
+ // console.log("main func expr:", mainFuncExpr.toString() );
17
+ void expressify(mainFuncExpr, undefined, // loopReplacements
18
+ tirProgram);
17
19
  return mainFuncExpr.toIR(ToIRTermCtx.root());
18
20
  }
@@ -9,6 +9,8 @@ import { TirNamedDeconstructVarDecl } from "../../tir/statements/TirVarDecl/TirN
9
9
  import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
10
10
  import { TirDataStructType } from "../../tir/types/TirStructType.js";
11
11
  import { TirType } from "../../tir/types/TirType.js";
12
+ import { TypedProgram } from "../../tir/program/TypedProgram.js";
13
+ import { TirVarDecl } from "../../tir/statements/TirVarDecl/TirVarDecl.js";
12
14
  /**
13
15
  * Static Single Assignment (SSA) variable name.
14
16
  *
@@ -29,6 +31,7 @@ export declare function isExpressifyFuncParam(thing: any): thing is ExpressifyFu
29
31
  export declare class ExpressifyCtx {
30
32
  readonly parent: ExpressifyCtx | undefined;
31
33
  returnType: TirType;
34
+ readonly program: TypedProgram;
32
35
  /** var name -> latest constant name */
33
36
  readonly variables: Map<string, LatestVarNameSSA>;
34
37
  /** constant name -> func param name (to build var access) */
@@ -38,7 +41,7 @@ export declare class ExpressifyCtx {
38
41
  /** var name -> prop name -> constant name (letted field extraction expr or var access for SoP)*/
39
42
  readonly properties: Map<string, Map<string, string>>;
40
43
  readonly hoisted: Map<string, TirHoistedExpr | TirNativeFunc>;
41
- constructor(parent: ExpressifyCtx | undefined, returnType: TirType, hoisted?: Map<string, TirHoistedExpr | TirNativeFunc>,
44
+ constructor(parent: ExpressifyCtx | undefined, returnType: TirType, program: TypedProgram, hoisted?: Map<string, TirHoistedExpr | TirNativeFunc>,
42
45
  /** var name -> latest constant name */
43
46
  variables?: Map<string, LatestVarNameSSA>,
44
47
  /** constant name -> func param name (to build var access) */
@@ -47,6 +50,7 @@ export declare class ExpressifyCtx {
47
50
  lettedConstants?: Map<string, TirLettedExpr>,
48
51
  /** var name -> prop name -> constant name (letted field extraction expr or var access for SoP)*/
49
52
  properties?: Map<string, Map<string, string>>);
53
+ allVariables(): string[];
50
54
  newChild(): ExpressifyCtx;
51
55
  setNewVariableName(oldName: string, newName: string): void;
52
56
  setFuncParam(name: string, type: TirType): void;
@@ -67,6 +71,12 @@ export declare class ExpressifyCtx {
67
71
  introduceSopConstrFieldsAsProperties(sopName: string, destructuredPattern: TirNamedDeconstructVarDecl): void;
68
72
  introduceSopConstrFieldsAsParamsOnly(destructuredPattern: TirNamedDeconstructVarDecl): void;
69
73
  introduceSingleConstrDataLettedFields(varName: string, structExpr: TirExpr, structType: TirDataStructType): void;
70
- introduceDeconstrDataLettedFields(stmt: TirNamedDeconstructVarDecl): TirAssertStmt[];
71
- introduceArrayDeconstr(stmt: TirArrayLikeDeconstr, isDestructuredField?: boolean): TirAssertStmt[];
74
+ introduceDeconstrDataLettedFields(stmt: TirNamedDeconstructVarDecl, lettedInitExpr: TirLettedExpr): {
75
+ implicitAssertions: TirAssertStmt[];
76
+ nestedDeconstructs: TirVarDecl[];
77
+ };
78
+ introduceArrayDeconstr(stmt: TirArrayLikeDeconstr, isDestructuredField?: boolean): {
79
+ implicitAssertions: TirAssertStmt[];
80
+ nestedDeconstructs: TirVarDecl[];
81
+ };
72
82
  }
@@ -26,12 +26,13 @@ export function isExpressifyFuncParam(thing) {
26
26
  export class ExpressifyCtx {
27
27
  parent;
28
28
  returnType;
29
+ program;
29
30
  variables;
30
31
  funcParams;
31
32
  lettedConstants;
32
33
  properties;
33
34
  hoisted;
34
- constructor(parent, returnType, hoisted,
35
+ constructor(parent, returnType, program, hoisted,
35
36
  /** var name -> latest constant name */
36
37
  variables = new Map(),
37
38
  /** constant name -> func param name (to build var access) */
@@ -42,14 +43,22 @@ export class ExpressifyCtx {
42
43
  properties = new Map()) {
43
44
  this.parent = parent;
44
45
  this.returnType = returnType;
46
+ this.program = program;
45
47
  this.variables = variables;
46
48
  this.funcParams = funcParams;
47
49
  this.lettedConstants = lettedConstants;
48
50
  this.properties = properties;
49
51
  this.hoisted = hoisted ?? this.parent?.hoisted ?? new Map();
50
52
  }
53
+ allVariables() {
54
+ const thisVars = new Set([
55
+ ...this.variables.keys(),
56
+ ...this.lettedConstants.keys()
57
+ ]);
58
+ return (this.parent?.allVariables() ?? []).concat(...thisVars);
59
+ }
51
60
  newChild() {
52
- return new ExpressifyCtx(this, this.returnType);
61
+ return new ExpressifyCtx(this, this.returnType, this.program);
53
62
  }
54
63
  setNewVariableName(oldName, newName) {
55
64
  let latestNameSSA = this.variables.get(oldName);
@@ -92,7 +101,7 @@ export class ExpressifyCtx {
92
101
  const result = (this._getNonHoistedVariable(name)
93
102
  ?? this.hoisted.get(name));
94
103
  if (!result) {
95
- console.log(this);
104
+ // console.log( this );
96
105
  throw new Error(`variable '${name}' not found in the context`);
97
106
  }
98
107
  return result;
@@ -130,7 +139,7 @@ export class ExpressifyCtx {
130
139
  if (constr.fields.length === 0)
131
140
  return; // no fields to extract
132
141
  const lettedRawFieldsName = getUniqueInternalName(`${varName}_fields`);
133
- const lettedFields = this.introduceLettedConstant(lettedRawFieldsName, new TirCallExpr(TirNativeFunc.unConstrDataResultFields, [new TirCallExpr(TirNativeFunc.unConstrData, [structExpr], new TirUnConstrDataResultT(), structExpr.range)], new TirListT(data_t), structExpr.range), structExpr.range);
142
+ const lettedFields = this.introduceLettedConstant(lettedRawFieldsName, new TirLettedExpr(lettedRawFieldsName, new TirCallExpr(TirNativeFunc.unConstrDataResultFields, [new TirCallExpr(TirNativeFunc.unConstrData, [structExpr], new TirUnConstrDataResultT(), structExpr.range)], new TirListT(data_t), structExpr.range), structExpr.range), structExpr.range);
134
143
  const fieldsMap = new Map();
135
144
  for (let i = 0; i < constr.fields.length; i++) {
136
145
  const field = constr.fields[i];
@@ -150,36 +159,37 @@ export class ExpressifyCtx {
150
159
  }
151
160
  this.properties.set(varName, fieldsMap);
152
161
  }
153
- introduceDeconstrDataLettedFields(stmt) {
162
+ introduceDeconstrDataLettedFields(stmt, lettedInitExpr) {
154
163
  const structType = stmt.type;
155
164
  if (!(stmt.initExpr))
156
165
  throw new Error("expected init expr in deconstruct data statement");
157
166
  if (!(structType instanceof TirDataStructType))
158
167
  throw new Error("expected data struct type in deconstruct data statement");
159
- const varName = getUniqueInternalName(structType.toString().toLowerCase());
168
+ const varName = lettedInitExpr.varName ?? getUniqueInternalName(structType.toString().toLowerCase());
160
169
  const constrName = stmt.constrName;
161
170
  const constrIdx = structType.constructors.findIndex(c => c.name === constrName);
162
171
  if (constrIdx < 0)
163
172
  throw new Error(`constructor ${constrName} not found in data struct ${structType.name}`);
164
173
  const constr = structType.constructors[constrIdx];
165
174
  if (constr.fields.length === 0)
166
- return []; // no fields to extract, no assertions
167
- const structExpr = stmt.initExpr;
175
+ return { implicitAssertions: [], nestedDeconstructs: [] }; // no fields to extract, no assertions
176
+ const structExpr = lettedInitExpr ?? stmt.initExpr;
168
177
  const lettedUnconstrName = getUniqueInternalName(`${varName}_unconstrPair`);
169
- const lettedUnconstr = this.introduceLettedConstant(lettedUnconstrName, new TirCallExpr(TirNativeFunc.unBData, [stmt.initExpr], new TirUnConstrDataResultT(), stmt.range), stmt.range);
178
+ const lettedUnconstr = this.introduceLettedConstant(lettedUnconstrName, new TirCallExpr(TirNativeFunc.unConstrData, [structExpr], new TirUnConstrDataResultT(), stmt.range), stmt.range);
170
179
  const assertions = [];
171
- if (structType.constructors.length > 0)
180
+ const nestedDeconstructs = [];
181
+ if (structType.constructors.length > 1)
172
182
  assertions.push(new TirAssertStmt(new TirEqualExpr(new TirCallExpr(TirNativeFunc.unConstrDataResultIndex, [lettedUnconstr], int_t, stmt.range), new TirLitIntExpr(BigInt(constrIdx), stmt.range), stmt.range), undefined, // no trace message
173
183
  stmt.range));
174
184
  const lettedRawFieldsName = getUniqueInternalName(`${varName}_fields`);
175
- const lettedFields = this.introduceLettedConstant(lettedRawFieldsName, new TirCallExpr(TirNativeFunc.unConstrDataResultFields, [lettedUnconstr], new TirListT(data_t), stmt.range), stmt.range);
185
+ const lettedFields = this.introduceLettedConstant(lettedRawFieldsName, new TirLettedExpr(lettedRawFieldsName, new TirCallExpr(TirNativeFunc.unConstrDataResultFields, [lettedUnconstr], new TirListT(data_t), stmt.range), stmt.range), stmt.range);
176
186
  const fieldsToIntroduce = [...stmt.fields.keys()];
177
187
  const hasRest = typeof stmt.rest === "string";
178
188
  const fieldsMap = new Map();
179
189
  for (let i = 0; i < constr.fields.length; i++) {
180
190
  const field = constr.fields[i];
181
191
  const fieldName = field.name;
182
- const fieldType = field.type;
192
+ let fieldType = field.type;
183
193
  const isFieldToIntroduce = fieldsToIntroduce.includes(fieldName);
184
194
  if (!hasRest && !isFieldToIntroduce)
185
195
  continue; // skip unused field
@@ -198,32 +208,18 @@ export class ExpressifyCtx {
198
208
  if (fieldVarDecl instanceof TirSimpleVarDecl) {
199
209
  this.variables.set(fieldVarDecl.name, { latestName: lettedField.varName });
200
210
  }
201
- // data structs cannot have sop-encoded fields (thanks god)
202
- // recursively introduce letted fields for nested single-constructor data structs
203
- if (!(fieldType instanceof TirDataStructType))
204
- continue;
205
- // if the field is simply introduced but still a single constr struct
206
- // we need to introduce its fields as well
207
- if (fieldVarDecl instanceof TirSimpleVarDecl
208
- && fieldType.constructors.length === 1) {
209
- this.introduceSingleConstrDataLettedFields(fieldVarName, lettedField, fieldType);
210
- }
211
- else if (fieldVarDecl instanceof TirNamedDeconstructVarDecl
212
- || fieldVarDecl instanceof TirSingleDeconstructVarDecl) {
213
- // if the field is destructured, we need to introduce its fields as well
214
- const namedVarDecl = toNamedDeconstructVarDecl(fieldVarDecl);
215
- namedVarDecl.initExpr = lettedField;
216
- assertions.push(...this.introduceDeconstrDataLettedFields(namedVarDecl));
217
- }
218
- else if (fieldVarDecl instanceof TirArrayLikeDeconstr) {
211
+ else {
212
+ // fieldVarDecl.type ??= fieldType;
219
213
  fieldVarDecl.initExpr = lettedField;
220
- assertions.push(...this.introduceArrayDeconstr(fieldVarDecl, true // is destructured field
221
- ));
214
+ nestedDeconstructs.push(fieldVarDecl);
222
215
  }
223
216
  }
224
217
  if (hasRest)
225
218
  this.properties.set(stmt.rest, fieldsMap);
226
- return assertions;
219
+ return {
220
+ implicitAssertions: assertions,
221
+ nestedDeconstructs
222
+ };
227
223
  }
228
224
  introduceArrayDeconstr(stmt, isDestructuredField = false) {
229
225
  if (!(stmt.initExpr))
@@ -240,6 +236,7 @@ export class ExpressifyCtx {
240
236
  lettedArrayExpr = this.introduceLettedConstant(lettedArrayName, stmt.initExpr, stmt.range);
241
237
  }
242
238
  const assertions = [];
239
+ const nestedDeconstructs = [];
243
240
  const nElems = stmt.elements.length;
244
241
  for (let i = 0; i < nElems; i++) {
245
242
  const elemVarDecl = stmt.elements[i];
@@ -261,12 +258,16 @@ export class ExpressifyCtx {
261
258
  || elemVarDecl instanceof TirSingleDeconstructVarDecl) {
262
259
  const namedVarDecl = toNamedDeconstructVarDecl(elemVarDecl);
263
260
  namedVarDecl.initExpr = lettedElem;
264
- assertions.push(...this.introduceDeconstrDataLettedFields(namedVarDecl));
261
+ const introduceFieldsResult = this.introduceDeconstrDataLettedFields(namedVarDecl, lettedElem);
262
+ assertions.push(...introduceFieldsResult.implicitAssertions);
263
+ nestedDeconstructs.push(...introduceFieldsResult.nestedDeconstructs);
265
264
  }
266
265
  else if (elemVarDecl instanceof TirArrayLikeDeconstr) {
267
266
  elemVarDecl.initExpr = lettedElem;
268
- assertions.push(...this.introduceArrayDeconstr(elemVarDecl, true // is destructured field
269
- ));
267
+ const introduceFieldsResult = this.introduceArrayDeconstr(elemVarDecl, true // is destructured field
268
+ );
269
+ assertions.push(...introduceFieldsResult.implicitAssertions);
270
+ nestedDeconstructs.push(...introduceFieldsResult.nestedDeconstructs);
270
271
  }
271
272
  }
272
273
  if (stmt.rest) {
@@ -277,6 +278,9 @@ export class ExpressifyCtx {
277
278
  lettedArrayExpr
278
279
  ], new TirListT(elemsType), stmt.range), stmt.range);
279
280
  }
280
- return assertions;
281
+ return {
282
+ implicitAssertions: assertions,
283
+ nestedDeconstructs
284
+ };
281
285
  }
282
286
  }