@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
@@ -8,513 +8,312 @@ import { IRHoisted } from "../../../IRNodes/IRHoisted.js";
8
8
  import { IRNative } from "../../../IRNodes/IRNative/index.js";
9
9
  import { IRNativeTag } from "../../../IRNodes/IRNative/IRNativeTag.js";
10
10
  import { IRVar } from "../../../IRNodes/IRVar.js";
11
- import { _ir_apps } from "../../../tree_utils/_ir_apps.js";
12
11
  import { IRRecursive } from "../../../IRNodes/IRRecursive.js";
13
12
  import { IRSelfCall } from "../../../IRNodes/IRSelfCall.js";
14
- import { IRError } from "../../../IRNodes/index.js";
13
+ import { IRError } from "../../../IRNodes/IRError.js";
14
+ import { _ir_apps } from "../../../IRNodes/IRApp.js";
15
15
  import { _ir_let } from "../../../tree_utils/_ir_let.js";
16
+ import { _ir_lazyChooseList } from "../../../tree_utils/_ir_lazyChooseList.js";
16
17
  import { _ir_lazyIfThenElse } from "../../../tree_utils/_ir_lazyIfThenElse.js";
17
- const hoisted_id = new IRHoisted(new IRFunc(1, new IRVar(0)));
18
+ import { hoisted_drop4, hoisted_drop2, hoisted_drop3 } from "../_comptimeDropN.js";
19
+ import { IRConstr } from "../../../IRNodes/index.js";
20
+ function _ir_strictAnd(left, right) {
21
+ return _ir_apps(IRNative.strictIfThenElse, left, right, IRConst.bool(false));
22
+ }
23
+ const id_arg_sym = Symbol("id_arg");
24
+ export const hoisted_id = new IRHoisted(new IRFunc([id_arg_sym], new IRVar(id_arg_sym)));
18
25
  hoisted_id.hash;
19
- const hoisted_not = new IRHoisted(new IRFunc(1, // someBool
20
- _ir_apps(IRNative.strictIfThenElse, new IRVar(0), // someBool
21
- IRConst.bool(false), // someBool == true -> false
22
- IRConst.bool(true) // someBool == false -> true
23
- )));
26
+ export const hoisted_not = new IRHoisted((() => {
27
+ const someBool = Symbol("someBool");
28
+ return new IRFunc([someBool], _ir_apps(IRNative.strictIfThenElse, new IRVar(someBool), IRConst.bool(false), IRConst.bool(true)));
29
+ })());
24
30
  hoisted_not.hash;
25
- const hoisted_drop2 = new IRHoisted(new IRFunc(1, // lst
26
- _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, new IRVar(0) // lst
27
- ))));
28
- hoisted_drop2.hash;
29
- const hoisted_drop3 = new IRHoisted(new IRFunc(1, // lst
30
- _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, new IRVar(0) // lst
31
- )))));
32
- hoisted_drop3.hash;
33
- const hoisted_drop4 = new IRHoisted(new IRFunc(1, // lst
34
- _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, _ir_apps(IRNative.tailList, new IRVar(0) // lst
35
- ))))));
36
- hoisted_drop4.hash;
37
- const hoisted_drop8 = new IRHoisted(new IRFunc(1, // lst
38
- _ir_apps(hoisted_drop4.clone(), _ir_apps(hoisted_drop4.clone(), new IRVar(0) // lst
39
- ))));
40
- hoisted_drop8.hash;
41
- const hoisted_drop16 = new IRHoisted(new IRFunc(1, // lst
42
- _ir_apps(hoisted_drop8.clone(), _ir_apps(hoisted_drop8.clone(), new IRVar(0) // lst
43
- ))));
44
- hoisted_drop16.hash;
45
- const hoisted_drop32 = new IRHoisted(new IRFunc(1, // lst
46
- _ir_apps(hoisted_drop16.clone(), _ir_apps(hoisted_drop16.clone(), new IRVar(0) // lst
47
- ))));
48
- hoisted_drop32.hash;
49
- const hoisted_incr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
31
+ export const hoisted_incr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
50
32
  hoisted_incr.hash;
51
- const hoisted_decr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
33
+ export const hoisted_decr = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
52
34
  hoisted_decr.hash;
53
- const hoisted_isZero = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(0)));
35
+ export const hoisted_isZero = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(0)));
54
36
  hoisted_isZero.hash;
55
- const hoisted_isOne = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(1)));
37
+ export const hoisted_isOne = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(1)));
56
38
  hoisted_isZero.hash;
57
- const hoisted_isTwo = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(2)));
39
+ export const hoisted_isTwo = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(2)));
58
40
  hoisted_isTwo.hash;
59
- const hoisted_isThree = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(3)));
60
- const hoisted_addOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
41
+ export const hoisted_isThree = new IRHoisted(new IRApp(IRNative.equalsInteger, IRConst.int(3)));
42
+ export const hoisted_addOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(1)));
61
43
  hoisted_addOne.hash;
62
- const hoisted_subOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
44
+ export const hoisted_subOne = new IRHoisted(new IRApp(IRNative.addInteger, IRConst.int(-1)));
63
45
  hoisted_subOne.hash;
64
- const hoisted_isPositive = new IRHoisted(new IRApp(IRNative.lessThanInteger, IRConst.int(0)));
46
+ export const hoisted_isPositive = new IRHoisted(new IRApp(IRNative.lessThanInteger, IRConst.int(0)));
65
47
  hoisted_isPositive.hash;
66
- const hoisted_isNonNegative = new IRHoisted(new IRApp(IRNative.lessThanEqualInteger, IRConst.int(0)));
48
+ export const hoisted_isNonNegative = new IRHoisted(new IRApp(IRNative.lessThanEqualInteger, IRConst.int(0)));
67
49
  hoisted_isNonNegative.hash;
68
- const innerZ = new IRFunc(1, // f
69
- new IRApp(new IRVar(1), // Z
70
- new IRFunc(1, new IRApp(new IRApp(new IRVar(1), // toMakeRecursive
71
- new IRVar(1) // toMakeRecursive ( self )
72
- ), new IRVar(0) // first argument (other than self)
73
- ))));
74
- innerZ.hash;
75
- const hoisted_z_comb = new IRHoisted(new IRFunc(1, // Z
76
- new IRApp(innerZ.clone(), innerZ.clone())));
77
- hoisted_z_comb.hash;
78
- const hoisted_matchList = new IRHoisted(new IRFunc(3, // delayed_matchNil, matchCons, list
79
- new IRForced(new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(0), // list, last argument of IRFunc above
80
- new IRVar(2), // delayed_matchNil (`delayed( resultT )`)
81
- new IRDelayed(// delay
82
- _ir_apps(new IRVar(1), // matchCons
83
- new IRApp(IRNative.headList, new IRVar(0) // list
84
- ), new IRApp(IRNative.tailList, new IRVar(0) // list
85
- ))))))));
50
+ export const hoisted_matchList = new IRHoisted((() => {
51
+ const delayed_matchNil = Symbol("delayed_matchNil");
52
+ const matchCons = Symbol("matchCons");
53
+ const list = Symbol("list");
54
+ return new IRFunc([delayed_matchNil, matchCons, list], new IRForced(new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(list), new IRVar(delayed_matchNil), new IRDelayed(_ir_apps(new IRVar(matchCons), new IRApp(IRNative.headList, new IRVar(list)), new IRApp(IRNative.tailList, new IRVar(list))))))));
55
+ })());
86
56
  hoisted_matchList.hash;
