@harmoniclabs/pebble 0.1.0-dev5 → 0.1.0-dev7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/dist/IR/IRHash.d.ts +3 -3
  2. package/dist/IR/IRHash.js +47 -52
  3. package/dist/IR/IRNodes/IRApp.d.ts +12 -8
  4. package/dist/IR/IRNodes/IRApp.js +34 -20
  5. package/dist/IR/IRNodes/IRCase.d.ts +11 -7
  6. package/dist/IR/IRNodes/IRCase.js +33 -32
  7. package/dist/IR/IRNodes/IRConst.d.ts +7 -5
  8. package/dist/IR/IRNodes/IRConst.js +23 -13
  9. package/dist/IR/IRNodes/IRConstr.d.ts +11 -7
  10. package/dist/IR/IRNodes/IRConstr.js +34 -37
  11. package/dist/IR/IRNodes/IRDelayed.d.ts +12 -9
  12. package/dist/IR/IRNodes/IRDelayed.js +22 -18
  13. package/dist/IR/IRNodes/IRError.d.ts +9 -6
  14. package/dist/IR/IRNodes/IRError.js +12 -5
  15. package/dist/IR/IRNodes/IRForced.d.ts +9 -6
  16. package/dist/IR/IRNodes/IRForced.js +22 -18
  17. package/dist/IR/IRNodes/IRFunc.d.ts +14 -10
  18. package/dist/IR/IRNodes/IRFunc.js +35 -38
  19. package/dist/IR/IRNodes/IRHoisted.d.ts +16 -9
  20. package/dist/IR/IRNodes/IRHoisted.js +36 -18
  21. package/dist/IR/IRNodes/IRLetted.d.ts +14 -34
  22. package/dist/IR/IRNodes/IRLetted.js +65 -297
  23. package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +3 -3
  24. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +4 -4
  25. package/dist/IR/IRNodes/IRNative/index.d.ts +10 -8
  26. package/dist/IR/IRNodes/IRNative/index.js +56 -18
  27. package/dist/IR/IRNodes/IRNative/isForcedNative.d.ts +2 -0
  28. package/dist/IR/IRNodes/IRNative/isForcedNative.js +1 -1
  29. package/dist/IR/IRNodes/IRRecursive.d.ts +18 -10
  30. package/dist/IR/IRNodes/IRRecursive.js +36 -44
  31. package/dist/IR/IRNodes/IRSelfCall.d.ts +10 -24
  32. package/dist/IR/IRNodes/IRSelfCall.js +25 -87
  33. package/dist/IR/IRNodes/IRVar.d.ts +11 -19
  34. package/dist/IR/IRNodes/IRVar.js +26 -54
  35. package/dist/IR/IRNodes/utils/dependsByDbns.d.ts +1 -1
  36. package/dist/IR/IRNodes/utils/dependsByDbns.js +5 -11
  37. package/dist/IR/IRNodes/utils/hashVarSym.d.ts +1 -0
  38. package/dist/IR/IRNodes/utils/hashVarSym.js +37 -0
  39. package/dist/IR/IRNodes/utils/makeArrayLikeProxy.d.ts +2 -1
  40. package/dist/IR/IRTerm.d.ts +7 -0
  41. package/dist/IR/toUPLC/CompilerOptions.d.ts +5 -0
  42. package/dist/IR/toUPLC/CompilerOptions.js +10 -1
  43. package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +3 -0
  44. package/dist/IR/toUPLC/_internal/findAll.js +2 -73
  45. package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +7 -34
  46. package/dist/IR/toUPLC/_internal/iterTree.js +3 -17
  47. package/dist/IR/toUPLC/common_hoisted.d.ts +2 -0
  48. package/dist/IR/toUPLC/common_hoisted.js +4 -0
  49. package/dist/IR/toUPLC/compileIRToUPLC.d.ts +1 -1
  50. package/dist/IR/toUPLC/compileIRToUPLC.js +91 -14
  51. package/dist/IR/toUPLC/ctx/ToUplcCtx.d.ts +16 -0
  52. package/dist/IR/toUPLC/ctx/ToUplcCtx.js +67 -0
  53. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.d.ts +8 -0
  54. package/dist/IR/toUPLC/subRoutines/_comptimeDropN.js +95 -0
  55. package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +7 -54
  56. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +6 -13
  57. package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +65 -71
  58. package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +44 -170
  59. package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +7 -3
  60. package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +3 -2
  61. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.d.ts +22 -0
  62. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.js +59 -0
  63. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts +0 -0
  64. package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.js +217 -0
  65. package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +12 -49
  66. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +1 -1
  67. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +11 -14
  68. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/{index.d.ts → performUplcOptimizationsAndReturnRoot.d.ts} +0 -2
  69. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +151 -0
  70. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.d.ts +11 -0
  71. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.js +46 -0
  72. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.d.ts +2 -0
  73. package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js +80 -0
  74. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +18 -11
  75. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +45 -0
  76. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +277 -478
  77. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.d.ts +2 -0
  78. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +85 -0
  79. package/dist/IR/toUPLC/subRoutines/sanifyTree.js +1 -0
  80. package/dist/IR/toUPLC/utils/getApplicationTerms.d.ts +6 -0
  81. package/dist/IR/toUPLC/utils/getApplicationTerms.js +37 -0
  82. package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +2 -2
  83. package/dist/IR/tree_utils/_ir_lazyChooseList.js +4 -2
  84. package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +1 -1
  85. package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +4 -2
  86. package/dist/IR/tree_utils/_ir_let.d.ts +2 -1
  87. package/dist/IR/tree_utils/_ir_let.js +6 -2
  88. package/dist/IR/utils/isClosedIRTerm.d.ts +1 -0
  89. package/dist/IR/utils/isClosedIRTerm.js +40 -26
  90. package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
  91. package/dist/IR/utils/positiveIntAsBytes.js +4 -4
  92. package/dist/IR/utils/showIR.d.ts +10 -21
  93. package/dist/IR/utils/showIR.js +66 -64
  94. package/dist/ast/nodes/common/Identifier.d.ts +1 -0
  95. package/dist/ast/nodes/common/Identifier.js +3 -0
  96. package/dist/ast/nodes/expr/CaseExpr.d.ts +5 -5
  97. package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +2 -2
  98. package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +1 -1
  99. package/dist/ast/nodes/expr/PebbleExpr.d.ts +2 -1
  100. package/dist/ast/nodes/expr/PropAccessExpr.d.ts +3 -3
  101. package/dist/ast/nodes/expr/TernaryExpr.d.ts +3 -3
  102. package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +2 -1
  103. package/dist/ast/nodes/expr/TypeConversionExpr.js +2 -0
  104. package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +42 -42
  105. package/dist/ast/nodes/expr/functions/CallExpr.d.ts +1 -1
  106. package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +2 -1
  107. package/dist/ast/nodes/expr/functions/FuncExpr.js +6 -0
  108. package/dist/ast/nodes/expr/litteral/LitContextExpr.d.ts +6 -0
  109. package/dist/ast/nodes/expr/litteral/LitContextExpr.js +6 -0
  110. package/dist/ast/nodes/expr/litteral/LitFailExpr.d.ts +6 -0
  111. package/dist/ast/nodes/expr/litteral/LitFailExpr.js +6 -0
  112. package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +3 -1
  113. package/dist/ast/nodes/expr/litteral/LitteralExpr.js +5 -1
  114. package/dist/ast/nodes/statements/AssertStmt.d.ts +2 -2
  115. package/dist/ast/nodes/statements/AssignmentStmt.d.ts +1 -1
  116. package/dist/ast/nodes/statements/BlockStmt.d.ts +1 -1
  117. package/dist/ast/nodes/statements/FailStmt.d.ts +1 -1
  118. package/dist/ast/nodes/statements/ForOfStmt.d.ts +4 -2
  119. package/dist/ast/nodes/statements/ForOfStmt.js +6 -0
  120. package/dist/ast/nodes/statements/ForStmt.d.ts +6 -4
  121. package/dist/ast/nodes/statements/ForStmt.js +6 -0
  122. package/dist/ast/nodes/statements/IfStmt.d.ts +8 -5
  123. package/dist/ast/nodes/statements/IfStmt.js +13 -0
  124. package/dist/ast/nodes/statements/MatchStmt.d.ts +13 -4
  125. package/dist/ast/nodes/statements/MatchStmt.js +22 -1
  126. package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
  127. package/dist/ast/nodes/statements/PebbleStmt.js +3 -1
  128. package/dist/ast/nodes/statements/ReturnStmt.d.ts +1 -1
  129. package/dist/ast/nodes/statements/WhileStmt.d.ts +4 -2
  130. package/dist/ast/nodes/statements/WhileStmt.js +6 -0
  131. package/dist/ast/nodes/statements/declarations/ContractDecl.d.ts +17 -0
  132. package/dist/ast/nodes/statements/declarations/ContractDecl.js +22 -0
  133. package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +1 -1
  134. package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +1 -1
  135. package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +1 -1
  136. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +2 -1
  137. package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +6 -0
  138. package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +1 -1
  139. package/dist/compiler/AstCompiler/AstCompiler.d.ts +7 -2
  140. package/dist/compiler/AstCompiler/AstCompiler.js +129 -25
  141. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.d.ts +10 -0
  142. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +777 -0
  143. package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +1 -1
  144. package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +5 -1
  145. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +7 -4
  146. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +8 -2
  147. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +1 -1
  148. package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +2 -1
  149. package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
  150. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
  151. package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +8 -8
  152. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +2 -2
  153. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +48 -24
  154. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
  155. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +2 -1
  156. package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +4 -3
  157. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +1 -1
  158. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +4 -1
  159. package/dist/compiler/AstCompiler/scope/AstScope.d.ts +1 -0
  160. package/dist/compiler/AstCompiler/scope/AstScope.js +9 -3
  161. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
  162. package/dist/compiler/Compiler.js +7 -1
  163. package/dist/compiler/TirCompiler/compileTirProgram.js +4 -1
  164. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +17 -5
  165. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +79 -49
  166. package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +13 -2
  167. package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
  168. package/dist/compiler/TirCompiler/expressify/expressify.js +102 -41
  169. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
  170. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +77 -12
  171. package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
  172. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
  173. package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +16 -9
  174. package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -8
  175. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +146 -13
  176. package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
  177. package/dist/compiler/internalVar.d.ts +1 -1
  178. package/dist/compiler/internalVar.js +31 -24
  179. package/dist/compiler/io/CompilerIoApi.d.ts +1 -1
  180. package/dist/compiler/io/IOutputStream.d.ts +1 -0
  181. package/dist/compiler/io/IOutputStream.js +18 -3
  182. package/dist/compiler/path/getAbsolutePath.js +4 -6
  183. package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
  184. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
  185. package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
  186. package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
  187. package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
  188. package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
  189. package/dist/compiler/tir/expressions/TirCaseExpr.js +105 -60
  190. package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
  191. package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
  192. package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
  193. package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
  194. package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
  195. package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
  196. package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
  197. package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
  198. package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
  199. package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
  200. package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
  201. package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
  202. package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +6 -3
  203. package/dist/compiler/tir/expressions/TirLettedExpr.js +20 -7
  204. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +9 -5
  205. package/dist/compiler/tir/expressions/TirNativeFunc.js +58 -22
  206. package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
  207. package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
  208. package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
  209. package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -1
  210. package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
  211. package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
  212. package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
  213. package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
  214. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
  215. package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
  216. package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
  217. package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
  218. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +6 -3
  219. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +22 -8
  220. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +19 -20
  221. package/dist/compiler/tir/expressions/ToIRTermCtx.js +74 -50
  222. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +41 -0
  223. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +180 -4
  224. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
  225. package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
  226. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
  227. package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
  228. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
  229. package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
  230. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
  231. package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
  232. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
  233. package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
  234. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
  235. package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
  236. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
  237. package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
  238. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
  239. package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
  240. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
  241. package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
  242. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
  243. package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
  244. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
  245. package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
  246. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
  247. package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
  248. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
  249. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
  250. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
  251. package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
  252. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
  253. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
  254. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
  255. package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
  256. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
  257. package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
  258. package/dist/compiler/tir/program/TypedProgram.d.ts +3 -2
  259. package/dist/compiler/tir/program/TypedProgram.js +9 -0
  260. package/dist/compiler/tir/program/stdScope/stdScope.js +135 -149
  261. package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
  262. package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
  263. package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
  264. package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
  265. package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
  266. package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
  267. package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
  268. package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
  269. package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
  270. package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
  271. package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
  272. package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
  273. package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
  274. package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
  275. package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
  276. package/dist/compiler/tir/statements/TirForStmt.js +21 -0
  277. package/dist/compiler/tir/statements/TirIfStmt.d.ts +2 -0
  278. package/dist/compiler/tir/statements/TirIfStmt.js +16 -0
  279. package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
  280. package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
  281. package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
  282. package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
  283. package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
  284. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
  285. package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
  286. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
  287. package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
  288. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
  289. package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
  290. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
  291. package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
  292. package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
  293. package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
  294. package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
  295. package/dist/diagnostics/DiagnosticEmitter.js +1 -1
  296. package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
  297. package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
  298. package/dist/parser/Parser.d.ts +8 -3
  299. package/dist/parser/Parser.js +180 -32
  300. package/dist/parser/Precedence.js +1 -0
  301. package/dist/tokenizer/Token.d.ts +81 -72
  302. package/dist/tokenizer/Token.js +82 -72
  303. package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
  304. package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
  305. package/dist/utils/BitUtils/index.js +1 -1
  306. package/dist/utils/UPLCFlatUtils/index.js +1 -1
  307. package/dist/utils/array/keepSortedArrInplace.js +1 -0
  308. package/package.json +3 -1
  309. package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
  310. package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
  311. package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
  312. package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
  313. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
  314. package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
  315. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
  316. package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
  317. package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
  318. package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
  319. package/dist/IR/tree_utils/_ir_apps.js +0 -8
  320. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
  321. package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -37
