@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
@@ -0,0 +1,2 @@
1
+ import { IRTerm } from "../../IRTerm.js";
2
+ export declare function rewriteNativesAppliedToConstantsAndReturnRoot(term: IRTerm): IRTerm;
@@ -0,0 +1,85 @@
1
+ import { _ir_apps } from "../../IRNodes/IRApp.js";
2
+ import { IRConst } from "../../IRNodes/IRConst.js";
3
+ import { IRFunc } from "../../IRNodes/IRFunc.js";
4
+ import { IRHoisted } from "../../IRNodes/IRHoisted.js";
5
+ import { IRLetted } from "../../IRNodes/IRLetted.js";
6
+ import { IRNative } from "../../IRNodes/IRNative/index.js";
7
+ import { IRNativeTag } from "../../IRNodes/IRNative/IRNativeTag.js";
8
+ import { IRVar } from "../../IRNodes/IRVar.js";
9
+ import { _modifyChildFromTo } from "../_internal/_modifyChildFromTo.js";
10
+ import { getApplicationTerms } from "../utils/getApplicationTerms.js";
11
+ import { _compTimeDropN } from "./_comptimeDropN.js";
12
+ export function rewriteNativesAppliedToConstantsAndReturnRoot(term) {
13
+ // traverse the tree, find applications of natives to constants
14
+ // and replace them with the optimized equivalent
15
+ const stack = [term];
16
+ while (stack.length > 0) {
17
+ const current = stack.pop();
18
+ const parent = current.parent;
19
+ const appTerms = getApplicationTerms(current);
20
+ if (!appTerms) {
21
+ stack.unshift(...current.children());
22
+ continue;
23
+ }
24
+ const { func, args } = appTerms;
25
+ const [fstArg, ...restArgs] = args;
26
+ if (isId(func)
27
+ && restArgs.length === 0) {
28
+ if (parent) {
29
+ _modifyChildFromTo(parent, current, fstArg);
30
+ }
31
+ else {
32
+ term = fstArg;
33
+ term.parent = undefined;
34
+ }
35
+ stack.unshift(fstArg);
36
+ continue;
37
+ }
38
+ if (!(fstArg instanceof IRConst)) {
39
+ stack.unshift(...current.children());
40
+ continue;
41
+ }
42
+ if (isDropList(func)
43
+ && (typeof fstArg.value === "bigint"
44
+ || typeof fstArg.value === "number")) {
45
+ const newTerm = restArgs.length >= 1 ? _ir_apps(_compTimeDropN(fstArg.value), ...restArgs) : _compTimeDropN(fstArg.value);
46
+ if (parent) {
47
+ _modifyChildFromTo(parent, current, newTerm);
48
+ }
49
+ else {
50
+ term = newTerm;
51
+ term.parent = undefined;
52
+ }
53
+ stack.unshift(newTerm);
54
+ continue;
55
+ }
56
+ // const tsEnsureExhaustiveCheck: never = func;
57
+ stack.unshift(...current.children());
58
+ }
59
+ return term;
60
+ }
61
+ function isDropList(term) {
62
+ while (term instanceof IRHoisted
63
+ || term instanceof IRLetted) {
64
+ if (term instanceof IRHoisted)
65
+ term = term.hoisted;
66
+ else if (term instanceof IRLetted)
67
+ term = term.value;
68
+ }
69
+ return (term instanceof IRNative
70
+ && term.tag === IRNativeTag._dropList);
71
+ }
72
+ function isId(term) {
73
+ while (term instanceof IRHoisted
74
+ || term instanceof IRLetted) {
75
+ if (term instanceof IRHoisted)
76
+ term = term.hoisted;
77
+ else if (term instanceof IRLetted)
78
+ term = term.value;
79
+ }
80
+ return ((term instanceof IRNative
81
+ && term.tag === IRNativeTag._id) || (term instanceof IRFunc
82
+ && term.params.length === 1
83
+ && term.body instanceof IRVar
84
+ && term.body.name === term.params[0]));
85
+ }
@@ -81,4 +81,5 @@ export function sanifyTree(ir) {
81
81
  }
82
82
  return;
83
83
  }
84
+ const tsEnsureExhaustiveCheck = ir;
84
85
  }
