@enspirit/elo 0.9.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 +21 -0
- package/README.md +322 -0
- package/bin/elo +2 -0
- package/bin/eloc +2 -0
- package/dist/src/ast.d.ts +309 -0
- package/dist/src/ast.d.ts.map +1 -0
- package/dist/src/ast.js +173 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/bindings/javascript.d.ts +17 -0
- package/dist/src/bindings/javascript.d.ts.map +1 -0
- package/dist/src/bindings/javascript.js +350 -0
- package/dist/src/bindings/javascript.js.map +1 -0
- package/dist/src/bindings/ruby.d.ts +20 -0
- package/dist/src/bindings/ruby.d.ts.map +1 -0
- package/dist/src/bindings/ruby.js +365 -0
- package/dist/src/bindings/ruby.js.map +1 -0
- package/dist/src/bindings/sql.d.ts +20 -0
- package/dist/src/bindings/sql.d.ts.map +1 -0
- package/dist/src/bindings/sql.js +319 -0
- package/dist/src/bindings/sql.js.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +225 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/compile.d.ts +47 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +55 -0
- package/dist/src/compile.js.map +1 -0
- package/dist/src/compilers/javascript.d.ts +41 -0
- package/dist/src/compilers/javascript.d.ts.map +1 -0
- package/dist/src/compilers/javascript.js +323 -0
- package/dist/src/compilers/javascript.js.map +1 -0
- package/dist/src/compilers/ruby.d.ts +40 -0
- package/dist/src/compilers/ruby.d.ts.map +1 -0
- package/dist/src/compilers/ruby.js +326 -0
- package/dist/src/compilers/ruby.js.map +1 -0
- package/dist/src/compilers/sql.d.ts +37 -0
- package/dist/src/compilers/sql.d.ts.map +1 -0
- package/dist/src/compilers/sql.js +164 -0
- package/dist/src/compilers/sql.js.map +1 -0
- package/dist/src/elo.d.ts +3 -0
- package/dist/src/elo.d.ts.map +1 -0
- package/dist/src/elo.js +187 -0
- package/dist/src/elo.js.map +1 -0
- package/dist/src/eloc.d.ts +3 -0
- package/dist/src/eloc.d.ts.map +1 -0
- package/dist/src/eloc.js +232 -0
- package/dist/src/eloc.js.map +1 -0
- package/dist/src/eval.d.ts +3 -0
- package/dist/src/eval.d.ts.map +1 -0
- package/dist/src/eval.js +196 -0
- package/dist/src/eval.js.map +1 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +36 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ir.d.ts +295 -0
- package/dist/src/ir.d.ts.map +1 -0
- package/dist/src/ir.js +224 -0
- package/dist/src/ir.js.map +1 -0
- package/dist/src/parser.d.ts +137 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +1266 -0
- package/dist/src/parser.js.map +1 -0
- package/dist/src/preludes/index.d.ts +14 -0
- package/dist/src/preludes/index.d.ts.map +1 -0
- package/dist/src/preludes/index.js +27 -0
- package/dist/src/preludes/index.js.map +1 -0
- package/dist/src/runtime.d.ts +23 -0
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/runtime.js +326 -0
- package/dist/src/runtime.js.map +1 -0
- package/dist/src/stdlib.d.ts +121 -0
- package/dist/src/stdlib.d.ts.map +1 -0
- package/dist/src/stdlib.js +237 -0
- package/dist/src/stdlib.js.map +1 -0
- package/dist/src/transform.d.ts +38 -0
- package/dist/src/transform.d.ts.map +1 -0
- package/dist/src/transform.js +322 -0
- package/dist/src/transform.js.map +1 -0
- package/dist/src/typedefs.d.ts +50 -0
- package/dist/src/typedefs.d.ts.map +1 -0
- package/dist/src/typedefs.js +294 -0
- package/dist/src/typedefs.js.map +1 -0
- package/dist/src/types.d.ts +54 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +62 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elo - A small expression language that compiles to Ruby, JavaScript and PostgreSQL
|
|
3
|
+
*/
|
|
4
|
+
export * from './ast';
|
|
5
|
+
export * from './parser';
|
|
6
|
+
export { compile } from './compile';
|
|
7
|
+
export type { CompileOptions, EloRuntime } from './compile';
|
|
8
|
+
export { compileToRuby } from './compilers/ruby';
|
|
9
|
+
export type { RubyCompileOptions } from './compilers/ruby';
|
|
10
|
+
export { compileToJavaScript, compileToJavaScriptWithMeta } from './compilers/javascript';
|
|
11
|
+
export type { JavaScriptCompileOptions, JavaScriptCompileResult } from './compilers/javascript';
|
|
12
|
+
export { compileToSQL } from './compilers/sql';
|
|
13
|
+
export type { SQLCompileOptions } from './compilers/sql';
|
|
14
|
+
export { JS_HELPERS } from './runtime';
|
|
15
|
+
export { getPrelude } from './preludes';
|
|
16
|
+
export type { Target as PreludeTarget } from './preludes';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC1F,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Elo - A small expression language that compiles to Ruby, JavaScript and PostgreSQL
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.getPrelude = exports.JS_HELPERS = exports.compileToSQL = exports.compileToJavaScriptWithMeta = exports.compileToJavaScript = exports.compileToRuby = exports.compile = void 0;
|
|
21
|
+
__exportStar(require("./ast"), exports);
|
|
22
|
+
__exportStar(require("./parser"), exports);
|
|
23
|
+
var compile_1 = require("./compile");
|
|
24
|
+
Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compile_1.compile; } });
|
|
25
|
+
var ruby_1 = require("./compilers/ruby");
|
|
26
|
+
Object.defineProperty(exports, "compileToRuby", { enumerable: true, get: function () { return ruby_1.compileToRuby; } });
|
|
27
|
+
var javascript_1 = require("./compilers/javascript");
|
|
28
|
+
Object.defineProperty(exports, "compileToJavaScript", { enumerable: true, get: function () { return javascript_1.compileToJavaScript; } });
|
|
29
|
+
Object.defineProperty(exports, "compileToJavaScriptWithMeta", { enumerable: true, get: function () { return javascript_1.compileToJavaScriptWithMeta; } });
|
|
30
|
+
var sql_1 = require("./compilers/sql");
|
|
31
|
+
Object.defineProperty(exports, "compileToSQL", { enumerable: true, get: function () { return sql_1.compileToSQL; } });
|
|
32
|
+
var runtime_1 = require("./runtime");
|
|
33
|
+
Object.defineProperty(exports, "JS_HELPERS", { enumerable: true, get: function () { return runtime_1.JS_HELPERS; } });
|
|
34
|
+
var preludes_1 = require("./preludes");
|
|
35
|
+
Object.defineProperty(exports, "getPrelude", { enumerable: true, get: function () { return preludes_1.getPrelude; } });
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,wCAAsB;AACtB,2CAAyB;AACzB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,yCAAiD;AAAxC,qGAAA,aAAa,OAAA;AAEtB,qDAA0F;AAAjF,iHAAA,mBAAmB,OAAA;AAAE,yHAAA,2BAA2B,OAAA;AAEzD,uCAA+C;AAAtC,mGAAA,YAAY,OAAA;AAErB,qCAAuC;AAA9B,qGAAA,UAAU,OAAA;AACnB,uCAAwC;AAA/B,sGAAA,UAAU,OAAA"}
|
package/dist/src/ir.d.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intermediate Representation (IR) for Elo
|
|
3
|
+
*
|
|
4
|
+
* The IR is a typed representation of Elo expressions where:
|
|
5
|
+
* - Literals carry their type explicitly
|
|
6
|
+
* - Operators are replaced by typed function calls
|
|
7
|
+
* - Temporal keywords are replaced by function calls
|
|
8
|
+
*
|
|
9
|
+
* This allows target compilers to generate optimal code based on types.
|
|
10
|
+
*/
|
|
11
|
+
import { EloType } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* IR expression types
|
|
14
|
+
*/
|
|
15
|
+
export type IRExpr = IRIntLiteral | IRFloatLiteral | IRBoolLiteral | IRNullLiteral | IRStringLiteral | IRDateLiteral | IRDateTimeLiteral | IRDurationLiteral | IRObjectLiteral | IRArrayLiteral | IRVariable | IRCall | IRApply | IRLet | IRMemberAccess | IRIf | IRLambda | IRAlternative | IRDataPath | IRTypeDef;
|
|
16
|
+
/**
|
|
17
|
+
* Integer literal
|
|
18
|
+
*/
|
|
19
|
+
export interface IRIntLiteral {
|
|
20
|
+
type: 'int_literal';
|
|
21
|
+
value: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Float literal
|
|
25
|
+
*/
|
|
26
|
+
export interface IRFloatLiteral {
|
|
27
|
+
type: 'float_literal';
|
|
28
|
+
value: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Boolean literal
|
|
32
|
+
*/
|
|
33
|
+
export interface IRBoolLiteral {
|
|
34
|
+
type: 'bool_literal';
|
|
35
|
+
value: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Null literal
|
|
39
|
+
*/
|
|
40
|
+
export interface IRNullLiteral {
|
|
41
|
+
type: 'null_literal';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* String literal
|
|
45
|
+
*/
|
|
46
|
+
export interface IRStringLiteral {
|
|
47
|
+
type: 'string_literal';
|
|
48
|
+
value: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Date literal (ISO8601 date)
|
|
52
|
+
*/
|
|
53
|
+
export interface IRDateLiteral {
|
|
54
|
+
type: 'date_literal';
|
|
55
|
+
value: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* DateTime literal (ISO8601 datetime)
|
|
59
|
+
*/
|
|
60
|
+
export interface IRDateTimeLiteral {
|
|
61
|
+
type: 'datetime_literal';
|
|
62
|
+
value: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Duration literal (ISO8601 duration)
|
|
66
|
+
*/
|
|
67
|
+
export interface IRDurationLiteral {
|
|
68
|
+
type: 'duration_literal';
|
|
69
|
+
value: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Object literal property
|
|
73
|
+
*/
|
|
74
|
+
export interface IRObjectProperty {
|
|
75
|
+
key: string;
|
|
76
|
+
value: IRExpr;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Object literal: {key: value, ...}
|
|
80
|
+
*/
|
|
81
|
+
export interface IRObjectLiteral {
|
|
82
|
+
type: 'object_literal';
|
|
83
|
+
properties: IRObjectProperty[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Array literal: [expr, expr, ...]
|
|
87
|
+
*/
|
|
88
|
+
export interface IRArrayLiteral {
|
|
89
|
+
type: 'array_literal';
|
|
90
|
+
elements: IRExpr[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Variable reference with inferred type
|
|
94
|
+
*/
|
|
95
|
+
export interface IRVariable {
|
|
96
|
+
type: 'variable';
|
|
97
|
+
name: string;
|
|
98
|
+
inferredType: EloType;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Function call (includes operators rewritten as functions)
|
|
102
|
+
*
|
|
103
|
+
* The fn field contains a simple function name (e.g., 'add', 'sub', 'mul')
|
|
104
|
+
* rather than a type-mangled name. The argTypes array provides the types
|
|
105
|
+
* of each argument, allowing compilers to dispatch to the correct implementation.
|
|
106
|
+
*/
|
|
107
|
+
export interface IRCall {
|
|
108
|
+
type: 'call';
|
|
109
|
+
fn: string;
|
|
110
|
+
args: IRExpr[];
|
|
111
|
+
argTypes: EloType[];
|
|
112
|
+
resultType: EloType;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Lambda application (calling a lambda stored in a variable)
|
|
116
|
+
*
|
|
117
|
+
* Unlike IRCall which dispatches to stdlib functions, IRApply calls
|
|
118
|
+
* a lambda expression that's been bound to a variable.
|
|
119
|
+
*/
|
|
120
|
+
export interface IRApply {
|
|
121
|
+
type: 'apply';
|
|
122
|
+
fn: IRExpr;
|
|
123
|
+
args: IRExpr[];
|
|
124
|
+
argTypes: EloType[];
|
|
125
|
+
resultType: EloType;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Let binding
|
|
129
|
+
*/
|
|
130
|
+
export interface IRLetBinding {
|
|
131
|
+
name: string;
|
|
132
|
+
value: IRExpr;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Let expression
|
|
136
|
+
*/
|
|
137
|
+
export interface IRLet {
|
|
138
|
+
type: 'let';
|
|
139
|
+
bindings: IRLetBinding[];
|
|
140
|
+
body: IRExpr;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Member access (dot notation)
|
|
144
|
+
*/
|
|
145
|
+
export interface IRMemberAccess {
|
|
146
|
+
type: 'member_access';
|
|
147
|
+
object: IRExpr;
|
|
148
|
+
property: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* If expression: if condition then consequent else alternative
|
|
152
|
+
*/
|
|
153
|
+
export interface IRIf {
|
|
154
|
+
type: 'if';
|
|
155
|
+
condition: IRExpr;
|
|
156
|
+
then: IRExpr;
|
|
157
|
+
else: IRExpr;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Lambda parameter with inferred type
|
|
161
|
+
*/
|
|
162
|
+
export interface IRLambdaParam {
|
|
163
|
+
name: string;
|
|
164
|
+
inferredType: EloType;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Lambda expression: fn( params ~> body )
|
|
168
|
+
*/
|
|
169
|
+
export interface IRLambda {
|
|
170
|
+
type: 'lambda';
|
|
171
|
+
params: IRLambdaParam[];
|
|
172
|
+
body: IRExpr;
|
|
173
|
+
resultType: EloType;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Alternative expression: a | b | c
|
|
177
|
+
* Evaluates alternatives left-to-right, returns first non-null value.
|
|
178
|
+
*/
|
|
179
|
+
export interface IRAlternative {
|
|
180
|
+
type: 'alternative';
|
|
181
|
+
alternatives: IRExpr[];
|
|
182
|
+
resultType: EloType;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* DataPath literal: .x.y.z or .items.0.name
|
|
186
|
+
* A path for navigating data structures.
|
|
187
|
+
* Segments can be property names (strings) or array indices (numbers).
|
|
188
|
+
*/
|
|
189
|
+
export interface IRDataPath {
|
|
190
|
+
type: 'datapath';
|
|
191
|
+
segments: (string | number)[];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* IR type expression (used in type definitions)
|
|
195
|
+
*/
|
|
196
|
+
export type IRTypeExpr = IRTypeRef | IRTypeSchema | IRSubtypeConstraint | IRArrayType | IRUnionType;
|
|
197
|
+
/**
|
|
198
|
+
* Reference to a base type
|
|
199
|
+
*/
|
|
200
|
+
export interface IRTypeRef {
|
|
201
|
+
kind: 'type_ref';
|
|
202
|
+
name: string;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Object type schema
|
|
206
|
+
* extras controls handling of extra attributes:
|
|
207
|
+
* - undefined/'closed': extra attributes are not allowed (default)
|
|
208
|
+
* - 'ignored': extra attributes are allowed but not included in output
|
|
209
|
+
* - IRTypeExpr: extra attributes are allowed and must match this type
|
|
210
|
+
*/
|
|
211
|
+
export interface IRTypeSchema {
|
|
212
|
+
kind: 'type_schema';
|
|
213
|
+
properties: IRTypeSchemaProperty[];
|
|
214
|
+
extras?: 'closed' | 'ignored' | IRTypeExpr;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Subtype constraint: Int(i | i > 0)
|
|
218
|
+
*/
|
|
219
|
+
export interface IRSubtypeConstraint {
|
|
220
|
+
kind: 'subtype_constraint';
|
|
221
|
+
baseType: IRTypeExpr;
|
|
222
|
+
variable: string;
|
|
223
|
+
constraint: IRExpr;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Array type: [Int]
|
|
227
|
+
*/
|
|
228
|
+
export interface IRArrayType {
|
|
229
|
+
kind: 'array_type';
|
|
230
|
+
elementType: IRTypeExpr;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Union type: Int|String
|
|
234
|
+
* Tries each type in order, returns first successful parse
|
|
235
|
+
*/
|
|
236
|
+
export interface IRUnionType {
|
|
237
|
+
kind: 'union_type';
|
|
238
|
+
types: IRTypeExpr[];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Property in a type schema
|
|
242
|
+
*/
|
|
243
|
+
export interface IRTypeSchemaProperty {
|
|
244
|
+
key: string;
|
|
245
|
+
typeExpr: IRTypeExpr;
|
|
246
|
+
optional?: boolean;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Type definition: let Person = { name: String, age: Int } in body
|
|
250
|
+
*/
|
|
251
|
+
export interface IRTypeDef {
|
|
252
|
+
type: 'typedef';
|
|
253
|
+
name: string;
|
|
254
|
+
typeExpr: IRTypeExpr;
|
|
255
|
+
body: IRExpr;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Factory functions for creating IR nodes
|
|
259
|
+
*/
|
|
260
|
+
export declare function irInt(value: number): IRIntLiteral;
|
|
261
|
+
export declare function irFloat(value: number): IRFloatLiteral;
|
|
262
|
+
export declare function irBool(value: boolean): IRBoolLiteral;
|
|
263
|
+
export declare function irNull(): IRNullLiteral;
|
|
264
|
+
export declare function irString(value: string): IRStringLiteral;
|
|
265
|
+
export declare function irDate(value: string): IRDateLiteral;
|
|
266
|
+
export declare function irDateTime(value: string): IRDateTimeLiteral;
|
|
267
|
+
export declare function irDuration(value: string): IRDurationLiteral;
|
|
268
|
+
export declare function irObject(properties: IRObjectProperty[]): IRObjectLiteral;
|
|
269
|
+
export declare function irArray(elements: IRExpr[]): IRArrayLiteral;
|
|
270
|
+
export declare function irVariable(name: string, inferredType?: EloType): IRVariable;
|
|
271
|
+
export declare function irCall(fn: string, args: IRExpr[], argTypes: EloType[], resultType?: EloType): IRCall;
|
|
272
|
+
export declare function irApply(fn: IRExpr, args: IRExpr[], argTypes: EloType[], resultType?: EloType): IRApply;
|
|
273
|
+
export declare function irLet(bindings: IRLetBinding[], body: IRExpr): IRLet;
|
|
274
|
+
export declare function irMemberAccess(object: IRExpr, property: string): IRMemberAccess;
|
|
275
|
+
export declare function irIf(condition: IRExpr, thenBranch: IRExpr, elseBranch: IRExpr): IRIf;
|
|
276
|
+
export declare function irLambda(params: IRLambdaParam[], body: IRExpr, resultType: EloType): IRLambda;
|
|
277
|
+
export declare function irAlternative(alternatives: IRExpr[], resultType: EloType): IRAlternative;
|
|
278
|
+
export declare function irDataPath(segments: (string | number)[]): IRDataPath;
|
|
279
|
+
export declare function irTypeRef(name: string): IRTypeRef;
|
|
280
|
+
export declare function irTypeSchema(properties: IRTypeSchemaProperty[], extras?: 'closed' | 'ignored' | IRTypeExpr): IRTypeSchema;
|
|
281
|
+
export declare function irSubtypeConstraint(baseType: IRTypeExpr, variable: string, constraint: IRExpr): IRSubtypeConstraint;
|
|
282
|
+
export declare function irArrayType(elementType: IRTypeExpr): IRArrayType;
|
|
283
|
+
export declare function irUnionType(types: IRTypeExpr[]): IRUnionType;
|
|
284
|
+
export declare function irTypeDef(name: string, typeExpr: IRTypeExpr, body: IRExpr): IRTypeDef;
|
|
285
|
+
/**
|
|
286
|
+
* Infer the type of an IR expression
|
|
287
|
+
*/
|
|
288
|
+
export declare function inferType(ir: IRExpr): EloType;
|
|
289
|
+
/**
|
|
290
|
+
* Check if an IR expression uses the input variable `_` as a free variable.
|
|
291
|
+
* This is used to determine if the compiled output needs to be wrapped
|
|
292
|
+
* as a function taking `_` as a parameter.
|
|
293
|
+
*/
|
|
294
|
+
export declare function usesInput(ir: IRExpr, boundVars?: Set<string>): boolean;
|
|
295
|
+
//# sourceMappingURL=ir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../src/ir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAS,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,MAAM,GACd,YAAY,GACZ,cAAc,GACd,aAAa,GACb,aAAa,GACb,eAAe,GACf,aAAa,GACb,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,cAAc,GACd,UAAU,GACV,MAAM,GACN,OAAO,GACP,KAAK,GACL,cAAc,GACd,IAAI,GACJ,QAAQ,GACR,aAAa,GACb,UAAU,GACV,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,cAAc,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,kBAAkB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,kBAAkB,C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,UAAU,EAAE,MAAM,GAAG,mBAAmB,CAEnH;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,UAAU,GAAG,WAAW,CAEhE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,WAAW,CAE5D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAErF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CA4C7C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,GAAE,GAAG,CAAC,MAAM,CAAa,GAAG,OAAO,CAgEjF"}
|
package/dist/src/ir.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Intermediate Representation (IR) for Elo
|
|
4
|
+
*
|
|
5
|
+
* The IR is a typed representation of Elo expressions where:
|
|
6
|
+
* - Literals carry their type explicitly
|
|
7
|
+
* - Operators are replaced by typed function calls
|
|
8
|
+
* - Temporal keywords are replaced by function calls
|
|
9
|
+
*
|
|
10
|
+
* This allows target compilers to generate optimal code based on types.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.irInt = irInt;
|
|
14
|
+
exports.irFloat = irFloat;
|
|
15
|
+
exports.irBool = irBool;
|
|
16
|
+
exports.irNull = irNull;
|
|
17
|
+
exports.irString = irString;
|
|
18
|
+
exports.irDate = irDate;
|
|
19
|
+
exports.irDateTime = irDateTime;
|
|
20
|
+
exports.irDuration = irDuration;
|
|
21
|
+
exports.irObject = irObject;
|
|
22
|
+
exports.irArray = irArray;
|
|
23
|
+
exports.irVariable = irVariable;
|
|
24
|
+
exports.irCall = irCall;
|
|
25
|
+
exports.irApply = irApply;
|
|
26
|
+
exports.irLet = irLet;
|
|
27
|
+
exports.irMemberAccess = irMemberAccess;
|
|
28
|
+
exports.irIf = irIf;
|
|
29
|
+
exports.irLambda = irLambda;
|
|
30
|
+
exports.irAlternative = irAlternative;
|
|
31
|
+
exports.irDataPath = irDataPath;
|
|
32
|
+
exports.irTypeRef = irTypeRef;
|
|
33
|
+
exports.irTypeSchema = irTypeSchema;
|
|
34
|
+
exports.irSubtypeConstraint = irSubtypeConstraint;
|
|
35
|
+
exports.irArrayType = irArrayType;
|
|
36
|
+
exports.irUnionType = irUnionType;
|
|
37
|
+
exports.irTypeDef = irTypeDef;
|
|
38
|
+
exports.inferType = inferType;
|
|
39
|
+
exports.usesInput = usesInput;
|
|
40
|
+
const types_1 = require("./types");
|
|
41
|
+
/**
|
|
42
|
+
* Factory functions for creating IR nodes
|
|
43
|
+
*/
|
|
44
|
+
function irInt(value) {
|
|
45
|
+
return { type: 'int_literal', value };
|
|
46
|
+
}
|
|
47
|
+
function irFloat(value) {
|
|
48
|
+
return { type: 'float_literal', value };
|
|
49
|
+
}
|
|
50
|
+
function irBool(value) {
|
|
51
|
+
return { type: 'bool_literal', value };
|
|
52
|
+
}
|
|
53
|
+
function irNull() {
|
|
54
|
+
return { type: 'null_literal' };
|
|
55
|
+
}
|
|
56
|
+
function irString(value) {
|
|
57
|
+
return { type: 'string_literal', value };
|
|
58
|
+
}
|
|
59
|
+
function irDate(value) {
|
|
60
|
+
return { type: 'date_literal', value };
|
|
61
|
+
}
|
|
62
|
+
function irDateTime(value) {
|
|
63
|
+
return { type: 'datetime_literal', value };
|
|
64
|
+
}
|
|
65
|
+
function irDuration(value) {
|
|
66
|
+
return { type: 'duration_literal', value };
|
|
67
|
+
}
|
|
68
|
+
function irObject(properties) {
|
|
69
|
+
return { type: 'object_literal', properties };
|
|
70
|
+
}
|
|
71
|
+
function irArray(elements) {
|
|
72
|
+
return { type: 'array_literal', elements };
|
|
73
|
+
}
|
|
74
|
+
function irVariable(name, inferredType = types_1.Types.any) {
|
|
75
|
+
return { type: 'variable', name, inferredType };
|
|
76
|
+
}
|
|
77
|
+
function irCall(fn, args, argTypes, resultType = types_1.Types.any) {
|
|
78
|
+
return { type: 'call', fn, args, argTypes, resultType };
|
|
79
|
+
}
|
|
80
|
+
function irApply(fn, args, argTypes, resultType = types_1.Types.any) {
|
|
81
|
+
return { type: 'apply', fn, args, argTypes, resultType };
|
|
82
|
+
}
|
|
83
|
+
function irLet(bindings, body) {
|
|
84
|
+
return { type: 'let', bindings, body };
|
|
85
|
+
}
|
|
86
|
+
function irMemberAccess(object, property) {
|
|
87
|
+
return { type: 'member_access', object, property };
|
|
88
|
+
}
|
|
89
|
+
function irIf(condition, thenBranch, elseBranch) {
|
|
90
|
+
return { type: 'if', condition, then: thenBranch, else: elseBranch };
|
|
91
|
+
}
|
|
92
|
+
function irLambda(params, body, resultType) {
|
|
93
|
+
return { type: 'lambda', params, body, resultType };
|
|
94
|
+
}
|
|
95
|
+
function irAlternative(alternatives, resultType) {
|
|
96
|
+
return { type: 'alternative', alternatives, resultType };
|
|
97
|
+
}
|
|
98
|
+
function irDataPath(segments) {
|
|
99
|
+
return { type: 'datapath', segments };
|
|
100
|
+
}
|
|
101
|
+
function irTypeRef(name) {
|
|
102
|
+
return { kind: 'type_ref', name };
|
|
103
|
+
}
|
|
104
|
+
function irTypeSchema(properties, extras) {
|
|
105
|
+
return { kind: 'type_schema', properties, extras };
|
|
106
|
+
}
|
|
107
|
+
function irSubtypeConstraint(baseType, variable, constraint) {
|
|
108
|
+
return { kind: 'subtype_constraint', baseType, variable, constraint };
|
|
109
|
+
}
|
|
110
|
+
function irArrayType(elementType) {
|
|
111
|
+
return { kind: 'array_type', elementType };
|
|
112
|
+
}
|
|
113
|
+
function irUnionType(types) {
|
|
114
|
+
return { kind: 'union_type', types };
|
|
115
|
+
}
|
|
116
|
+
function irTypeDef(name, typeExpr, body) {
|
|
117
|
+
return { type: 'typedef', name, typeExpr, body };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Infer the type of an IR expression
|
|
121
|
+
*/
|
|
122
|
+
function inferType(ir) {
|
|
123
|
+
switch (ir.type) {
|
|
124
|
+
case 'int_literal':
|
|
125
|
+
return types_1.Types.int;
|
|
126
|
+
case 'float_literal':
|
|
127
|
+
return types_1.Types.float;
|
|
128
|
+
case 'bool_literal':
|
|
129
|
+
return types_1.Types.bool;
|
|
130
|
+
case 'null_literal':
|
|
131
|
+
return types_1.Types.null;
|
|
132
|
+
case 'string_literal':
|
|
133
|
+
return types_1.Types.string;
|
|
134
|
+
case 'date_literal':
|
|
135
|
+
return types_1.Types.date;
|
|
136
|
+
case 'datetime_literal':
|
|
137
|
+
return types_1.Types.datetime;
|
|
138
|
+
case 'duration_literal':
|
|
139
|
+
return types_1.Types.duration;
|
|
140
|
+
case 'object_literal':
|
|
141
|
+
return types_1.Types.object;
|
|
142
|
+
case 'array_literal':
|
|
143
|
+
return types_1.Types.array;
|
|
144
|
+
case 'variable':
|
|
145
|
+
return ir.inferredType;
|
|
146
|
+
case 'call':
|
|
147
|
+
return ir.resultType;
|
|
148
|
+
case 'apply':
|
|
149
|
+
return ir.resultType;
|
|
150
|
+
case 'let':
|
|
151
|
+
return inferType(ir.body);
|
|
152
|
+
case 'member_access':
|
|
153
|
+
return types_1.Types.any;
|
|
154
|
+
case 'if':
|
|
155
|
+
return inferType(ir.then);
|
|
156
|
+
case 'lambda':
|
|
157
|
+
return types_1.Types.fn;
|
|
158
|
+
case 'alternative':
|
|
159
|
+
return ir.resultType;
|
|
160
|
+
case 'datapath':
|
|
161
|
+
return types_1.Types.fn; // DataPath is a function that takes data and returns a value
|
|
162
|
+
case 'typedef':
|
|
163
|
+
return inferType(ir.body);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Check if an IR expression uses the input variable `_` as a free variable.
|
|
168
|
+
* This is used to determine if the compiled output needs to be wrapped
|
|
169
|
+
* as a function taking `_` as a parameter.
|
|
170
|
+
*/
|
|
171
|
+
function usesInput(ir, boundVars = new Set()) {
|
|
172
|
+
switch (ir.type) {
|
|
173
|
+
case 'int_literal':
|
|
174
|
+
case 'float_literal':
|
|
175
|
+
case 'bool_literal':
|
|
176
|
+
case 'null_literal':
|
|
177
|
+
case 'string_literal':
|
|
178
|
+
case 'date_literal':
|
|
179
|
+
case 'datetime_literal':
|
|
180
|
+
case 'duration_literal':
|
|
181
|
+
return false;
|
|
182
|
+
case 'variable':
|
|
183
|
+
return ir.name === '_' && !boundVars.has('_');
|
|
184
|
+
case 'object_literal':
|
|
185
|
+
return ir.properties.some(p => usesInput(p.value, boundVars));
|
|
186
|
+
case 'array_literal':
|
|
187
|
+
return ir.elements.some(e => usesInput(e, boundVars));
|
|
188
|
+
case 'member_access':
|
|
189
|
+
return usesInput(ir.object, boundVars);
|
|
190
|
+
case 'call':
|
|
191
|
+
return ir.args.some(arg => usesInput(arg, boundVars));
|
|
192
|
+
case 'apply':
|
|
193
|
+
return usesInput(ir.fn, boundVars) || ir.args.some(arg => usesInput(arg, boundVars));
|
|
194
|
+
case 'let': {
|
|
195
|
+
// Check binding values with current bound vars
|
|
196
|
+
const bindingsUseInput = ir.bindings.some(b => usesInput(b.value, boundVars));
|
|
197
|
+
// Add bound names for body check
|
|
198
|
+
const newBound = new Set(boundVars);
|
|
199
|
+
ir.bindings.forEach(b => newBound.add(b.name));
|
|
200
|
+
return bindingsUseInput || usesInput(ir.body, newBound);
|
|
201
|
+
}
|
|
202
|
+
case 'if':
|
|
203
|
+
return usesInput(ir.condition, boundVars) ||
|
|
204
|
+
usesInput(ir.then, boundVars) ||
|
|
205
|
+
usesInput(ir.else, boundVars);
|
|
206
|
+
case 'lambda': {
|
|
207
|
+
// Lambda params shadow outer variables
|
|
208
|
+
const newBound = new Set(boundVars);
|
|
209
|
+
ir.params.forEach(p => newBound.add(p.name));
|
|
210
|
+
return usesInput(ir.body, newBound);
|
|
211
|
+
}
|
|
212
|
+
case 'alternative':
|
|
213
|
+
return ir.alternatives.some(alt => usesInput(alt, boundVars));
|
|
214
|
+
case 'datapath':
|
|
215
|
+
return false; // DataPath is a pure value, doesn't reference variables
|
|
216
|
+
case 'typedef': {
|
|
217
|
+
// Type definitions add the type name to bound vars for the body
|
|
218
|
+
const newBound = new Set(boundVars);
|
|
219
|
+
newBound.add(ir.name);
|
|
220
|
+
return usesInput(ir.body, newBound);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=ir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir.js","sourceRoot":"","sources":["../../src/ir.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAgTH,sBAEC;AAED,0BAEC;AAED,wBAEC;AAED,wBAEC;AAED,4BAEC;AAED,wBAEC;AAED,gCAEC;AAED,gCAEC;AAED,4BAEC;AAED,0BAEC;AAED,gCAEC;AAED,wBAEC;AAED,0BAEC;AAED,sBAEC;AAED,wCAEC;AAED,oBAEC;AAED,4BAEC;AAED,sCAEC;AAED,gCAEC;AAED,8BAEC;AAED,oCAEC;AAED,kDAEC;AAED,kCAEC;AAED,kCAEC;AAED,8BAEC;AAKD,8BA4CC;AAOD,8BAgEC;AAxgBD,mCAAyC;AA0SzC;;GAEG;AAEH,SAAgB,KAAK,CAAC,KAAa;IACjC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC;AAED,SAAgB,OAAO,CAAC,KAAa;IACnC,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;AAC1C,CAAC;AAED,SAAgB,MAAM,CAAC,KAAc;IACnC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AACzC,CAAC;AAED,SAAgB,MAAM;IACpB,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;AAClC,CAAC;AAED,SAAgB,QAAQ,CAAC,KAAa;IACpC,OAAO,EAAE,IAAI,EAAE,gBAAgB,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