87
- const hosited_lazyChooseList = new IRHoisted(new IRFunc(3, // list, delayed_caseNil, delayed_caseCons
88
- new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(2), new IRVar(1), new IRVar(0)))));
57
+ // hoisted_recursiveList (needed by hoisted_foldr)
58
+ const recList_matchNil = Symbol("matchNil");
59
+ const recList_matchCons = Symbol("matchCons");
60
+ const recList_self = Symbol("recursiveList_self");
61
+ const recList_lst = Symbol("lst");
62
+ export const hoisted_recursiveList = new IRHoisted(new IRFunc([recList_matchNil, recList_matchCons], new IRRecursive(recList_self, new IRFunc([recList_lst], _ir_apps(hoisted_matchList.clone(), new IRApp(new IRVar(recList_matchNil), new IRSelfCall(recList_self)), new IRApp(new IRVar(recList_matchCons), new IRSelfCall(recList_self)), new IRVar(recList_lst))))));
63
+ hoisted_recursiveList.hash;
64
+ // hoisted_foldr
65
+ const foldr_reduce = Symbol("reduceFunc");
66
+ const foldr_acc = Symbol("accumulator");
67
+ const foldr__dummy = Symbol("_self");
68
+ const foldr_self = Symbol("self");
69
+ const foldr_head = Symbol("head");
70
+ const foldr_tail = Symbol("tail");
71
+ export const hoisted_foldr = new IRHoisted(new IRFunc([foldr_reduce, foldr_acc], _ir_apps(hoisted_recursiveList.clone(), new IRFunc([foldr__dummy], new IRDelayed(new IRVar(foldr_acc))), new IRFunc([foldr_self, foldr_head, foldr_tail], _ir_apps(new IRVar(foldr_reduce), new IRVar(foldr_head), new IRApp(new IRVar(foldr_self), new IRVar(foldr_tail)))))));
72
+ hoisted_foldr.hash;
73
+ export const hosited_lazyChooseList = new IRHoisted((() => {
74
+ const list = Symbol("list");
75
+ const delayed_caseNil = Symbol("delayed_caseNil");
76
+ const delayed_caseCons = Symbol("delayed_caseCons");
77
+ return new IRFunc([list, delayed_caseNil, delayed_caseCons], new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(list), new IRVar(delayed_caseNil), new IRVar(delayed_caseCons))));
78
+ })());
89
79
  hosited_lazyChooseList.hash;
90
80
  //*/
91
- const hoisted_isMoreThanOrEqualTo4 = new IRHoisted(_ir_apps(IRNative.lessThanInteger, IRConst.int(4)));
81
+ export const hoisted_isMoreThanOrEqualTo4 = new IRHoisted(_ir_apps(IRNative.lessThanInteger, IRConst.int(4)));
92
82
  hoisted_isMoreThanOrEqualTo4.hash;
93
- const hoisted_sub4 = new IRHoisted(_ir_apps(IRNative.addInteger, IRConst.int(-4)));
94
- const hoisted_dropList = new IRHoisted(new IRRecursive(// self,
95
- new IRFunc(2, // 2: self, 1: n, 0: lst
96
- _ir_lazyIfThenElse(_ir_apps(hoisted_isMoreThanOrEqualTo4.clone(), new IRVar(1) // n
97
- ),
98
- // then
99
- _ir_apps(new IRSelfCall(2), // self
100
- _ir_apps(hoisted_sub4.clone(), new IRVar(1) // n
101
- ), _ir_apps(hoisted_drop4.clone(), new IRVar(0) // lst
102
- )),
103
- // else
104
- _ir_lazyIfThenElse(_ir_apps(hoisted_isZero.clone(), new IRVar(1) // n
105
- ),
106
- // then
107
- new IRVar(0), // lst
108
- // else
109
- _ir_lazyIfThenElse(_ir_apps(hoisted_isOne.clone(), new IRVar(1) // n
110
- ),
111
- // then
112
- _ir_apps(IRNative.tailList, new IRVar(0) // lst
113
- ),
114
- // else
115
- _ir_lazyIfThenElse(_ir_apps(hoisted_isTwo.clone(), new IRVar(1) // n
116
- ),
117
- // then
118
- _ir_apps(hoisted_drop2.clone(), new IRVar(0) // lst
119
- ),
120
- // else
121
- _ir_apps(hoisted_drop3.clone(), new IRVar(0) // lst
122
- ))))))));
83
+ export const hoisted_sub4 = new IRHoisted(_ir_apps(IRNative.addInteger, IRConst.int(-4)));
84
+ hoisted_sub4.hash;
85
+ const self_length = Symbol("self_length");
86
+ const length_list_sym = Symbol("length_list_sym");
87
+ export const hoisted_length = new IRHoisted(new IRRecursive(self_length, new IRFunc([length_list_sym], _ir_lazyChooseList(new IRVar(length_list_sym), IRConst.int(0), _ir_apps(hoisted_incr.clone(), new IRApp(new IRSelfCall(self_length), // self
88
+ new IRApp(IRNative.tailList, new IRVar(length_list_sym) // list
89
+ )))))));
90
+ hoisted_length.hash;
91
+ // REPLACED hoisted_dropList (was numeric arity + dbn)
92
+ const drop_self = Symbol("drop_self");
93
+ const drop_n = Symbol("n");
94
+ const drop_lst = Symbol("lst");
95
+ export const hoisted_dropList = new IRHoisted(new IRRecursive(drop_self, new IRFunc([drop_n, drop_lst], _ir_lazyIfThenElse(_ir_apps(hoisted_isMoreThanOrEqualTo4.clone(), new IRVar(drop_n)), _ir_apps(new IRSelfCall(drop_self), _ir_apps(hoisted_sub4.clone(), new IRVar(drop_n)), _ir_apps(hoisted_drop4.clone(), new IRVar(drop_lst))), _ir_lazyIfThenElse(_ir_apps(hoisted_isZero.clone(), new IRVar(drop_n)), new IRVar(drop_lst), _ir_lazyIfThenElse(_ir_apps(hoisted_isOne.clone(), new IRVar(drop_n)), _ir_apps(IRNative.tailList, new IRVar(drop_lst)), _ir_lazyIfThenElse(_ir_apps(hoisted_isTwo.clone(), new IRVar(drop_n)), _ir_apps(hoisted_drop2.clone(), new IRVar(drop_lst)), _ir_apps(hoisted_drop3.clone(), new IRVar(drop_lst)))))))));
123
96
  hoisted_dropList.hash;
