@elaraai/east 0.0.1-beta.1 → 0.0.1-beta.10
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/README.md +9 -6
- package/dist/src/analyze.d.ts +4 -4
- package/dist/src/analyze.d.ts.map +1 -1
- package/dist/src/analyze.js +142 -44
- package/dist/src/analyze.js.map +1 -1
- package/dist/src/ast.d.ts +18 -7
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast.js +1 -146
- package/dist/src/ast.js.map +1 -1
- package/dist/src/ast_to_ir.d.ts +7 -0
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +80 -11
- package/dist/src/ast_to_ir.js.map +1 -1
- package/dist/src/builtins.d.ts +1 -1
- package/dist/src/builtins.d.ts.map +1 -1
- package/dist/src/builtins.js +89 -64
- package/dist/src/builtins.js.map +1 -1
- package/dist/src/comparison.d.ts.map +1 -1
- package/dist/src/comparison.js +19 -2
- package/dist/src/comparison.js.map +1 -1
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +137 -221
- package/dist/src/compile.js.map +1 -1
- package/dist/src/default.d.ts.map +1 -1
- package/dist/src/default.js +2 -0
- package/dist/src/default.js.map +1 -1
- package/dist/src/eastir.d.ts +12 -10
- package/dist/src/eastir.d.ts.map +1 -1
- package/dist/src/eastir.js +20 -19
- package/dist/src/eastir.js.map +1 -1
- package/dist/src/expr/array.d.ts +66 -0
- package/dist/src/expr/array.d.ts.map +1 -1
- package/dist/src/expr/array.js +161 -51
- package/dist/src/expr/array.js.map +1 -1
- package/dist/src/expr/ast.d.ts.map +1 -1
- package/dist/src/expr/ast.js +6 -0
- package/dist/src/expr/ast.js.map +1 -1
- package/dist/src/expr/asyncfunction.d.ts +49 -0
- package/dist/src/expr/asyncfunction.d.ts.map +1 -0
- package/dist/src/expr/asyncfunction.js +60 -0
- package/dist/src/expr/asyncfunction.js.map +1 -0
- package/dist/src/expr/blob.d.ts +25 -1
- package/dist/src/expr/blob.d.ts.map +1 -1
- package/dist/src/expr/blob.js +36 -1
- package/dist/src/expr/blob.js.map +1 -1
- package/dist/src/expr/block.d.ts +82 -8
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +278 -16
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/dict.js +47 -47
- package/dist/src/expr/dict.js.map +1 -1
- package/dist/src/expr/expr.d.ts +9 -0
- package/dist/src/expr/expr.d.ts.map +1 -1
- package/dist/src/expr/expr.js +5 -1
- package/dist/src/expr/expr.js.map +1 -1
- package/dist/src/expr/index.d.ts +112 -2
- package/dist/src/expr/index.d.ts.map +1 -1
- package/dist/src/expr/index.js +110 -8
- package/dist/src/expr/index.js.map +1 -1
- package/dist/src/expr/libs/array.js +1 -1
- package/dist/src/expr/libs/array.js.map +1 -1
- package/dist/src/expr/libs/dict.js +3 -3
- package/dist/src/expr/libs/dict.js.map +1 -1
- package/dist/src/expr/libs/integer.d.ts +19 -0
- package/dist/src/expr/libs/integer.d.ts.map +1 -1
- package/dist/src/expr/libs/integer.js +47 -0
- package/dist/src/expr/libs/integer.js.map +1 -1
- package/dist/src/expr/libs/set.js +2 -2
- package/dist/src/expr/libs/set.js.map +1 -1
- package/dist/src/expr/ref.js +1 -1
- package/dist/src/expr/ref.js.map +1 -1
- package/dist/src/expr/set.js +38 -38
- package/dist/src/expr/set.js.map +1 -1
- package/dist/src/expr/struct.d.ts +2 -0
- package/dist/src/expr/struct.d.ts.map +1 -1
- package/dist/src/expr/types.d.ts +8 -5
- package/dist/src/expr/types.d.ts.map +1 -1
- package/dist/src/expr/variant.d.ts +53 -0
- package/dist/src/expr/variant.d.ts.map +1 -1
- package/dist/src/expr/variant.js +56 -0
- package/dist/src/expr/variant.js.map +1 -1
- package/dist/src/fuzz.d.ts.map +1 -1
- package/dist/src/fuzz.js +5 -0
- package/dist/src/fuzz.js.map +1 -1
- package/dist/src/internal.d.ts +7 -0
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +7 -0
- package/dist/src/internal.js.map +1 -1
- package/dist/src/ir.d.ts +231 -33
- package/dist/src/ir.d.ts.map +1 -1
- package/dist/src/ir.js +3 -1
- package/dist/src/ir.js.map +1 -1
- package/dist/src/serialization/beast.d.ts.map +1 -1
- package/dist/src/serialization/beast.js +59 -18
- package/dist/src/serialization/beast.js.map +1 -1
- package/dist/src/serialization/beast2-stream.d.ts.map +1 -1
- package/dist/src/serialization/beast2-stream.js +5 -0
- package/dist/src/serialization/beast2-stream.js.map +1 -1
- package/dist/src/serialization/beast2.d.ts.map +1 -1
- package/dist/src/serialization/beast2.js +10 -4
- package/dist/src/serialization/beast2.js.map +1 -1
- package/dist/src/serialization/csv.d.ts +139 -0
- package/dist/src/serialization/csv.d.ts.map +1 -0
- package/dist/src/serialization/csv.js +615 -0
- package/dist/src/serialization/csv.js.map +1 -0
- package/dist/src/serialization/east.d.ts.map +1 -1
- package/dist/src/serialization/east.js +9 -1
- package/dist/src/serialization/east.js.map +1 -1
- package/dist/src/serialization/index.d.ts +1 -0
- package/dist/src/serialization/index.d.ts.map +1 -1
- package/dist/src/serialization/index.js +1 -0
- package/dist/src/serialization/index.js.map +1 -1
- package/dist/src/serialization/json.d.ts.map +1 -1
- package/dist/src/serialization/json.js +8 -2
- package/dist/src/serialization/json.js.map +1 -1
- package/dist/src/type_of_type.d.ts +20 -3
- package/dist/src/type_of_type.d.ts.map +1 -1
- package/dist/src/type_of_type.js +101 -13
- package/dist/src/type_of_type.js.map +1 -1
- package/dist/src/types.d.ts +59 -16
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +141 -91
- package/dist/src/types.js.map +1 -1
- package/package.json +4 -4
package/dist/src/expr/block.d.ts
CHANGED
|
@@ -15,12 +15,33 @@ import { StringExpr } from "./string.js";
|
|
|
15
15
|
import { ArrayExpr } from "./array.js";
|
|
16
16
|
import { SetExpr } from "./set.js";
|
|
17
17
|
import { DictExpr } from "./dict.js";
|
|
18
|
-
import { type CallableFunctionExpr } from "./function.js";
|
|
18
|
+
import { type CallableFunctionExpr, FunctionExpr } from "./function.js";
|
|
19
19
|
import type { PlatformFunction } from "../platform.js";
|
|
20
|
+
import { AsyncFunctionExpr, type CallableAsyncFunctionExpr } from "./asyncfunction.js";
|
|
20
21
|
/** A factory function to help build `Expr` from AST.
|
|
21
22
|
* We inject this into each concrete `Expr` type so they can create new expressions recursively, without having circular dependencies between JavaScript modules.
|
|
22
23
|
*/
|
|
23
24
|
export declare function fromAst<T extends AST>(ast: T): Expr<T["type"]>;
|
|
25
|
+
/**
|
|
26
|
+
* Compile a function expression into a JavaScript function.
|
|
27
|
+
*
|
|
28
|
+
* @param f the function expression to compile
|
|
29
|
+
* @param platform the platform functions available during compilation
|
|
30
|
+
* @returns the compiled function
|
|
31
|
+
*/
|
|
32
|
+
export declare function compile<I extends EastType[], O extends EastType, F extends FunctionExpr<I, O>>(f: F, platform: PlatformFunction[]): (...inputs: {
|
|
33
|
+
[K in keyof I]: ValueTypeOf<I[K]>;
|
|
34
|
+
}) => ValueTypeOf<O>;
|
|
35
|
+
/**
|
|
36
|
+
* Compile an async function expression into a JavaScript function.
|
|
37
|
+
*
|
|
38
|
+
* @param f the async function expression to compile
|
|
39
|
+
* @param platform the platform functions available during compilation
|
|
40
|
+
* @returns the compiled async function
|
|
41
|
+
*/
|
|
42
|
+
export declare function compileAsync<I extends EastType[], O extends EastType, F extends AsyncFunctionExpr<I, O>>(f: F, platform: PlatformFunction[]): (...inputs: {
|
|
43
|
+
[K in keyof I]: ValueTypeOf<I[K]>;
|
|
44
|
+
}) => Promise<ValueTypeOf<O>>;
|
|
24
45
|
/**
|
|
25
46
|
* Create an East expression from a JavaScript value
|
|
26
47
|
*/
|
|
@@ -39,6 +60,19 @@ export declare function func<const I extends EastType[], O extends EastType>(inp
|
|
|
39
60
|
export declare function func<const I extends EastType[], F extends ($: BlockBuilder<NeverType>, ...inputs: {
|
|
40
61
|
[K in keyof I]: ExprType<I[K]>;
|
|
41
62
|
}) => any>(input_types: I, output_type: undefined, body: F): CallableFunctionExpr<I, TypeOf<ReturnType<F> extends void ? NeverType : ReturnType<F>>>;
|
|
63
|
+
/** Define an East function.
|
|
64
|
+
*
|
|
65
|
+
* The function may either be a free function or a closure.
|
|
66
|
+
* A closure is a function defined within another function that "captures", or refers to, one or more variables from an outer function.
|
|
67
|
+
* Functions without captures are called free functions and can be compiled and executed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function asyncFunction<const I extends EastType[], O extends EastType>(input_types: I, output_type: O, body: ($: BlockBuilder<O>, ...inputs: {
|
|
70
|
+
[K in keyof I]: ExprType<I[K]>;
|
|
71
|
+
}) => SubtypeExprOrValue<O> | void): CallableAsyncFunctionExpr<I, O>;
|
|
72
|
+
/** @internal */
|
|
73
|
+
export declare function asyncFunction<const I extends EastType[], F extends ($: BlockBuilder<NeverType>, ...inputs: {
|
|
74
|
+
[K in keyof I]: ExprType<I[K]>;
|
|
75
|
+
}) => any>(input_types: I, output_type: undefined, body: F): CallableAsyncFunctionExpr<I, TypeOf<ReturnType<F> extends void ? NeverType : ReturnType<F>>>;
|
|
42
76
|
/** Template string literal to create an East string dynamically from components
|
|
43
77
|
*
|
|
44
78
|
* @example
|
|
@@ -89,16 +123,26 @@ export declare function greaterEqual<T>(left: Expr<T>, right: SubtypeExprOrValue
|
|
|
89
123
|
export declare function is<T>(left: Expr<T>, right: SubtypeExprOrValue<NoInfer<T>>): BooleanExpr;
|
|
90
124
|
/** Print a value as a string. */
|
|
91
125
|
export declare function print(value: Expr): StringExpr;
|
|
92
|
-
/**
|
|
126
|
+
/** Callable helper type for synchronous platform functions. */
|
|
127
|
+
export type PlatformDefinition<Inputs extends EastType[], Output extends EastType> = ((...args: {
|
|
128
|
+
[K in keyof Inputs]: SubtypeExprOrValue<Inputs[K]>;
|
|
129
|
+
}) => ExprType<Output>) & {
|
|
130
|
+
implement: (fn: (...args: {
|
|
131
|
+
[K in keyof Inputs]: ValueTypeOf<Inputs[K]>;
|
|
132
|
+
}) => Output extends NullType ? null | undefined | void : ValueTypeOf<Output>) => PlatformFunction;
|
|
133
|
+
};
|
|
134
|
+
/** Create a callable helper to invoke a synchronous platform function.
|
|
93
135
|
*
|
|
94
136
|
* Platform functions provide access to external capabilities (logging, I/O, database access, etc.)
|
|
95
137
|
* that East code can call. They are defined by the platform when compiling and executing East IR.
|
|
96
138
|
*
|
|
97
|
-
* @param name - The name of the platform function
|
|
139
|
+
* @param name - The name of the platform function
|
|
98
140
|
* @param input_types - Array of input parameter types for the platform function
|
|
99
141
|
* @param output_type - The return type of the platform function
|
|
100
142
|
* @returns A callable function that creates Platform AST nodes when invoked
|
|
101
143
|
*
|
|
144
|
+
* @see {@link asyncPlatform} for defining asynchronous platform functions (that return `Promise`s)
|
|
145
|
+
*
|
|
102
146
|
* @example
|
|
103
147
|
* ```ts
|
|
104
148
|
// Define a platform function helper for logging
|
|
@@ -118,21 +162,51 @@ const compiled = myFunction.toIR().compile(platform);
|
|
|
118
162
|
compiled(); // Logs "Hello, world!" to the console
|
|
119
163
|
* ```
|
|
120
164
|
*/
|
|
121
|
-
export declare function platform<const Inputs extends EastType[], Output extends EastType>(name: string, input_types: Inputs, output_type: Output):
|
|
165
|
+
export declare function platform<const Inputs extends EastType[], Output extends EastType>(name: string, input_types: Inputs, output_type: Output): PlatformDefinition<Inputs, Output>;
|
|
166
|
+
/** Callable helper type for asynchronous platform functions. */
|
|
167
|
+
export type AsyncPlatformDefinition<Inputs extends EastType[], Output extends EastType> = ((...args: {
|
|
122
168
|
[K in keyof Inputs]: SubtypeExprOrValue<Inputs[K]>;
|
|
123
169
|
}) => ExprType<Output>) & {
|
|
124
170
|
implement: (fn: (...args: {
|
|
125
171
|
[K in keyof Inputs]: ValueTypeOf<Inputs[K]>;
|
|
126
|
-
}) => Output extends NullType ? null | undefined | void : ValueTypeOf<Output>) => PlatformFunction;
|
|
127
|
-
implementAsync: (fn: (...args: {
|
|
128
|
-
[K in keyof Inputs]: ValueTypeOf<Inputs[K]>;
|
|
129
172
|
}) => Output extends NullType ? Promise<null | undefined | void> : Promise<ValueTypeOf<Output>>) => PlatformFunction;
|
|
130
173
|
};
|
|
174
|
+
/** Create a callable helper to invoke an asynchronous platform function.
|
|
175
|
+
*
|
|
176
|
+
* Platform functions provide access to external capabilities (logging, I/O, database access, etc.)
|
|
177
|
+
* that East code can call. They are defined by the platform when compiling and executing East IR.
|
|
178
|
+
*
|
|
179
|
+
* @param name - The name of the asynchronous platform function
|
|
180
|
+
* @param input_types - Array of input parameter types for the platform function
|
|
181
|
+
* @param output_type - The return type of the platform function
|
|
182
|
+
* @returns A callable function that creates Platform AST nodes when invoked
|
|
183
|
+
*
|
|
184
|
+
* @see {@link platform} for defining synchronous platform functions
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
// Define a platform function for reading files as a string
|
|
189
|
+
const readFile = East.asyncPlatform("readFile", [StringType], StringType);
|
|
190
|
+
|
|
191
|
+
// Use it in East code
|
|
192
|
+
const myFunction = East.asyncFunction([], StringType, ($) => {
|
|
193
|
+
$.return(readFile("data.txt"));
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Provide the (async) implementation when compiling
|
|
197
|
+
const platform = [
|
|
198
|
+
readFile.implement((filename: string) => fs.promises.readFile(filename, 'utf-8')),
|
|
199
|
+
];
|
|
200
|
+
const compiled = myFunction.toIR().compile(platform);
|
|
201
|
+
compiled(); // Logs "Hello, world!" to the console
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export declare function asyncPlatform<const Inputs extends EastType[], Output extends EastType>(name: string, input_types: Inputs, output_type: Output): AsyncPlatformDefinition<Inputs, Output>;
|
|
131
205
|
/** A helper for building blocks of code.
|
|
132
206
|
* Methods like `let`, `if`, `for` etc are available on the builder.
|
|
133
207
|
* You can also add expressions (having side effects) directly by calling the builder as a function.
|
|
134
208
|
*/
|
|
135
|
-
export type BlockBuilder<Ret> = (
|
|
209
|
+
export type BlockBuilder<Ret> = ((expr: Expr) => void) & {
|
|
136
210
|
/** @internal */
|
|
137
211
|
statements: AST[];
|
|
138
212
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../src/expr/block.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnH,OAAO,EAA+B,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,KAAK,QAAQ,EAA2B,QAAQ,EAA0B,UAAU,EAAE,SAAS,EAAE,WAAW,EAAe,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAEzN,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAa,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,OAAO,EAAE,KAAK,oBAAoB,EAAsB,MAAM,eAAe,CAAC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIv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AAK,IAAI,GAAG,IAAI,GAAG,IAAI;IAkC7K,0KAA0K;IAC1K,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,IAAI,GAAG,IAAI;CAsB3D"}
|
package/dist/src/expr/block.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import {} from "../ast.js";
|
|
6
6
|
import { get_location, printLocation } from "../location.js";
|
|
7
|
-
import { FunctionType, isSubtype, NullType, printType, isTypeEqual, StringType, NeverType, VariantType, BooleanType, TypeUnion, IntegerType, StructType, ArrayType } from "../types.js";
|
|
7
|
+
import { FunctionType, isSubtype, NullType, printType, isTypeEqual, StringType, NeverType, VariantType, BooleanType, TypeUnion, IntegerType, StructType, ArrayType, AsyncFunctionType } from "../types.js";
|
|
8
8
|
import { AstSymbol, Expr } from "./expr.js";
|
|
9
9
|
import { NeverExpr } from "./never.js";
|
|
10
10
|
import { NullExpr } from "./null.js";
|
|
@@ -19,10 +19,11 @@ import { SetExpr } from "./set.js";
|
|
|
19
19
|
import { DictExpr } from "./dict.js";
|
|
20
20
|
import { StructExpr } from "./struct.js";
|
|
21
21
|
import { VariantExpr } from "./variant.js";
|
|
22
|
-
import { createFunctionExpr } from "./function.js";
|
|
22
|
+
import { createFunctionExpr, FunctionExpr } from "./function.js";
|
|
23
23
|
import { valueOrExprToAst, valueOrExprToAstTyped } from "./ast.js";
|
|
24
24
|
import { toEastTypeValue } from "../type_of_type.js";
|
|
25
25
|
import { RefExpr } from "./ref.js";
|
|
26
|
+
import { AsyncFunctionExpr, createAsyncFunctionExpr } from "./asyncfunction.js";
|
|
26
27
|
/** A factory function to help build `Expr` from AST.
|
|
27
28
|
* We inject this into each concrete `Expr` type so they can create new expressions recursively, without having circular dependencies between JavaScript modules.
|
|
28
29
|
*/
|
|
@@ -83,10 +84,33 @@ export function fromAst(ast) {
|
|
|
83
84
|
else if (type === "Function") {
|
|
84
85
|
return createFunctionExpr(ast.type.inputs, ast.type.output, ast, fromAst);
|
|
85
86
|
}
|
|
87
|
+
else if (type === "AsyncFunction") {
|
|
88
|
+
return createAsyncFunctionExpr(ast.type.inputs, ast.type.output, ast, fromAst);
|
|
89
|
+
}
|
|
86
90
|
else {
|
|
87
91
|
throw new Error(`fromAst not implemented for type ${printType(ast.type)} at ${printLocation(ast.location)}`);
|
|
88
92
|
}
|
|
89
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Compile a function expression into a JavaScript function.
|
|
96
|
+
*
|
|
97
|
+
* @param f the function expression to compile
|
|
98
|
+
* @param platform the platform functions available during compilation
|
|
99
|
+
* @returns the compiled function
|
|
100
|
+
*/
|
|
101
|
+
export function compile(f, platform) {
|
|
102
|
+
return f.toIR().compile(platform);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Compile an async function expression into a JavaScript function.
|
|
106
|
+
*
|
|
107
|
+
* @param f the async function expression to compile
|
|
108
|
+
* @param platform the platform functions available during compilation
|
|
109
|
+
* @returns the compiled async function
|
|
110
|
+
*/
|
|
111
|
+
export function compileAsync(f, platform) {
|
|
112
|
+
return f.toIR().compile(platform);
|
|
113
|
+
}
|
|
90
114
|
export function from(value, type) {
|
|
91
115
|
if (value instanceof Expr) {
|
|
92
116
|
if (type) {
|
|
@@ -172,15 +196,92 @@ export function from(value, type) {
|
|
|
172
196
|
if (!isSubtype(body_ast.type, output)) {
|
|
173
197
|
throw new Error(`Expected function definition to return type ${printType(output)}, got ${printType(body_ast.type)}`);
|
|
174
198
|
}
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
199
|
+
const ast = {
|
|
200
|
+
ast_type: "Function",
|
|
201
|
+
type: FunctionType(inputs, output),
|
|
202
|
+
location: get_location(3),
|
|
203
|
+
parameters: input_variables,
|
|
204
|
+
body: body_ast,
|
|
205
|
+
};
|
|
206
|
+
return fromAst(ast);
|
|
207
|
+
}
|
|
208
|
+
else if (type && type.type === "AsyncFunction") {
|
|
209
|
+
if (typeof value !== "function") {
|
|
210
|
+
throw new Error(`Expected function but got ${typeof value}`);
|
|
211
|
+
}
|
|
212
|
+
const { inputs, output } = type;
|
|
213
|
+
const input_variables = inputs.map(i => ({
|
|
214
|
+
ast_type: "Variable",
|
|
215
|
+
type: i,
|
|
216
|
+
location: get_location(3),
|
|
217
|
+
mutable: false,
|
|
218
|
+
}));
|
|
219
|
+
const $ = BlockBuilder(output);
|
|
220
|
+
const input_exprs = input_variables.map(fromAst);
|
|
221
|
+
const ret = value($, ...input_exprs);
|
|
222
|
+
const statements = $.statements;
|
|
223
|
+
if (ret !== undefined) {
|
|
224
|
+
if (ret instanceof Expr) {
|
|
225
|
+
// It is possible this expression is already the last statement.
|
|
226
|
+
// Input of the form `$ => $.xxx()` or `$ => { ...; return $.xxx(); }` will cause this
|
|
227
|
+
// So we filter out this case to avoid unintended repeated statements (and if users write an identical expression twice, they won't be `===`)
|
|
228
|
+
if (statements.length === 0 || statements[statements.length - 1] !== ret[AstSymbol]) {
|
|
229
|
+
statements.push(Expr.ast(ret));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
const retAst = valueOrExprToAstTyped(ret, output);
|
|
234
|
+
statements.push(retAst);
|
|
179
235
|
}
|
|
180
236
|
}
|
|
237
|
+
let body_ast;
|
|
238
|
+
if (isTypeEqual(output, NullType)) {
|
|
239
|
+
if (statements.length === 0) {
|
|
240
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(2), value: null };
|
|
241
|
+
}
|
|
242
|
+
else if (statements.length === 1 && isSubtype(statements[0].type, NullType)) {
|
|
243
|
+
body_ast = statements[0];
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
if (!isSubtype(statements[statements.length - 1].type, NullType)) {
|
|
247
|
+
statements.push({ ast_type: "Value", type: NullType, location: get_location(3), value: null });
|
|
248
|
+
}
|
|
249
|
+
body_ast = {
|
|
250
|
+
ast_type: "Block",
|
|
251
|
+
type: statements[statements.length - 1].type,
|
|
252
|
+
location: get_location(3),
|
|
253
|
+
statements: statements,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
if (statements.length === 0) {
|
|
259
|
+
throw new Error(`Function expected output of type ${printType(output)}, but no function body or statements were provided`);
|
|
260
|
+
}
|
|
261
|
+
else if (statements.length === 1) {
|
|
262
|
+
if (!isSubtype(statements[0].type, output)) {
|
|
263
|
+
throw new Error(`Function expected output of type ${printType(output)}, but function body has type ${printType(statements[0].type)}`);
|
|
264
|
+
}
|
|
265
|
+
body_ast = statements[0];
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
if (!isSubtype(statements[statements.length - 1].type, output)) {
|
|
269
|
+
throw new Error(`Function expected output of type ${printType(output)}, but function body has type ${printType(statements[statements.length - 1].type)}`);
|
|
270
|
+
}
|
|
271
|
+
body_ast = {
|
|
272
|
+
ast_type: "Block",
|
|
273
|
+
type: statements[statements.length - 1].type,
|
|
274
|
+
location: get_location(3),
|
|
275
|
+
statements: statements,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (!isSubtype(body_ast.type, output)) {
|
|
280
|
+
throw new Error(`Expected function definition to return type ${printType(output)}, got ${printType(body_ast.type)}`);
|
|
281
|
+
}
|
|
181
282
|
const ast = {
|
|
182
|
-
ast_type: "
|
|
183
|
-
type: FunctionType(inputs, output
|
|
283
|
+
ast_type: "AsyncFunction",
|
|
284
|
+
type: FunctionType(inputs, output),
|
|
184
285
|
location: get_location(3),
|
|
185
286
|
parameters: input_variables,
|
|
186
287
|
body: body_ast,
|
|
@@ -229,7 +330,7 @@ export function func(input_types, output_type, body) {
|
|
|
229
330
|
}
|
|
230
331
|
const ast = {
|
|
231
332
|
ast_type: "Function",
|
|
232
|
-
type: FunctionType(input_types, ret_type
|
|
333
|
+
type: FunctionType(input_types, ret_type),
|
|
233
334
|
location: get_location(2),
|
|
234
335
|
parameters: parameters,
|
|
235
336
|
body: body_ast,
|
|
@@ -264,7 +365,89 @@ export function func(input_types, output_type, body) {
|
|
|
264
365
|
// }
|
|
265
366
|
const ast = {
|
|
266
367
|
ast_type: "Function",
|
|
267
|
-
type: FunctionType(input_types, output_type
|
|
368
|
+
type: FunctionType(input_types, output_type),
|
|
369
|
+
location: get_location(2),
|
|
370
|
+
parameters: parameters,
|
|
371
|
+
body: body_ast,
|
|
372
|
+
};
|
|
373
|
+
return fromAst(ast);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
export function asyncFunction(input_types, output_type, body) {
|
|
377
|
+
const parameters = input_types.map(i => ({
|
|
378
|
+
ast_type: "Variable",
|
|
379
|
+
type: i,
|
|
380
|
+
location: get_location(2),
|
|
381
|
+
mutable: false,
|
|
382
|
+
}));
|
|
383
|
+
const $ = BlockBuilder(output_type ?? NeverType);
|
|
384
|
+
let ret = body($, ...parameters.map(fromAst));
|
|
385
|
+
const statements = $.statements;
|
|
386
|
+
if (output_type === undefined) {
|
|
387
|
+
if (ret === undefined) {
|
|
388
|
+
throw new Error(`When output_type is not specified, function body must return a value`);
|
|
389
|
+
}
|
|
390
|
+
const ret_ast = ret instanceof Expr ? Expr.ast(ret) : valueOrExprToAst(ret);
|
|
391
|
+
if (statements.length === 0 || statements[statements.length - 1] !== ret_ast) { // avoid duplicate statements
|
|
392
|
+
statements.push(ret_ast);
|
|
393
|
+
}
|
|
394
|
+
const ret_type = ret_ast.type;
|
|
395
|
+
let body_ast;
|
|
396
|
+
if (statements.length === 0) {
|
|
397
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(2), value: null };
|
|
398
|
+
}
|
|
399
|
+
else if (statements.length === 1) {
|
|
400
|
+
body_ast = statements[0];
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
body_ast = {
|
|
404
|
+
ast_type: "Block",
|
|
405
|
+
type: statements[statements.length - 1].type,
|
|
406
|
+
location: get_location(2),
|
|
407
|
+
statements: statements,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (!isSubtype(body_ast.type, ret_type)) {
|
|
411
|
+
throw new Error(`function expected to return a value of type ${printType(ret_type)}, got ${printType(body_ast.type)}`);
|
|
412
|
+
}
|
|
413
|
+
const ast = {
|
|
414
|
+
ast_type: "AsyncFunction",
|
|
415
|
+
type: AsyncFunctionType(input_types, ret_type),
|
|
416
|
+
location: get_location(2),
|
|
417
|
+
parameters: parameters,
|
|
418
|
+
body: body_ast,
|
|
419
|
+
};
|
|
420
|
+
return fromAst(ast);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
if (ret !== undefined) {
|
|
424
|
+
const ret_ast = valueOrExprToAstTyped(ret, output_type);
|
|
425
|
+
if (statements.length === 0 || statements[statements.length - 1] !== ret_ast) { // avoid duplicate statements
|
|
426
|
+
statements.push(ret_ast);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
let body_ast;
|
|
430
|
+
if (statements.length === 0) {
|
|
431
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(2), value: null };
|
|
432
|
+
}
|
|
433
|
+
else if (statements.length === 1) {
|
|
434
|
+
body_ast = statements[0];
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
body_ast = {
|
|
438
|
+
ast_type: "Block",
|
|
439
|
+
type: statements[statements.length - 1].type,
|
|
440
|
+
location: get_location(2),
|
|
441
|
+
statements: statements,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
// This is an interesting one - do we have implicit returns? Do we need to track the absence of control flow?
|
|
445
|
+
// if (!isSubtype(expr.type, output_type)) {
|
|
446
|
+
// throw new Error(`func expected to return a value of type ${printType(output_type)}, got ${printType(expr.type)}`);
|
|
447
|
+
// }
|
|
448
|
+
const ast = {
|
|
449
|
+
ast_type: "AsyncFunction",
|
|
450
|
+
type: AsyncFunctionType(input_types, output_type),
|
|
268
451
|
location: get_location(2),
|
|
269
452
|
parameters: parameters,
|
|
270
453
|
body: body_ast,
|
|
@@ -682,16 +865,18 @@ export function print(value) {
|
|
|
682
865
|
arguments: [valueAst],
|
|
683
866
|
});
|
|
684
867
|
}
|
|
685
|
-
/** Create a callable helper to invoke a platform function.
|
|
868
|
+
/** Create a callable helper to invoke a synchronous platform function.
|
|
686
869
|
*
|
|
687
870
|
* Platform functions provide access to external capabilities (logging, I/O, database access, etc.)
|
|
688
871
|
* that East code can call. They are defined by the platform when compiling and executing East IR.
|
|
689
872
|
*
|
|
690
|
-
* @param name - The name of the platform function
|
|
873
|
+
* @param name - The name of the platform function
|
|
691
874
|
* @param input_types - Array of input parameter types for the platform function
|
|
692
875
|
* @param output_type - The return type of the platform function
|
|
693
876
|
* @returns A callable function that creates Platform AST nodes when invoked
|
|
694
877
|
*
|
|
878
|
+
* @see {@link asyncPlatform} for defining asynchronous platform functions (that return `Promise`s)
|
|
879
|
+
*
|
|
695
880
|
* @example
|
|
696
881
|
* ```ts
|
|
697
882
|
// Define a platform function helper for logging
|
|
@@ -742,6 +927,7 @@ export function platform(name, input_types, output_type) {
|
|
|
742
927
|
location: get_location(2),
|
|
743
928
|
name: name,
|
|
744
929
|
arguments: argAsts,
|
|
930
|
+
async: false,
|
|
745
931
|
});
|
|
746
932
|
};
|
|
747
933
|
fn.implement = (fnImpl) => {
|
|
@@ -767,7 +953,73 @@ export function platform(name, input_types, output_type) {
|
|
|
767
953
|
};
|
|
768
954
|
}
|
|
769
955
|
};
|
|
770
|
-
fn
|
|
956
|
+
return fn;
|
|
957
|
+
}
|
|
958
|
+
/** Create a callable helper to invoke an asynchronous platform function.
|
|
959
|
+
*
|
|
960
|
+
* Platform functions provide access to external capabilities (logging, I/O, database access, etc.)
|
|
961
|
+
* that East code can call. They are defined by the platform when compiling and executing East IR.
|
|
962
|
+
*
|
|
963
|
+
* @param name - The name of the asynchronous platform function
|
|
964
|
+
* @param input_types - Array of input parameter types for the platform function
|
|
965
|
+
* @param output_type - The return type of the platform function
|
|
966
|
+
* @returns A callable function that creates Platform AST nodes when invoked
|
|
967
|
+
*
|
|
968
|
+
* @see {@link platform} for defining synchronous platform functions
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* ```ts
|
|
972
|
+
// Define a platform function for reading files as a string
|
|
973
|
+
const readFile = East.asyncPlatform("readFile", [StringType], StringType);
|
|
974
|
+
|
|
975
|
+
// Use it in East code
|
|
976
|
+
const myFunction = East.asyncFunction([], StringType, ($) => {
|
|
977
|
+
$.return(readFile("data.txt"));
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
// Provide the (async) implementation when compiling
|
|
981
|
+
const platform = [
|
|
982
|
+
readFile.implement((filename: string) => fs.promises.readFile(filename, 'utf-8')),
|
|
983
|
+
];
|
|
984
|
+
const compiled = myFunction.toIR().compile(platform);
|
|
985
|
+
compiled(); // Logs "Hello, world!" to the console
|
|
986
|
+
* ```
|
|
987
|
+
*/
|
|
988
|
+
export function asyncPlatform(name, input_types, output_type) {
|
|
989
|
+
const fn = (...args) => {
|
|
990
|
+
if (args.length !== input_types.length) {
|
|
991
|
+
throw new Error(`Platform function ${name} expected ${input_types.length} arguments, got ${args.length}`);
|
|
992
|
+
}
|
|
993
|
+
const argAsts = args.map((arg, index) => {
|
|
994
|
+
const expectedType = input_types[index];
|
|
995
|
+
let ast = valueOrExprToAstTyped(arg, expectedType);
|
|
996
|
+
if (ast.type.type === "Never") {
|
|
997
|
+
throw new Error(`Platform function ${name} argument ${index} expected type ${printType(expectedType)}, got Never type`);
|
|
998
|
+
}
|
|
999
|
+
if (!isTypeEqual(ast.type, expectedType)) {
|
|
1000
|
+
if (!isSubtype(ast.type, expectedType)) {
|
|
1001
|
+
throw new Error(`Platform function ${name} argument ${index} expected type ${printType(expectedType)}, got ${printType(ast.type)}`);
|
|
1002
|
+
}
|
|
1003
|
+
// Insert implicit cast
|
|
1004
|
+
ast = {
|
|
1005
|
+
ast_type: "As",
|
|
1006
|
+
type: expectedType,
|
|
1007
|
+
location: get_location(2),
|
|
1008
|
+
value: ast,
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
return ast;
|
|
1012
|
+
});
|
|
1013
|
+
return fromAst({
|
|
1014
|
+
ast_type: "Platform",
|
|
1015
|
+
type: output_type,
|
|
1016
|
+
location: get_location(2),
|
|
1017
|
+
name: name,
|
|
1018
|
+
arguments: argAsts,
|
|
1019
|
+
async: true,
|
|
1020
|
+
});
|
|
1021
|
+
};
|
|
1022
|
+
fn.implement = (fnImpl) => {
|
|
771
1023
|
// Convert types from EastType to EastTypeValue once at implementation time
|
|
772
1024
|
const inputsAsValues = input_types.map(t => toEastTypeValue(t));
|
|
773
1025
|
const outputAsValue = toEastTypeValue(output_type);
|
|
@@ -797,7 +1049,6 @@ export const BlockBuilder = (return_type) => {
|
|
|
797
1049
|
const $ = ((expr) => {
|
|
798
1050
|
const ast = Expr.ast(expr);
|
|
799
1051
|
statements.push(ast);
|
|
800
|
-
return expr;
|
|
801
1052
|
});
|
|
802
1053
|
$.statements = statements;
|
|
803
1054
|
$.type = () => {
|
|
@@ -870,7 +1121,11 @@ export const BlockBuilder = (return_type) => {
|
|
|
870
1121
|
if (isTypeEqual($.type(), NeverType)) {
|
|
871
1122
|
throw new Error(`Unreachable statement detected at ${printLocation(get_location(2))}`);
|
|
872
1123
|
}
|
|
873
|
-
|
|
1124
|
+
let v = Expr.ast(variable);
|
|
1125
|
+
// Handle RecursiveType variables which are auto-unwrapped by fromAst
|
|
1126
|
+
if (v.ast_type === "UnwrapRecursive") {
|
|
1127
|
+
v = v.value;
|
|
1128
|
+
}
|
|
874
1129
|
if (v.ast_type !== "Variable") {
|
|
875
1130
|
throw new Error("Can only assign to a variable");
|
|
876
1131
|
}
|
|
@@ -897,6 +1152,12 @@ export const BlockBuilder = (return_type) => {
|
|
|
897
1152
|
if (!isSubtype(expAst.type, return_type)) {
|
|
898
1153
|
throw new Error(`Return expected to have type ${printType(return_type)}, got ${printType(expAst.type)}`);
|
|
899
1154
|
}
|
|
1155
|
+
// Deduplicate: if the expression is already the last statement (e.g., from $()),
|
|
1156
|
+
// don't push it again - just wrap it in the Return
|
|
1157
|
+
const exprAstRef = expr instanceof Expr ? Expr.ast(expr) : null;
|
|
1158
|
+
if (exprAstRef !== null && statements.length > 0 && statements[statements.length - 1] === exprAstRef) {
|
|
1159
|
+
statements.pop();
|
|
1160
|
+
}
|
|
900
1161
|
const ast = {
|
|
901
1162
|
ast_type: "Return",
|
|
902
1163
|
type: NeverType,
|
|
@@ -1491,6 +1752,7 @@ Object.assign(Expr, {
|
|
|
1491
1752
|
error,
|
|
1492
1753
|
tryCatch,
|
|
1493
1754
|
function: func,
|
|
1755
|
+
asyncFunction,
|
|
1494
1756
|
print,
|
|
1495
1757
|
str,
|
|
1496
1758
|
equal,
|