@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.
- package/LICENSE.md +682 -0
- package/README.md +276 -0
- package/dist/src/analyze.d.ts +95 -0
- package/dist/src/analyze.d.ts.map +1 -0
- package/dist/src/analyze.js +1110 -0
- package/dist/src/analyze.js.map +1 -0
- package/dist/src/ast.d.ts +263 -0
- package/dist/src/ast.d.ts.map +1 -0
- package/dist/src/ast.js +151 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/ast_to_ir.d.ts +24 -0
- package/dist/src/ast_to_ir.d.ts.map +1 -0
- package/dist/src/ast_to_ir.js +834 -0
- package/dist/src/ast_to_ir.js.map +1 -0
- package/dist/src/builtins.d.ts +18 -0
- package/dist/src/builtins.d.ts.map +1 -0
- package/dist/src/builtins.js +1105 -0
- package/dist/src/builtins.js.map +1 -0
- package/dist/src/comparison.d.ts +28 -0
- package/dist/src/comparison.d.ts.map +1 -0
- package/dist/src/comparison.js +1017 -0
- package/dist/src/comparison.js.map +1 -0
- package/dist/src/compile.d.ts +22 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +3260 -0
- package/dist/src/compile.js.map +1 -0
- package/dist/src/containers/ref.d.ts +106 -0
- package/dist/src/containers/ref.d.ts.map +1 -0
- package/dist/src/containers/ref.js +100 -0
- package/dist/src/containers/ref.js.map +1 -0
- package/dist/src/containers/sortedmap.d.ts +165 -0
- package/dist/src/containers/sortedmap.d.ts.map +1 -0
- package/dist/src/containers/sortedmap.js +237 -0
- package/dist/src/containers/sortedmap.js.map +1 -0
- package/dist/src/containers/sortedset.d.ts +185 -0
- package/dist/src/containers/sortedset.d.ts.map +1 -0
- package/dist/src/containers/sortedset.js +312 -0
- package/dist/src/containers/sortedset.js.map +1 -0
- package/dist/src/containers/variant.d.ts +131 -0
- package/dist/src/containers/variant.d.ts.map +1 -0
- package/dist/src/containers/variant.js +68 -0
- package/dist/src/containers/variant.js.map +1 -0
- package/dist/src/datetime_format/parse.d.ts +50 -0
- package/dist/src/datetime_format/parse.d.ts.map +1 -0
- package/dist/src/datetime_format/parse.js +908 -0
- package/dist/src/datetime_format/parse.js.map +1 -0
- package/dist/src/datetime_format/print.d.ts +35 -0
- package/dist/src/datetime_format/print.d.ts.map +1 -0
- package/dist/src/datetime_format/print.js +157 -0
- package/dist/src/datetime_format/print.js.map +1 -0
- package/dist/src/datetime_format/tokenize.d.ts +76 -0
- package/dist/src/datetime_format/tokenize.d.ts.map +1 -0
- package/dist/src/datetime_format/tokenize.js +271 -0
- package/dist/src/datetime_format/tokenize.js.map +1 -0
- package/dist/src/datetime_format/types.d.ts +99 -0
- package/dist/src/datetime_format/types.d.ts.map +1 -0
- package/dist/src/datetime_format/types.js +103 -0
- package/dist/src/datetime_format/types.js.map +1 -0
- package/dist/src/datetime_format/validate.d.ts +51 -0
- package/dist/src/datetime_format/validate.d.ts.map +1 -0
- package/dist/src/datetime_format/validate.js +208 -0
- package/dist/src/datetime_format/validate.js.map +1 -0
- package/dist/src/default.d.ts +21 -0
- package/dist/src/default.d.ts.map +1 -0
- package/dist/src/default.js +82 -0
- package/dist/src/default.js.map +1 -0
- package/dist/src/eastir.d.ts +33 -0
- package/dist/src/eastir.d.ts.map +1 -0
- package/dist/src/eastir.js +92 -0
- package/dist/src/eastir.js.map +1 -0
- package/dist/src/error.d.ts +13 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +8 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/expr/array.d.ts +1711 -0
- package/dist/src/expr/array.d.ts.map +1 -0
- package/dist/src/expr/array.js +1805 -0
- package/dist/src/expr/array.js.map +1 -0
- package/dist/src/expr/ast.d.ts +17 -0
- package/dist/src/expr/ast.d.ts.map +1 -0
- package/dist/src/expr/ast.js +302 -0
- package/dist/src/expr/ast.js.map +1 -0
- package/dist/src/expr/blob.d.ts +141 -0
- package/dist/src/expr/blob.d.ts.map +1 -0
- package/dist/src/expr/blob.js +198 -0
- package/dist/src/expr/blob.js.map +1 -0
- package/dist/src/expr/block.d.ts +201 -0
- package/dist/src/expr/block.d.ts.map +1 -0
- package/dist/src/expr/block.js +1505 -0
- package/dist/src/expr/block.js.map +1 -0
- package/dist/src/expr/boolean.d.ts +207 -0
- package/dist/src/expr/boolean.d.ts.map +1 -0
- package/dist/src/expr/boolean.js +261 -0
- package/dist/src/expr/boolean.js.map +1 -0
- package/dist/src/expr/datetime.d.ts +544 -0
- package/dist/src/expr/datetime.d.ts.map +1 -0
- package/dist/src/expr/datetime.js +980 -0
- package/dist/src/expr/datetime.js.map +1 -0
- package/dist/src/expr/dict.d.ts +1242 -0
- package/dist/src/expr/dict.d.ts.map +1 -0
- package/dist/src/expr/dict.js +1492 -0
- package/dist/src/expr/dict.js.map +1 -0
- package/dist/src/expr/expr.d.ts +95 -0
- package/dist/src/expr/expr.d.ts.map +1 -0
- package/dist/src/expr/expr.js +171 -0
- package/dist/src/expr/expr.js.map +1 -0
- package/dist/src/expr/float.d.ts +357 -0
- package/dist/src/expr/float.d.ts.map +1 -0
- package/dist/src/expr/float.js +637 -0
- package/dist/src/expr/float.js.map +1 -0
- package/dist/src/expr/function.d.ts +46 -0
- package/dist/src/expr/function.d.ts.map +1 -0
- package/dist/src/expr/function.js +58 -0
- package/dist/src/expr/function.js.map +1 -0
- package/dist/src/expr/index.d.ts +450 -0
- package/dist/src/expr/index.d.ts.map +1 -0
- package/dist/src/expr/index.js +423 -0
- package/dist/src/expr/index.js.map +1 -0
- package/dist/src/expr/integer.d.ts +256 -0
- package/dist/src/expr/integer.d.ts.map +1 -0
- package/dist/src/expr/integer.js +311 -0
- package/dist/src/expr/integer.js.map +1 -0
- package/dist/src/expr/libs/array.d.ts +106 -0
- package/dist/src/expr/libs/array.d.ts.map +1 -0
- package/dist/src/expr/libs/array.js +140 -0
- package/dist/src/expr/libs/array.js.map +1 -0
- package/dist/src/expr/libs/blob.d.ts +42 -0
- package/dist/src/expr/libs/blob.d.ts.map +1 -0
- package/dist/src/expr/libs/blob.js +70 -0
- package/dist/src/expr/libs/blob.js.map +1 -0
- package/dist/src/expr/libs/datetime.d.ts +479 -0
- package/dist/src/expr/libs/datetime.d.ts.map +1 -0
- package/dist/src/expr/libs/datetime.js +624 -0
- package/dist/src/expr/libs/datetime.js.map +1 -0
- package/dist/src/expr/libs/dict.d.ts +66 -0
- package/dist/src/expr/libs/dict.d.ts.map +1 -0
- package/dist/src/expr/libs/dict.js +77 -0
- package/dist/src/expr/libs/dict.js.map +1 -0
- package/dist/src/expr/libs/float.d.ts +299 -0
- package/dist/src/expr/libs/float.d.ts.map +1 -0
- package/dist/src/expr/libs/float.js +564 -0
- package/dist/src/expr/libs/float.js.map +1 -0
- package/dist/src/expr/libs/integer.d.ts +228 -0
- package/dist/src/expr/libs/integer.d.ts.map +1 -0
- package/dist/src/expr/libs/integer.js +398 -0
- package/dist/src/expr/libs/integer.js.map +1 -0
- package/dist/src/expr/libs/set.d.ts +59 -0
- package/dist/src/expr/libs/set.d.ts.map +1 -0
- package/dist/src/expr/libs/set.js +69 -0
- package/dist/src/expr/libs/set.js.map +1 -0
- package/dist/src/expr/libs/string.d.ts +71 -0
- package/dist/src/expr/libs/string.d.ts.map +1 -0
- package/dist/src/expr/libs/string.js +75 -0
- package/dist/src/expr/libs/string.js.map +1 -0
- package/dist/src/expr/never.d.ts +15 -0
- package/dist/src/expr/never.d.ts.map +1 -0
- package/dist/src/expr/never.js +12 -0
- package/dist/src/expr/never.js.map +1 -0
- package/dist/src/expr/null.d.ts +15 -0
- package/dist/src/expr/null.d.ts.map +1 -0
- package/dist/src/expr/null.js +12 -0
- package/dist/src/expr/null.js.map +1 -0
- package/dist/src/expr/ref.d.ts +103 -0
- package/dist/src/expr/ref.d.ts.map +1 -0
- package/dist/src/expr/ref.js +131 -0
- package/dist/src/expr/ref.js.map +1 -0
- package/dist/src/expr/regex_validation.d.ts +25 -0
- package/dist/src/expr/regex_validation.d.ts.map +1 -0
- package/dist/src/expr/regex_validation.js +130 -0
- package/dist/src/expr/regex_validation.js.map +1 -0
- package/dist/src/expr/set.d.ts +1071 -0
- package/dist/src/expr/set.d.ts.map +1 -0
- package/dist/src/expr/set.js +1137 -0
- package/dist/src/expr/set.js.map +1 -0
- package/dist/src/expr/string.d.ts +414 -0
- package/dist/src/expr/string.d.ts.map +1 -0
- package/dist/src/expr/string.js +683 -0
- package/dist/src/expr/string.js.map +1 -0
- package/dist/src/expr/struct.d.ts +48 -0
- package/dist/src/expr/struct.d.ts.map +1 -0
- package/dist/src/expr/struct.js +65 -0
- package/dist/src/expr/struct.js.map +1 -0
- package/dist/src/expr/types.d.ts +68 -0
- package/dist/src/expr/types.d.ts.map +1 -0
- package/dist/src/expr/types.js +6 -0
- package/dist/src/expr/types.js.map +1 -0
- package/dist/src/expr/variant.d.ts +137 -0
- package/dist/src/expr/variant.d.ts.map +1 -0
- package/dist/src/expr/variant.js +105 -0
- package/dist/src/expr/variant.js.map +1 -0
- package/dist/src/fuzz.d.ts +80 -0
- package/dist/src/fuzz.d.ts.map +1 -0
- package/dist/src/fuzz.js +300 -0
- package/dist/src/fuzz.js.map +1 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal.d.ts +36 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/src/internal.js +11 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/ir.d.ts +1571 -0
- package/dist/src/ir.d.ts.map +1 -0
- package/dist/src/ir.js +56 -0
- package/dist/src/ir.js.map +1 -0
- package/dist/src/location.d.ts +48 -0
- package/dist/src/location.d.ts.map +1 -0
- package/dist/src/location.js +62 -0
- package/dist/src/location.js.map +1 -0
- package/dist/src/platform.d.ts +21 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/src/platform.js +8 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/serialization/beast.d.ts +39 -0
- package/dist/src/serialization/beast.d.ts.map +1 -0
- package/dist/src/serialization/beast.js +555 -0
- package/dist/src/serialization/beast.js.map +1 -0
- package/dist/src/serialization/beast2-stream.d.ts +38 -0
- package/dist/src/serialization/beast2-stream.d.ts.map +1 -0
- package/dist/src/serialization/beast2-stream.js +665 -0
- package/dist/src/serialization/beast2-stream.js.map +1 -0
- package/dist/src/serialization/beast2.d.ts +41 -0
- package/dist/src/serialization/beast2.d.ts.map +1 -0
- package/dist/src/serialization/beast2.js +489 -0
- package/dist/src/serialization/beast2.js.map +1 -0
- package/dist/src/serialization/binary-utils.d.ts +151 -0
- package/dist/src/serialization/binary-utils.d.ts.map +1 -0
- package/dist/src/serialization/binary-utils.js +929 -0
- package/dist/src/serialization/binary-utils.js.map +1 -0
- package/dist/src/serialization/east.d.ts +84 -0
- package/dist/src/serialization/east.d.ts.map +1 -0
- package/dist/src/serialization/east.js +1802 -0
- package/dist/src/serialization/east.js.map +1 -0
- package/dist/src/serialization/index.d.ts +11 -0
- package/dist/src/serialization/index.d.ts.map +1 -0
- package/dist/src/serialization/index.js +12 -0
- package/dist/src/serialization/index.js.map +1 -0
- package/dist/src/serialization/json.d.ts +36 -0
- package/dist/src/serialization/json.d.ts.map +1 -0
- package/dist/src/serialization/json.js +849 -0
- package/dist/src/serialization/json.js.map +1 -0
- package/dist/src/type_of_type.d.ts +115 -0
- package/dist/src/type_of_type.d.ts.map +1 -0
- package/dist/src/type_of_type.js +362 -0
- package/dist/src/type_of_type.js.map +1 -0
- package/dist/src/types.d.ts +648 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1631 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,423 @@
|
|
|
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
|
+
// Re-export all types
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
// Re-export abstract base and concrete classes
|
|
8
|
+
import { Expr } from './expr.js';
|
|
9
|
+
export { Expr } from './expr.js';
|
|
10
|
+
// Import factory implementation
|
|
11
|
+
import { from, equal, notEqual, less, lessEqual, print, is, greaterEqual, greater, func, str, platform } from './block.js';
|
|
12
|
+
export { BlockBuilder } from './block.js';
|
|
13
|
+
// import type { FunctionExpr } from './function.js';
|
|
14
|
+
// Import standard libraries
|
|
15
|
+
import IntegerLib from './libs/integer.js';
|
|
16
|
+
import FloatLib from './libs/float.js';
|
|
17
|
+
import DateTimeLib from './libs/datetime.js';
|
|
18
|
+
import StringLib from './libs/string.js';
|
|
19
|
+
import BlobLib from './libs/blob.js';
|
|
20
|
+
import ArrayLib from './libs/array.js';
|
|
21
|
+
import SetLib from './libs/set.js';
|
|
22
|
+
import DictLib from './libs/dict.js';
|
|
23
|
+
// /** Compile an East function to executable JavaScript.
|
|
24
|
+
// *
|
|
25
|
+
// * This is a convenience wrapper around `fn.toIR().compile(platform)`.
|
|
26
|
+
// *
|
|
27
|
+
// * @param fn - The East function to compile
|
|
28
|
+
// * @param platform - Object mapping platform function names to their JavaScript implementations
|
|
29
|
+
// * @returns Compiled JavaScript function that can be called with the specified input types
|
|
30
|
+
// *
|
|
31
|
+
// * @example
|
|
32
|
+
// * ```ts
|
|
33
|
+
// * const add = East.function([IntegerType, IntegerType], IntegerType, ($, a, b) => a.add(b));
|
|
34
|
+
// * const compiled = East.compile(add, {});
|
|
35
|
+
// * const result = compiled(5n, 3n); // 8n
|
|
36
|
+
// * ```
|
|
37
|
+
// */
|
|
38
|
+
// function compile<I extends any[], O extends any>(
|
|
39
|
+
// fn: FunctionExpr<I, O>,
|
|
40
|
+
// platform: Record<string, (...args: any[]) => any>
|
|
41
|
+
// ): any {
|
|
42
|
+
// return fn.toIR().compile(platform);
|
|
43
|
+
// }
|
|
44
|
+
/**
|
|
45
|
+
* Standard entry point for constructing East expressions.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Create expressions from values
|
|
50
|
+
* East.value(3.14).add(2)
|
|
51
|
+
*
|
|
52
|
+
* // String interpolation
|
|
53
|
+
* East.str`Hello, ${name}!`
|
|
54
|
+
*
|
|
55
|
+
* // Comparisons
|
|
56
|
+
* East.equal(x, y)
|
|
57
|
+
* East.less(x, y)
|
|
58
|
+
*
|
|
59
|
+
* // Create functions
|
|
60
|
+
* East.function([IntegerType], IntegerType, ($, x) => $.return(x.add(1n)))
|
|
61
|
+
*
|
|
62
|
+
* // Standard library
|
|
63
|
+
* East.Integer.printCommaSeperated(1234567890n)
|
|
64
|
+
* East.Array.range(0n, 10n)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export const East = {
|
|
68
|
+
// Expr factories
|
|
69
|
+
/**
|
|
70
|
+
* Creates an East expression from a JavaScript value.
|
|
71
|
+
* Type is inferred from the value, or can be explicitly specified.
|
|
72
|
+
*
|
|
73
|
+
* @param value - The JavaScript value to convert to an East expression
|
|
74
|
+
* @param type - Optional explicit type specification
|
|
75
|
+
* @returns An East expression wrapping the value
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* East.value(42n) // IntegerExpr
|
|
80
|
+
* East.value(3.14) // FloatExpr
|
|
81
|
+
* East.value("hello") // StringExpr
|
|
82
|
+
* East.value([1n, 2n, 3n]) // ArrayExpr<IntegerType>
|
|
83
|
+
* East.value(new Map([[1n, "a"]])) // DictExpr<IntegerType, StringType>
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
value: from,
|
|
87
|
+
/**
|
|
88
|
+
* Creates a string expression with interpolation support.
|
|
89
|
+
* Allows embedding East expressions inside template literals.
|
|
90
|
+
*
|
|
91
|
+
* @returns A StringExpr with the interpolated values
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* East.str`Hello, ${name}!`
|
|
96
|
+
* East.str`Total: ${count} items`
|
|
97
|
+
* East.str`Result: ${x.add(y)}`
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
str,
|
|
101
|
+
/**
|
|
102
|
+
* Creates an East function with typed inputs and output.
|
|
103
|
+
* Functions can be nested, serialized to IR, and compiled to JavaScript.
|
|
104
|
+
*
|
|
105
|
+
* @param inputs - Array of East types for function parameters
|
|
106
|
+
* @param output - East type for function return value
|
|
107
|
+
* @param body - Function body using block builder and parameters
|
|
108
|
+
* @returns A FunctionExpr that can be compiled or serialized
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const add = East.function(
|
|
113
|
+
* [IntegerType, IntegerType],
|
|
114
|
+
* IntegerType,
|
|
115
|
+
* ($, a, b) => $.return(a.add(b))
|
|
116
|
+
* );
|
|
117
|
+
*
|
|
118
|
+
* const fibonacci = East.function([IntegerType], IntegerType, ($, n) => {
|
|
119
|
+
* $.if(East.lessEqual(n, 1n), $ => $.return(n));
|
|
120
|
+
* $.return(fibonacci(n.subtract(1n)).add(fibonacci(n.subtract(2n))));
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function: func,
|
|
125
|
+
/**
|
|
126
|
+
* Defines a platform function that can be called from East code.
|
|
127
|
+
* Platform functions allow East code to interact with the external environment.
|
|
128
|
+
*
|
|
129
|
+
* @param name - The name of the platform function
|
|
130
|
+
* @param inputs - Array of East types for the function parameters
|
|
131
|
+
* @param output - East type for the function return value
|
|
132
|
+
* @returns A callable platform function helper
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const log = East.platform("log", [StringType], NullType);
|
|
137
|
+
* const readFile = East.platform("readFile", [StringType], StringType);
|
|
138
|
+
*
|
|
139
|
+
* const myFunction = East.function([StringType], NullType, ($, msg) => {
|
|
140
|
+
* $(log(East.str`Message: ${msg}`));
|
|
141
|
+
* $.return(null);
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* const platform = [
|
|
145
|
+
* log.implement(console.log),
|
|
146
|
+
* readFile.implement(fs.readFileSync),
|
|
147
|
+
* ];
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
platform,
|
|
151
|
+
// compile,
|
|
152
|
+
// block,
|
|
153
|
+
// error,
|
|
154
|
+
// tryCatch,
|
|
155
|
+
// match: matchExpr,
|
|
156
|
+
// builtins
|
|
157
|
+
/**
|
|
158
|
+
* Converts any East expression to its string representation.
|
|
159
|
+
* Uses the East serialization format (not JSON).
|
|
160
|
+
*
|
|
161
|
+
* @param expr - The expression to convert to a string
|
|
162
|
+
* @returns A StringExpr containing the string representation
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* East.print(42n) // "42"
|
|
167
|
+
* East.print(3.14) // "3.14"
|
|
168
|
+
* East.print([1n, 2n, 3n]) // "[1, 2, 3]"
|
|
169
|
+
* East.print({a: 1n, b: true}) // "(a=1, b=true)"
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
print,
|
|
173
|
+
/**
|
|
174
|
+
* Deep equality comparison between two expressions.
|
|
175
|
+
* Compares values recursively, including nested structures.
|
|
176
|
+
*
|
|
177
|
+
* @param a - First expression to compare
|
|
178
|
+
* @param b - Second expression to compare
|
|
179
|
+
* @returns BooleanExpr that is true if values are deeply equal
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* East.equal(42n, 42n) // true
|
|
184
|
+
* East.equal([1n, 2n], [1n, 2n]) // true
|
|
185
|
+
* East.equal({a: 1n}, {a: 1n}) // true
|
|
186
|
+
* East.equal(x, y) // compare two expressions
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
equal,
|
|
190
|
+
/**
|
|
191
|
+
* Deep inequality comparison between two expressions.
|
|
192
|
+
* Returns true if values are not deeply equal.
|
|
193
|
+
*
|
|
194
|
+
* @param a - First expression to compare
|
|
195
|
+
* @param b - Second expression to compare
|
|
196
|
+
* @returns BooleanExpr that is true if values are not equal
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* East.notEqual(42n, 43n) // true
|
|
201
|
+
* East.notEqual([1n, 2n], [1n, 3n]) // true
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
notEqual,
|
|
205
|
+
/**
|
|
206
|
+
* Less-than comparison using East's total ordering.
|
|
207
|
+
* All East types have a defined total ordering, even complex structures.
|
|
208
|
+
*
|
|
209
|
+
* @param a - First expression to compare
|
|
210
|
+
* @param b - Second expression to compare
|
|
211
|
+
* @returns BooleanExpr that is true if a < b
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* East.less(1n, 2n) // true
|
|
216
|
+
* East.less(3.14, 2.0) // false
|
|
217
|
+
* East.less("apple", "banana") // true
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
less,
|
|
221
|
+
/**
|
|
222
|
+
* Less-than-or-equal comparison using East's total ordering.
|
|
223
|
+
*
|
|
224
|
+
* @param a - First expression to compare
|
|
225
|
+
* @param b - Second expression to compare
|
|
226
|
+
* @returns BooleanExpr that is true if a <= b
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* East.lessEqual(1n, 1n) // true
|
|
231
|
+
* East.lessEqual(2n, 1n) // false
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
lessEqual,
|
|
235
|
+
/**
|
|
236
|
+
* Greater-than comparison using East's total ordering.
|
|
237
|
+
*
|
|
238
|
+
* @param a - First expression to compare
|
|
239
|
+
* @param b - Second expression to compare
|
|
240
|
+
* @returns BooleanExpr that is true if a > b
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* East.greater(2n, 1n) // true
|
|
245
|
+
* East.greater("banana", "apple") // true
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
greater,
|
|
249
|
+
/**
|
|
250
|
+
* Greater-than-or-equal comparison using East's total ordering.
|
|
251
|
+
*
|
|
252
|
+
* @param a - First expression to compare
|
|
253
|
+
* @param b - Second expression to compare
|
|
254
|
+
* @returns BooleanExpr that is true if a >= b
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* East.greaterEqual(2n, 2n) // true
|
|
259
|
+
* East.greaterEqual(1n, 2n) // false
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
greaterEqual,
|
|
263
|
+
/**
|
|
264
|
+
* Reference equality comparison for mutable types (Array, Set, Dict).
|
|
265
|
+
* Checks if two expressions reference the same object in memory.
|
|
266
|
+
*
|
|
267
|
+
* @param a - First expression to compare
|
|
268
|
+
* @param b - Second expression to compare
|
|
269
|
+
* @returns BooleanExpr that is true if they reference the same object
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```ts
|
|
273
|
+
* const arr = $.let(East.value([1n, 2n]));
|
|
274
|
+
* East.is(arr, arr) // true (same reference)
|
|
275
|
+
* East.is([1n, 2n], [1n, 2n]) // false (different objects)
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
is,
|
|
279
|
+
// Root stdlib
|
|
280
|
+
/**
|
|
281
|
+
* Returns the minimum of two values using East's total ordering.
|
|
282
|
+
*
|
|
283
|
+
* @param a - First value
|
|
284
|
+
* @param b - Second value
|
|
285
|
+
* @returns The smaller of the two values
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* East.min(5n, 3n) // 3n
|
|
290
|
+
* East.min(3.14, 2.71) // 2.71
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
min: Expr.min,
|
|
294
|
+
/**
|
|
295
|
+
* Returns the maximum of two values using East's total ordering.
|
|
296
|
+
*
|
|
297
|
+
* @param a - First value
|
|
298
|
+
* @param b - Second value
|
|
299
|
+
* @returns The larger of the two values
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* East.max(5n, 3n) // 5n
|
|
304
|
+
* East.max(3.14, 2.71) // 3.14
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
max: Expr.max,
|
|
308
|
+
/**
|
|
309
|
+
* Clamps a value between minimum and maximum bounds.
|
|
310
|
+
*
|
|
311
|
+
* @param value - The value to clamp
|
|
312
|
+
* @param min - The minimum bound
|
|
313
|
+
* @param max - The maximum bound
|
|
314
|
+
* @returns The clamped value
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* East.clamp(5n, 0n, 10n) // 5n
|
|
319
|
+
* East.clamp(-5n, 0n, 10n) // 0n
|
|
320
|
+
* East.clamp(15n, 0n, 10n) // 10n
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
clamp: Expr.clamp,
|
|
324
|
+
// Type stdlibs
|
|
325
|
+
/**
|
|
326
|
+
* Standard library functions for Integer operations.
|
|
327
|
+
* Provides formatting, rounding, and utility functions for integers.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* East.Integer.printCommaSeperated(1234567n) // "1,234,567"
|
|
332
|
+
* East.Integer.printCompact(1500000n) // "1.5M"
|
|
333
|
+
* East.Integer.printOrdinal(42n) // "42nd"
|
|
334
|
+
* East.Integer.roundNearest(47n, 10n) // 50n
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
Integer: IntegerLib,
|
|
338
|
+
/**
|
|
339
|
+
* Standard library functions for Float operations.
|
|
340
|
+
* Provides rounding, formatting, and comparison functions for floating-point numbers.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* East.Float.roundToDecimals(3.14159, 2n) // 3.14
|
|
345
|
+
* East.Float.printCurrency(1234.56) // "$1234.56"
|
|
346
|
+
* East.Float.printPercentage(0.452, 1n) // "45.2%"
|
|
347
|
+
* East.Float.approxEqual(0.1, 0.10001, 0.001) // true
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
Float: FloatLib,
|
|
351
|
+
/**
|
|
352
|
+
* Standard library functions for DateTime operations.
|
|
353
|
+
* Provides construction, parsing, and rounding functions for date/time values.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* East.DateTime.fromEpochMilliseconds(1640000000000n)
|
|
358
|
+
* East.DateTime.fromComponents(2025n, 1n, 15n, 10n, 30n)
|
|
359
|
+
* East.DateTime.roundDownDay(date, 1n)
|
|
360
|
+
* East.DateTime.parseFormatted("%Y-%m-%d", "2025-01-15")
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
DateTime: DateTimeLib,
|
|
364
|
+
/**
|
|
365
|
+
* Standard library functions for String operations.
|
|
366
|
+
* Provides error formatting utilities.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* East.String.printError(errorMsg, stackTrace)
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
String: StringLib,
|
|
374
|
+
/**
|
|
375
|
+
* Standard library functions for Blob operations.
|
|
376
|
+
* Provides binary encoding utilities.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* East.Blob.encodeBeast(myValue, 'v2') // Encode to BEAST format
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
Blob: BlobLib,
|
|
384
|
+
/**
|
|
385
|
+
* Standard library functions for Array operations.
|
|
386
|
+
* Provides generation utilities for creating arrays.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* East.Array.range(0n, 10n, 2n) // [0n, 2n, 4n, 6n, 8n]
|
|
391
|
+
* East.Array.linspace(0.0, 1.0, 11n) // [0.0, 0.1, ..., 1.0]
|
|
392
|
+
* East.Array.generate(5n, IntegerType, ($, i) => i.multiply(i))
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
Array: ArrayLib,
|
|
396
|
+
/**
|
|
397
|
+
* Standard library functions for Set operations.
|
|
398
|
+
* Provides generation utilities for creating sets.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* East.Set.generate(5n, IntegerType, ($, i) => i.multiply(2n))
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
Set: SetLib,
|
|
406
|
+
/**
|
|
407
|
+
* Standard library functions for Dict operations.
|
|
408
|
+
* Provides generation utilities for creating dictionaries.
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```ts
|
|
412
|
+
* East.Dict.generate(
|
|
413
|
+
* 5n,
|
|
414
|
+
* IntegerType,
|
|
415
|
+
* IntegerType,
|
|
416
|
+
* ($, i) => i,
|
|
417
|
+
* ($, i) => i.multiply(10n)
|
|
418
|
+
* )
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
Dict: DictLib,
|
|
422
|
+
};
|
|
423
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/expr/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AACtB,cAAc,YAAY,CAAC;AAE3B,+CAA+C;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,gCAAgC;AAChC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3H,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,qDAAqD;AAGrD,4BAA4B;AAC5B,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAC3C,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAMrC,yDAAyD;AACzD,KAAK;AACL,yEAAyE;AACzE,KAAK;AACL,8CAA8C;AAC9C,kGAAkG;AAClG,6FAA6F;AAC7F,KAAK;AACL,cAAc;AACd,WAAW;AACX,gGAAgG;AAChG,6CAA6C;AAC7C,4CAA4C;AAC5C,SAAS;AACT,MAAM;AACN,oDAAoD;AACpD,4BAA4B;AAC5B,sDAAsD;AACtD,WAAW;AACX,wCAAwC;AACxC,IAAI;AAEJ;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,iBAAiB;IAEjB;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,EAAE,IAAI;IAEX;;;;;;;;;;;;OAYG;IACH,GAAG;IAEH;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,EAAE,IAAI;IAEd;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,QAAQ;IACR,WAAW;IACX,SAAS;IACT,SAAS;IACT,YAAY;IACZ,oBAAoB;IAEpB,WAAW;IAEX;;;;;;;;;;;;;;OAcG;IACH,KAAK;IAEL;;;;;;;;;;;;;;;OAeG;IACH,KAAK;IAEL;;;;;;;;;;;;;OAaG;IACH,QAAQ;IAER;;;;;;;;;;;;;;OAcG;IACH,IAAI;IAEJ;;;;;;;;;;;;OAYG;IACH,SAAS;IAET;;;;;;;;;;;;OAYG;IACH,OAAO;IAEP;;;;;;;;;;;;OAYG;IACH,YAAY;IAEZ;;;;;;;;;;;;;;OAcG;IACH,EAAE;IAEF,cAAc;IAEd;;;;;;;;;;;;OAYG;IACH,GAAG,EAAE,IAAI,CAAC,GAAG;IAEb;;;;;;;;;;;;OAYG;IACH,GAAG,EAAE,IAAI,CAAC,GAAG;IAEb;;;;;;;;;;;;;;OAcG;IACH,KAAK,EAAE,IAAI,CAAC,KAAK;IAEjB,eAAe;IAEf;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,UAAU;IAEnB;;;;;;;;;;;OAWG;IACH,KAAK,EAAE,QAAQ;IAEf;;;;;;;;;;;OAWG;IACH,QAAQ,EAAE,WAAW;IAErB;;;;;;;;OAQG;IACH,MAAM,EAAE,SAAS;IAEjB;;;;;;;;OAQG;IACH,IAAI,EAAE,OAAO;IAEb;;;;;;;;;;OAUG;IACH,KAAK,EAAE,QAAQ;IAEf;;;;;;;;OAQG;IACH,GAAG,EAAE,MAAM;IAEX;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,OAAO;CACd,CAAC"}
|
|
@@ -0,0 +1,256 @@
|
|
|
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 type { AST } from "../ast.js";
|
|
6
|
+
import { FloatType, IntegerType } from "../types.js";
|
|
7
|
+
import { Expr, type ToExpr } from "./expr.js";
|
|
8
|
+
import type { FloatExpr } from "./float.js";
|
|
9
|
+
/**
|
|
10
|
+
* Expression representing integer values and operations.
|
|
11
|
+
*
|
|
12
|
+
* IntegerExpr provides arithmetic, comparison, and conversion operations for 64-bit signed integers.
|
|
13
|
+
* Operations automatically promote to FloatExpr when mixed with float operands.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Basic arithmetic
|
|
18
|
+
* const calculate = East.function([IntegerType, IntegerType], IntegerType, ($, a, b) => {
|
|
19
|
+
* const sum = a.add(b);
|
|
20
|
+
* const product = a.multiply(b);
|
|
21
|
+
* const power = a.pow(2n);
|
|
22
|
+
* $.return(sum.add(product).add(power));
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Integer division and remainder
|
|
26
|
+
* const divMod = East.function([IntegerType, IntegerType], StructType({quot: IntegerType, rem: IntegerType}), ($, x, y) => {
|
|
27
|
+
* $.return({quot: x.divide(y), rem: x.remainder(y)});
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Type promotion with floats
|
|
31
|
+
* const mixed = East.function([IntegerType], FloatType, ($, x) => {
|
|
32
|
+
* $.return(x.add(2.5)); // Returns FloatExpr
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class IntegerExpr extends Expr<IntegerType> {
|
|
37
|
+
constructor(ast: AST, createExpr: ToExpr);
|
|
38
|
+
/**
|
|
39
|
+
* Negates an integer value (-x).
|
|
40
|
+
*
|
|
41
|
+
* @returns The negated integer
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const negate = East.function([IntegerType], IntegerType, ($, x) => {
|
|
46
|
+
* $.return(x.negate());
|
|
47
|
+
* });
|
|
48
|
+
* const compiled = East.compile(negate.toIR(), []);
|
|
49
|
+
* compiled(5n); // -5n
|
|
50
|
+
* compiled(-3n); // 3n
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
negate(): IntegerExpr;
|
|
54
|
+
/**
|
|
55
|
+
* Adds two integers or promotes to float if adding a float.
|
|
56
|
+
*
|
|
57
|
+
* @param y - The integer or float to add
|
|
58
|
+
* @returns IntegerExpr if both operands are integers, FloatExpr if either is a float
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const addIntegers = East.function([IntegerType, IntegerType], IntegerType, ($, x, y) => {
|
|
63
|
+
* $.return(x.add(y));
|
|
64
|
+
* });
|
|
65
|
+
* const compiled = East.compile(addIntegers.toIR(), []);
|
|
66
|
+
* compiled(3n, 4n); // 7n
|
|
67
|
+
*
|
|
68
|
+
* // Adding with float promotes to float
|
|
69
|
+
* const addFloat = East.function([IntegerType], FloatType, ($, x) => {
|
|
70
|
+
* $.return(x.add(2.5));
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
add(y: Expr<IntegerType> | bigint): IntegerExpr;
|
|
75
|
+
add(y: Expr<FloatType> | number): FloatExpr;
|
|
76
|
+
/**
|
|
77
|
+
* Subtracts two integers or promotes to float if subtracting a float.
|
|
78
|
+
*
|
|
79
|
+
* @param y - The integer or float to subtract
|
|
80
|
+
* @returns IntegerExpr if both operands are integers, FloatExpr if either is a float
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const subtractIntegers = East.function([IntegerType, IntegerType], IntegerType, ($, x, y) => {
|
|
85
|
+
* $.return(x.subtract(y));
|
|
86
|
+
* });
|
|
87
|
+
* const compiled = East.compile(subtractIntegers.toIR(), []);
|
|
88
|
+
* compiled(10n, 3n); // 7n
|
|
89
|
+
* compiled(5n, 8n); // -3n
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
subtract(y: Expr<IntegerType> | bigint): IntegerExpr;
|
|
93
|
+
subtract(y: Expr<FloatType> | number): FloatExpr;
|
|
94
|
+
/**
|
|
95
|
+
* Multiplies two integers or promotes to float if multiplying by a float.
|
|
96
|
+
*
|
|
97
|
+
* @param y - The integer or float to multiply by
|
|
98
|
+
* @returns IntegerExpr if both operands are integers, FloatExpr if either is a float
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const multiplyIntegers = East.function([IntegerType, IntegerType], IntegerType, ($, x, y) => {
|
|
103
|
+
* $.return(x.multiply(y));
|
|
104
|
+
* });
|
|
105
|
+
* const compiled = East.compile(multiplyIntegers.toIR(), []);
|
|
106
|
+
* compiled(6n, 7n); // 42n
|
|
107
|
+
* compiled(-3n, 4n); // -12n
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
multiply(y: Expr<IntegerType> | bigint): IntegerExpr;
|
|
111
|
+
multiply(y: Expr<FloatType> | number): FloatExpr;
|
|
112
|
+
/**
|
|
113
|
+
* Divides two integers (floor division) or promotes to float if dividing by a float.
|
|
114
|
+
*
|
|
115
|
+
* @param y - The integer or float divisor
|
|
116
|
+
* @returns IntegerExpr (floor division) if both are integers, FloatExpr if either is a float
|
|
117
|
+
*
|
|
118
|
+
* @remarks Integer division by zero returns 0 (does not throw error).
|
|
119
|
+
* When dividing by a float, uses normal floating point division.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const divideIntegers = East.function([IntegerType, IntegerType], IntegerType, ($, x, y) => {
|
|
124
|
+
* $.return(x.divide(y));
|
|
125
|
+
* });
|
|
126
|
+
* const compiled = East.compile(divideIntegers.toIR(), []);
|
|
127
|
+
* compiled(10n, 3n); // 3n (floor division)
|
|
128
|
+
* compiled(10n, 2n); // 5n
|
|
129
|
+
* compiled(10n, 0n); // 0n (division by zero returns 0)
|
|
130
|
+
* compiled(-10n, 3n); // -4n (floor towards negative infinity)
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
divide(y: Expr<IntegerType> | bigint): IntegerExpr;
|
|
134
|
+
divide(y: Expr<FloatType> | number): FloatExpr;
|
|
135
|
+
/**
|
|
136
|
+
* Computes the remainder of integer division or promotes to float.
|
|
137
|
+
*
|
|
138
|
+
* @param y - The integer or float divisor
|
|
139
|
+
* @returns IntegerExpr if both are integers, FloatExpr if either is a float
|
|
140
|
+
*
|
|
141
|
+
* @remarks Integer remainder by zero returns 0 (does not throw error).
|
|
142
|
+
* Result has the same sign as the divisor (floor division semantics).
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const getRemainder = East.function([IntegerType, IntegerType], IntegerType, ($, x, y) => {
|
|
147
|
+
* $.return(x.remainder(y));
|
|
148
|
+
* });
|
|
149
|
+
* const compiled = East.compile(getRemainder.toIR(), []);
|
|
150
|
+
* compiled(10n, 3n); // 1n (10 = 3*3 + 1)
|
|
151
|
+
* compiled(10n, 4n); // 2n
|
|
152
|
+
* compiled(-10n, 3n); // 2n (floor division: -10 = 3*(-4) + 2)
|
|
153
|
+
* compiled(10n, 0n); // 0n (remainder by zero returns 0)
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
remainder(y: Expr<IntegerType> | bigint): IntegerExpr;
|
|
157
|
+
remainder(y: Expr<FloatType> | number): FloatExpr;
|
|
158
|
+
/**
|
|
159
|
+
* Raises an integer to a power or promotes to float.
|
|
160
|
+
*
|
|
161
|
+
* @param y - The integer or float exponent
|
|
162
|
+
* @returns IntegerExpr if both are integers, FloatExpr if either is a float
|
|
163
|
+
*
|
|
164
|
+
* @remarks Integer exponentiation with negative exponent returns 0.
|
|
165
|
+
* When using a float exponent, uses floating point exponentiation.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const power = East.function([IntegerType, IntegerType], IntegerType, ($, base, exp) => {
|
|
170
|
+
* $.return(base.pow(exp));
|
|
171
|
+
* });
|
|
172
|
+
* const compiled = East.compile(power.toIR(), []);
|
|
173
|
+
* compiled(2n, 3n); // 8n (2^3)
|
|
174
|
+
* compiled(5n, 2n); // 25n
|
|
175
|
+
* compiled(10n, 0n); // 1n (anything^0 = 1)
|
|
176
|
+
* compiled(2n, -1n); // 0n (negative exponent returns 0 for integers)
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
pow(y: Expr<IntegerType> | bigint): IntegerExpr;
|
|
180
|
+
pow(y: Expr<FloatType> | number): FloatExpr;
|
|
181
|
+
/**
|
|
182
|
+
* Returns the absolute value of an integer.
|
|
183
|
+
*
|
|
184
|
+
* @returns The absolute value (always non-negative)
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* const absoluteValue = East.function([IntegerType], IntegerType, ($, x) => {
|
|
189
|
+
* $.return(x.abs());
|
|
190
|
+
* });
|
|
191
|
+
* const compiled = East.compile(absoluteValue.toIR(), []);
|
|
192
|
+
* compiled(5n); // 5n
|
|
193
|
+
* compiled(-5n); // 5n
|
|
194
|
+
* compiled(0n); // 0n
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
abs(): IntegerExpr;
|
|
198
|
+
/**
|
|
199
|
+
* Returns the sign of an integer (-1 for negative, 0 for zero, 1 for positive).
|
|
200
|
+
*
|
|
201
|
+
* @returns -1n, 0n, or 1n depending on the sign of the integer
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const getSign = East.function([IntegerType], IntegerType, ($, x) => {
|
|
206
|
+
* $.return(x.sign());
|
|
207
|
+
* });
|
|
208
|
+
* const compiled = East.compile(getSign.toIR(), []);
|
|
209
|
+
* compiled(42n); // 1n
|
|
210
|
+
* compiled(-17n); // -1n
|
|
211
|
+
* compiled(0n); // 0n
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
sign(): IntegerExpr;
|
|
215
|
+
/**
|
|
216
|
+
* Computes the integer logarithm with a specified base (floor of log).
|
|
217
|
+
*
|
|
218
|
+
* @param base - The base for the logarithm
|
|
219
|
+
* @returns The floor of log_base(x)
|
|
220
|
+
*
|
|
221
|
+
* @remarks Returns 0 if x <= 0 or base <= 1.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const logarithm = East.function([IntegerType, IntegerType], IntegerType, ($, x, base) => {
|
|
226
|
+
* $.return(x.log(base));
|
|
227
|
+
* });
|
|
228
|
+
* const compiled = East.compile(logarithm.toIR(), []);
|
|
229
|
+
* compiled(1000n, 10n); // 3n (10^3 = 1000)
|
|
230
|
+
* compiled(8n, 2n); // 3n (2^3 = 8)
|
|
231
|
+
* compiled(100n, 10n); // 2n (10^2 = 100)
|
|
232
|
+
* compiled(7n, 2n); // 2n (floor of log_2(7) ≈ 2.8)
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
log(base: Expr<IntegerType> | bigint): IntegerExpr;
|
|
236
|
+
/**
|
|
237
|
+
* Converts an integer to a floating-point number.
|
|
238
|
+
*
|
|
239
|
+
* @returns The integer as a FloatExpr
|
|
240
|
+
*
|
|
241
|
+
* @remarks May lose precision for very large integers (beyond 2^53).
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* const convertToFloat = East.function([IntegerType], FloatType, ($, x) => {
|
|
246
|
+
* $.return(x.toFloat());
|
|
247
|
+
* });
|
|
248
|
+
* const compiled = East.compile(convertToFloat.toIR(), []);
|
|
249
|
+
* compiled(42n); // 42.0
|
|
250
|
+
* compiled(-17n); // -17.0
|
|
251
|
+
* compiled(0n); // 0.0
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
toFloat(): FloatExpr;
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=integer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integer.d.ts","sourceRoot":"","sources":["../../../src/expr/integer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAe,MAAM,aAAa,CAAC;AAClE,OAAO,EAAa,IAAI,EAAiB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC;gBACpC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM;IAIxC;;;;;;;;;;;;;;OAcG;IACH,MAAM,IAAI,WAAW;IAWrB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;IAC/C,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS;IAwB3C;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;IACpD,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS;IAwBhD;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;IACpD,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS;IAwBhD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;IAClD,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS;IAwB9C;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;IACrD,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS;IAwBjD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;IAC/C,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS;IAwB3C;;;;;;;;;;;;;;;OAeG;IACH,GAAG,IAAI,WAAW;IAWlB;;;;;;;;;;;;;;;OAeG;IACH,IAAI,IAAI,WAAW;IAWnB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;IAYlD;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,IAAI,SAAS;CAUrB"}
|