@@ -0,0 +1,6 @@
1
+ import { IRTerm } from "../../IRTerm.js";
2
+ export interface ApplicationTerms {
3
+ func: IRTerm;
4
+ args: IRTerm[];
5
+ }
6
+ export declare function getApplicationTerms(term: IRTerm): ApplicationTerms | undefined;
@@ -0,0 +1,37 @@
1
+ import { IRApp } from "../../IRNodes/IRApp.js";
2
+ import { IRCase } from "../../IRNodes/IRCase.js";
3
+ import { IRConstr } from "../../IRNodes/IRConstr.js";
4
+ export function getApplicationTerms(term) {
5
+ const args = [];
6
+ while (term instanceof IRApp
7
+ || (term instanceof IRCase
8
+ && term.continuations.length === 1
9
+ && term.constrTerm instanceof IRConstr
10
+ && Number(term.constrTerm.index) === 0)
11
+ // go "through" letted and hoisted
12
+ // || term instanceof IRLetted
13
+ // || term instanceof IRHoisted
14
+ ) {
15
+ if (term instanceof IRApp) {
16
+ args.unshift(term.arg);
17
+ term = term.fn;
18
+ continue;
19
+ }
20
+ if (term instanceof IRCase
21
+ && term.continuations.length === 1
22
+ && term.constrTerm instanceof IRConstr
23
+ && Number(term.constrTerm.index) === 0) {
24
+ args.push(...term.constrTerm.fields);
25
+ term = term.continuations[0];
26
+ continue;
27
+ }
28
+ // if( term instanceof IRLetted ) term = term.value;
29
+ // else if( term instanceof IRHoisted ) term = term.hoisted;
30
+ }
31
+ if (args.length === 0)
32
+ return undefined;
33
+ return {
34
+ func: term,
35
+ args,
36
+ };
37
+ }
@@ -1,3 +1,3 @@
1
- import { IRForced } from "../IRNodes/index.js";
2
- import { IRTerm } from "../IRTerm.js";
1
+ import { IRForced } from "../IRNodes/IRForced.js";
2
+ import type { IRTerm } from "../IRTerm.js";
3
3
  export declare function _ir_lazyChooseList(listTerm: IRTerm, caseNil: IRTerm, caseCons: IRTerm): IRForced;
@@ -1,5 +1,7 @@
1
- import { IRDelayed, IRForced, IRNative } from "../IRNodes/index.js";
2
- import { _ir_apps } from "./_ir_apps.js";
1
+ import { _ir_apps } from "../IRNodes/IRApp.js";
2
+ import { IRDelayed } from "../IRNodes/IRDelayed.js";
3
+ import { IRForced } from "../IRNodes/IRForced.js";
4
+ import { IRNative } from "../IRNodes/IRNative/index.js";
3
5
  export function _ir_lazyChooseList(listTerm, caseNil, caseCons) {
4
6
  return new IRForced(_ir_apps(IRNative.strictChooseList, listTerm, new IRDelayed(caseNil), new IRDelayed(caseCons)));
5
7
  }
@@ -1,3 +1,3 @@
1
- import { IRForced } from "../IRNodes/index.js";
1
+ import { IRForced } from "../IRNodes/IRForced.js";
2
2
  import { IRTerm } from "../IRTerm.js";
3
3
  export declare function _ir_lazyIfThenElse(condition: IRTerm, thenBranch: IRTerm, elseBranch: IRTerm): IRForced;
@@ -1,5 +1,7 @@
1
- import { IRDelayed, IRForced, IRNative } from "../IRNodes/index.js";
2
- import { _ir_apps } from "./_ir_apps.js";
1
+ import { _ir_apps } from "../IRNodes/IRApp.js";
2
+ import { IRDelayed } from "../IRNodes/IRDelayed.js";
3
+ import { IRForced } from "../IRNodes/IRForced.js";
4
+ import { IRNative } from "../IRNodes/IRNative/index.js";
3
5
  export function _ir_lazyIfThenElse(condition, thenBranch, elseBranch) {
4
6
  return new IRForced(_ir_apps(IRNative.strictIfThenElse, condition, new IRDelayed(thenBranch), new IRDelayed(elseBranch)));
5
7
  }