@@ -3,20 +3,64 @@ import { getUniqueInternalName } from "../../internalVar.js";
3
3
  import { TirLitNamedObjExpr } from "../../tir/expressions/litteral/TirLitNamedObjExpr.js";
4
4
  import { TirCallExpr } from "../../tir/expressions/TirCallExpr.js";
5
5
  import { TirFuncExpr } from "../../tir/expressions/TirFuncExpr.js";
6
+ import { TirPropAccessExpr } from "../../tir/expressions/TirPropAccessExpr.js";
6
7
  import { TirVariableAccessExpr } from "../../tir/expressions/TirVariableAccessExpr.js";
8
+ import { TirUnaryExclamation } from "../../tir/expressions/unary/TirUnaryExclamation.js";
9
+ import { TirAssignmentStmt } from "../../tir/statements/TirAssignmentStmt.js";
7
10
  import { TirBlockStmt } from "../../tir/statements/TirBlockStmt.js";
8
11
  import { TirBreakStmt } from "../../tir/statements/TirBreakStmt.js";
9
12
  import { TirContinueStmt } from "../../tir/statements/TirContinueStmt.js";
13
+ import { TirForOfStmt } from "../../tir/statements/TirForOfStmt.js";
10
14
  import { TirForStmt } from "../../tir/statements/TirForStmt.js";