124
- const hoisted_recursiveList = new IRHoisted(new IRFunc(2, // matchNil (3), matchCons (2)
125
- new IRRecursive(// self (1)
126
- new IRFunc(1, // lst (0)
127
- _ir_apps(hoisted_matchList.clone(), new IRApp(new IRVar(3), // matchNil
128
- new IRSelfCall(1) // self
129
- ), new IRApp(new IRVar(2), // matchCons,
130
- new IRSelfCall(1) // self
131
- ), new IRVar(0))))));
132
- hoisted_recursiveList.hash;
133
- const hoisted_lazyOr = new IRHoisted(new IRFunc(2, // a(1), delayed_b (0)
134
- new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRVar(1), // a
135
- new IRDelayed(IRConst.bool(true)), // a == true -> true // const 7 bits; var 8 bits
136
- new IRVar(0) // a == false -> whatever b is
137
- ))));
138
- hoisted_lazyOr.hash;
139
- const hoisted_lazyAnd = new IRHoisted(new IRFunc(2, // a, b
140
- new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRVar(1), // a
141
- new IRVar(0), // a == true -> whatever b is
142
- new IRDelayed(IRConst.bool(false)) // a == false -> false
143
- ))));
144
- hoisted_lazyAnd.hash;
145
- const hoisted_foldr = new IRHoisted(new IRFunc(2, // reduceFunc, accmulator
146
- _ir_apps(hoisted_recursiveList.clone(), new IRFunc(1, // _self
147
- new IRDelayed(new IRVar(1))), new IRFunc(3, // self, head, tail
148
- _ir_apps(new IRVar(4), // reduceFunc ( up to 2 are of callback, 3 is accum, 4 is reduce )
149
- new IRVar(1), // head
150
- // strictly evaluated
151
- // recursive call happens before this `reduce` call
152
- new IRApp(new IRVar(2), // self
153
- new IRVar(0) // tail
154
- ))))));
155
- hoisted_foldr.hash;
156
- const MAX_WORD4 = BigInt(1) << BigInt(32);
157
- const hoisted_sizeofPositiveInt = new IRHoisted(_ir_apps(new IRRecursive(// self
158
- new IRFunc(2, // count_words, n
159
- new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(0) // n
160
- ),
161
- // then n === 0
162
- new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(1) // count_words
163
- ),
164
- // then count_words === 0
165
- // at least one word is needed to represent 0, so we return 4 bytes (1 word)
166
- new IRDelayed(IRConst.int(4)),
167
- // else count_words > 0
168
- // return count_words * 4
169
- new IRDelayed(_ir_apps(IRNative.multiplyInteger, IRConst.int(4), new IRVar(1)))))),
170
- // else n > 0
171
- new IRDelayed(_ir_apps(new IRSelfCall(2), // self
172
- _ir_apps(hoisted_addOne.clone(), new IRVar(1) // count_words
173
- ), _ir_apps(IRNative.divideInteger, new IRVar(0), // n
174
- IRConst.int(MAX_WORD4)))))))), IRConst.int(0)));
97
+ const MAX_WORD4 = 0xFFFFFFFF;
98
+ // Added missing symbols & refactored hoisted_sizeofPositiveInt if previously numeric
99
+ const sizeof_self = Symbol("sizeofPositiveInt_self");
100
+ const sizeof_n = Symbol("n");
101
+ const sizeof_countWords = Symbol("count_words");
102
+ export const hoisted_sizeofPositiveInt = new IRHoisted(_ir_apps(new IRRecursive(sizeof_self, new IRFunc([sizeof_n, sizeof_countWords], new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(sizeof_n)), new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(sizeof_countWords)), new IRDelayed(IRConst.int(4)), new IRDelayed(_ir_apps(IRNative.multiplyInteger, IRConst.int(4), new IRVar(sizeof_countWords)))))), new IRDelayed(_ir_apps(new IRSelfCall(sizeof_self), _ir_apps(hoisted_addOne.clone(), new IRVar(sizeof_countWords)), _ir_apps(IRNative.divideInteger, new IRVar(sizeof_n), IRConst.int(MAX_WORD4)))))))), IRConst.int(0)));
103
+ const foldl_reduce = Symbol("reduceFunc");
104
+ const foldl_self = Symbol("foldl_self");
105
+ const foldl_acc = Symbol("accum");
106
+ const foldl_head = Symbol("head");
107
+ const foldl_tail = Symbol("tail");
108
+ const hoiseted_foldl = new IRHoisted(new IRFunc([foldl_reduce], new IRRecursive(foldl_self, new IRFunc([foldl_acc], _ir_apps(hoisted_matchList.clone(), new IRDelayed(new IRVar(foldl_acc)), new IRFunc([foldl_head, foldl_tail], _ir_apps(new IRSelfCall(foldl_self), _ir_apps(new IRVar(foldl_reduce), new IRVar(foldl_acc), new IRVar(foldl_head)), new IRVar(foldl_tail))))))));
109
+ hoiseted_foldl.hash;
110
+ // hoisted _findSopOptional
111
+ // (predicate: (a -> Bool)) -> (list: [a]) -> Optional<a>
112
+ const findSop_predicate = Symbol("predicate");
113
+ const findSop_self = Symbol("findOpt_self");
114
+ const findSop_list = Symbol("list");
115
+ const findSop_head = Symbol("head");
116
+ export const hoisted_findSopOptional = new IRHoisted(new IRFunc([findSop_predicate], new IRRecursive(findSop_self, new IRFunc([findSop_list], _ir_lazyChooseList(new IRVar(findSop_list),
117
+ // case nil
118
+ new IRConstr(1, []), // None
119
+ // case cons
120
+ new IRFunc([findSop_head], _ir_lazyIfThenElse(_ir_apps(new IRVar(findSop_predicate), new IRVar(findSop_head)),
121
+ // then => Some(head)
122
+ new IRConstr(1, [new IRVar(findSop_head)]), // Some{ head }
123
+ // else => self(tail)
124
+ _ir_apps(new IRSelfCall(findSop_self), _ir_apps(IRNative.tailList, new IRVar(findSop_list))))))))));
125
+ hoisted_findSopOptional.hash;
126
+ // hoisted _mkFindDataOptional
127
+ const mkFind_elemToData = Symbol("elemToData");
128
+ const mkFind_pred = Symbol("predicate");
129
+ const mkFind_self = Symbol("findOpt_self");
130
+ const mkFind_list = Symbol("list");
131
+ const mkFind_head = Symbol("head");
132
+ export const hoisted_mkFindDataOptional = new IRHoisted(new IRFunc([mkFind_elemToData, mkFind_pred], new IRRecursive(mkFind_self, new IRFunc([mkFind_list], new IRForced(_ir_apps(new IRApp(IRNative.strictChooseList, new IRVar(mkFind_list)), new IRDelayed(IRConst.data(new DataConstr(1, []))), new IRDelayed(new IRApp(new IRFunc([mkFind_head], new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRApp(new IRVar(mkFind_pred), new IRVar(mkFind_head)), new IRDelayed(_ir_apps(IRNative.constrData, IRConst.int(0), new IRApp(new IRVar(mkFind_elemToData), new IRVar(mkFind_head)))), new IRDelayed(new IRApp(new IRSelfCall(mkFind_self), new IRApp(IRNative.tailList, new IRVar(mkFind_list))))))), new IRApp(IRNative.headList, new IRVar(mkFind_list))))))))));
133
+ hoisted_mkFindDataOptional.hash;
134
+ // hoisted strictAnd / strictOr
135
+ const strictAnd_a = Symbol("a");
136
+ const strictAnd_b = Symbol("b");
137
+ export const hoisted_strictAnd = new IRHoisted(new IRFunc([strictAnd_a, strictAnd_b], _ir_apps(IRNative.strictIfThenElse, new IRVar(strictAnd_a), new IRVar(strictAnd_b), IRConst.bool(false))));
138
+ hoisted_strictAnd.hash;
139
+ const strictOr_a = Symbol("a");
140
+ const strictOr_b = Symbol("b");
141
+ export const hoisted_strictOr = new IRHoisted(new IRFunc([strictOr_a, strictOr_b], _ir_apps(IRNative.strictIfThenElse, new IRVar(strictOr_a), IRConst.bool(true), new IRVar(strictOr_b))));
142
+ hoisted_strictOr.hash;
143
+ // hoisted _some
144
+ const some_pred = Symbol("predicate");
145
+ const some_dummy = Symbol("_self");
146
+ const some_self = Symbol("self");
147
+ const some_head = Symbol("head");
148
+ const some_tail = Symbol("tail");
149
+ export const hoisted_some = new IRHoisted(new IRFunc([some_pred], _ir_apps(hoisted_recursiveList.clone(), new IRFunc([some_dummy], new IRDelayed(IRConst.bool(false))), new IRFunc([some_self, some_head, some_tail], new IRForced(_ir_apps(hoisted_strictOr.clone(), new IRDelayed(new IRApp(new IRVar(some_pred), new IRVar(some_head))), new IRDelayed(new IRApp(new IRVar(some_self), new IRVar(some_tail)))))))));
150
+ hoisted_some.hash;
151
+ // hoisted _every
152
+ const every_pred = Symbol("predicate");
153
+ const every_dummy = Symbol("_self");
154
+ const every_self = Symbol("self");
155
+ const every_head = Symbol("head");
156
+ const every_tail = Symbol("tail");
157
+ export const hoisted_every = new IRHoisted(new IRFunc([every_pred], _ir_apps(hoisted_recursiveList.clone(), new IRFunc([every_dummy], new IRDelayed(IRConst.bool(true))), new IRFunc([every_self, every_head, every_tail], new IRForced(_ir_apps(hoisted_strictAnd.clone(), new IRDelayed(new IRApp(new IRVar(every_pred), new IRVar(every_head))), new IRDelayed(new IRApp(new IRVar(every_self), new IRVar(every_tail)))))))));
158
+ hoisted_every.hash;
159
+ // hoisted _mkFilter
160
+ const filt_pnil = Symbol("pnilOfType");
161
+ const filt_pred = Symbol("predicate");
162
+ const filt_elem = Symbol("elem");
163
+ const filt_acc = Symbol("accum");
164
+ export const hoisted_mkFilter = new IRHoisted(new IRFunc([filt_pnil, filt_pred], _ir_apps(hoisted_foldr.clone(), new IRFunc([filt_elem, filt_acc], new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRApp(new IRVar(filt_pred), new IRVar(filt_elem)), new IRDelayed(_ir_apps(IRNative.mkCons, new IRVar(filt_elem), new IRVar(filt_acc))), new IRDelayed(new IRVar(filt_acc))))), new IRVar(filt_pnil))));
165
+ hoisted_mkFilter.hash;
166
+ // comparison & conversion hoisted (previously inline)
167
+ const gtbs_a = Symbol("a"), gtbs_b = Symbol("b");
168
+ export const hoisted_gtBS = new IRHoisted(new IRFunc([gtbs_a, gtbs_b], _ir_apps(IRNative.lessThanByteString, new IRVar(gtbs_b), new IRVar(gtbs_a))));
169
+ hoisted_gtBS.hash;
170
+ const gteqbs_a = Symbol("a"), gteqbs_b = Symbol("b");
171
+ export const hoisted_gtEqBS = new IRHoisted(new IRFunc([gteqbs_a, gteqbs_b], _ir_apps(IRNative.lessThanEqualsByteString, new IRVar(gteqbs_b), new IRVar(gteqbs_a))));
172
+ hoisted_gtEqBS.hash;
173
+ const gt_a = Symbol("a"), gt_b = Symbol("b");
174
+ export const hoisted_gtInt = new IRHoisted(new IRFunc([gt_a, gt_b], _ir_apps(IRNative.lessThanInteger, new IRVar(gt_b), new IRVar(gt_a))));
175
+ hoisted_gtInt.hash;
176
+ const gteq_a = Symbol("a"), gteq_b = Symbol("b");
177
+ export const hoisted_gtEqInt = new IRHoisted(new IRFunc([gteq_a, gteq_b], _ir_apps(IRNative.lessThanEqualInteger, new IRVar(gteq_b), new IRVar(gteq_a))));
178
+ hoisted_gtEqInt.hash;
179
+ const s2d_str = Symbol("str");
180
+ export const hoisted_strToData = new IRHoisted(new IRFunc([s2d_str], new IRApp(IRNative.bData, new IRApp(IRNative.encodeUtf8, new IRVar(s2d_str)))));
181
+ hoisted_strToData.hash;
182
+ const pdt_pair = Symbol("pair");
183
+ export const hoisted_pairDataToData = new IRHoisted(new IRFunc([pdt_pair], new IRApp(IRNative.listData, _ir_apps(IRNative.mkCons, new IRApp(IRNative.fstPair, new IRVar(pdt_pair)), _ir_apps(IRNative.mkCons, new IRApp(IRNative.sndPair, new IRVar(pdt_pair)), new IRApp(IRNative.mkNilData, IRConst.unit))))));
184
+ hoisted_pairDataToData.hash;
185
+ const dataStr = Symbol("data");
186
+ export const hoisted_strFromData = new IRHoisted(new IRFunc([dataStr], new IRApp(IRNative.decodeUtf8, new IRApp(IRNative.unBData, new IRVar(dataStr)))));
187
+ hoisted_strFromData.hash;
188
+ const pdfd_data = Symbol("data");
189
+ const pdfd_unlisted = Symbol("unlisted_data");
190
+ export const hoisted_pairDataFromData = new IRHoisted(new IRFunc([pdfd_data], new IRApp(new IRFunc([pdfd_unlisted], _ir_apps(IRNative.mkPairData, new IRApp(IRNative.headList, new IRVar(pdfd_unlisted)), new IRApp(IRNative.headList, new IRApp(IRNative.tailList, new IRVar(pdfd_unlisted))))), new IRApp(IRNative.unListData, new IRVar(pdfd_data)))));
191
+ hoisted_pairDataFromData.hash;
192
+ const boolSym = Symbol("bool");
193
+ export const hoisted_boolToInt = new IRHoisted(new IRFunc([boolSym], _ir_apps(IRNative.strictIfThenElse, new IRVar(boolSym), IRConst.int(1), IRConst.int(0))));
194
+ hoisted_boolToInt.hash;
195
+ const intSym = Symbol("int");
196
+ export const hoisted_intToBytesBE = new IRHoisted(new IRFunc([intSym], _ir_apps(IRNative.integerToByteString, IRConst.bool(true), _ir_apps(hoisted_sizeofPositiveInt.clone(), new IRVar(intSym)), new IRVar(intSym))));
197
+ hoisted_intToBytesBE.hash;
198
+ // hoisted exponentiateInteger
199
+ const baseSym = Symbol("base");
200
+ const expSym = Symbol("exponent");
201
+ const exp_self = Symbol("expInt_self");
202
+ const nSym = Symbol("n");
203
+ const xSym = Symbol("x");
204
+ export const hoisted_exponentiateInteger = new IRHoisted(new IRFunc([baseSym, expSym], new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isNonNegative.clone(), new IRVar(expSym)), new IRDelayed(new IRRecursive(exp_self, new IRFunc([nSym, xSym], new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(nSym)), new IRDelayed(IRConst.int(1)), new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isOne.clone(), new IRVar(nSym)), new IRDelayed(new IRVar(xSym)), new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), _ir_apps(IRNative.modInteger, new IRVar(nSym), IRConst.int(2))), new IRDelayed(_ir_let(_ir_apps(new IRSelfCall(exp_self), new IRVar(xSym), _ir_apps(IRNative.divideInteger, new IRVar(nSym), IRConst.int(2))), halfSym => _ir_apps(IRNative.multiplyInteger, new IRVar(halfSym), new IRVar(halfSym)))), new IRDelayed(_ir_apps(IRNative.multiplyInteger, new IRVar(xSym), _ir_apps(new IRSelfCall(exp_self), new IRVar(xSym), _ir_apps(hoisted_subOne.clone(), new IRVar(nSym)))))))))))))))), new IRDelayed(new IRError())))));
205
+ hoisted_exponentiateInteger.hash;
206
+ // already external: hoiseted_foldl
175
207
  export function nativeToIR(native) {
176
208
  // positive natives are translated to uplc builtins (no need to hoist)
177
209
  if (native.tag >= 0)
178
210
  return native;
179
211
  switch (native.tag) {
180
- case IRNativeTag._foldr:
181
- return hoisted_foldr.clone();
182
- break;
183
- case IRNativeTag._foldl:
184
- return new IRHoisted(new IRFunc(1, // reduceFunc (4)
185
- new IRRecursive(// self (3)
186
- new IRFunc(1, // accum (2)
187
- _ir_apps(hoisted_matchList.clone(), new IRDelayed(new IRVar(0)), // pdelay( accum )
188
- new IRFunc(2, // head (1), tail (0)
189
- _ir_apps(new IRSelfCall(3), // self
190
- // compute new accumoulator before proceeding
191
- _ir_apps(new IRVar(4), // reduceFunc
192
- new IRVar(2), // accum
193
- new IRVar(1)), new IRVar(0) // tail
194
- )))))));
195
- break;
196
- case IRNativeTag._mkFindDataOptional:
197
- return new IRHoisted(new IRFunc(2, // elemToData (4), predicate (3)
198
- new IRRecursive(// self (2)
199
- new IRFunc(1, // list (1)
200
- new IRForced(_ir_apps(new IRApp(IRNative.strictChooseList, new IRVar(0) // list
201
- ),
202
- // then (caseNil)
203
- // Nothing data
204
- new IRDelayed(IRConst.data(new DataConstr(1, []) // Nothing is the second contructor
205
- )),
206
- // else // caseCons
207
- new IRDelayed(new IRApp(new IRFunc(1, // head (0) (pletted)
208
- new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRApp(new IRVar(3), // predicate
209
- new IRVar(0) // head
210
- ),
211
- // then
212
- new IRDelayed(_ir_apps(IRNative.constrData, IRConst.int(0), // just contructor
213
- new IRApp(new IRVar(4), // elemToData
214
- new IRVar(0) // head
215
- ))),
216
- // else
217
- new IRDelayed(new IRApp(new IRSelfCall(2), // self
218
- new IRApp(IRNative.tailList, new IRVar(1) // list
219
- )))))), new IRApp(IRNative.headList, new IRVar(0) // list
220
- )))))))));
221
- break;
222
- case IRNativeTag._length:
223
- return new IRHoisted(new IRRecursive(// self
224
- new IRFunc(1, // list
225
- new IRForced(_ir_apps(new IRApp(IRNative.strictChooseList, new IRVar(0) // list
226
- ),
227
- // then
228
- IRConst.int(0),
229
- // else
230
- _ir_apps(hoisted_incr.clone(), new IRApp(new IRSelfCall(1), // self
231
- new IRApp(// list.tail
232
- IRNative.tailList, new IRVar(0) // list
233
- ))))))));
234
- break;
235
- case IRNativeTag._some:
236
- return new IRHoisted(new IRFunc(1, // predicate
237
- _ir_apps(hoisted_recursiveList.clone(), new IRFunc(1, // _self
238
- new IRDelayed(// pdelay( pBool( true ) )
239
- IRConst.bool(false))), new IRFunc(3, // self, head, tail
240
- _ir_apps(hoisted_lazyOr.clone(), // lazy in second
241
- new IRApp(new IRVar(3), // predicate ( 0, 1, 2 are of callback, 3 is predicate )
242
- new IRVar(1)), new IRDelayed(new IRApp(new IRVar(2), // self
243
- new IRVar(0) // tail
244
- )))))));
245
- break;
246
- case IRNativeTag._every:
247
- return new IRHoisted(new IRFunc(1, // predicate
248
- _ir_apps(hoisted_recursiveList.clone(), new IRFunc(1, // _self
249
- new IRDelayed(// pdelay( pBool( true ) )
250
- IRConst.bool(true))), new IRFunc(3, // self, head, tail
251
- _ir_apps(hoisted_lazyAnd.clone(), // lazy in second
252
- new IRApp(new IRVar(3), // predicate ( 0, 1, 2 are of callback, 3 is predicate )
253
- new IRVar(1)), new IRDelayed(new IRApp(new IRVar(2), // self
254
- new IRVar(0) // tail
255
- )))))));
256
- break;
257
- case IRNativeTag._mkFilter:
258
- return new IRHoisted(new IRFunc(2, // pnilOfType, predicate
259
- _ir_apps(hoisted_foldr.clone(), new IRFunc(2, // elem, accum
260
- new IRForced(_ir_apps(IRNative.strictIfThenElse, new IRApp(new IRVar(2), // predicate
261
- new IRVar(1) // elem
262
- ),
263
- // then
264
- new IRDelayed(_ir_apps(IRNative.mkCons, new IRVar(1), // elem
265
- new IRVar(0) // accum
266
- )),
267
- // else
268
- // filter out this element
269
- new IRDelayed(new IRVar(0) // accum
270
- )))),
271
- // initial accum
272
- new IRVar(3) // pnilOfType
273
- )));
274
- break;
275
- // case IRNativeTag._fstPair :
276
- // return new IRHoisted();
277
- // break;
278
- // case IRNativeTag._sndPair :
279
- // return new IRHoisted();
280
- // break;
281
- case IRNativeTag._id:
282
- return hoisted_id.clone();
283
- break;
284
- case IRNativeTag._not:
285
- return hoisted_not.clone();
286
- break;
287
- case IRNativeTag._strictAnd:
288
- return new IRHoisted(new IRFunc(2, // a, b
289
- _ir_apps(IRNative.strictIfThenElse, new IRVar(1), // a
290
- new IRVar(0), // a == true -> whatever b is
291
- IRConst.bool(false) // a == false -> false
292
- )));
293
- break;
294
- case IRNativeTag._and:
295
- return hoisted_lazyAnd.clone();
296
- break;
297
- case IRNativeTag._strictOr:
298
- return new IRHoisted(new IRFunc(2, // a, b
299
- _ir_apps(IRNative.strictIfThenElse, new IRVar(1), // a
300
- IRConst.bool(true), // a == true -> true
301
- new IRVar(0) // a == false -> whatever b is
302
- )));
303
- break;
304
- case IRNativeTag._or:
305
- return hoisted_lazyOr.clone();
306
- break;
307
- case IRNativeTag._gtBS:
308
- return new IRHoisted(new IRFunc(2, // a, b
309
- _ir_apps(IRNative.lessThanByteString, new IRVar(0), // b
310
- new IRVar(1))));
311
- break;
312
- case IRNativeTag._gtEqBS:
313
- return new IRHoisted(new IRFunc(2, // a, b
314
- _ir_apps(IRNative.lessThanEqualsByteString, new IRVar(0), // b
315
- new IRVar(1))));
316
- break;
317
- case IRNativeTag._gtInt:
318
- return new IRHoisted(new IRFunc(2, // a, b
319
- _ir_apps(IRNative.lessThanInteger, new IRVar(0), // b
320
- new IRVar(1))));
321
- break;
322
- case IRNativeTag._gtEqInt:
323
- return new IRHoisted(new IRFunc(2, // a, b
324
- _ir_apps(IRNative.lessThanEqualInteger, new IRVar(0), // b
325
- new IRVar(1))));
326
- break;
327
- case IRNativeTag._strToData:
328
- return new IRHoisted(new IRFunc(1, // str
329
- new IRApp(IRNative.bData, new IRApp(IRNative.encodeUtf8, new IRVar(0) // str
330
- ))));
331
- break;
332
- case IRNativeTag._pairDataToData:
333
- return new IRHoisted(new IRFunc(1, // pair
334
- new IRApp(IRNative.listData, _ir_apps(IRNative.mkCons, new IRApp(IRNative.fstPair, new IRVar(0)), _ir_apps(IRNative.mkCons, new IRApp(IRNative.sndPair, new IRVar(0)), new IRApp(IRNative.mkNilData, IRConst.unit))))));
335
- break;
336
- case IRNativeTag._strFromData:
337
- return new IRHoisted(new IRFunc(1, // data
338
- new IRApp(IRNative.decodeUtf8, new IRApp(IRNative.unBData, new IRVar(0) // data
339
- ))));
340
- break;
341
- case IRNativeTag._pairDataFromData:
342
- return new IRHoisted(new IRFunc(1, // data
343
- new IRApp(new IRFunc(1, // unlisted_data
344
- _ir_apps(IRNative.mkPairData, new IRApp(IRNative.headList, new IRVar(0) // unlised_data
345
- ), new IRApp(IRNative.headList, new IRApp(IRNative.tailList, new IRVar(0) // unlised_data
346
- )))), new IRApp(IRNative.unListData, new IRVar(0) // data
347
- ))));
348
- break;
349
- case IRNativeTag._mkMapList:
350
- {
351
- return new IRHoisted(new IRFunc(2, // nilListOfType, mapFn
352
- new IRRecursive(// self
353
- new IRFunc(1, // lst
354
- new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(0), // lst
355
- // case Nil
356
- new IRDelayed(new IRVar(3)), // delay( nilListOfType )
357
- // case Cons
358
- new IRDelayed(_ir_apps(IRNative.mkCons, _ir_apps(new IRVar(2), // mapFn
359
- _ir_apps(IRNative.headList, new IRVar(0) // lst
360
- )), _ir_apps(new IRSelfCall(1), // self
361
- _ir_apps(IRNative.tailList, new IRVar(0) // lst
362
- ))))))))));
363
- }
364
- break;
365
- case IRNativeTag._equalBoolean:
366
- {
367
- return new IRHoisted(new IRFunc(1, _ir_apps(IRNative.strictIfThenElse, new IRVar(0), // a
368
- hoisted_id.clone(), // a == true -> true
369
- hoisted_not.clone() // a == false -> b ? false : true
370
- )));
371
- }
372
- break;
373
- case IRNativeTag._negateInt:
374
- {
375
- return new IRHoisted(_ir_apps(IRNative.subtractInteger, IRConst.int(0)));
376
- }
377
- break;
378
- case IRNativeTag._bytesToIntBE:
379
- {
380
- return new IRHoisted(_ir_apps(IRNative.byteStringToInteger, IRConst.bool(true) // big endian
381
- ));
382
- }
383
- break;
384
- case IRNativeTag._boolToInt:
385
- {
386
- return new IRHoisted(new IRFunc(1, // bool
387
- _ir_apps(IRNative.strictIfThenElse, new IRVar(0), // bool
388
- IRConst.int(1), // b == true -> 1
389
- IRConst.int(0) // b == false -> 0
390
- )));
391
- }
392
- break;
393
- case IRNativeTag._intToBytesBE:
394
- {
395
- return new IRHoisted(new IRFunc(1, // int
396
- _ir_apps(IRNative.integerToByteString, IRConst.bool(true), // big endian
397
- _ir_apps(// int size
398
- hoisted_sizeofPositiveInt.clone(),
399
- // integerToByteString fails for negative integers
400
- // so we don't bother converting negative to positive here
401
- new IRVar(0) // int
402
- ), new IRVar(0) // int
403
- )));
404
- }
405
- break;
406
- case IRNativeTag._intToBool:
407
- {
408
- return hoisted_isNonNegative.clone();
409
- }
410
- break;
411
- case IRNativeTag._exponentiateInteger:
412
- {
413
- return new IRHoisted(new IRFunc(2, // base, exponent
414
- new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isNonNegative.clone(), new IRVar(0) // exponent
415
- ),
416
- // then, normal exponentiation
417
- new IRDelayed(new IRRecursive(new IRFunc(2, // expInt, x, n
418
- new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), new IRVar(0) // n
419
- ),
420
- // then (n == 0)
421
- // yes, even `0 ** 0` is 1
422
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation#description
423
- new IRDelayed(IRConst.int(1)), // return 1
424
- // else (n > 0)
425
- new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isOne.clone(), new IRVar(0) // n
426
- ),
427
- // then (n == 1)
428
- new IRDelayed(new IRVar(1)), // return x
429
- // else (n > 1)
430
- new IRDelayed(new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(hoisted_isZero.clone(), _ir_apps(IRNative.modInteger, new IRVar(0), // exponent
431
- IRConst.int(2))),
432
- // then (exponent % 2 == 0)
433
- new IRDelayed(_ir_let(_ir_apps(new IRSelfCall(2), // expInt
434
- new IRVar(1), // x
435
- _ir_apps(IRNative.divideInteger, new IRVar(0), // exponent
436
- IRConst.int(2))), // half
437
- _ir_apps(IRNative.multiplyInteger, new IRVar(0), // half
438
- new IRVar(0) // half
439
- ))),
440
- // else (exponent % 2 == 1)
441
- new IRDelayed(_ir_apps(// x * expInt( x, n - 1 )
442
- IRNative.multiplyInteger, new IRVar(1), // x
443
- _ir_apps(new IRSelfCall(2), // expInt
444
- new IRVar(1), // x
445
- _ir_apps(hoisted_subOne.clone(), new IRVar(0)))))))))))))))),
446
- // else (exponent < 0) fails
447
- new IRDelayed(new IRError())))));
448
- }
449
- break;
450
- case IRNativeTag._amountOfValue:
451
- {
452
- // ((policy => bool), value, (tokenName => bool)) => amount
453
- return hoisted_amountOfValue.clone();
454
- }
455
- break;
456
- case IRNativeTag._isZero:
457
- {
458
- return hoisted_isZero.clone();
459
- }
460
- break;
461
- case IRNativeTag._sortedValueLovelaces:
462
- {
463
- return new IRHoisted(new IRFunc(1, // value
464
- _ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, _ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, new IRVar(0) // value
465
- ))))))));
466
- }
467
- break;
468
- case IRNativeTag._dropList:
469
- {
470
- return hoisted_dropList.clone();
471
- }
472
- break;
473
- default: throw new Error("unknown (negative) native calling 'nativeToIR'; " +
474
- "number: " + native.tag + "; " +
475
- "name: " + IRNativeTag[native.tag]);
212
+ case IRNativeTag._foldr: return hoisted_foldr.clone();
213
+ case IRNativeTag._foldl: return hoiseted_foldl.clone();
214
+ case IRNativeTag._mkFindDataOptional: return hoisted_mkFindDataOptional.clone();
215
+ case IRNativeTag._findSopOptional: return hoisted_findSopOptional.clone();
216
+ case IRNativeTag._length: return hoisted_length.clone();
217
+ case IRNativeTag._some: return hoisted_some.clone();
218
+ case IRNativeTag._every: return hoisted_every.clone();
219
+ case IRNativeTag._mkFilter: return hoisted_mkFilter.clone();
220
+ case IRNativeTag._id: return hoisted_id.clone();
221
+ case IRNativeTag._not: return hoisted_not.clone();
222
+ case IRNativeTag._strictAnd: return hoisted_strictAnd.clone();
223
+ case IRNativeTag._strictOr: return hoisted_strictOr.clone();
224
+ case IRNativeTag._gtBS: return hoisted_gtBS.clone();
225
+ case IRNativeTag._gtEqBS: return hoisted_gtEqBS.clone();
226
+ case IRNativeTag._gtInt: return hoisted_gtInt.clone();
227
+ case IRNativeTag._gtEqInt: return hoisted_gtEqInt.clone();
228
+ case IRNativeTag._strToData: return hoisted_strToData.clone();
229
+ case IRNativeTag._pairDataToData: return hoisted_pairDataToData.clone();
230
+ case IRNativeTag._strFromData: return hoisted_strFromData.clone();
231
+ case IRNativeTag._pairDataFromData: return hoisted_pairDataFromData.clone();
232
+ case IRNativeTag._boolToInt: return hoisted_boolToInt.clone();
233
+ case IRNativeTag._intToBytesBE: return hoisted_intToBytesBE.clone();
234
+ case IRNativeTag._intToBool: return hoisted_isNonNegative.clone();
235
+ case IRNativeTag._exponentiateInteger: return hoisted_exponentiateInteger.clone();
236
+ case IRNativeTag._amountOfValue: return hoisted_amountOfValue.clone();
237
+ case IRNativeTag._isZero: return hoisted_isZero.clone();
238
+ case IRNativeTag._sortedValueLovelaces: return hoisted_sortedValueLovelaces.clone();
239
+ case IRNativeTag._getCredentialsHash: return hoisted_getCredentialsHash.clone();
240
+ case IRNativeTag._dropList: return hoisted_dropList.clone();
241
+ case IRNativeTag._mkMapList: return hoisted_mkMapList.clone();
242
+ // case IRNativeTag._mkEqualsList: return hoisted_mkEqualsList.clone();
243
+ default:
244
+ throw new Error("unknown (negative) native calling 'nativeToIR'; " +
245
+ "number: " + native.tag + "; name: " + IRNativeTag[native.tag]);
476
246
  }