@@ -1,3 +1,4 @@
1
1
  import { IRApp } from "../IRNodes/index.js";
2
2
  import { IRTerm } from "../IRTerm.js";
3
- export declare function _ir_let(value: IRTerm, body: IRTerm): IRApp;
3
+ export declare function _ir_let(value: IRTerm, mkBody: (varName: symbol) => IRTerm): IRApp;
4
+ export declare function _ir_let_sym(sym: symbol, value: IRTerm, body: IRTerm): IRApp;
@@ -1,4 +1,8 @@
1
1
  import { IRApp, IRFunc } from "../IRNodes/index.js";
2
- export function _ir_let(value, body) {
3
- return new IRApp(new IRFunc(1, body), value);
2
+ export function _ir_let(value, mkBody) {
3
+ const name = Symbol("lettedVar");
4
+ return new IRApp(new IRFunc([name], mkBody(name)), value);
5
+ }
6
+ export function _ir_let_sym(sym, value, body) {
7
+ return new IRApp(new IRFunc([sym], body), value);
4
8
  }
@@ -1,2 +1,3 @@
1
1
  import { IRTerm } from "../IRTerm.js";
2
2
  export declare function isClosedIRTerm(term: IRTerm): boolean;
3
+ export declare function _debug_assertClosedIR(term: IRTerm): void;
@@ -2,7 +2,6 @@ import { IRConst } from "../IRNodes/IRConst.js";
2
2
  import { IRFunc } from "../IRNodes/IRFunc.js";
3
3
  import { IRApp } from "../IRNodes/IRApp.js";
4
4
  import { IRError } from "../IRNodes/IRError.js";
5
- import { IRNative } from "../IRNodes/IRNative/index.js";
6
5
  import { IRHoisted } from "../IRNodes/IRHoisted.js";
7
6
  import { IRLetted } from "../IRNodes/IRLetted.js";
8
7
  import { IRVar } from "../IRNodes/IRVar.js";
@@ -12,29 +11,33 @@ import { IRConstr } from "../IRNodes/IRConstr.js";
12
11
  import { IRCase } from "../IRNodes/IRCase.js";
13
12
  import { IRRecursive } from "../IRNodes/IRRecursive.js";
14
13
  import { IRSelfCall } from "../IRNodes/IRSelfCall.js";
15
- function _isClosedIRTerm(term, dbn, parent) {
16
- if (term instanceof IRVar) {
17
- return term.dbn < dbn;
18
- }
19
- if (term instanceof IRSelfCall) {
20
- return term.dbn < dbn;
21
- }
14
+ import { IRNative } from "../IRNodes/IRNative/index.js";
15
+ import { getUnboundedIRVars } from "../toUPLC/subRoutines/handleLetted/groupByScope.js";
16
+ import { prettyIRInline } from "./showIR.js";
17
+ function _isClosedIRTerm(term, boundedVars, parent) {
18
+ if (term instanceof IRVar)
19
+ return boundedVars.has(term.name);
20
+ if (term instanceof IRSelfCall)
21
+ return boundedVars.has(term.name);
22
22
  if (term instanceof IRFunc) {
23
- return _isClosedIRTerm(term.body, dbn + term.arity, term);
23
+ boundedVars = new Set(boundedVars);
24
+ for (const param of term.params)
25
+ boundedVars.add(param);
26
+ return _isClosedIRTerm(term.body, boundedVars, term);
24
27
  }
25
28
  if (term instanceof IRRecursive) {
26
- return _isClosedIRTerm(term.body, dbn + term.arity, term);
27
- }
28
- if (term instanceof IRApp) {
29
- return _isClosedIRTerm(term.fn, dbn, term) && _isClosedIRTerm(term.arg, dbn, term);
30
- }
31
- if (term instanceof IRConstr) {
32
- return Array.from(term.fields).every(f => _isClosedIRTerm(f, dbn, term));
33
- }
34
- if (term instanceof IRCase) {
35
- return _isClosedIRTerm(term.constrTerm, dbn, term) &&
36
- Array.from(term.continuations).every(cont => _isClosedIRTerm(cont, dbn, term));
29
+ boundedVars = new Set(boundedVars);
30
+ boundedVars.add(term.name);
31
+ return _isClosedIRTerm(term.body, boundedVars, term);
37
32
  }
33
+ if (term instanceof IRApp)
34
+ return _isClosedIRTerm(term.fn, boundedVars, term) && _isClosedIRTerm(term.arg, boundedVars, term);
35
+ if (term instanceof IRConstr)
36
+ return Array.from(term.fields).every(f => _isClosedIRTerm(f, boundedVars, term));
37
+ if (term instanceof IRCase)
38
+ return (_isClosedIRTerm(term.constrTerm, boundedVars, term)
39
+ && Array.from(term.continuations)
40
+ .every(cont => _isClosedIRTerm(cont, boundedVars, term)));
38
41
  if (term instanceof IRConst)
39
42
  return true;
40
43
  if (term instanceof IRError)
@@ -42,17 +45,28 @@ function _isClosedIRTerm(term, dbn, parent) {
42
45
  if (term instanceof IRNative)
43
46
  return true;
44
47
  if (term instanceof IRHoisted)
45
- return true;
48
+ return _isClosedIRTerm(term.hoisted, boundedVars, term);
46
49
  if (term instanceof IRLetted)
47
- return _isClosedIRTerm(term.value, dbn, term);
50
+ return _isClosedIRTerm(term.value, boundedVars, term);
48
51
  if (term instanceof IRForced)
49
- return _isClosedIRTerm(term.forced, dbn, term);
52
+ return _isClosedIRTerm(term.forced, boundedVars, term);
50
53
  if (term instanceof IRDelayed)
51
- return _isClosedIRTerm(term.delayed, dbn, term);
54
+ return _isClosedIRTerm(term.delayed, boundedVars, term);
55
+ const tsEnsureExhaustiveCheck = term;
52
56
  // not even an IRTerm
53
- console.log(parent);
57
+ console.error(parent);
54
58
  throw new Error("`isClosedIRTerm` called on non-IR argument");
55
59
  }
56
60
  export function isClosedIRTerm(term) {
57
- return _isClosedIRTerm(term, 0);
61
+ return _isClosedIRTerm(term, new Set(), undefined);
62
+ }
63
+ export function _debug_assertClosedIR(term) {
64
+ if (!isClosedIRTerm(term)) {
65
+ const unboundedVars = getUnboundedIRVars(term);
66
+ console.error("unbounded vars:", unboundedVars.map(variab => variab.name));
67
+ console.error("term:", prettyIRInline(term));
68
+ console.error("unbounded parents:", unboundedVars.map(variab => prettyIRInline(variab.parent ?? variab)));
69
+ console.error("unbounded parents:", unboundedVars.map(variab => variab._creationStack));
70
+ throw new Error("Term is not closed");
71
+ }
58
72
  }
@@ -3,3 +3,4 @@
3
3
  */
4
4
  export declare function positiveIntAsBytes(n: number | bigint): Uint8Array;
5
5
  export declare function positiveBigIntAsBytes(n: bigint): Uint8Array;
6
+ export declare function zigzagBigintAsBytes(n: bigint): Uint8Array;
@@ -1,4 +1,5 @@
1
1
  import { fromHex } from "@harmoniclabs/uint8array-utils";
2
+ import UPLCFlatUtils from "../../utils/UPLCFlatUtils/index.js";
2
3
  /**
3
4
  * writes the number in a new `Uint8Array` Big Endian
4
5
  */
@@ -7,8 +8,6 @@ export function positiveIntAsBytes(n) {
7
8
  return positiveBigIntAsBytes(n);
8
9
  }
9
10
  if (!Number.isSafeInteger(n) || n < 0) {
10
- console.log(n);
11
- console.trace(); // some help
12
11
  throw new Error("how did you end up here? the name of the function explicitly says 'positiveIntAsBytes'");
13
12
  }
14
13
  let str = n.toString(16);
@@ -17,11 +16,12 @@ export function positiveIntAsBytes(n) {
17
16
  }
18
17
  export function positiveBigIntAsBytes(n) {
19
18
  if (n < 0 || typeof n !== "bigint") {
20
- console.log(n);
21
- console.trace(); // some help
22
19
  throw new Error("how did you end up here? the name of the function explicitly says 'positiveBigIntAsBytes'");
23
20
  }
24
21
  let strHex = n.toString(16);
25
22
  strHex = strHex.length % 2 === 0 ? strHex : "0" + strHex;
26
23
  return fromHex(strHex);
27
24
  }
25
+ export function zigzagBigintAsBytes(n) {
26
+ return positiveBigIntAsBytes(UPLCFlatUtils.zigzagBigint(BigInt(n)));
27
+ }
@@ -3,33 +3,20 @@ import { IRTerm } from "../IRTerm.js";
3
3
  import { IRHoisted } from "../IRNodes/IRHoisted.js";
4
4
  import { IRConst } from "../IRNodes/IRConst.js";
5
5
  export declare function showIRText(_ir: IRTerm): string;
6
- export declare function showIR(_ir: IRTerm): {
7
- text: string;
8
- letted: {
9
- [hash: string]: string;
10
- };
11
- hoisted: {
12
- [hash: string]: string;
13
- };
14
- };
15
- export declare function prettyIRText(_ir: IRTerm, _indent?: number): string | {
16
- text: string;
17
- letted: {
18
- [hash: string]: string;
19
- };
20
- hoisted: {
21
- [hash: string]: string;
22
- };
23
- };
24
- export type PrettiedIR = {
6
+ export declare function showIR(_ir: IRTerm): PrettiedIR;
7
+ export declare function prettyIRText(_ir: IRTerm, _indent?: number): string;
8
+ export interface PrettiedIR extends HoistedAndLetted {
25
9
  text: string;
10
+ }
11
+ export type PrettiedLetted = string;
12
+ export interface HoistedAndLetted {
26
13
  letted: {
27
- [hash: string]: string;
14
+ [hash: string]: PrettiedLetted;
28
15
  };
29
16
  hoisted: {
30
17
  [hash: string]: string;
31
18
  };
32
- };
19
+ }
33
20
  export declare function prettyIR(_ir: IRTerm, _indent?: number): PrettiedIR;
34
21
  export interface PrettyIRJsonStrOpts {
35
22
  text: boolean;
@@ -41,3 +28,5 @@ export declare function hoistedToStr(ir: IRHoisted): string;
41
28
  export declare function lettedToStr(ir: IRLetted): string;
42
29
  export declare function constToString(ir: IRConst): string;
43
30
  export declare function prettyIRInline(_ir: IRTerm, _indent?: number): string;
31
+ export declare function unfromatStr(str: string): string;
32
+ export declare function onlyHoistedAndLetted(prettied: PrettiedIR): HoistedAndLetted;
@@ -42,9 +42,9 @@ export function showIRText(_ir) {
42
42
  return hoistedToStr(ir);
43
43
  }
44
44
  if (ir instanceof IRVar)
45
- return getVarNameForDbn(dbn - 1 - ir.dbn);
45
+ return ir.name.description;
46
46
  if (ir instanceof IRSelfCall)
47
- return "self_" + getVarNameForDbn(dbn - 1 - ir.dbn);
47
+ return "self_" + ir.name.description;
48
48
  if (ir instanceof IRConst)
49
49
  return constToString(ir);
50
50
  if (ir instanceof IRDelayed)
@@ -54,11 +54,9 @@ export function showIRText(_ir) {
54
54
  if (ir instanceof IRError)
55
55
  return "(error)";
56
56
  if (ir instanceof IRFunc) {
57
- let vars = new Array(ir.arity);
58
- for (let i = 0; i < ir.arity; i++) {
59
- vars[i] = getVarNameForDbn(dbn++);
60
- }
61
- return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn)})`;
57
+ const syms = ir.params;
58
+ const names = syms.map(s => s.description);
59
+ return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length)})`;
62
60
  }
63
61
  if (ir instanceof IRRecursive) {
64
62
  const varName = "self_" + getVarNameForDbn(dbn++);
@@ -78,13 +76,8 @@ export function showIR(_ir) {
78
76
  for (let i = 0; i < deps.length; i++) {
79
77
  addHoisted(deps[i].hoisted);
80
78
  }
81
- hoistedHashes.push(hash.slice());
82
- Object.defineProperty(hoisted, irHashToHex(hash), {
83
- value: showIRText(h.hoisted),
84
- writable: false,
85
- enumerable: true,
86
- configurable: false
87
- });
79
+ hoistedHashes.push(hash);
80
+ hoisted[irHashToHex(hash)] = prettyIRText(h.hoisted);
88
81
  }
89
82
  }
90
83
  const lettedHashes = [];
@@ -97,14 +90,9 @@ export function showIR(_ir) {
97
90
  for (let i = 0; i < nDeps; i++) {
98
91
  addLetted(deps[i].letted);
99
92
  }
100
- lettedHashes.push(hash.slice());
93
+ lettedHashes.push(hash);
101
94
  getHoistedTerms(l.value).forEach(({ hoisted }) => addHoisted(hoisted));
102
- Object.defineProperty(letted, irHashToHex(hash), {
103
- value: showIRText(l.value),
104
- writable: false,
105
- enumerable: true,
106
- configurable: false
107
- });
95
+ letted[irHashToHex(hash)] = showIRText(l.value);
108
96
  }
109
97
  }
110
98
  function _loop(ir, dbn) {
@@ -125,9 +113,9 @@ export function showIR(_ir) {
125
113
  return hoistedToStr(ir);
126
114
  }
127
115
  if (ir instanceof IRVar)
128
- return getVarNameForDbn(dbn - 1 - ir.dbn);
116
+ return ir.name.description;
129
117
  if (ir instanceof IRSelfCall)
130
- return "self_" + getVarNameForDbn(dbn - 1 - ir.dbn);
118
+ return "self_" + ir.name.description;
131
119
  if (ir instanceof IRConst)
132
120
  return constToString(ir);
133
121
  if (ir instanceof IRDelayed)
@@ -137,11 +125,9 @@ export function showIR(_ir) {
137
125
  if (ir instanceof IRError)
138
126
  return "(error)";
139
127
  if (ir instanceof IRFunc) {
140
- let vars = new Array(ir.arity);
141
- for (let i = 0; i < ir.arity; i++) {
142
- vars[i] = getVarNameForDbn(dbn++);
143
- }
144
- return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn)})`;
128
+ const syms = ir.params;
129
+ const names = syms.map(s => s.description);
130
+ return `(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length)})`;
145
131
  }
146
132
  if (ir instanceof IRRecursive) {
147
133
  const varName = "self_" + getVarNameForDbn(dbn++);
@@ -158,7 +144,7 @@ export function showIR(_ir) {
158
144
  }
159
145
  export function prettyIRText(_ir, _indent = 2) {
160
146
  if (!Number.isSafeInteger(_indent) || _indent < 1)
161
- return showIR(_ir);
147
+ return showIR(_ir).text;
162
148
  const indentStr = " ".repeat(_indent);
163
149
  function _loop(ir, dbn, depth) {
164
150
  const indent = `\n${indentStr.repeat(depth)}`;
@@ -178,9 +164,9 @@ export function prettyIRText(_ir, _indent = 2) {
178
164
  return `${indent}${hoistedToStr(ir)}`;
179
165
  }
180
166
  if (ir instanceof IRVar)
181
- return indent + getVarNameForDbn(dbn - 1 - ir.dbn);
167
+ return indent + ir.name.description;
182
168
  if (ir instanceof IRSelfCall)
183
- return indent + "self_" + getVarNameForDbn(dbn - 1 - ir.dbn);
169
+ return indent + "self_" + ir.name.description;
184
170
  if (ir instanceof IRConst)
185
171
  return `${indent}${constToString(ir)}`;
186
172
  if (ir instanceof IRDelayed)
@@ -190,16 +176,15 @@ export function prettyIRText(_ir, _indent = 2) {
190
176
  if (ir instanceof IRError)
191
177
  return "(error)";
192
178
  if (ir instanceof IRFunc) {
193
- let vars = new Array(ir.arity);
194
- for (let i = 0; i < ir.arity; i++) {
195
- vars[i] = getVarNameForDbn(dbn++);
196
- }
197
- return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
179
+ const syms = ir.params;
180
+ const names = syms.map(s => s.description);
181
+ return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length, depth + 1)}${indent})`;
198
182
  }
