@elaraai/east 0.0.1-beta.0

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 (251) hide show
  1. package/LICENSE.md +682 -0
  2. package/README.md +276 -0
  3. package/dist/src/analyze.d.ts +95 -0
  4. package/dist/src/analyze.d.ts.map +1 -0
  5. package/dist/src/analyze.js +1110 -0
  6. package/dist/src/analyze.js.map +1 -0
  7. package/dist/src/ast.d.ts +263 -0
  8. package/dist/src/ast.d.ts.map +1 -0
  9. package/dist/src/ast.js +151 -0
  10. package/dist/src/ast.js.map +1 -0
  11. package/dist/src/ast_to_ir.d.ts +24 -0
  12. package/dist/src/ast_to_ir.d.ts.map +1 -0
  13. package/dist/src/ast_to_ir.js +834 -0
  14. package/dist/src/ast_to_ir.js.map +1 -0
  15. package/dist/src/builtins.d.ts +18 -0
  16. package/dist/src/builtins.d.ts.map +1 -0
  17. package/dist/src/builtins.js +1105 -0
  18. package/dist/src/builtins.js.map +1 -0
  19. package/dist/src/comparison.d.ts +28 -0
  20. package/dist/src/comparison.d.ts.map +1 -0
  21. package/dist/src/comparison.js +1017 -0
  22. package/dist/src/comparison.js.map +1 -0
  23. package/dist/src/compile.d.ts +22 -0
  24. package/dist/src/compile.d.ts.map +1 -0
  25. package/dist/src/compile.js +3260 -0
  26. package/dist/src/compile.js.map +1 -0
  27. package/dist/src/containers/ref.d.ts +106 -0
  28. package/dist/src/containers/ref.d.ts.map +1 -0
  29. package/dist/src/containers/ref.js +100 -0
  30. package/dist/src/containers/ref.js.map +1 -0
  31. package/dist/src/containers/sortedmap.d.ts +165 -0
  32. package/dist/src/containers/sortedmap.d.ts.map +1 -0
  33. package/dist/src/containers/sortedmap.js +237 -0
  34. package/dist/src/containers/sortedmap.js.map +1 -0
  35. package/dist/src/containers/sortedset.d.ts +185 -0
  36. package/dist/src/containers/sortedset.d.ts.map +1 -0
  37. package/dist/src/containers/sortedset.js +312 -0
  38. package/dist/src/containers/sortedset.js.map +1 -0
  39. package/dist/src/containers/variant.d.ts +131 -0
  40. package/dist/src/containers/variant.d.ts.map +1 -0
  41. package/dist/src/containers/variant.js +68 -0
  42. package/dist/src/containers/variant.js.map +1 -0
  43. package/dist/src/datetime_format/parse.d.ts +50 -0
  44. package/dist/src/datetime_format/parse.d.ts.map +1 -0
  45. package/dist/src/datetime_format/parse.js +908 -0
  46. package/dist/src/datetime_format/parse.js.map +1 -0
  47. package/dist/src/datetime_format/print.d.ts +35 -0
  48. package/dist/src/datetime_format/print.d.ts.map +1 -0
  49. package/dist/src/datetime_format/print.js +157 -0
  50. package/dist/src/datetime_format/print.js.map +1 -0
  51. package/dist/src/datetime_format/tokenize.d.ts +76 -0
  52. package/dist/src/datetime_format/tokenize.d.ts.map +1 -0
  53. package/dist/src/datetime_format/tokenize.js +271 -0
  54. package/dist/src/datetime_format/tokenize.js.map +1 -0
  55. package/dist/src/datetime_format/types.d.ts +99 -0
  56. package/dist/src/datetime_format/types.d.ts.map +1 -0
  57. package/dist/src/datetime_format/types.js +103 -0
  58. package/dist/src/datetime_format/types.js.map +1 -0
  59. package/dist/src/datetime_format/validate.d.ts +51 -0
  60. package/dist/src/datetime_format/validate.d.ts.map +1 -0
  61. package/dist/src/datetime_format/validate.js +208 -0
  62. package/dist/src/datetime_format/validate.js.map +1 -0
  63. package/dist/src/default.d.ts +21 -0
  64. package/dist/src/default.d.ts.map +1 -0
  65. package/dist/src/default.js +82 -0
  66. package/dist/src/default.js.map +1 -0
  67. package/dist/src/eastir.d.ts +33 -0
  68. package/dist/src/eastir.d.ts.map +1 -0
  69. package/dist/src/eastir.js +92 -0
  70. package/dist/src/eastir.js.map +1 -0
  71. package/dist/src/error.d.ts +13 -0
  72. package/dist/src/error.d.ts.map +1 -0
  73. package/dist/src/error.js +8 -0
  74. package/dist/src/error.js.map +1 -0
  75. package/dist/src/expr/array.d.ts +1711 -0
  76. package/dist/src/expr/array.d.ts.map +1 -0
  77. package/dist/src/expr/array.js +1805 -0
  78. package/dist/src/expr/array.js.map +1 -0
  79. package/dist/src/expr/ast.d.ts +17 -0
  80. package/dist/src/expr/ast.d.ts.map +1 -0
  81. package/dist/src/expr/ast.js +302 -0
  82. package/dist/src/expr/ast.js.map +1 -0
  83. package/dist/src/expr/blob.d.ts +141 -0
  84. package/dist/src/expr/blob.d.ts.map +1 -0
  85. package/dist/src/expr/blob.js +198 -0
  86. package/dist/src/expr/blob.js.map +1 -0
  87. package/dist/src/expr/block.d.ts +201 -0
  88. package/dist/src/expr/block.d.ts.map +1 -0
  89. package/dist/src/expr/block.js +1505 -0
  90. package/dist/src/expr/block.js.map +1 -0
  91. package/dist/src/expr/boolean.d.ts +207 -0
  92. package/dist/src/expr/boolean.d.ts.map +1 -0
  93. package/dist/src/expr/boolean.js +261 -0
  94. package/dist/src/expr/boolean.js.map +1 -0
  95. package/dist/src/expr/datetime.d.ts +544 -0
  96. package/dist/src/expr/datetime.d.ts.map +1 -0
  97. package/dist/src/expr/datetime.js +980 -0
  98. package/dist/src/expr/datetime.js.map +1 -0
  99. package/dist/src/expr/dict.d.ts +1242 -0
  100. package/dist/src/expr/dict.d.ts.map +1 -0
  101. package/dist/src/expr/dict.js +1492 -0
  102. package/dist/src/expr/dict.js.map +1 -0
  103. package/dist/src/expr/expr.d.ts +95 -0
  104. package/dist/src/expr/expr.d.ts.map +1 -0
  105. package/dist/src/expr/expr.js +171 -0
  106. package/dist/src/expr/expr.js.map +1 -0
  107. package/dist/src/expr/float.d.ts +357 -0
  108. package/dist/src/expr/float.d.ts.map +1 -0
  109. package/dist/src/expr/float.js +637 -0
  110. package/dist/src/expr/float.js.map +1 -0
  111. package/dist/src/expr/function.d.ts +46 -0
  112. package/dist/src/expr/function.d.ts.map +1 -0
  113. package/dist/src/expr/function.js +58 -0
  114. package/dist/src/expr/function.js.map +1 -0
  115. package/dist/src/expr/index.d.ts +450 -0
  116. package/dist/src/expr/index.d.ts.map +1 -0
  117. package/dist/src/expr/index.js +423 -0
  118. package/dist/src/expr/index.js.map +1 -0
  119. package/dist/src/expr/integer.d.ts +256 -0
  120. package/dist/src/expr/integer.d.ts.map +1 -0
  121. package/dist/src/expr/integer.js +311 -0
  122. package/dist/src/expr/integer.js.map +1 -0
  123. package/dist/src/expr/libs/array.d.ts +106 -0
  124. package/dist/src/expr/libs/array.d.ts.map +1 -0
  125. package/dist/src/expr/libs/array.js +140 -0
  126. package/dist/src/expr/libs/array.js.map +1 -0
  127. package/dist/src/expr/libs/blob.d.ts +42 -0
  128. package/dist/src/expr/libs/blob.d.ts.map +1 -0
  129. package/dist/src/expr/libs/blob.js +70 -0
  130. package/dist/src/expr/libs/blob.js.map +1 -0
  131. package/dist/src/expr/libs/datetime.d.ts +479 -0
  132. package/dist/src/expr/libs/datetime.d.ts.map +1 -0
  133. package/dist/src/expr/libs/datetime.js +624 -0
  134. package/dist/src/expr/libs/datetime.js.map +1 -0
  135. package/dist/src/expr/libs/dict.d.ts +66 -0
  136. package/dist/src/expr/libs/dict.d.ts.map +1 -0
  137. package/dist/src/expr/libs/dict.js +77 -0
  138. package/dist/src/expr/libs/dict.js.map +1 -0
  139. package/dist/src/expr/libs/float.d.ts +299 -0
  140. package/dist/src/expr/libs/float.d.ts.map +1 -0
  141. package/dist/src/expr/libs/float.js +564 -0
  142. package/dist/src/expr/libs/float.js.map +1 -0
  143. package/dist/src/expr/libs/integer.d.ts +228 -0
  144. package/dist/src/expr/libs/integer.d.ts.map +1 -0
  145. package/dist/src/expr/libs/integer.js +398 -0
  146. package/dist/src/expr/libs/integer.js.map +1 -0
  147. package/dist/src/expr/libs/set.d.ts +59 -0
  148. package/dist/src/expr/libs/set.d.ts.map +1 -0
  149. package/dist/src/expr/libs/set.js +69 -0
  150. package/dist/src/expr/libs/set.js.map +1 -0
  151. package/dist/src/expr/libs/string.d.ts +71 -0
  152. package/dist/src/expr/libs/string.d.ts.map +1 -0
  153. package/dist/src/expr/libs/string.js +75 -0
  154. package/dist/src/expr/libs/string.js.map +1 -0
  155. package/dist/src/expr/never.d.ts +15 -0
  156. package/dist/src/expr/never.d.ts.map +1 -0
  157. package/dist/src/expr/never.js +12 -0
  158. package/dist/src/expr/never.js.map +1 -0
  159. package/dist/src/expr/null.d.ts +15 -0
  160. package/dist/src/expr/null.d.ts.map +1 -0
  161. package/dist/src/expr/null.js +12 -0
  162. package/dist/src/expr/null.js.map +1 -0
  163. package/dist/src/expr/ref.d.ts +103 -0
  164. package/dist/src/expr/ref.d.ts.map +1 -0
  165. package/dist/src/expr/ref.js +131 -0
  166. package/dist/src/expr/ref.js.map +1 -0
  167. package/dist/src/expr/regex_validation.d.ts +25 -0
  168. package/dist/src/expr/regex_validation.d.ts.map +1 -0
  169. package/dist/src/expr/regex_validation.js +130 -0
  170. package/dist/src/expr/regex_validation.js.map +1 -0
  171. package/dist/src/expr/set.d.ts +1071 -0
  172. package/dist/src/expr/set.d.ts.map +1 -0
  173. package/dist/src/expr/set.js +1137 -0
  174. package/dist/src/expr/set.js.map +1 -0
  175. package/dist/src/expr/string.d.ts +414 -0
  176. package/dist/src/expr/string.d.ts.map +1 -0
  177. package/dist/src/expr/string.js +683 -0
  178. package/dist/src/expr/string.js.map +1 -0
  179. package/dist/src/expr/struct.d.ts +48 -0
  180. package/dist/src/expr/struct.d.ts.map +1 -0
  181. package/dist/src/expr/struct.js +65 -0
  182. package/dist/src/expr/struct.js.map +1 -0
  183. package/dist/src/expr/types.d.ts +68 -0
  184. package/dist/src/expr/types.d.ts.map +1 -0
  185. package/dist/src/expr/types.js +6 -0
  186. package/dist/src/expr/types.js.map +1 -0
  187. package/dist/src/expr/variant.d.ts +137 -0
  188. package/dist/src/expr/variant.d.ts.map +1 -0
  189. package/dist/src/expr/variant.js +105 -0
  190. package/dist/src/expr/variant.js.map +1 -0
  191. package/dist/src/fuzz.d.ts +80 -0
  192. package/dist/src/fuzz.d.ts.map +1 -0
  193. package/dist/src/fuzz.js +300 -0
  194. package/dist/src/fuzz.js.map +1 -0
  195. package/dist/src/index.d.ts +21 -0
  196. package/dist/src/index.d.ts.map +1 -0
  197. package/dist/src/index.js +21 -0
  198. package/dist/src/index.js.map +1 -0
  199. package/dist/src/internal.d.ts +36 -0
  200. package/dist/src/internal.d.ts.map +1 -0
  201. package/dist/src/internal.js +11 -0
  202. package/dist/src/internal.js.map +1 -0
  203. package/dist/src/ir.d.ts +1571 -0
  204. package/dist/src/ir.d.ts.map +1 -0
  205. package/dist/src/ir.js +56 -0
  206. package/dist/src/ir.js.map +1 -0
  207. package/dist/src/location.d.ts +48 -0
  208. package/dist/src/location.d.ts.map +1 -0
  209. package/dist/src/location.js +62 -0
  210. package/dist/src/location.js.map +1 -0
  211. package/dist/src/platform.d.ts +21 -0
  212. package/dist/src/platform.d.ts.map +1 -0
  213. package/dist/src/platform.js +8 -0
  214. package/dist/src/platform.js.map +1 -0
  215. package/dist/src/serialization/beast.d.ts +39 -0
  216. package/dist/src/serialization/beast.d.ts.map +1 -0
  217. package/dist/src/serialization/beast.js +555 -0
  218. package/dist/src/serialization/beast.js.map +1 -0
  219. package/dist/src/serialization/beast2-stream.d.ts +38 -0
  220. package/dist/src/serialization/beast2-stream.d.ts.map +1 -0
  221. package/dist/src/serialization/beast2-stream.js +665 -0
  222. package/dist/src/serialization/beast2-stream.js.map +1 -0
  223. package/dist/src/serialization/beast2.d.ts +41 -0
  224. package/dist/src/serialization/beast2.d.ts.map +1 -0
  225. package/dist/src/serialization/beast2.js +489 -0
  226. package/dist/src/serialization/beast2.js.map +1 -0
  227. package/dist/src/serialization/binary-utils.d.ts +151 -0
  228. package/dist/src/serialization/binary-utils.d.ts.map +1 -0
  229. package/dist/src/serialization/binary-utils.js +929 -0
  230. package/dist/src/serialization/binary-utils.js.map +1 -0
  231. package/dist/src/serialization/east.d.ts +84 -0
  232. package/dist/src/serialization/east.d.ts.map +1 -0
  233. package/dist/src/serialization/east.js +1802 -0
  234. package/dist/src/serialization/east.js.map +1 -0
  235. package/dist/src/serialization/index.d.ts +11 -0
  236. package/dist/src/serialization/index.d.ts.map +1 -0
  237. package/dist/src/serialization/index.js +12 -0
  238. package/dist/src/serialization/index.js.map +1 -0
  239. package/dist/src/serialization/json.d.ts +36 -0
  240. package/dist/src/serialization/json.d.ts.map +1 -0
  241. package/dist/src/serialization/json.js +849 -0
  242. package/dist/src/serialization/json.js.map +1 -0
  243. package/dist/src/type_of_type.d.ts +115 -0
  244. package/dist/src/type_of_type.d.ts.map +1 -0
  245. package/dist/src/type_of_type.js +362 -0
  246. package/dist/src/type_of_type.js.map +1 -0
  247. package/dist/src/types.d.ts +648 -0
  248. package/dist/src/types.d.ts.map +1 -0
  249. package/dist/src/types.js +1631 -0
  250. package/dist/src/types.js.map +1 -0
  251. package/package.json +87 -0