477
247
  }
248
+ // ( a => b => bool ) => [a] => [b] => bool
249
+ const eqList_eqFunc = Symbol("elemEq");
250
+ const eqList_self = Symbol("eqList_self");
251
+ const eqList_listA = Symbol("listA");
252
+ const eqList_listB = Symbol("listB");
253
+ export const hoisted_mkEqualsList = new IRHoisted(new IRFunc([eqList_eqFunc], new IRRecursive(eqList_self, new IRFunc([eqList_listA, eqList_listB], _ir_lazyChooseList(new IRVar(eqList_listA),
254
+ // case nil: check if listB is also nil
255
+ _ir_apps(IRNative.nullList, new IRVar(eqList_listB)),
256
+ // case cons
257
+ _ir_lazyChooseList(new IRVar(eqList_listB),
258
+ // listB is nil => false
259
+ IRConst.bool(false),
260
+ // both lists are cons
261
+ _ir_strictAnd(_ir_apps(new IRVar(eqList_eqFunc), new IRApp(IRNative.headList, new IRVar(eqList_listA)), new IRApp(IRNative.headList, new IRVar(eqList_listB))), _ir_apps(new IRSelfCall(eqList_self), new IRApp(IRNative.tailList, new IRVar(eqList_listA)), new IRApp(IRNative.tailList, new IRVar(eqList_listB))))))))));
262
+ hoisted_mkEqualsList.hash;
263
+ // (nil of type) => ( a => b ) => [a] => [b]
264
+ const mkMap_nil = Symbol("nilOfType");
265
+ const mkMap_mapFunc = Symbol("mapFunc");
266
+ const mkMap_map = Symbol("map_self");
267
+ const mkMap_list = Symbol("list");
268
+ export const hoisted_mkMapList = new IRHoisted(new IRFunc([mkMap_nil, mkMap_mapFunc], new IRRecursive(mkMap_map, new IRFunc([mkMap_list], _ir_lazyChooseList(new IRVar(mkMap_list),
269
+ // case nil: return nil of type
270
+ new IRVar(mkMap_nil),
271
+ // case cons
272
+ _ir_apps(IRNative.mkCons,
273
+ // mapFunc( head list )
274
+ _ir_apps(new IRVar(mkMap_mapFunc), new IRApp(IRNative.headList, new IRVar(mkMap_list))),
275
+ // recurse tail
276
+ _ir_apps(new IRSelfCall(mkMap_map), new IRApp(IRNative.tailList, new IRVar(mkMap_list)))))))));
277
+ hoisted_mkMapList.hash;
278
+ const credHash_credentials = Symbol("credentials");
279
+ export const hoisted_getCredentialsHash = new IRHoisted(new IRFunc([credHash_credentials], _ir_apps(IRNative.unBData, _ir_apps(IRNative.headList, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.unConstrData, new IRVar(credHash_credentials)))))));
280
+ hoisted_getCredentialsHash.hash;
281
+ // If _sortedValueLovelaces was previously inline, hoist it:
282
+ const sorted_value = Symbol("value");
283
+ export const hoisted_sortedValueLovelaces = new IRHoisted(new IRFunc([sorted_value], _ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, _ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, _ir_apps(IRNative.headList, new IRVar(sorted_value)))))))));
284
+ hoisted_sortedValueLovelaces.hash;
478
285
  // ((policy => bool), value, (tokenName => bool)) => amount