11
15
  import { TirIfStmt } from "../../tir/statements/TirIfStmt.js";
12
16
  import { TirReturnStmt } from "../../tir/statements/TirReturnStmt.js";
13
17
  import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
18
+ import { TirBoolT } from "../../tir/types/TirNativeType/index.js";
14
19
  import { TirFuncT } from "../../tir/types/TirNativeType/native/function.js";
20
+ import { getListTypeArg } from "../../tir/types/utils/getListTypeArg.js";
15
21
  import { expressifyFuncBody } from "./expressify.js";
16
22
  import { isExpressifyFuncParam } from "./ExpressifyCtx.js";
17
- export function whileToFor(stmt) {
23
+ import { expressifyVars } from "./expressifyVars.js";
24
+ export function loopToForStmt(stmt) {
18
25
  if (stmt instanceof TirForStmt)
19
26
  return stmt;
27
+ if (stmt instanceof TirForOfStmt) {
28
+ // convert for of to for
29
+ const partialListName = getUniqueInternalName("for_of_partial_list");
30
+ const iterElemType = getListTypeArg(stmt.iterable.type);
31
+ if (!iterElemType)
32
+ throw new Error("Iterable type is not a list");
33
+ const varRange = stmt.elemDeclaration.range;
34
+ const partialListVar = new TirSimpleVarDecl(partialListName, // name
35
+ stmt.iterable.type, // type
36
+ stmt.iterable, // initial value
37
+ false, // is constant
38
+ varRange // range
39
+ );
40
+ const partialListVarAccess = new TirVariableAccessExpr({
41
+ isDefinedOutsideFuncScope: false,
42
+ variableInfos: {
43
+ name: partialListVar.name,
44
+ type: partialListVar.type,
45
+ isConstant: false,
46
+ },
47
+ }, varRange);
48
+ // `!partialList.isEmpty()`
49
+ const runCondition = new TirUnaryExclamation(new TirCallExpr(new TirPropAccessExpr(partialListVarAccess.clone(), new Identifier("isEmpty", varRange), new TirFuncT([], new TirBoolT()), varRange), [], // args
50
+ new TirBoolT(), varRange), new TirBoolT(), varRange);
51
+ const updatePartialList = new TirAssignmentStmt(partialListVarAccess.clone(), new TirCallExpr(new TirPropAccessExpr(partialListVarAccess.clone(), new Identifier("tail", varRange), new TirFuncT([], stmt.iterable.type), varRange), [], // args
52
+ stmt.iterable.type, varRange), varRange);
53
+ let body = stmt.body instanceof TirBlockStmt ? stmt.body : new TirBlockStmt([stmt.body], stmt.range);
54
+ const elemDecl = stmt.elemDeclaration;
55
+ elemDecl.initExpr = new TirCallExpr(new TirPropAccessExpr(partialListVarAccess.clone(), new Identifier("head", varRange), new TirFuncT([], iterElemType), varRange), [], // args
56
+ iterElemType, varRange);
57
+ body.stmts.unshift(elemDecl);
58
+ return new TirForStmt([partialListVar], // init
59
+ runCondition, // condition
60
+ [updatePartialList], // update
61
+ body, // loopBody
62
+ stmt.range);
63
+ }
20
64
  // convert while to for
21
65
  return new TirForStmt([], // no init
22
66
  stmt.condition, // condition
@@ -25,14 +69,24 @@ export function whileToFor(stmt) {
25
69
  stmt.range);
26
70
  }
27
71
  export function expressifyForStmt(ctx, stmt, returnType, bodyStateType, initState) {
28
- const loopBody = stmt.body instanceof TirBlockStmt ? stmt.body : new TirBlockStmt([stmt.body], stmt.range);
29
- if (stmt.condition)
30
- loopBody.stmts.unshift(new TirIfStmt(stmt.condition,
31
- // then
32
- loopBody,
33
- // else
34
- new TirBlockStmt([new TirBreakStmt(stmt.condition.range)], stmt.condition.range), stmt.condition.range));
72
+ let loopBody = stmt.body instanceof TirBlockStmt ? stmt.body : new TirBlockStmt([stmt.body], stmt.range);
73
+ loopBody = new TirBlockStmt(loopBody.stmts.slice(), loopBody.range);
74
+ // add final loop updates
75
+ if (Array.isArray(stmt.update))
76
+ for (const updateStmt of stmt.update) {
77
+ loopBody.stmts.push(updateStmt);
78
+ }
79
+ // ALWAYS add a final `continue;` to the end of the loop body
35
80
  loopBody.stmts.push(new TirContinueStmt(loopBody.range.atEnd()));
81
+ if (stmt.condition) {
82
+ loopBody = new TirBlockStmt([
83
+ new TirIfStmt(stmt.condition,
84
+ // then
85
+ loopBody,
86
+ // else
87
+ new TirBlockStmt([new TirBreakStmt(stmt.condition.range)], stmt.condition.range), stmt.condition.range)
88
+ ], loopBody.range);
89
+ }
36
90
  const loopFuncName = getUniqueInternalName("loop");
37
91
  const loopFuncType = new TirFuncT(bodyStateType.constructors[0].fields.map(f => f.type), returnType);
38
92
  const loopReplacements = {
@@ -105,11 +159,22 @@ export function expressifyForStmt(ctx, stmt, returnType, bodyStateType, initStat
105
159
  for (const { name, type } of bodyStateType.constructors[0].fields) {
106
160
  loopCompilationCtx.setFuncParam(name, type);
107
161
  }
108
- return new TirCallExpr(new TirFuncExpr(loopFuncName, bodyStateType.constructors[0].fields.map(f => new TirSimpleVarDecl(f.name, f.type, undefined, // no initial value
162
+ const loopFuncExpr = new TirFuncExpr(loopFuncName, // func name
163
+ // func params
164
+ bodyStateType.constructors[0].fields.map(f => new TirSimpleVarDecl(f.name, f.type, undefined, // no initial value
109
165
  false, // is constant
110
- stmt.range)), returnType, new TirBlockStmt([
166
+ stmt.range)),
167
+ // func return type
168
+ returnType,
169
+ // func body
170
+ new TirBlockStmt([
111
171
  new TirReturnStmt(expressifyFuncBody(loopCompilationCtx, loopBody.stmts, loopReplacements, [] // assertions
112
172
  ), stmt.range)
113
- ], stmt.range), stmt.range, true // is loop
114
- ), initState.values, returnType, stmt.range);
173
+ ], stmt.range),
174
+ // func range
175
+ stmt.range, true // is loop
176
+ );
177
+ return new TirCallExpr(loopFuncExpr,
178
+ // loop call init args
179
+ initState.values.map(v => expressifyVars(ctx, v.clone())), returnType, stmt.range);
115
180
  }
@@ -100,6 +100,6 @@ function replaceReturnStatements(body, wrapReturnExpr, sopType) {
100
100
  replaceReturnStatements(stmt.body.stmts, wrapReturnExpr, sopType);
101
101
  continue;
102
102
  }
103
- const tsEnsureExsautstiveCheck = stmt;
103
+ const tsEnsureExhautstiveCheck = stmt;
104
104
  }
105
105
  }
@@ -1,4 +1,3 @@
1
1
  import { TirAssignmentStmt } from "../../tir/statements/TirAssignmentStmt.js";
2
- import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
3
2
  import { ExpressifyCtx } from "./ExpressifyCtx.js";
4
- export declare function expressifyVarAssignmentStmt(ctx: ExpressifyCtx, stmt: TirAssignmentStmt): TirSimpleVarDecl;
3
+ export declare function expressifyVarAssignmentStmt(ctx: ExpressifyCtx, stmt: TirAssignmentStmt): void;
@@ -1,20 +1,27 @@
1
1
  import { getUniqueInternalName } from "../../internalVar.js";
2
- import { TirLettedExpr } from "../../tir/expressions/TirLettedExpr.js";
3
- import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
4
2
  import { expressifyVars } from "./expressifyVars.js";
5
3
  export function expressifyVarAssignmentStmt(ctx, stmt) {
4
+ // since we no longer return a new TirSimpleVarDecl,
5
+ // we need to expressify the assigned expression here
6
+ //
7
+ // !!! IMPORTANT !!! we MUST NOT do it if we instead returned a new TirSimpleVarDecl,
8
+ // otherwise it would be re-processed, casing bugs
6
9
  const assignedExpr = expressifyVars(ctx, stmt.assignedExpr);
7
10
  const originalName = stmt.varIdentifier.resolvedValue.variableInfos.name;
8
- const latestVarNameSSA = ctx.variables.get(originalName);
11
+ const latestVarNameSSA = ctx.getVariableSSA(originalName);
9
12
  if (!latestVarNameSSA) {
10
- throw new Error("re-assigning constant variable");
13
+ throw new Error("re-assigning constant variable '" + originalName + "'");
11
14
  }
12
15
  const newUniqueName = getUniqueInternalName(originalName);
13
- latestVarNameSSA.latestName = newUniqueName;
16
+ ctx.setNewVariableName(originalName, newUniqueName);
14
17
  // point to the same object
15
- ctx.variables.set(newUniqueName, latestVarNameSSA);
16
- ctx.lettedConstants.set(newUniqueName, new TirLettedExpr(newUniqueName, assignedExpr, stmt.range));
18
+ ctx.introduceLettedConstant(newUniqueName, assignedExpr, stmt.range);
17
19
  // will replace re-assignment in body
18
- return new TirSimpleVarDecl(newUniqueName, stmt.varIdentifier.resolvedValue.variableInfos.type, assignedExpr, true, // isConst
19
- stmt.range);
20
+ // return new TirSimpleVarDecl(
21
+ // newUniqueName,
22
+ // stmt.varIdentifier.resolvedValue.variableInfos.type,
23
+ // assignedExpr,
24
+ // true, // isConst
25
+ // stmt.range,
26
+ // );
20
27
  }
@@ -1,4 +1,3 @@
1
- import { TirLettedExpr } from "../../tir/expressions/TirLettedExpr.js";
2
1
  import { TirArrayLikeDeconstr } from "../../tir/statements/TirVarDecl/TirArrayLikeDeconstr.js";
3
2
  import { TirNamedDeconstructVarDecl } from "../../tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js";
4
3
  import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
@@ -9,26 +8,25 @@ export function expressifyVarDecl(ctx, stmt) {
9
8
  if (stmt.initExpr)
10
9
  expressifyVars(ctx, stmt.initExpr);
11
10
  if (stmt instanceof TirSimpleVarDecl) {
12
- if (stmt.isConst) {
13
- void ctx.variables.set(stmt.name, { latestName: stmt.name });
14
- /// @ts-ignore Cannot assign to 'isConst' because it is a read-only property.
15
- stmt.isConst = true;
11
+ if (!stmt.isConst) {
12
+ void ctx.setNewVariableName(stmt.name, stmt.name);
13
+ // stmt.isConst = true;
16
14
  }
17
- ctx.lettedConstants.set(stmt.name, new TirLettedExpr(stmt.name, stmt.initExpr, stmt.range));
15
+ ctx.introduceLettedConstant(stmt.name, stmt.initExpr, stmt.range);
18
16
  }
19
17
  if (stmt instanceof TirNamedDeconstructVarDecl
20
18
  || stmt instanceof TirSingleDeconstructVarDecl) {
21
19
  for (const [_field, varDecl] of stmt.fields)
22
20
  expressifyVarDecl(ctx, varDecl);
23
21
  if (stmt.rest)
24
- ctx.variables.set(stmt.rest, { latestName: stmt.rest });
22
+ ctx.setNewVariableName(stmt.rest, stmt.rest);
25
23
  return;
26
24
  }
27
25
  if (stmt instanceof TirArrayLikeDeconstr) {
28
26
  for (const varDecl of stmt.elements)
29
27
  expressifyVarDecl(ctx, varDecl);
30
28
  if (stmt.rest)
31
- ctx.variables.set(stmt.rest, { latestName: stmt.rest });
29
+ ctx.setNewVariableName(stmt.rest, stmt.rest);
32
30
  return;
33
31
  }
34
32
  }
@@ -1,6 +1,7 @@
1
- import { isUnaryPrefixExpr } from "../../../ast/nodes/expr/unary/UnaryPrefixExpr.js";
1
+ import { SourceRange } from "../../../ast/Source/SourceRange.js";
2
2
  import { isTirBinaryExpr } from "../../tir/expressions/binary/TirBinaryExpr.js";
3
3
  import { TirLitArrExpr } from "../../tir/expressions/litteral/TirLitArrExpr.js";
4
+ import { TirLitFailExpr } from "../../tir/expressions/litteral/TirLitFailExpr.js";
4
5
  import { TirLitFalseExpr } from "../../tir/expressions/litteral/TirLitFalseExpr.js";
5
6
  import { TirLitHexBytesExpr } from "../../tir/expressions/litteral/TirLitHexBytesExpr.js";
6
7
  import { TirLitIntExpr } from "../../tir/expressions/litteral/TirLitIntExpr.js";
@@ -32,11 +33,17 @@ import { TirVariableAccessExpr } from "../../tir/expressions/TirVariableAccessEx
32
33
  import { TirUnaryExclamation } from "../../tir/expressions/unary/TirUnaryExclamation.js";
33
34
  import { TirUnaryMinus } from "../../tir/expressions/unary/TirUnaryMinus.js";
34
35
  import { TirUnaryPlus } from "../../tir/expressions/unary/TirUnaryPlus.js";
36
+ import { isTirUnaryPrefixExpr } from "../../tir/expressions/unary/TirUnaryPrefixExpr.js";
35
37
  import { TirUnaryTilde } from "../../tir/expressions/unary/TirUnaryTilde.js";
38
+ import { bool_t } from "../../tir/program/stdScope/stdScope.js";
36
39
  import { TirReturnStmt } from "../../tir/statements/TirReturnStmt.js";
37
40
  import { TirArrayLikeDeconstr } from "../../tir/statements/TirVarDecl/TirArrayLikeDeconstr.js";
38
41
  import { TirNamedDeconstructVarDecl } from "../../tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js";
39
42
  import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
43
+ import { TirAliasType } from "../../tir/types/TirAliasType.js";
44
+ import { TirFuncT, TirListT } from "../../tir/types/TirNativeType/index.js";
45
+ import { TirDataStructType, TirSoPStructType } from "../../tir/types/TirStructType.js";
46
+ import { getListTypeArg } from "../../tir/types/utils/getListTypeArg.js";
40
47
  import { getUnaliased } from "../../tir/types/utils/getUnaliased.js";
41
48
  import { expressify, expressifyFuncBody } from "./expressify.js";
42
49
  import { isExpressifyFuncParam } from "./ExpressifyCtx.js";
@@ -54,6 +61,7 @@ export function expressifyVars(ctx, expr) {
54
61
  if (
55
62
  // isTirLitteralExpr( expr )
56
63
  expr instanceof TirLitVoidExpr
64
+ || expr instanceof TirLitFailExpr
57
65
  || expr instanceof TirLitUndefExpr
58
66
  || expr instanceof TirLitTrueExpr
59
67
  || expr instanceof TirLitFalseExpr
@@ -75,22 +83,26 @@ export function expressifyVars(ctx, expr) {
75
83
  if (expr instanceof TirPropAccessExpr) {
76
84
  const objectExpr = expressifyVars(ctx, expr.object);
77
85
  expr.object = objectExpr;
78
- return getVarAccessFromPropAccess(ctx, expr);
86
+ return expressifyPropAccess(ctx, expr);
79
87
  }
80
88
  if (expr instanceof TirVariableAccessExpr) {
81
89
  const originalVarName = expr.resolvedValue.variableInfos.name;
82
90
  const resolvedVariable = ctx.getVariable(originalVarName);
83
91
  if (!resolvedVariable)
84
92
  return expr; // variable not found, keep the original expression
93
+ // if variable was shadowed
85
94
  if (isExpressifyFuncParam(resolvedVariable)) {
86
- // variable was shadowed
95
+ // !!! IMPORTANT !!!
96
+ // we must clone the expression to avoid modifying other instances of it elsewhere
97
+ // THIS IS CRUCIAL I SPENT A DAY DEBUGGING THIS
98
+ expr = expr.clone();
87
99
  expr.resolvedValue.variableInfos.name = resolvedVariable.name;
88
100
  return expr;
89
101
  }
90
102
  // resovledVariable instanceof TirVariableAccessExpr
91
- return resolvedVariable;
103
+ return resolvedVariable.clone();
92
104
  }
93
- if (isUnaryPrefixExpr(expr)) {
105
+ if (isTirUnaryPrefixExpr(expr)) {
94
106
  const modifiedExpr = expressifyVars(ctx, expr.operand);
95
107
  expr.operand = modifiedExpr;
96
108
  return expr;
@@ -102,10 +114,19 @@ export function expressifyVars(ctx, expr) {
102
114
  return expr;
103
115
  }
104
116
  if (expr instanceof TirFuncExpr) {
105
- expressify(expr, undefined, ctx);
117
+ expressify(expr, undefined, ctx.program, ctx);
106
118
  return expr;
107
119
  }
108
120
  if (expr instanceof TirCallExpr) {
121
+ while (expr.func instanceof TirParentesizedExpr)
122
+ expr.func = expr.func.expr;
123
+ if (expr.func instanceof TirPropAccessExpr) {
124
+ for (let i = 0; i < expr.args.length; i++) {
125
+ const arg = expressifyVars(ctx, expr.args[i]);
126
+ expr.args[i] = arg;
127
+ }
128
+ return expressifyMethodCall(ctx, expr);
129
+ }
109
130
  const func = expressifyVars(ctx, expr.func);
110
131
  expr.func = func;
111
132
  for (let i = 0; i < expr.args.length; i++) {
@@ -193,17 +214,18 @@ export function expressifyVars(ctx, expr) {
193
214
  }
194
215
  if (expr instanceof TirInlineClosedIR)
195
216
  return expr;
196
- const tsEnsureExsautstiveCheck = expr;
217
+ const tsEnsureExhautstiveCheck = expr;
197
218
  console.error(expr);
198
219
  throw new Error("unreachable::expressifyVars");
199
220
  }
200
- function getVarAccessFromPropAccess(ctx, propAccessExpr) {
221
+ function expressifyPropAccess(ctx, propAccessExpr) {
201
222
  let expr = propAccessExpr.object;
202
223
  const prop = propAccessExpr.prop.text;
203
224
  while (expr instanceof TirParentesizedExpr)
204
225
  expr = expr.expr;
205
226
  if (expr instanceof TirLitVoidExpr
206
227
  || expr instanceof TirLitUndefExpr
228
+ || expr instanceof TirLitFailExpr
207
229
  || expr instanceof TirLitTrueExpr
208
230
  || expr instanceof TirLitFalseExpr
209
231
  // methods on these should have already been converted to functions
@@ -230,7 +252,7 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
230
252
  let varName = ctx.properties.get("this")?.get(prop);
231
253
  if (!varName)
232
254
  throw new Error(`Property '${prop}' does not exist on 'this'`);
233
- varName = ctx.variables.get(varName)?.latestName ?? varName;
255
+ varName = ctx.getVariableSSA(varName)?.latestName ?? varName;
234
256
  const expr = ctx.getVariable(varName);
235
257
  if (isExpressifyFuncParam(expr)) {
236
258
  return new TirVariableAccessExpr({
@@ -244,6 +266,7 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
244
266
  }
245
267
  return expr;
246
268
  }
269
+ // expressify as normal variable
247
270
  if (expr instanceof TirLitObjExpr
248
271
  || expr instanceof TirLitNamedObjExpr) {
249
272
  const valIdx = expr.fieldNames.findIndex(f => f.text === prop);
@@ -269,7 +292,7 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
269
292
  || expr instanceof TirVariableAccessExpr) {
270
293
  let varName = ctx.properties.get(expr.varName)?.get(prop);
271
294
  if (varName) {
272
- varName = ctx.variables.get(varName)?.latestName ?? varName;
295
+ varName = ctx.getVariableSSA(varName)?.latestName ?? varName;
273
296
  const result = ctx.getVariable(varName);
274
297
  if (isExpressifyFuncParam(result)) {
275
298
  return new TirVariableAccessExpr({
@@ -288,8 +311,10 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
288
311
  }
289
312
  const objType = getUnaliased(expr.type);
290
313
  if (!isSingleConstrStruct(objType)) {
291
- console.log(objType);
292
- throw new Error("cannot access property on non-struct type");
314
+ // IMPORTANT: we only care about fields here
315
+ // any methods should have already been converted to functions
316
+ console.error(objType, expr.toString());
317
+ throw new Error(`cannot access property '${prop}' on non-struct type`);
293
318
  }
294
319
  const ctor = objType.constructors[0];
295
320
  const fIdx = ctor.fields.findIndex(f => f.name === prop);
@@ -315,6 +340,114 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
315
340
  fType, propAccessExpr.range);
316
341
  }
317
342
  ;
318
- const tsEnsureExsautstiveCheck = expr;
343
+ const tsEnsureExhautstiveCheck = expr;
319
344
  throw new Error("Invalid property access expression");
320
345
  }
346
+ function expressifyMethodCall(ctx, methodCall) {
347
+ const methodPropAccess = methodCall.func;
348
+ if (!(methodPropAccess instanceof TirPropAccessExpr))
349
+ throw new Error("Invalid method call expression");
350
+ const methodIdentifierProp = methodPropAccess.prop;
351
+ const methodName = methodIdentifierProp.text;
352
+ const objectExpr = expressifyVars(ctx, methodPropAccess.object);
353
+ let objectType = objectExpr.type;
354
+ while (objectType instanceof TirAliasType) {
355
+ const aliasMethds = objectType.methodsNamesPtr;
356
+ const tirMethodName = aliasMethds.get(methodName);
357
+ if (!tirMethodName) {
358
+ objectType = objectType.aliased;
359
+ continue;
360
+ }
361
+ const funcExpr = ctx.program.functions.get(tirMethodName);
362
+ if (!funcExpr)
363
+ throw new Error(`Definition of method '${methodName}' on type '${objectType.toString()}' is missing.`);
364
+ return new TirCallExpr(funcExpr, [objectExpr, ...methodCall.args], methodCall.type, SourceRange.join(methodIdentifierProp.range, methodCall.range.atEnd()));
365
+ }
366
+ if (objectType instanceof TirDataStructType
367
+ || objectType instanceof TirSoPStructType) {
368
+ const structMethods = objectType.methodNamesPtr;
369
+ const tirMethodName = structMethods.get(methodName);
370
+ if (!tirMethodName)
371
+ throw new Error(`Method '${methodName}' does not exist on type '${objectType.toString()}'`);
372
+ const funcExpr = ctx.program.functions.get(tirMethodName);
373
+ if (!funcExpr)
374
+ throw new Error(`Definition of method '${methodName}' on type '${objectType.toString()}' is missing.`);
375
+ return new TirCallExpr(funcExpr, [objectExpr, ...methodCall.args], methodCall.type, SourceRange.join(methodIdentifierProp.range, methodCall.range.atEnd()));
376
+ }
377
+ if (objectType instanceof TirListT) {
378
+ const result = expressifyListMethodCall(ctx, objectExpr, methodCall, methodName, objectType, SourceRange.join(methodIdentifierProp.range, methodCall.range.atEnd()));
379
+ if (result)
380
+ return result;
381
+ }
382
+ throw new Error(`not implemented::expressifyMethodCall for type '${objectType.toString()}' (method name: '${methodName}')`);
383
+ // const tsEnsureExhautstiveCheck: never = objectType;
384
+ throw new Error(`Cannot call method '${methodName}' on non-struct type '${objectType.toString()}'`);
385
+ }
386
+ function expressifyListMethodCall(ctx, objectExpr, methodCall, methodName, listType, exprRange) {
387
+ const elemsType = getListTypeArg(listType);
388
+ if (!elemsType)
389
+ throw new Error("Invalid list type");
390
+ if (methodName === "length") {
391
+ if (methodCall.args.length !== 0)
392
+ throw new Error(`Method 'length' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
393
+ return new TirCallExpr(TirNativeFunc._length(elemsType), [objectExpr], methodCall.type, exprRange);
394
+ }
395
+ if (methodName === "some") {
396
+ if (methodCall.args.length !== 1)
397
+ throw new Error(`Method 'includes' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
398
+ return new TirCallExpr(TirNativeFunc._some(elemsType), [methodCall.args[0], objectExpr], methodCall.type, exprRange);
399
+ }
400
+ if (methodName === "every") {
401
+ if (methodCall.args.length !== 1)
402
+ throw new Error(`Method 'every' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
403
+ return new TirCallExpr(TirNativeFunc._every(elemsType), [methodCall.args[0], objectExpr], methodCall.type, exprRange);
404
+ }
405
+ if (methodName === "includes") {
406
+ if (methodCall.args.length !== 1)
407
+ throw new Error(`Method 'includes' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
408
+ return new TirCallExpr(TirNativeFunc._some(elemsType), [
409
+ new TirCallExpr(TirNativeFunc._equals(elemsType), [methodCall.args[0]], new TirFuncT([elemsType], bool_t), methodCall.args[0].range),
410
+ objectExpr
411
+ ], methodCall.type, exprRange);
412
+ }
413
+ if (methodName === "head") {
414
+ if (methodCall.args.length !== 0)
415
+ throw new Error(`Method 'head' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
416
+ return new TirCallExpr(TirNativeFunc.headList(elemsType), [objectExpr], methodCall.type, exprRange);
417
+ }
418
+ if (methodName === "tail") {
419
+ if (methodCall.args.length !== 0)
420
+ throw new Error(`Method 'tail' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
421
+ return new TirCallExpr(TirNativeFunc.tailList(elemsType), [objectExpr], methodCall.type, exprRange);
422
+ }
423
+ if (methodName === "isEmpty") {
424
+ if (methodCall.args.length !== 0)
425
+ throw new Error(`Method 'isEmpty' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
426
+ return new TirCallExpr(TirNativeFunc.nullList(elemsType), [objectExpr], methodCall.type, exprRange);
427
+ }
428
+ if (methodName === "find") {
429
+ if (methodCall.args.length !== 1)
430
+ throw new Error(`Method 'find' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
431
+ // const finalType = getUnaliased( methodCall.type );
432
+ // console.log( finalType );
433
+ return new TirCallExpr(TirNativeFunc._findSopOptional(elemsType), [methodCall.args[0], objectExpr], methodCall.type, exprRange);
434
+ }
435
+ // TODO
436
+ /*
437
+ {
438
+ isEmpty: new TirFuncT( [], bool_t ),
439
+ show: new TirFuncT( [], bytes_t ),
440
+ reverse: new TirFuncT( [], new TirListT( elemsType ) ),
441
+ find: new TirFuncT([
442
+ new TirFuncT( [elemsType], bool_t )
443
+ ], new TirSopOptT( elemsType ) ),
444
+ filter: new TirFuncT([
445
+ new TirFuncT( [elemsType], bool_t )
446
+ ], new TirListT( elemsType ) ),
447
+ prepend: new TirFuncT( [elemsType], new TirListT( elemsType ) ),
448
+ map: new TirFuncT([
449
+ new TirFuncT([ elemsType ], mapReturnT )
450
+ ], new TirListT( mapReturnT ) ),
451
+ };
452
+ */
453
+ }
@@ -15,6 +15,7 @@ export function flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedD
15
15
  if (varDecl instanceof TirSimpleVarDecl) {
16
16
  restFields.set(fName, varDecl.name);
17
17
  ctx.introduceFuncParams([varDecl]);
18
+ ctx.setNewVariableName(fName, varDecl.name); // added to fix reassigned variables on non-terminating statements
18
19
  if (isSingleConstrStruct(varDecl.type)) {
19
20
  const structType = getUnaliased(varDecl.type);
20
21
  const constr = structType.constructors[0];
@@ -6,8 +6,8 @@ export declare const PEBBLE_INTERNAL_IDENTIFIER_SEPARATOR = "#";
6
6
  * Creates and tracks unique internal variable names for the Pebble compiler
7
7
  */
8
8
  export declare class UidGenerator {
9
+ private counter;
9
10
  constructor();
10
- private readonly uids;
11
11
  getUid(): string;
12
12
  /**
13
13
  * Generates a unique internal variable name
@@ -1,39 +1,46 @@
1
- import { isObject } from "@harmoniclabs/obj-utils";
2
- import { toHex } from "@harmoniclabs/uint8array-utils";
3
1
  /** invalid char for normal js identifiers */
4
2
  export const PEBBLE_INTERNAL_IDENTIFIER_PREFIX = "§";
5
3
  /** invalid char for normal js identifiers */
6
4
  export const PEBBLE_INTERNAL_IDENTIFIER_SEPARATOR = "#";
7
5
  // Keep getRandomBytes outside the class as requested
8
- let getRandomBytes = (bytes) => {
9
- for (let i = 0; i < bytes.length; i++)
10
- bytes[i] = ((Math.random() * 0x100) >>> 0);
11
- return bytes;
12
- };
13
- try {
14
- if (typeof globalThis !== "undefined"
15
- && typeof globalThis.crypto !== "undefined"
16
- && isObject(globalThis.crypto)
17
- && typeof globalThis.crypto.getRandomValues === "function")
18
- getRandomBytes = globalThis.crypto.getRandomValues.bind(globalThis.crypto);
19
- }
20
- catch { }
21
- const uidSet = new Set();
6
+ // let getRandomBytes = (bytes: Uint8Array) => {
7
+ // for (let i = 0; i < bytes.length; i++)
8
+ // bytes[i] = ((Math.random() * 0x100) >>> 0);
9
+ // return bytes;
10
+ // }
11
+ //
12
+ // try {
13
+ // if (
14
+ // typeof globalThis !== "undefined"
15
+ // && typeof globalThis.crypto !== "undefined"
16
+ // && isObject(globalThis.crypto)
17
+ // && typeof globalThis.crypto.getRandomValues === "function"
18
+ // ) getRandomBytes = globalThis.crypto.getRandomValues.bind(globalThis.crypto);
19
+ // } catch {}
20
+ //
21
+ // const uidSet = new Set<string>();
22
22
  /**
23
23
  * Creates and tracks unique internal variable names for the Pebble compiler
24
24
  */
25
25
  export class UidGenerator {
26
+ counter;
26
27
  constructor() {
27
- this.uids = uidSet;
28
+ // this.uids = uidSet;
29
+ this.counter = 0n;
28
30
  }
29
- uids;
31
+ // private readonly uids: Set<string>;
32
+ // getUid(): string {
33
+ // const bytes = new Uint8Array(Math.max(1, Math.log1p(this.uids.size) >>> 0));
34
+ // let uid: string;
35
+ // do {
36
+ // uid = toHex(getRandomBytes(bytes));
37
+ // } while( this.uids.has( uid ) );
38
+ // this.uids.add(uid);
39
+ // return uid;
40
+ // }
30
41
  getUid() {
31
- const bytes = new Uint8Array(Math.max(1, Math.log1p(this.uids.size) >>> 0));
32
- let uid;
33
- do {
34
- uid = toHex(getRandomBytes(bytes));
35
- } while (this.uids.has(uid));
36
- this.uids.add(uid);
42
+ const uid = this.counter.toString(36);
43
+ this.counter++;
37
44
  return uid;
38
45
  }
39
46
  /**
@@ -4,7 +4,7 @@ import { IOutputStream } from "./IOutputStream.js";
4
4
  /** Compiler API options. */
5
5
  export interface CompilerIoApi {
6
6
  /** Standard output stream to use. */
7
- readonly stdout: IOutputStream;
7
+ stdout: IOutputStream;
8
8
  /** Standard error stream to use. */
9
9
  readonly stderr: IOutputStream;
10
10
  /** Reads a file from disk (or memory). */
@@ -4,6 +4,7 @@ export interface IOutputStream {
4
4
  write(chunk: Uint8Array | string): void;
5
5
  }
6
6
  export declare class ConsoleLogStream implements IOutputStream {
7
+ private _pending;
7
8
  write(chunk: Uint8Array | string): void;
8
9
  }
9
10
  export declare class ConsoleErrorStream implements IOutputStream {
@@ -1,11 +1,26 @@
1
1
  import { fromUtf8, concatUint8Array, toUtf8 } from "@harmoniclabs/uint8array-utils";
2
2
  export class ConsoleLogStream {
3
+ _pending = "";
3
4
  write(chunk) {
4
- if (chunk instanceof Uint8Array) {
5
- console.log(toUtf8(chunk));
5
+ const newChunk = (chunk instanceof Uint8Array) ? toUtf8(chunk) : chunk.toString();
6
+ if (newChunk.includes("\n")) {
7
+ const parts = newChunk.split("\n");
8
+ if (parts.length === 1) {
9
+ // only one \n
10
+ console.log(this._pending + parts[0]);
11
+ this._pending = "";
12
+ }
13
+ else {
14
+ // multiple \n
15
+ console.log(this._pending + parts[0]);
16
+ for (let i = 1; i < parts.length - 1; i++) {
17
+ console.log(parts[i]);
18
+ }
19
+ this._pending = parts[parts.length - 1];
20
+ }
6
21
  }
7
22
  else {
8
- console.log(chunk.toString());
23
+ this._pending += newChunk;
9
24
  }
10
25
  }
11
26
  }
@@ -58,17 +58,15 @@ export function getEnvRelativePath(filePath, projectRoot) {
58
58
  if (!(typeof filePath === 'string' &&
59
59
  typeof projectRoot === 'string'))
60
60
  return undefined;
61
+ projectRoot = projectRoot.trim();
62
+ if (!projectRoot.endsWith(PATH_DELIMITER))
63
+ projectRoot += PATH_DELIMITER;
61
64
  if (isAbsolutePath(filePath))
62
65
  return filePath;
63
- projectRoot = projectRoot.trim();
64
66
  filePath = getAbsolutePath(filePath.trim(), projectRoot);
65
67
  if (!filePath)
66
68
  return undefined;
67
- if (!projectRoot.endsWith(PATH_DELIMITER))
68
- projectRoot = projectRoot + PATH_DELIMITER;
69
- while (filePath.startsWith(PATH_DELIMITER))
70
- filePath = filePath.slice(PATH_DELIMITER.length);
71
- return projectRoot + filePath;
69
+ return filePath.startsWith(projectRoot) ? filePath : projectRoot + filePath;
72
70
  }
73
71
  /**
74
72
  * Takes a relative path and an absolute path, and returns the absolute path
@@ -8,4 +8,6 @@ export interface ITirExpr extends HasSourceRange {
8
8
  deps: () => string[];
9
9
  toIR: (ctx: ToIRTermCtx) => IRTerm;
10
10
  clone: () => ITirExpr;
11
+ toString: () => string;
12
+ pretty: (indent: number) => string;
11
13
  }