@@ -0,0 +1,311 @@
1
+ import { get_location } from "../location.js";
2
+ import { FloatType, IntegerType, isTypeEqual } from "../types.js";
3
+ import { AstSymbol, Expr, FactorySymbol } from "./expr.js";
4
+ import { valueOrExprToAst } from "./ast.js";
5
+ /**
6
+ * Expression representing integer values and operations.
7
+ *
8
+ * IntegerExpr provides arithmetic, comparison, and conversion operations for 64-bit signed integers.
9
+ * Operations automatically promote to FloatExpr when mixed with float operands.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // Basic arithmetic
14
+ * const calculate = East.function([IntegerType, IntegerType], IntegerType, ($, a, b) => {
15
+ * const sum = a.add(b);
16
+ * const product = a.multiply(b);
17
+ * const power = a.pow(2n);
18
+ * $.return(sum.add(product).add(power));
19
+ * });
20
+ *
21
+ * // Integer division and remainder
22
+ * const divMod = East.function([IntegerType, IntegerType], StructType({quot: IntegerType, rem: IntegerType}), ($, x, y) => {
23
+ * $.return({quot: x.divide(y), rem: x.remainder(y)});
24
+ * });
25
+ *
26
+ * // Type promotion with floats
27
+ * const mixed = East.function([IntegerType], FloatType, ($, x) => {
28
+ * $.return(x.add(2.5)); // Returns FloatExpr
29
+ * });
30
+ * ```
31
+ */
32
+ export class IntegerExpr extends Expr {
33
+ constructor(ast, createExpr) {
34
+ super(IntegerType, ast, createExpr);
35
+ }
36
+ /**
37
+ * Negates an integer value (-x).
38
+ *
39
+ * @returns The negated integer
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const negate = East.function([IntegerType], IntegerType, ($, x) => {
44
+ * $.return(x.negate());
45
+ * });
46
+ * const compiled = East.compile(negate.toIR(), []);
47
+ * compiled(5n); // -5n
48
+ * compiled(-3n); // 3n
49
+ * ```
50
+ */
51
+ negate() {
52
+ return this[FactorySymbol]({
53
+ ast_type: "Builtin",
54
+ type: IntegerType,
55
+ location: get_location(2),
56
+ builtin: "IntegerNegate",
57
+ type_parameters: [],
58
+ arguments: [this[AstSymbol]],
59
+ });
60
+ }
61
+ add(y) {
62
+ const rightAst = valueOrExprToAst(y);
63
+ if (isTypeEqual(rightAst.type, FloatType)) {
64
+ return this[FactorySymbol]({
65
+ ast_type: "Builtin",
66
+ type: FloatType,
67
+ location: get_location(2),
68
+ builtin: "FloatAdd",
69
+ type_parameters: [],
70
+ arguments: [this.toFloat()[AstSymbol], rightAst],
71
+ });
72
+ }
73
+ else {
74
+ return this[FactorySymbol]({
75
+ ast_type: "Builtin",
76
+ type: IntegerType,
77
+ location: get_location(2),
78
+ builtin: "IntegerAdd",
79
+ type_parameters: [],
80
+ arguments: [this[AstSymbol], rightAst],
81
+ });
82
+ }
83
+ }
84
+ subtract(y) {
85
+ const rightAst = valueOrExprToAst(y);
86
+ if (isTypeEqual(rightAst.type, FloatType)) {
87
+ return this[FactorySymbol]({
88
+ ast_type: "Builtin",
89
+ type: FloatType,
90
+ location: get_location(2),
91
+ builtin: "FloatSubtract",
92
+ type_parameters: [],
93
+ arguments: [this.toFloat()[AstSymbol], rightAst],
94
+ });
95
+ }
96
+ else {
97
+ return this[FactorySymbol]({
98
+ ast_type: "Builtin",
99
+ type: IntegerType,
100
+ location: get_location(2),
101
+ builtin: "IntegerSubtract",
102
+ type_parameters: [],
103
+ arguments: [this[AstSymbol], rightAst],
104
+ });
105
+ }
106
+ }
107
+ multiply(y) {
108
+ const rightAst = valueOrExprToAst(y);
109
+ if (isTypeEqual(rightAst.type, FloatType)) {
110
+ return this[FactorySymbol]({
111
+ ast_type: "Builtin",
112
+ type: FloatType,
113
+ location: get_location(2),
114
+ builtin: "FloatMultiply",
115
+ type_parameters: [],
116
+ arguments: [this.toFloat()[AstSymbol], rightAst],
117
+ });
118
+ }
119
+ else {
120
+ return this[FactorySymbol]({
121
+ ast_type: "Builtin",
122
+ type: IntegerType,
123
+ location: get_location(2),
124
+ builtin: "IntegerMultiply",
125
+ type_parameters: [],
126
+ arguments: [this[AstSymbol], rightAst],
127
+ });
128
+ }
129
+ }
130
+ divide(y) {
131
+ const rightAst = valueOrExprToAst(y);
132
+ if (isTypeEqual(rightAst.type, FloatType)) {
133
+ return this[FactorySymbol]({
134
+ ast_type: "Builtin",
135
+ type: FloatType,
136
+ location: get_location(2),
137
+ builtin: "FloatDivide",
138
+ type_parameters: [],
139
+ arguments: [this.toFloat()[AstSymbol], rightAst],
140
+ });
141
+ }
142
+ else {
143
+ return this[FactorySymbol]({
144
+ ast_type: "Builtin",
145
+ type: IntegerType,
146
+ location: get_location(2),
147
+ builtin: "IntegerDivide",
148
+ type_parameters: [],
149
+ arguments: [this[AstSymbol], rightAst],
150
+ });
151
+ }
152
+ }
153
+ remainder(y) {
154
+ const rightAst = valueOrExprToAst(y);
155
+ if (isTypeEqual(rightAst.type, FloatType)) {
156
+ return this[FactorySymbol]({
157
+ ast_type: "Builtin",
158
+ type: FloatType,
159
+ location: get_location(2),
160
+ builtin: "FloatRemainder",
161
+ type_parameters: [],
162
+ arguments: [this.toFloat()[AstSymbol], rightAst],
163
+ });
164
+ }
165
+ else {
166
+ return this[FactorySymbol]({
167
+ ast_type: "Builtin",
168
+ type: IntegerType,
169
+ location: get_location(2),
170
+ builtin: "IntegerRemainder",
171
+ type_parameters: [],
172
+ arguments: [this[AstSymbol], rightAst],
173
+ });
174
+ }
175
+ }
176
+ pow(y) {
177
+ const rightAst = valueOrExprToAst(y);
178
+ if (isTypeEqual(rightAst.type, FloatType)) {
179
+ return this[FactorySymbol]({
180
+ ast_type: "Builtin",
181
+ type: FloatType,
182
+ location: get_location(2),
183
+ builtin: "FloatPow",
184
+ type_parameters: [],
185
+ arguments: [this.toFloat()[AstSymbol], rightAst],
186
+ });
187
+ }
188
+ else {
189
+ return this[FactorySymbol]({
190
+ ast_type: "Builtin",
191
+ type: IntegerType,
192
+ location: get_location(2),
193
+ builtin: "IntegerPow",
194
+ type_parameters: [],
195
+ arguments: [this[AstSymbol], rightAst],
196
+ });
197
+ }
198
+ }
199
+ /**
200
+ * Returns the absolute value of an integer.
201
+ *
202
+ * @returns The absolute value (always non-negative)
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const absoluteValue = East.function([IntegerType], IntegerType, ($, x) => {
207
+ * $.return(x.abs());
208
+ * });
209
+ * const compiled = East.compile(absoluteValue.toIR(), []);
210
+ * compiled(5n); // 5n
211
+ * compiled(-5n); // 5n
212
+ * compiled(0n); // 0n
213
+ * ```
214
+ */
215
+ abs() {
216
+ return this[FactorySymbol]({
217
+ ast_type: "Builtin",
218
+ type: IntegerType,
219
+ location: get_location(2),
220
+ builtin: "IntegerAbs",
221
+ type_parameters: [],
222
+ arguments: [this[AstSymbol]],
223
+ });
224
+ }
225
+ /**
226
+ * Returns the sign of an integer (-1 for negative, 0 for zero, 1 for positive).
227
+ *
228
+ * @returns -1n, 0n, or 1n depending on the sign of the integer
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * const getSign = East.function([IntegerType], IntegerType, ($, x) => {
233
+ * $.return(x.sign());
234
+ * });
235
+ * const compiled = East.compile(getSign.toIR(), []);
236
+ * compiled(42n); // 1n
237
+ * compiled(-17n); // -1n
238
+ * compiled(0n); // 0n
239
+ * ```
240
+ */
241
+ sign() {
242
+ return this[FactorySymbol]({
243
+ ast_type: "Builtin",
244
+ type: IntegerType,
245
+ location: get_location(2),
246
+ builtin: "IntegerSign",
247
+ type_parameters: [],
248
+ arguments: [this[AstSymbol]],
249
+ });
250
+ }
251
+ /**
252
+ * Computes the integer logarithm with a specified base (floor of log).
253
+ *
254
+ * @param base - The base for the logarithm
255
+ * @returns The floor of log_base(x)
256
+ *
257
+ * @remarks Returns 0 if x <= 0 or base <= 1.
258
+ *
259
+ * @example
260
+ * ```ts
261
+ * const logarithm = East.function([IntegerType, IntegerType], IntegerType, ($, x, base) => {
262
+ * $.return(x.log(base));
263
+ * });
264
+ * const compiled = East.compile(logarithm.toIR(), []);
265
+ * compiled(1000n, 10n); // 3n (10^3 = 1000)
266
+ * compiled(8n, 2n); // 3n (2^3 = 8)
267
+ * compiled(100n, 10n); // 2n (10^2 = 100)
268
+ * compiled(7n, 2n); // 2n (floor of log_2(7) ≈ 2.8)
269
+ * ```
270
+ */
271
+ log(base) {
272
+ const baseAst = valueOrExprToAst(base);
273
+ return this[FactorySymbol]({
274
+ ast_type: "Builtin",
275
+ type: IntegerType,
276
+ location: get_location(2),
277
+ builtin: "IntegerLog",
278
+ type_parameters: [],
279
+ arguments: [this[AstSymbol], baseAst],
280
+ });
281
+ }
282
+ /**
283
+ * Converts an integer to a floating-point number.
284
+ *
285
+ * @returns The integer as a FloatExpr
286
+ *
287
+ * @remarks May lose precision for very large integers (beyond 2^53).
288
+ *
289
+ * @example
290
+ * ```ts
291
+ * const convertToFloat = East.function([IntegerType], FloatType, ($, x) => {
292
+ * $.return(x.toFloat());
293
+ * });
294
+ * const compiled = East.compile(convertToFloat.toIR(), []);
295
+ * compiled(42n); // 42.0
296
+ * compiled(-17n); // -17.0
297
+ * compiled(0n); // 0.0
298
+ * ```
299
+ */
300
+ toFloat() {
301
+ return this[FactorySymbol]({
302
+ ast_type: "Builtin",
303
+ type: FloatType,
304
+ location: get_location(2),
305
+ builtin: "IntegerToFloat",
306
+ type_parameters: [],
307
+ arguments: [this[AstSymbol]],
308
+ });
309
+ }
310
+ }
311
+ //# sourceMappingURL=integer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integer.js","sourceRoot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O,IAAI,CAAC,aAAa,CAAC,CAAC;YACzB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;YACzB,OAAO,EAAE,YAAY;YACrB,eAAe,EAAE,EAAE;YACnB,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;SACtC,CAAgB,CAAC;IACpB,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;YACzB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;YACzB,OAAO,EAAE,gBAAgB;YACzB,eAAe,EAAE,EAAE;YACnB,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC7B,CAAc,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ import { ArrayType, FloatType, FunctionType, IntegerType } from "../../types.js";
6
+ import { Expr } from "../expr.js";
7
+ import type { ExprType, SubtypeExprOrValue } from "../types.js";
8
+ /** Standard library functions for arrays */
9
+ declare const _default: {
10
+ /**
11
+ * Creates an array containing a linear range of integers.
12
+ *
13
+ * @param start - The starting value (inclusive)
14
+ * @param end - The ending value (exclusive)
15
+ * @param step - The step size between consecutive values (default: 1)
16
+ * @returns An array expression containing the integer range
17
+ *
18
+ * @remarks
19
+ * The end of the range is exclusive, such that `East.range(0n, n)` produces `[0, 1, 2, ..., n-1]`.
20
+ * This corresponds with the indices of an array of size `n`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const makeRange = East.function([], ArrayType(IntegerType), ($) => {
25
+ * $.return(East.Array.range(0n, 5n));
26
+ * });
27
+ * const compiled = East.compile(makeRange.toIR(), []);
28
+ * compiled(); // [0n, 1n, 2n, 3n, 4n]
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // With step
34
+ * const makeRangeStep = East.function([], ArrayType(IntegerType), ($) => {
35
+ * $.return(East.Array.range(1n, 10n, 2n));
36
+ * });
37
+ * const compiled = East.compile(makeRangeStep.toIR(), []);
38
+ * compiled(); // [1n, 3n, 5n, 7n, 9n]
39
+ * ```
40
+ */
41
+ range(start: Expr<IntegerType> | bigint, end: Expr<IntegerType> | bigint, step?: Expr<IntegerType> | bigint): ExprType<ArrayType<IntegerType>>;
42
+ /**
43
+ * Creates an array containing equally-spaced floating point values.
44
+ *
45
+ * @param start - The starting value (inclusive)
46
+ * @param stop - The ending value (inclusive)
47
+ * @param size - The number of values to generate
48
+ * @returns An array expression containing the equally-spaced float values
49
+ *
50
+ * @remarks
51
+ * The stop value is inclusive, such that `East.linspace(0.0, 1.0, 11n)` produces 11 values
52
+ * from `0.0` to `1.0` with a step of `0.1`.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const makeLinspace = East.function([], ArrayType(FloatType), ($) => {
57
+ * $.return(East.Array.linspace(0.0, 1.0, 11n));
58
+ * });
59
+ * const compiled = East.compile(makeLinspace.toIR(), []);
60
+ * compiled(); // [0.0, 0.1, 0.2, ..., 0.9, 1.0]
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * // Different spacing
66
+ * const makeLinspace2 = East.function([], ArrayType(FloatType), ($) => {
67
+ * $.return(East.Array.linspace(0.0, 10.0, 5n));
68
+ * });
69
+ * const compiled = East.compile(makeLinspace2.toIR(), []);
70
+ * compiled(); // [0.0, 2.5, 5.0, 7.5, 10.0]
71
+ * ```
72
+ */
73
+ linspace(start: Expr<FloatType> | number, stop: Expr<FloatType> | number, size: Expr<IntegerType> | bigint): ExprType<ArrayType<FloatType>>;
74
+ /**
75
+ * Generates an array of a given size programmatically with a function from index to value.
76
+ *
77
+ * @typeParam T - The type of elements in the generated array
78
+ * @param size - The size of the array to generate
79
+ * @param valueType - The East type of the array elements
80
+ * @param valueFn - A function that takes an index and returns the value at that index
81
+ * @returns An array expression containing the programmatically generated values
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * // Generate array [0, 1, 4, 9, 16] (squares)
86
+ * const makeSquares = East.function([], ArrayType(IntegerType), ($) => {
87
+ * $.return(East.Array.generate(5n, IntegerType, ($, i) => i.multiply(i)));
88
+ * });
89
+ * const compiled = East.compile(makeSquares.toIR(), []);
90
+ * compiled(); // [0n, 1n, 4n, 9n, 16n]
91
+ * ```
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * // Generate array of strings ["Item 0", "Item 1", "Item 2"]
96
+ * const makeItems = East.function([], ArrayType(StringType), ($) => {
97
+ * $.return(East.Array.generate(3n, StringType, ($, i) => Expr.str`Item ${i}`));
98
+ * });
99
+ * const compiled = East.compile(makeItems.toIR(), []);
100
+ * compiled(); // ["Item 0", "Item 1", "Item 2"]
101
+ * ```
102
+ */
103
+ generate<T>(size: Expr<IntegerType> | bigint, valueType: T, valueFn: SubtypeExprOrValue<FunctionType<[IntegerType], NoInfer<T>>>): ExprType<ArrayType<T>>;
104
+ };
105
+ export default _default;
106
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../../src/expr/libs/array.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAa,IAAI,EAAc,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEhE,4CAA4C;;IAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;iBACU,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,SAAQ,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAQ,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAclJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;oBACa,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,QAAQ,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,QAAQ,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAc3I;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;aACM,CAAC,QAAQ,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,aAAa,CAAC,WAAW,kBAAkB,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;;AAxH3J,wBAqIC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ import { ArrayType, FloatType, FunctionType, IntegerType } from "../../types.js";
6
+ import { AstSymbol, Expr, TypeSymbol } from "../expr.js";
7
+ /** Standard library functions for arrays */
8
+ export default {
9
+ /**
10
+ * Creates an array containing a linear range of integers.
11
+ *
12
+ * @param start - The starting value (inclusive)
13
+ * @param end - The ending value (exclusive)
14
+ * @param step - The step size between consecutive values (default: 1)
15
+ * @returns An array expression containing the integer range
16
+ *
17
+ * @remarks
18
+ * The end of the range is exclusive, such that `East.range(0n, n)` produces `[0, 1, 2, ..., n-1]`.
19
+ * This corresponds with the indices of an array of size `n`.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const makeRange = East.function([], ArrayType(IntegerType), ($) => {
24
+ * $.return(East.Array.range(0n, 5n));
25
+ * });
26
+ * const compiled = East.compile(makeRange.toIR(), []);
27
+ * compiled(); // [0n, 1n, 2n, 3n, 4n]
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // With step
33
+ * const makeRangeStep = East.function([], ArrayType(IntegerType), ($) => {
34
+ * $.return(East.Array.range(1n, 10n, 2n));
35
+ * });
36
+ * const compiled = East.compile(makeRangeStep.toIR(), []);
37
+ * compiled(); // [1n, 3n, 5n, 7n, 9n]
38
+ * ```
39
+ */
40
+ range(start, end, step = 1n) {
41
+ const start_val = Expr.from(start, IntegerType);
42
+ const end_val = Expr.from(end, IntegerType);
43
+ const step_val = Expr.from(step, IntegerType);
44
+ return Expr.fromAst({
45
+ ast_type: "Builtin",
46
+ type: ArrayType(IntegerType),
47
+ builtin: "ArrayRange",
48
+ type_parameters: [],
49
+ arguments: [start_val[AstSymbol], end_val[AstSymbol], step_val[AstSymbol]],
50
+ location: start_val[AstSymbol].location,
51
+ });
52
+ },
53
+ /**
54
+ * Creates an array containing equally-spaced floating point values.
55
+ *
56
+ * @param start - The starting value (inclusive)
57
+ * @param stop - The ending value (inclusive)
58
+ * @param size - The number of values to generate
59
+ * @returns An array expression containing the equally-spaced float values
60
+ *
61
+ * @remarks
62
+ * The stop value is inclusive, such that `East.linspace(0.0, 1.0, 11n)` produces 11 values
63
+ * from `0.0` to `1.0` with a step of `0.1`.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const makeLinspace = East.function([], ArrayType(FloatType), ($) => {
68
+ * $.return(East.Array.linspace(0.0, 1.0, 11n));
69
+ * });
70
+ * const compiled = East.compile(makeLinspace.toIR(), []);
71
+ * compiled(); // [0.0, 0.1, 0.2, ..., 0.9, 1.0]
72
+ * ```
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * // Different spacing
77
+ * const makeLinspace2 = East.function([], ArrayType(FloatType), ($) => {
78
+ * $.return(East.Array.linspace(0.0, 10.0, 5n));
79
+ * });
80
+ * const compiled = East.compile(makeLinspace2.toIR(), []);
81
+ * compiled(); // [0.0, 2.5, 5.0, 7.5, 10.0]
82
+ * ```
83
+ */
84
+ linspace(start, stop, size) {
85
+ const start_val = Expr.from(start, FloatType);
86
+ const stop_val = Expr.from(stop, FloatType);
87
+ const count_val = Expr.from(size, IntegerType);
88
+ return Expr.fromAst({
89
+ ast_type: "Builtin",
90
+ type: ArrayType(FloatType),
91
+ builtin: "ArrayLinspace",
92
+ type_parameters: [],
93
+ arguments: [start_val[AstSymbol], stop_val[AstSymbol], count_val[AstSymbol]],
94
+ location: start_val[AstSymbol].location,
95
+ });
96
+ },
97
+ /**
98
+ * Generates an array of a given size programmatically with a function from index to value.
99
+ *
100
+ * @typeParam T - The type of elements in the generated array
101
+ * @param size - The size of the array to generate
102
+ * @param valueType - The East type of the array elements
103
+ * @param valueFn - A function that takes an index and returns the value at that index
104
+ * @returns An array expression containing the programmatically generated values
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * // Generate array [0, 1, 4, 9, 16] (squares)
109
+ * const makeSquares = East.function([], ArrayType(IntegerType), ($) => {
110
+ * $.return(East.Array.generate(5n, IntegerType, ($, i) => i.multiply(i)));
111
+ * });
112
+ * const compiled = East.compile(makeSquares.toIR(), []);
113
+ * compiled(); // [0n, 1n, 4n, 9n, 16n]
114
+ * ```
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * // Generate array of strings ["Item 0", "Item 1", "Item 2"]
119
+ * const makeItems = East.function([], ArrayType(StringType), ($) => {
120
+ * $.return(East.Array.generate(3n, StringType, ($, i) => Expr.str`Item ${i}`));
121
+ * });
122
+ * const compiled = East.compile(makeItems.toIR(), []);
123
+ * compiled(); // ["Item 0", "Item 1", "Item 2"]
124
+ * ```
125
+ */
126
+ generate(size, valueType, valueFn) {
127
+ const length_expr = Expr.from(size, IntegerType);
128
+ const generator_expr = Expr.from(valueFn, FunctionType([IntegerType], valueType, []));
129
+ const value_type_deduced = generator_expr[TypeSymbol].output;
130
+ return Expr.fromAst({
131
+ ast_type: "Builtin",
132
+ type: ArrayType(value_type_deduced),
133
+ builtin: "ArrayGenerate",
134
+ type_parameters: [value_type_deduced],
135
+ arguments: [length_expr[AstSymbol], generator_expr[AstSymbol]],
136
+ location: length_expr[AstSymbol].location,
137
+ });
138
+ },
139
+ };
140
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../../src/expr/libs/array.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGzD,4CAA4C;AAC5C,eAAe;IACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,KAAK,CAAC,KAAiC,EAAE,GAA+B,EAAE,OAAmC,EAAE;QAC7G,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC;YAC5B,OAAO,EAAE,YAAY;YACrB,eAAe,EAAE,EAAE;YACnB,SAAS,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;YAC1E,QAAQ,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ;SACxC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,QAAQ,CAAC,KAA+B,EAAE,IAA8B,EAAE,IAAgC;QACxG,MA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AAE,WAAW,CAAC,SAAS,CAAC,CAAC,QAAQ;SAC1C,CAAC,CAAC;IACL,CAAC;CACF,CAAA"}
@@ -0,0 +1,42 @@
1
+ import type { BlobExpr } from "../blob.js";
2
+ import { Expr } from "../expr.js";
3
+ /** Standard library for blobs */
4
+ declare const _default: {
5
+ /**
6
+ * Encodes a value to the binary East format (BEAST).
7
+ *
8
+ * @param value - The East value to encode
9
+ * @param version - The BEAST format version to use: `'v1'` or `'v2'` (default: `'v1'`)
10
+ * @returns A blob expression containing the encoded binary data
11
+ *
12
+ * @throws Error when an unsupported version string is provided
13
+ *
14
+ * @remarks
15
+ * BEAST (Binary East) is a compact binary serialization format for East values.
16
+ * Version 1 (v1) is the original format, while version 2 (v2) provides improved
17
+ * encoding for certain types.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Encode an array to BEAST v1 format
22
+ * const encodeArray = East.function([ArrayType(IntegerType)], BlobType, ($, arr) => {
23
+ * $.return(East.Blob.encodeBeast(arr));
24
+ * });
25
+ * const compiled = East.compile(encodeArray.toIR(), []);
26
+ * const blob = compiled([1n, 2n, 3n]); // Binary blob containing encoded array
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Encode using BEAST v2 format
32
+ * const encodeV2 = East.function([IntegerType], BlobType, ($, num) => {
33
+ * $.return(East.Blob.encodeBeast(num, 'v2'));
34
+ * });
35
+ * const compiled = East.compile(encodeV2.toIR(), []);
36
+ * const blob = compiled(42n); // Binary blob with v2 encoding
37
+ * ```
38
+ */
39
+ encodeBeast(value: Expr, version?: "v1" | "v2"): BlobExpr;
40
+ };
41
+ export default _default;
42
+ //# sourceMappingURL=blob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../../../src/expr/libs/blob.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,iCAAiC;;IAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;uBACgB,IAAI,YAAW,IAAI,GAAG,IAAI,GAAU,QAAQ;;AAnCjE,wBA0DC"}