479
- const hoisted_amountOfValue = new IRHoisted(new IRFunc(1, // 0: isPolicy
480
- new IRRecursive(// 1: isPolicy, 0: policyLoop
481
- new IRFunc(1, // 2: isPolicy, 1: policyLoop, 0: value
482
- new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(0), // value
483
- // case nil
484
- new IRDelayed(new IRFunc(1, IRConst.int(0)) // isTokenName => 0
485
- ),
286
+ // REPLACED hoisted_amountOfValue (symbol-based)
287
+ const amount_isPolicy = Symbol("isPolicy");
288
+ const amount_policyLoop = Symbol("policyLoop_self");
289
+ const amount_value = Symbol("value");
290
+ const amount_isTokenName = Symbol("isTokenName");
291
+ const amount_tokenNameLoop = Symbol("tokenNameLoop_self");
292
+ const amount_tokenMap = Symbol("tokenMap");
293
+ export const hoisted_amountOfValue = new IRHoisted(new IRFunc([amount_isPolicy], // (policy => bool)
294
+ new IRRecursive(amount_policyLoop, new IRFunc([amount_value], // value
295
+ new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(amount_value),
296
+ // case nil: return (tokenName => 0)
297
+ new IRDelayed(new IRFunc([amount_isTokenName], IRConst.int(0))),
486
298
  // case cons
487
- new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(0) // value
488
- ), // 3: isPolicy, 2: policyLoop, 1: value, 0: pairData
489
- new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(// isPolicy( pairData.fst as bytes )
490
- new IRVar(3), // isPolicy
491
- _ir_apps(IRNative.unBData, _ir_apps(IRNative.fstPair, new IRVar(0) // pairData
492
- ))),
493
- // then this is the policy
494
- new IRDelayed(new IRFunc(1, // 4: isPolicy, 3: policyLoop, 2: value, 1: pairData, 0: isTokenName
495
- _ir_apps(new IRRecursive(new IRFunc(1, // 6: isPolicy, 5: policyLoop, 4: value, 3: pairData, 2: isTokenName, 1: tokenNameLoop, 0: tokenMap
496
- new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(0), // tokenMap
497
- // case nil
299
+ new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(amount_value)), pairDataSym => new IRForced(_ir_apps(IRNative.strictIfThenElse,
300
+ // isPolicy( fst pairData as bytes )
301
+ _ir_apps(new IRVar(amount_isPolicy), _ir_apps(IRNative.unBData, _ir_apps(IRNative.fstPair, new IRVar(pairDataSym)))),
302
+ // then: build (tokenName => amount)
303
+ new IRDelayed(new IRFunc([amount_isTokenName], _ir_apps(new IRRecursive(amount_tokenNameLoop, new IRFunc([amount_tokenMap], new IRForced(_ir_apps(IRNative.strictChooseList, new IRVar(amount_tokenMap),
304
+ // token map empty => 0
498
305
  new IRDelayed(IRConst.int(0)),
499
- // case cons
500
- new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(0) // tokenMap
501
- ), // 7: isPolicy, 6: policyLoop, 5: value, 4: pairData, 3: isTokenName, 2: tokenNameLoop, 1: tokenMap, 0: pairDataToken
502
- new IRForced(_ir_apps(IRNative.strictIfThenElse, _ir_apps(// isTokenName( pairDataToken.fst as bytes )
503
- new IRVar(3), // isTokenName
504
- _ir_apps(IRNative.unBData, _ir_apps(IRNative.fstPair, new IRVar(0) // pairDataToken
505
- )),
506
- // then return amount
507
- new IRDelayed(_ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, new IRVar(0) // pairDataToken
508
- ))),
509
- // else check next token entry
510
- new IRDelayed(_ir_apps(new IRSelfCall(2), // tokenNameLoop
511
- _ir_apps(IRNative.tailList, new IRVar(1) // tokenMap
306
+ // token map cons
307
+ new IRDelayed(_ir_let(_ir_apps(IRNative.headList, new IRVar(amount_tokenMap)), pairDataTokenSym => new IRForced(_ir_apps(IRNative.strictIfThenElse,
308
+ // isTokenName( fst pairDataToken as bytes )
309
+ _ir_apps(new IRVar(amount_isTokenName), _ir_apps(IRNative.unBData, _ir_apps(IRNative.fstPair, new IRVar(pairDataTokenSym))),
310
+ // then: return amount
311
+ new IRDelayed(_ir_apps(IRNative.unIData, _ir_apps(IRNative.sndPair, new IRVar(pairDataTokenSym)))),
312
+ // else: recurse tail
313
+ new IRDelayed(_ir_apps(new IRSelfCall(amount_tokenNameLoop), _ir_apps(IRNative.tailList, new IRVar(amount_tokenMap) // tokenMap list
512
314
  )))))))))))),
513
- // tokenMap
514
- _ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, new IRVar(0) // pairData
515
- ))))),
516
- // else check next
517
- new IRDelayed(_ir_apps(new IRSelfCall(2), // policyLoop
518
- _ir_apps(IRNative.tailList, new IRVar(1) // value
519
- )))))))))))));
315
+ // pass token map (snd pairData)
316
+ _ir_apps(IRNative.unMapData, _ir_apps(IRNative.sndPair, new IRVar(pairDataSym)))))),
317
+ // else: recurse policyLoop on tail value list
318
+ new IRDelayed(_ir_apps(new IRSelfCall(amount_policyLoop), _ir_apps(IRNative.tailList, new IRVar(amount_value))))))))))))));
520
319
  hoisted_amountOfValue.hash;