199
183
  if (ir instanceof IRRecursive) {
200
184
  const varName = "self_" + getVarNameForDbn(dbn++);
201
185
  return `${indent}(recursive ${varName} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
202
186
  }
187
+ const tsEnsureExhaustiveCheck = ir;
203
188
  return "";
204
189
  }
205
190
  return _loop(_ir, 0, 0);
@@ -217,9 +202,8 @@ export function prettyIR(_ir, _indent = 2) {
217
202
  for (let i = 0; i < deps.length; i++) {
218
203
  addHoisted(deps[i].hoisted);
219
204
  }
220
- hoistedHashes.push(hash.slice());
221
- const hashStr = irHashToHex(hash);
222
- Object.defineProperty(hoisted, hashStr, { value: prettyIRText(h.hoisted, _indent), writable: true, enumerable: true });
205
+ hoistedHashes.push(hash);
206
+ hoisted[irHashToHex(hash)] = prettyIRText(h.hoisted, _indent);
223
207
  }
224
208
  }
225
209
  const lettedHashes = [];
@@ -232,14 +216,10 @@ export function prettyIR(_ir, _indent = 2) {
232
216
  for (let i = 0; i < nDeps; i++) {
233
217
  addLetted(deps[i].letted);
234
218
  }
235
- lettedHashes.push(hash.slice());
219
+ lettedHashes.push(hash);
236
220
  getHoistedTerms(l.value).forEach(({ hoisted }) => addHoisted(hoisted));
237
221
  const hashStr = irHashToHex(hash);
238
- Object.defineProperty(letted, hashStr, {
239
- value: prettyIRText(l.value, _indent),
240
- writable: true,
241
- enumerable: true
242
- });
222
+ letted[hashStr] = prettyIRText(l.value, _indent);
243
223
  }
244
224
  }
245
225
  function _loop(ir, dbn, depth) {
@@ -257,9 +237,9 @@ export function prettyIR(_ir, _indent = 2) {
257
237
  return `${indent}${hoistedToStr(ir)}`;
258
238
  }
259
239
  if (ir instanceof IRVar)
260
- return indent + getVarNameForDbn(dbn - 1 - ir.dbn);
240
+ return indent + ir.name.description;
261
241
  if (ir instanceof IRSelfCall)
262
- return indent + "self_" + getVarNameForDbn(dbn - 1 - ir.dbn);
242
+ return indent + "self_" + ir.name.description;
263
243
  if (ir instanceof IRConst)
264
244
  return `${indent}${constToString(ir)}`;
265
245
  if (ir instanceof IRDelayed)
@@ -269,17 +249,21 @@ export function prettyIR(_ir, _indent = 2) {
269
249
  if (ir instanceof IRError)
270
250
  return "(error)";
271
251
  if (ir instanceof IRFunc) {
272
- let vars = new Array(ir.arity);
273
- for (let i = 0; i < ir.arity; i++) {
274
- vars[i] = getVarNameForDbn(dbn++);
275
- }
276
- return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
252
+ const syms = ir.params;
253
+ const names = syms.map(s => s.description);
254
+ return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length, depth + 1)}${indent})`;
277
255
  }
