@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
@@ -1,13 +1,13 @@
1
1
  import { forceBigUInt } from "../../utils/ints.js";
2
- import { concatUint8Arr } from "../utils/concatUint8Arr.js";
3
2
  import { isIRParentTerm } from "../utils/isIRParentTerm.js";
4
- import { positiveIntAsBytes } from "../utils/positiveIntAsBytes.js";
5
3
  import { mapArrayLike } from "./utils/mapArrayLike.js";
6
4
  import { makeArrayLikeProxy } from "./utils/makeArrayLikeProxy.js";
7
- import { hashIrData, isIRHash } from "../IRHash.js";
8
- import { shallowEqualIRTermHash } from "../utils/equalIRTerm.js";
9
5
  import { IRNodeKind } from "../IRNodeKind.js";
10
6
  import { isIRTerm } from "../utils/isIRTerm.js";
7
+ import { hashIrData, irHashToBytes, isIRHash } from "../IRHash.js";
8
+ import { concatUint8Arr } from "../utils/concatUint8Arr.js";
9
+ import { positiveIntAsBytes } from "../utils/positiveIntAsBytes.js";
10
+ import { Constr } from "@harmoniclabs/uplc";
11
11
  export class IRConstr {
12
12
  index;
13
13
  fields;
@@ -19,49 +19,46 @@ export class IRConstr {
19
19
  const self = this;
20
20
  this.meta = meta;
21
21
  this._parent = undefined;
22
- Object.defineProperty(this, "index", {
23
- value: forceBigUInt(index),
24
- writable: false,
25
- enumerable: true,
26
- configurable: false
27
- });
28
- Object.defineProperty(this, "fields", {
29
- value: makeArrayLikeProxy(fields, isIRTerm,
30
- // initModifyElem
31
- newElem => {
32
- // newElem = newElem.clone();
33
- newElem.parent = self;
34
- // self.markHashAsInvalid()
35
- return newElem;
36
- },
37
- // modifyElem
38
- // called before setting the new value
39
- // the return value is the value that will be set
40
- (newElem, oldElem) => {
41
- if (!shallowEqualIRTermHash(oldElem, newElem))
42
- self.markHashAsInvalid();
43
- newElem.parent = self;
44
- return newElem;
45
- }),
46
- writable: false,
47
- enumerable: true,
48
- configurable: false
22
+ this.index = forceBigUInt(index);
23
+ this.fields = makeArrayLikeProxy(fields, isIRTerm,
24
+ // initModifyElem
25
+ newElem => {
26
+ // newElem = newElem.clone();
27
+ newElem.parent = self;
28
+ // self.markHashAsInvalid()
29
+ return newElem;
30
+ },
31
+ // modifyElem
32
+ // called before setting the new value
33
+ // the return value is the value that will be set
34
+ (newElem, oldElem) => {
35
+ newElem.parent = self;
36
+ return newElem;
49
37
  });
50
38
  this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
51
39
  }
40
+ toUPLC(ctx) {
41
+ if (this.fields.length <= 0) {
42
+ return new Constr(this.index, []);
43
+ }
44
+ const fields = mapArrayLike(this.fields, f => f.toUPLC(ctx));
45
+ return new Constr(this.index, fields);
46
+ }
52
47
  _hash;
53
48
  get hash() {
54
- if (!isIRHash(this._hash)) {
55
- // basically a merkle tree
56
- this._hash = hashIrData(concatUint8Arr(IRConstr.tag, positiveIntAsBytes(this.index), ...mapArrayLike(this.fields, f => f.hash)));
57
- }
49
+ if (isIRHash(this._hash))
50
+ return this._hash;
51
+ this._hash = hashIrData(concatUint8Arr(IRConstr.tag, positiveIntAsBytes(this.index), ...mapArrayLike(this.fields, f => irHashToBytes(f.hash))));
58
52
  return this._hash;
59
53
  }
54
+ isHashPresent() { return isIRHash(this._hash); }
60
55
  markHashAsInvalid() {
61
56
  this._hash = undefined;
62
57
  this.parent?.markHashAsInvalid();
63
58
  }
64
- isHashPresent() { return isIRHash(this._hash); }
59
+ children() {
60
+ return Array.from(this.fields);
61
+ }
65
62
  _parent;
66
63
  get parent() { return this._parent; }
67
64
  set parent(newParent) {
@@ -75,7 +72,7 @@ export class IRConstr {
75
72
  this._parent = newParent;
76
73
  }
77
74
  clone() {
78
- return new IRConstr(this.index, mapArrayLike(this.fields, f => f.clone()), { ...this.meta }, this.isHashPresent() ? this.hash : undefined);
75
+ return new IRConstr(this.index, mapArrayLike(this.fields, f => f.clone()), { ...this.meta }, this._hash);
79
76
  }
80
77
  toJSON() { return this.toJson(); }
81
78
  toJson() {
@@ -1,30 +1,33 @@
1
1
  import { Cloneable } from "@harmoniclabs/cbor/dist/utils/Cloneable";
2
2
  import { ToJson } from "../../utils/ToJson.js";
3
- import { IRTerm } from "../IRTerm.js";
4
- import { IHash } from "../interfaces/IHash.js";
3
+ import { IIRTerm, IRTerm } from "../IRTerm.js";
5
4
  import { IIRParent } from "../interfaces/IIRParent.js";
6
5
  import { IRParentTerm } from "../utils/isIRParentTerm.js";
7
6
  import { BaseIRMetadata } from "./BaseIRMetadata.js";
8
- import { IRHash } from "../IRHash.js";
9
7
  import { IRNodeKind } from "../IRNodeKind.js";
8
+ import { IRHash } from "../IRHash.js";
9
+ import { UPLCTerm } from "@harmoniclabs/uplc";
10
+ import { ToUplcCtx } from "../toUPLC/ctx/ToUplcCtx.js";
10
11
  export interface IRDelayedMetadata extends BaseIRMetadata {
11
12
  }
12
- export declare class IRDelayed implements Cloneable<IRDelayed>, IHash, IIRParent, ToJson {
13
+ export declare class IRDelayed implements IIRTerm, Cloneable<IRDelayed>, IIRParent, ToJson {
13
14
  readonly meta: IRDelayedMetadata;
14
- constructor(delayed: IRTerm, _unsafeHash?: IRHash);
15
+ constructor(delayed: IRTerm, _unsafeHash?: IRHash | undefined);
16
+ toUPLC(ctx: ToUplcCtx): UPLCTerm;
17
+ private _hash;
18
+ get hash(): IRHash;
19
+ isHashPresent(): boolean;
20
+ markHashAsInvalid(): void;
21
+ children(): IRTerm[];
15
22
  static get kind(): IRNodeKind.Delayed;
16
23
  get kind(): IRNodeKind.Delayed;
17
24
  static get tag(): Uint8Array;
18
25
  private _delayed;
19
26
  get delayed(): IRTerm;
20
27
  set delayed(newDelayed: IRTerm | undefined);
21
- private _hash;
22
- get hash(): IRHash;
23
28
  private _parent;
24
29
  get parent(): IRParentTerm | undefined;
25
30
  set parent(newParent: IRParentTerm | undefined);
26
- isHashPresent(): boolean;
27
- markHashAsInvalid(): void;
28
31
  clone(): IRDelayed;
29
32
  toJSON(): any;
30
33
  toJson(): any;
@@ -2,9 +2,9 @@ import { BasePlutsError } from "../../utils/BasePlutsError.js";
2
2
  import { concatUint8Arr } from "../utils/concatUint8Arr.js";
3
3
  import { isIRTerm } from "../utils/isIRTerm.js";
4
4
  import { isIRParentTerm } from "../utils/isIRParentTerm.js";
5
- import { hashIrData, isIRHash } from "../IRHash.js";
6
- import { shallowEqualIRTermHash } from "../utils/equalIRTerm.js";
7
5
  import { IRNodeKind } from "../IRNodeKind.js";
6
+ import { isIRHash, hashIrData, irHashToBytes } from "../IRHash.js";
7
+ import { Delay } from "@harmoniclabs/uplc";
8
8
  export class IRDelayed {
9
9
  meta = {};
10
10
  constructor(delayed, _unsafeHash) {
@@ -12,8 +12,26 @@ export class IRDelayed {
12
12
  throw new Error("IRDelayed argument was not an IRTerm");
13
13
  this._delayed = delayed;
14
14
  this._delayed.parent = this;
15
- this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
16
15
  this._parent = undefined;
16
+ this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
17
+ }
18
+ toUPLC(ctx) {
19
+ return new Delay(this.delayed.toUPLC(ctx));
20
+ }
21
+ _hash;
22
+ get hash() {
23
+ if (isIRHash(this._hash))
24
+ return this._hash;
25
+ this._hash = hashIrData(concatUint8Arr(IRDelayed.tag, irHashToBytes(this.delayed.hash)));
26
+ return this._hash;
27
+ }
28
+ isHashPresent() { return isIRHash(this._hash); }
29
+ markHashAsInvalid() {
30
+ this._hash = undefined;
31
+ this.parent?.markHashAsInvalid();
32
+ }
33
+ children() {
34
+ return [this.delayed];
17
35
  }
18
36
  static get kind() { return IRNodeKind.Delayed; }
19
37
  get kind() { return IRDelayed.kind; }
@@ -24,20 +42,11 @@ export class IRDelayed {
24
42
  if (!isIRTerm(newDelayed)) {
25
43
  throw new BasePlutsError("invalid IRTerm to be delayed");
26
44
  }
27
- if (!shallowEqualIRTermHash(this._delayed, newDelayed))
28
- this.markHashAsInvalid();
29
45
  // keep the parent reference in the old child, useful for compilation
30
46
  // _delayed.parent = undefined;
31
47
  this._delayed = newDelayed;
32
48
  this._delayed.parent = this;
33
49
  }
34
- _hash;
35
- get hash() {
36
- if (!isIRHash(this._hash)) {
37
- this._hash = hashIrData(concatUint8Arr(IRDelayed.tag, this.delayed.hash));
38
- }
39
- return this._hash;
40
- }
41
50
  _parent;
42
51
  get parent() { return this._parent; }
43
52
  set parent(newParent) {
@@ -50,13 +59,8 @@ export class IRDelayed {
50
59
  return;
51
60
  this._parent = newParent;
52
61
  }
53
- isHashPresent() { return isIRHash(this._hash); }
54
- markHashAsInvalid() {
55
- this._hash = undefined;
56
- this._parent?.markHashAsInvalid();
57
- }
58
62
  clone() {
59
- return new IRDelayed(this.delayed.clone(), this.isHashPresent() ? this.hash : undefined);
63
+ return new IRDelayed(this.delayed.clone(), this._hash);
60
64
  }
61
65
  toJSON() { return this.toJson(); }
62
66
  toJson() {
@@ -1,24 +1,27 @@
1
1
  import { Cloneable } from "@harmoniclabs/cbor/dist/utils/Cloneable";
2
2
  import { ToJson } from "../../utils/ToJson.js";
3
- import { IHash } from "../interfaces/IHash.js";
4
3
  import { IIRParent } from "../interfaces/IIRParent.js";
5
4
  import { IRParentTerm } from "../utils/isIRParentTerm.js";
6
5
  import { BaseIRMetadata } from "./BaseIRMetadata.js";
7
- import { IRHash } from "../IRHash.js";
8
6
  import { IRNodeKind } from "../IRNodeKind.js";
7
+ import { IIRTerm, IRTerm } from "../IRTerm.js";
8
+ import { IRHash } from "../IRHash.js";
9
+ import { UPLCTerm } from "@harmoniclabs/uplc";
9
10
  export interface IRErrorMetadata extends BaseIRMetadata {
10
11
  }
11
- export declare class IRError implements Cloneable<IRError>, IHash, IIRParent, ToJson {
12
+ export declare class IRError implements IIRTerm, Cloneable<IRError>, IIRParent, ToJson {
12
13
  readonly meta: IRErrorMetadata;
13
14
  msg?: string;
14
15
  addInfos?: any;
15
16
  constructor(msg?: string, addInfos?: any);
16
- static get kind(): IRNodeKind.Error;
17
- get kind(): IRNodeKind.Error;
18
- static get tag(): Uint8Array;
17
+ toUPLC(): UPLCTerm;
19
18
  get hash(): IRHash;
20
19
  isHashPresent(): boolean;
21
20
  markHashAsInvalid(): void;
21
+ children(): IRTerm[];
22
+ static get kind(): IRNodeKind.Error;
23
+ get kind(): IRNodeKind.Error;
24
+ static get tag(): Uint8Array;
22
25
  private _parent;
23
26
  get parent(): IRParentTerm | undefined;
24
27
  set parent(newParent: IRParentTerm | undefined);
@@ -1,8 +1,9 @@
1
1
  import { isIRParentTerm } from "../utils/isIRParentTerm.js";
2
- import { hashIrData } from "../IRHash.js";
3
2
  import { IRNodeKind } from "../IRNodeKind.js";
3
+ import { hashIrData } from "../IRHash.js";
4
+ import { ErrorUPLC } from "@harmoniclabs/uplc";
4
5
  const irErrorBitTag = new Uint8Array([IRNodeKind.Error]);
5
- const errorHash = hashIrData(irErrorBitTag.slice());
6
+ const irErrorHash = hashIrData(irErrorBitTag);
6
7
  export class IRError {
7
8
  meta;
8
9
  msg;
@@ -13,12 +14,18 @@ export class IRError {
13
14
  this.meta = {};
14
15
  this._parent = undefined;
15
16
  }
17
+ toUPLC() {
18
+ return new ErrorUPLC(this.msg, this.addInfos);
19
+ }
20
+ get hash() { return irErrorHash; }
21
+ isHashPresent() { return true; }
22
+ markHashAsInvalid() { throw new Error("IRError: hash is always present and valid"); }
23
+ children() {
24
+ return [];
25
+ }
16
26
  static get kind() { return IRNodeKind.Error; }
17
27
  get kind() { return IRError.kind; }
18
28
  static get tag() { return irErrorBitTag.slice(); }
19
- get hash() { return errorHash; }
20
- isHashPresent() { return true; }
21
- markHashAsInvalid() { throw new Error("IRError.markHashAsInvalid was called but error doesn't have childs"); }
22
29
  _parent;
23
30
  get parent() { return this._parent; }
24
31
  set parent(newParent) {
@@ -1,24 +1,27 @@
1
1
  import { Cloneable } from "@harmoniclabs/cbor/dist/utils/Cloneable";
2
2
  import { ToJson } from "../../utils/ToJson.js";
3
- import { IRTerm } from "../IRTerm.js";
4
- import { IHash } from "../interfaces/IHash.js";
3
+ import { IIRTerm, IRTerm } from "../IRTerm.js";
5
4
  import { IIRParent } from "../interfaces/IIRParent.js";
6
5
  import { IRParentTerm } from "../utils/isIRParentTerm.js";
7
6
  import { BaseIRMetadata } from "./BaseIRMetadata.js";
8
7
  import { IRHash } from "../IRHash.js";
9
8
  import { IRNodeKind } from "../IRNodeKind.js";
9
+ import { UPLCTerm } from "@harmoniclabs/uplc";
10
+ import { ToUplcCtx } from "../toUPLC/ctx/ToUplcCtx.js";
10
11
  export interface IRForcedMetadata extends BaseIRMetadata {
11
12
  }
12
- export declare class IRForced implements Cloneable<IRForced>, IHash, IIRParent, ToJson {
13
+ export declare class IRForced implements IIRTerm, Cloneable<IRForced>, IIRParent, ToJson {
13
14
  readonly meta: IRForcedMetadata;
14
15
  constructor(forced: IRTerm, _unsafeHash?: IRHash);
15
- private _forced;
16
- get forced(): IRTerm;
17
- set forced(newForced: IRTerm | undefined);
16
+ toUPLC(ctx: ToUplcCtx): UPLCTerm;
18
17
  private _hash;
19
18
  get hash(): IRHash;
20
19
  isHashPresent(): boolean;
21
20
  markHashAsInvalid(): void;
21
+ children(): IRTerm[];
22
+ private _forced;
23
+ get forced(): IRTerm;
24
+ set forced(newForced: IRTerm | undefined);
22
25
  private _parent;
23
26
  get parent(): IRParentTerm | undefined;
24
27
  set parent(newParent: IRParentTerm | undefined);
@@ -2,19 +2,37 @@ import { BasePlutsError } from "../../utils/BasePlutsError.js";
2
2
  import { concatUint8Arr } from "../utils/concatUint8Arr.js";
3
3
  import { isIRTerm } from "../utils/isIRTerm.js";
4
4
  import { isIRParentTerm } from "../utils/isIRParentTerm.js";
5
- import { hashIrData, isIRHash } from "../IRHash.js";
6
- import { shallowEqualIRTermHash } from "../utils/equalIRTerm.js";
5
+ import { hashIrData, irHashToBytes, isIRHash } from "../IRHash.js";
7
6
  import { IRNodeKind } from "../IRNodeKind.js";
7
+ import { Force } from "@harmoniclabs/uplc";
8
8
  export class IRForced {
9
9
  meta;
10
10
  constructor(forced, _unsafeHash) {
11
11
  this.meta = {};
12
- this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
13
12
  if (!isIRTerm(forced))
14
13
  throw new Error("IRForced argument was not an IRTerm");
15
14
  this._forced = forced;
16
15
  this._forced.parent = this;
17
16
  this._parent = undefined;
17
+ this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
18
+ }
19
+ toUPLC(ctx) {
20
+ return new Force(this.forced.toUPLC(ctx));
21
+ }
22
+ _hash;
23
+ get hash() {
24
+ if (isIRHash(this._hash))
25
+ return this._hash;
26
+ this._hash = hashIrData(concatUint8Arr(IRForced.tag, irHashToBytes(this.forced.hash)));
27
+ return this._hash;
28
+ }
29
+ isHashPresent() { return isIRHash(this._hash); }
30
+ markHashAsInvalid() {
31
+ this._hash = undefined;
32
+ this.parent?.markHashAsInvalid();
33
+ }
34
+ children() {
35
+ return [this._forced];
18
36
  }
19
37
  _forced;
20
38
  get forced() { return this._forced; }
@@ -22,25 +40,11 @@ export class IRForced {
22
40
  if (!isIRTerm(newForced)) {
23
41
  throw new BasePlutsError("invalid IRTerm to be forced");
24
42
  }
25
- if (!shallowEqualIRTermHash(this._forced, newForced))
26
- this.markHashAsInvalid();
27
43
  // keep the parent reference in the old child, useful for compilation
28
44
  // _forced.parent = undefined;
29
45
  this._forced = newForced;
30
46
  this._forced.parent = this;
31
47
  }
32
- _hash;
33
- get hash() {
34
- if (!isIRHash(this._hash)) {
35
- this._hash = hashIrData(concatUint8Arr(IRForced.tag, this._forced.hash));
36
- }
37
- return this._hash;
38
- }
39
- isHashPresent() { return isIRHash(this._hash); }
40
- markHashAsInvalid() {
41
- this._hash = undefined;
42
- this.parent?.markHashAsInvalid();
43
- }
44
48
  _parent;
45
49
  get parent() { return this._parent; }
46
50
  set parent(newParent) {
@@ -57,7 +61,7 @@ export class IRForced {
57
61
  get kind() { return IRForced.kind; }
58
62
  static get tag() { return new Uint8Array([IRForced.kind]); }
59
63
  clone() {
60
- return new IRForced(this.forced.clone(), this.isHashPresent() ? this.hash : undefined);
64
+ return new IRForced(this.forced.clone(), this._hash);
61
65
  }
62
66
  toJSON() { return this.toJson(); }
63
67
  toJson() {
@@ -1,27 +1,31 @@
1
1
  import { Cloneable } from "@harmoniclabs/cbor/dist/utils/Cloneable";
2
2
  import { ToJson } from "../../utils/ToJson.js";
3
- import { IRTerm } from "../IRTerm.js";
4
- import { IHash } from "../interfaces/IHash.js";
3
+ import { IIRTerm, IRTerm } from "../IRTerm.js";
5
4
  import { IIRParent } from "../interfaces/IIRParent.js";
6
5
  import { IRParentTerm } from "../utils/isIRParentTerm.js";
7
6
  import { BaseIRMetadata } from "./BaseIRMetadata.js";
8
- import { IRHash } from "../IRHash.js";
9
7
  import { IRNodeKind } from "../IRNodeKind.js";
8
+ import { IRHash } from "../IRHash.js";
9
+ import { UPLCTerm } from "@harmoniclabs/uplc";
10
+ import { ToUplcCtx } from "../toUPLC/ctx/ToUplcCtx.js";
10
11
  export interface IRFuncMetadata extends BaseIRMetadata {
11
12
  }
12
- export declare class IRFunc implements Cloneable<IRFunc>, IHash, IIRParent, ToJson {
13
- readonly arity: number;
14
- constructor(arity: number, body: IRTerm, func_name?: string | undefined, _unsafeHash?: IRHash);
13
+ export declare class IRFunc implements IIRTerm, Cloneable<IRFunc>, IIRParent, ToJson {
14
+ readonly params: symbol[];
15
+ get arity(): number;
16
+ constructor(params: symbol[], body: IRTerm, _unsafeHash?: IRHash | undefined);
17
+ toUPLC(ctx: ToUplcCtx): UPLCTerm;
18
+ private _hash;
19
+ get hash(): IRHash;
20
+ isHashPresent(): boolean;
21
+ markHashAsInvalid(): void;
22
+ children(): IRTerm[];
15
23
  static get kind(): IRNodeKind.Func;
16
24
  get kind(): IRNodeKind.Func;
17
25
  static get tag(): Uint8Array;
18
26
  private _body;
19
27
  get body(): IRTerm;
20
28
  set body(newBody: IRTerm);
21
- private _hash;
22
- get hash(): IRHash;
23
- isHashPresent(): boolean;
24
- markHashAsInvalid(): void;
25
29
  readonly meta: IRFuncMetadata;
26
30
  get name(): string | undefined;
27
31
  private _parent;
@@ -3,36 +3,46 @@ import { concatUint8Arr } from "../utils/concatUint8Arr.js";
3
3
  import { isIRTerm } from "../utils/isIRTerm.js";
4
4
  import { positiveIntAsBytes } from "../utils/positiveIntAsBytes.js";
5
5
  import { isIRParentTerm } from "../utils/isIRParentTerm.js";
6
- import { hashIrData, isIRHash } from "../IRHash.js";
7
- import { shallowEqualIRTermHash } from "../utils/equalIRTerm.js";
8
6
  import { IRNodeKind } from "../IRNodeKind.js";
7
+ import { hashIrData, irHashToBytes, isIRHash } from "../IRHash.js";
8
+ import { Lambda } from "@harmoniclabs/uplc";
9
9
  export class IRFunc {
10
- arity;
11
- constructor(arity, body, func_name, _unsafeHash) {
12
- if (!Number.isSafeInteger(arity) && arity >= 1)
13
- throw new BasePlutsError("invalid arity for 'IRFunc'");
10
+ params = [];
11
+ get arity() { return this.params.length; }
12
+ constructor(params, body, _unsafeHash) {
14
13
  if (!isIRTerm(body))
15
14
  throw new Error("IRFunc body argument was not an IRTerm");
16
- Object.defineProperties(this, {
17
- arity: {
18
- value: arity,
19
- writable: false,
20
- enumerable: true,
21
- configurable: false
22
- },
23
- meta: {
24
- value: {
25
- name: typeof func_name === "string" ? func_name : (void 0)
26
- },
27
- writable: true,
28
- enumerable: true,
29
- configurable: false
30
- }
31
- });
15
+ this.params = params.slice();
16
+ this.meta = {};
32
17
  this._body = body;
33
18
  this._body.parent = this;
34
- this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
35
19
  this._parent = undefined;
20
+ this._hash = isIRHash(_unsafeHash) ? _unsafeHash : undefined;
21
+ }
22
+ toUPLC(ctx) {
23
+ ctx = ctx.newChild(this.params);
24
+ const arity = this.params.length;
25
+ const irBody = this._body;
26
+ // IRRecursive not valid for uplc translation
27
+ let result = irBody.toUPLC(ctx);
28
+ for (let i = 0; i < arity; i++)
29
+ result = new Lambda(result);
30
+ return result;
31
+ }
32
+ _hash;
33
+ get hash() {
34
+ if (isIRHash(this._hash))
35
+ return this._hash;
36
+ this._hash = hashIrData(concatUint8Arr(IRFunc.tag, positiveIntAsBytes(this.arity), irHashToBytes(this._body.hash)));
37
+ return this._hash;
38
+ }
39
+ isHashPresent() { return isIRHash(this._hash); }
40
+ markHashAsInvalid() {
41
+ this._hash = undefined;
42
+ this.parent?.markHashAsInvalid();
43
+ }
44
+ children() {
45
+ return [this._body];
36
46
  }
37
47
  static get kind() { return IRNodeKind.Func; }
38
48
  get kind() { return IRFunc.kind; }
@@ -43,25 +53,11 @@ export class IRFunc {
43
53
  if (!isIRTerm(newBody)) {
44
54
  throw new BasePlutsError("invalid IRTerm to be a function body");
45
55
  }
46
- if (!shallowEqualIRTermHash(this._body, newBody))
47
- this.markHashAsInvalid();
48
56
  // keep the parent reference in the old child, useful for compilation
49
57
  // _body.parent = undefined;
50
58
  this._body = newBody;
51
59
  this._body.parent = this;
52
60
  }
53
- _hash;
54
- get hash() {
55
- if (!isIRHash(this._hash)) {
56
- this._hash = hashIrData(concatUint8Arr(IRFunc.tag, positiveIntAsBytes(this.arity), this._body.hash));
57
- }
58
- return this._hash;
59
- }
60
- isHashPresent() { return isIRHash(this._hash); }
61
- markHashAsInvalid() {
62
- this._hash = undefined;
63
- this.parent?.markHashAsInvalid();
64
- }
65
61
  meta;
66
62
  get name() { return this.meta.name; }
67
63
  ;
@@ -78,7 +74,8 @@ export class IRFunc {
78
74
  this._parent = newParent;
79
75
  }
80
76
  clone() {
81
- return new IRFunc(this.arity, this._body.clone(), this.meta.name, this.isHashPresent() ? this.hash : undefined);
77
+ return new IRFunc(this.params, // .slice() in constructor
78
+ this._body.clone());
82
79
  }
83
80
  toJSON() { return this.toJson(); }
84
81
  toJson() {
@@ -1,11 +1,12 @@
1
1
  import { IRMetadata } from "../interfaces/IRMetadata.js";
2
2
  import { Cloneable } from "@harmoniclabs/cbor/dist/utils/Cloneable";
3
3
  import { ToJson } from "../../utils/ToJson.js";
4
- import { IRTerm } from "../IRTerm.js";
5
- import { IHash, IIRParent } from "../interfaces/index.js";
4
+ import { IIRTerm, IRTerm } from "../IRTerm.js";
5
+ import { IIRParent } from "../interfaces/index.js";
6
6
  import { IRParentTerm } from "../utils/isIRParentTerm.js";
7
- import { IRHash } from "../IRHash.js";
8
7
  import { IRNodeKind } from "../IRNodeKind.js";
8
+ import { IRHash } from "../IRHash.js";
9
+ import { UPLCTerm } from "@harmoniclabs/uplc";
9
10
  export type HoistedSetEntry = {
10
11
  hoisted: IRHoisted;
11
12
  nReferences: number;
@@ -18,21 +19,26 @@ export interface IRHoistedMeta {
18
19
  **/
19
20
  forceHoist?: boolean;
20
21
  name?: string | undefined;
22
+ handled?: boolean;
21
23
  }
22
24
  export interface IRHoistedMetadata extends IRMetadata {
23
25
  meta: IRHoistedMeta;
24
26
  }
25
- export declare class IRHoisted implements Cloneable<IRHoisted>, IHash, IIRParent, ToJson, IRHoistedMetadata {
27
+ export declare class IRHoisted implements IIRTerm, Cloneable<IRHoisted>, IIRParent, ToJson, IRHoistedMetadata {
26
28
  readonly meta: IRHoistedMeta;
27
- constructor(hoisted: IRTerm, metadata?: Partial<IRHoistedMeta>, _unsafeHash?: IRHash);
28
- static get kind(): IRNodeKind.Hoisted;
29
- get kind(): IRNodeKind.Hoisted;
30
- static get tag(): Uint8Array;
29
+ get name(): symbol;
30
+ constructor(hoisted: IRTerm, metadata?: Partial<IRHoistedMeta>, _unsafeHash?: IRHash | undefined);
31
+ toUPLC(): UPLCTerm;
31
32
  private _hash;
32
33
  get hash(): IRHash;
33
- markHashAsInvalid(): void;
34
34
  isHashPresent(): boolean;
35
+ markHashAsInvalid(): void;
36
+ children(): IRTerm[];
37
+ static get kind(): IRNodeKind.Hoisted;
38
+ get kind(): IRNodeKind.Hoisted;
39
+ static get tag(): Uint8Array;
35
40
  private _hoisted;
41
+ get value(): IRTerm;
36
42
  get hoisted(): IRTerm;
37
43
  set hoisted(newHoisted: IRTerm);
38
44
  private _deps;
@@ -53,3 +59,4 @@ export declare class IRHoisted implements Cloneable<IRHoisted>, IHash, IIRParent
53
59
  export declare function getSortedHoistedSet(hoistedTerms: HoistedSetEntry[]): HoistedSetEntry[];
54
60
  export declare function getHoistedTerms(irTerm: IRTerm): HoistedSetEntry[];
55
61
  export declare function cloneHoistedSetEntry({ hoisted, nReferences }: HoistedSetEntry): HoistedSetEntry;
62
+ export declare function tryInferName(value: IRTerm): string | undefined;