278
256
  if (ir instanceof IRRecursive) {
279
257
  const varName = "self_" + getVarNameForDbn(dbn++);
280
258
  return `${indent}(recursive ${varName} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
281
259
  }
282
- return "";
260
+ if (ir instanceof IRConstr)
261
+ return `${indent}(constr ${ir.index.toString()} [${Array.from(ir.fields).map(f => _loop(f, dbn, depth + 1)).join(`, `)}${indent}])`;
262
+ if (ir instanceof IRCase)
263
+ return `${indent}(case ${_loop(ir.constrTerm, dbn, depth + 1)} ${indent}[${Array.from(ir.continuations).map(f => _loop(f, dbn, depth + 1)).join(", ")}${indent}])`;
264
+ const tsEnsureExhaustiveCheck = ir;
265
+ console.error(ir);
266
+ throw new Error("unknown IR node found");
283
267
  }
284
268
  const text = _loop(_ir, 0, 0);
285
269
  return {
@@ -316,7 +300,7 @@ export function hoistedToStr(ir) {
316
300
  return `(hoisted${(ir.meta.name ? " {" + ir.meta.name + "}" : "")} ${irHashToHex(ir.hash)})`;
317
301
  }
318
302
  export function lettedToStr(ir) {
319
- return `(letted${(ir.meta.name ? " {" + ir.meta.name + "}" : "")} ${ir.dbn} ${irHashToHex(ir.hash)})`;
303
+ return `(letted ${ir.name.description} ${irHashToHex(ir.hash)})`;
320
304
  }
321
305
  export function constToString(ir) {
322
306
  return `(const ${ir.type.toString()} ${showUPLCConstValue(ir.value)})`;
@@ -331,21 +315,25 @@ export function prettyIRInline(_ir, _indent = 2) {
331
315
  return `${indent}(native ${nativeTagToString(ir.tag)})`;
332
316
  if (ir instanceof IRLetted) {
333
317
  // addLetted( ir );
334
- return (`${indent}(letted${(ir.meta.name ? " {" + ir.meta.name + "}" : "")} ${ir.dbn} ${irHashToHex(ir.hash)}` +
335
- `${_loop(ir.value, dbn, depth + 1)}` +
318
+ return (`${indent}(letted ${ir.name.description}` +
319
+ `${indent + indentStr}{` +
320
+ `${_loop(ir.value, dbn, depth + 2)}` +
321
+ `${indent + indentStr}}` +
336
322
  `${indent})`);
337
323
  }
338
324
  if (ir instanceof IRHoisted) {
339
325
  // addHoisted( ir )
340
326
  // return `${indent}${hoistedToStr(ir)}`;
341
327
  return (`${indent}(hoisted${(ir.meta.name ? " {" + ir.meta.name + "}" : "")} ${irHashToHex(ir.hash)}` +
342
- `${_loop(ir.hoisted, dbn, depth + 1)}` +
328
+ `${indent + indentStr}{` +
329
+ `${_loop(ir.hoisted, dbn, depth + 2)}` +
330
+ `${indent + indentStr}}` +
343
331
  `${indent})`);
344
332
  }
345
333
  if (ir instanceof IRVar)
346
- return indent + getVarNameForDbn(dbn - 1 - ir.dbn);
334
+ return indent + ir.name.description;
347
335
  if (ir instanceof IRSelfCall)
348
- return indent + "self_" + getVarNameForDbn(dbn - 1 - ir.dbn);
336
+ return indent + "self_" + ir.name.description;
349
337
  if (ir instanceof IRConst)
350
338
  return `${indent}${constToString(ir)}`;
351
339
  if (ir instanceof IRDelayed)
@@ -355,11 +343,9 @@ export function prettyIRInline(_ir, _indent = 2) {
355
343
  if (ir instanceof IRError)
356
344
  return "(error)";
357
345
  if (ir instanceof IRFunc) {
358
- let vars = new Array(ir.arity);
359
- for (let i = 0; i < ir.arity; i++) {
360
- vars[i] = getVarNameForDbn(dbn++);
361
- }
362
- return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${vars.join(" ")} ${_loop(ir.body, dbn, depth + 1)}${indent})`;
346
+ const syms = ir.params;
347
+ const names = syms.map(s => s.description);
348
+ return `${indent}(func ${typeof ir.name === "string" ? "{" + ir.name + "}" : ""} ${names.join(" ")} ${_loop(ir.body, dbn + names.length, depth + 1)}${indent})`;
363
349
  }
364
350
  if (ir instanceof IRRecursive) {
365
351
  const varName = "self_" + getVarNameForDbn(dbn++);
@@ -370,3 +356,19 @@ export function prettyIRInline(_ir, _indent = 2) {
370
356
  const text = _loop(_ir, 0, 0);
371
357
  return text;
372
358
  }
359
+ export function unfromatStr(str) {
360
+ return str
361
+ .replace("\n", " ")
362
+ .replace(/\s+/g, " ");
363
+ }
364
+ export function onlyHoistedAndLetted(prettied) {
365
+ const result = { letted: {}, hoisted: {} };
366
+ Object.keys(prettied.letted).forEach(k => {
367
+ const letted = prettied.letted[k];
368
+ result.letted[k] = unfromatStr(letted);
369
+ });
370
+ Object.keys(prettied.hoisted).forEach(k => {
371
+ result.hoisted[k] = unfromatStr(prettied.hoisted[k]);
372
+ });
373
+ return result;
374
+ }