eny-ai 1.0.0 → 2.0.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/V2_README.md +414 -0
- package/dist/chunk-2NUS77CI.js +195 -0
- package/dist/chunk-5KPALVCK.js +280 -0
- package/dist/{chunk-2WFUL4XJ.js → chunk-5PZUUNHS.js} +717 -751
- package/dist/{chunk-E4KJZEXX.js → chunk-AJH2I5ZI.js} +5 -0
- package/dist/chunk-LVJ3GJRQ.js +360 -0
- package/dist/{chunk-PNKVD2UK.js → chunk-MXA7TAAG.js} +11 -1
- package/dist/cli.js +5 -4
- package/dist/firebase.cjs +296 -0
- package/dist/firebase.d.cts +136 -0
- package/dist/firebase.d.ts +136 -0
- package/dist/firebase.js +17 -0
- package/dist/hooks.cjs +236 -0
- package/dist/hooks.d.cts +184 -0
- package/dist/hooks.d.ts +184 -0
- package/dist/hooks.js +31 -0
- package/dist/index.cjs +1622 -1092
- package/dist/index.d.cts +16 -195
- package/dist/index.d.ts +16 -195
- package/dist/index.js +68 -262
- package/dist/runtime.cjs +366 -0
- package/dist/runtime.d.cts +229 -0
- package/dist/runtime.d.ts +229 -0
- package/dist/runtime.js +25 -0
- package/dist/symbols.js +2 -2
- package/examples/app-simbolico-completo.tsx +249 -0
- package/examples/nextjs-integration.tsx +446 -0
- package/examples/v2-demo.tsx +377 -0
- package/package.json +23 -11
- package/dist/react/index.cjs +0 -342
- package/dist/react/index.d.cts +0 -751
- package/dist/react/index.d.ts +0 -751
- package/dist/react/index.js +0 -284
|
@@ -1,9 +1,214 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-PNKVD2UK.js";
|
|
2
|
+
init_esm_shims
|
|
3
|
+
} from "./chunk-MXA7TAAG.js";
|
|
5
4
|
|
|
6
5
|
// src/lexer/tokenize.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
var TokenType = /* @__PURE__ */ ((TokenType2) => {
|
|
8
|
+
TokenType2["SYMBOL"] = "SYMBOL";
|
|
9
|
+
TokenType2["IDENTIFIER"] = "IDENTIFIER";
|
|
10
|
+
TokenType2["STRING"] = "STRING";
|
|
11
|
+
TokenType2["NUMBER"] = "NUMBER";
|
|
12
|
+
TokenType2["ARROW"] = "ARROW";
|
|
13
|
+
TokenType2["LBRACE"] = "LBRACE";
|
|
14
|
+
TokenType2["RBRACE"] = "RBRACE";
|
|
15
|
+
TokenType2["COLON"] = "COLON";
|
|
16
|
+
TokenType2["COMMA"] = "COMMA";
|
|
17
|
+
TokenType2["LPAREN"] = "LPAREN";
|
|
18
|
+
TokenType2["RPAREN"] = "RPAREN";
|
|
19
|
+
TokenType2["LBRACKET"] = "LBRACKET";
|
|
20
|
+
TokenType2["RBRACKET"] = "RBRACKET";
|
|
21
|
+
TokenType2["NEWLINE"] = "NEWLINE";
|
|
22
|
+
TokenType2["COMPARATOR"] = "COMPARATOR";
|
|
23
|
+
TokenType2["OPERATOR"] = "OPERATOR";
|
|
24
|
+
TokenType2["EOF"] = "EOF";
|
|
25
|
+
return TokenType2;
|
|
26
|
+
})(TokenType || {});
|
|
27
|
+
var SYMBOLS_STATE = /* @__PURE__ */ new Set([
|
|
28
|
+
"\u03A3",
|
|
29
|
+
// STATE - Estado global
|
|
30
|
+
"\u03C3",
|
|
31
|
+
// SUBSTATE - Estado local
|
|
32
|
+
"\xD8",
|
|
33
|
+
// VOID - Não-existência
|
|
34
|
+
"\u{1F512}",
|
|
35
|
+
// LOCK - Imutável
|
|
36
|
+
"\u{1F513}"
|
|
37
|
+
// UNLOCK - Mutável
|
|
38
|
+
]);
|
|
39
|
+
var SYMBOLS_EXEC = /* @__PURE__ */ new Set([
|
|
40
|
+
"\u0394",
|
|
41
|
+
// ACTION - Ação/função
|
|
42
|
+
"\u0192",
|
|
43
|
+
// FUNCTION - Capacidade lógica
|
|
44
|
+
"\u21C9",
|
|
45
|
+
// PARALLEL - Execução paralela
|
|
46
|
+
"\u25B3",
|
|
47
|
+
// DEPEND - Dependência
|
|
48
|
+
"\u25CF",
|
|
49
|
+
// CORE - Núcleo
|
|
50
|
+
"\u23F3"
|
|
51
|
+
// DELAY - Espera temporal
|
|
52
|
+
]);
|
|
53
|
+
var SYMBOLS_STRUCT = /* @__PURE__ */ new Set([
|
|
54
|
+
"\u03A9",
|
|
55
|
+
// OBJECT - Objeto
|
|
56
|
+
"\u25A0",
|
|
57
|
+
// OBJECT ALT - Entidade concreta
|
|
58
|
+
"\u25CB",
|
|
59
|
+
// CLASS - Classe/molde
|
|
60
|
+
"\u2B12",
|
|
61
|
+
// INHERIT - Herança
|
|
62
|
+
"\u2283",
|
|
63
|
+
// CONTAINS - Composição
|
|
64
|
+
"\u2254",
|
|
65
|
+
// ASSIGN - Atribuição
|
|
66
|
+
"\u29C9"
|
|
67
|
+
// MODULE - Módulo
|
|
68
|
+
]);
|
|
69
|
+
var SYMBOLS_TIME = /* @__PURE__ */ new Set([
|
|
70
|
+
"\u26A1",
|
|
71
|
+
// CAUSE - Causa/origem
|
|
72
|
+
"\u2726",
|
|
73
|
+
// CONSEQUENCE - Resultado
|
|
74
|
+
"\u21BB",
|
|
75
|
+
// LOOP - Repetição
|
|
76
|
+
"\u25CC",
|
|
77
|
+
// EVENT - Evento
|
|
78
|
+
"\u21C4",
|
|
79
|
+
// SYNC - Sincronização
|
|
80
|
+
"\u231B"
|
|
81
|
+
// TIMEOUT - Limite temporal
|
|
82
|
+
]);
|
|
83
|
+
var SYMBOLS_ENERGY = /* @__PURE__ */ new Set([
|
|
84
|
+
"\u03A8",
|
|
85
|
+
// ENERGY - Energia vital
|
|
86
|
+
"\u23EC",
|
|
87
|
+
// THROTTLE - Limitar
|
|
88
|
+
"\u23EB",
|
|
89
|
+
// BOOST - Acelerar
|
|
90
|
+
"\u20B5"
|
|
91
|
+
// COST - Custo
|
|
92
|
+
]);
|
|
93
|
+
var SYMBOLS_MEMORY = /* @__PURE__ */ new Set([
|
|
94
|
+
"\u{1D4DC}",
|
|
95
|
+
// MEMORY - Memória
|
|
96
|
+
"\u267E",
|
|
97
|
+
// PERSIST - Persistência
|
|
98
|
+
"\u2302"
|
|
99
|
+
// ROOT - Raiz do sistema
|
|
100
|
+
]);
|
|
101
|
+
var SYMBOLS_UI = /* @__PURE__ */ new Set([
|
|
102
|
+
"\u03A6",
|
|
103
|
+
// FORM - Form/UI
|
|
104
|
+
"\u0398",
|
|
105
|
+
// ANIMATION - Animação
|
|
106
|
+
"\u2610",
|
|
107
|
+
// INTERFACE - Interface
|
|
108
|
+
"\u{1F441}",
|
|
109
|
+
// VISUAL - Percepção visual
|
|
110
|
+
"\u2328",
|
|
111
|
+
// INPUT - Entrada
|
|
112
|
+
"\u{1F9ED}"
|
|
113
|
+
// POINTER - Ponteiro/direção
|
|
114
|
+
]);
|
|
115
|
+
var SYMBOLS_SECURITY = /* @__PURE__ */ new Set([
|
|
116
|
+
"\u{1F6E1}",
|
|
117
|
+
// SECURITY - Segurança
|
|
118
|
+
"\u{1F511}",
|
|
119
|
+
// KEY - Chave/autorização
|
|
120
|
+
"\u26A0",
|
|
121
|
+
// RISK - Risco
|
|
122
|
+
"\u26D4",
|
|
123
|
+
// BLOCK - Bloqueio
|
|
124
|
+
"\u{1F9EA}"
|
|
125
|
+
// SANDBOX - Isolamento
|
|
126
|
+
]);
|
|
127
|
+
var SYMBOLS_EVOLVE = /* @__PURE__ */ new Set([
|
|
128
|
+
"\u2301",
|
|
129
|
+
// EVOLVE BLOCK - Bloco de evolução
|
|
130
|
+
"\u27F3",
|
|
131
|
+
// EVOLVE - Evoluir
|
|
132
|
+
"\u2714",
|
|
133
|
+
// VERIFY - Verificar
|
|
134
|
+
"\u2713",
|
|
135
|
+
// VALID - Válido
|
|
136
|
+
"\u2716",
|
|
137
|
+
// INVALID - Inválido
|
|
138
|
+
"\u{1F4DC}"
|
|
139
|
+
// LOG - Registro
|
|
140
|
+
]);
|
|
141
|
+
var SYMBOLS_LOGIC = /* @__PURE__ */ new Set([
|
|
142
|
+
"\u039B",
|
|
143
|
+
// LOGIC - Lógica condicional
|
|
144
|
+
"\u2297"
|
|
145
|
+
// PARALLEL BLOCK - Bloco paralelo
|
|
146
|
+
]);
|
|
147
|
+
var SYMBOLS = /* @__PURE__ */ new Set([
|
|
148
|
+
...SYMBOLS_STATE,
|
|
149
|
+
...SYMBOLS_EXEC,
|
|
150
|
+
...SYMBOLS_STRUCT,
|
|
151
|
+
...SYMBOLS_TIME,
|
|
152
|
+
...SYMBOLS_ENERGY,
|
|
153
|
+
...SYMBOLS_MEMORY,
|
|
154
|
+
...SYMBOLS_UI,
|
|
155
|
+
...SYMBOLS_SECURITY,
|
|
156
|
+
...SYMBOLS_EVOLVE,
|
|
157
|
+
...SYMBOLS_LOGIC
|
|
158
|
+
]);
|
|
159
|
+
var SYMBOL_NAMES = {
|
|
160
|
+
"\u03A3": "STATE",
|
|
161
|
+
"\u03C3": "SUBSTATE",
|
|
162
|
+
"\xD8": "VOID",
|
|
163
|
+
"\u{1F512}": "LOCK",
|
|
164
|
+
"\u{1F513}": "UNLOCK",
|
|
165
|
+
"\u0394": "ACTION",
|
|
166
|
+
"\u0192": "FUNCTION",
|
|
167
|
+
"\u21C9": "PARALLEL",
|
|
168
|
+
"\u25B3": "DEPEND",
|
|
169
|
+
"\u25CF": "CORE",
|
|
170
|
+
"\u23F3": "DELAY",
|
|
171
|
+
"\u03A9": "OBJECT",
|
|
172
|
+
"\u25A0": "OBJECT_ALT",
|
|
173
|
+
"\u25CB": "CLASS",
|
|
174
|
+
"\u2B12": "INHERIT",
|
|
175
|
+
"\u2283": "CONTAINS",
|
|
176
|
+
"\u2254": "ASSIGN",
|
|
177
|
+
"\u29C9": "MODULE",
|
|
178
|
+
"\u26A1": "CAUSE",
|
|
179
|
+
"\u2726": "CONSEQUENCE",
|
|
180
|
+
"\u21BB": "LOOP",
|
|
181
|
+
"\u25CC": "EVENT",
|
|
182
|
+
"\u21C4": "SYNC",
|
|
183
|
+
"\u231B": "TIMEOUT",
|
|
184
|
+
"\u03A8": "ENERGY",
|
|
185
|
+
"\u23EC": "THROTTLE",
|
|
186
|
+
"\u23EB": "BOOST",
|
|
187
|
+
"\u20B5": "COST",
|
|
188
|
+
"\u{1D4DC}": "MEMORY",
|
|
189
|
+
"\u267E": "PERSIST",
|
|
190
|
+
"\u2302": "ROOT",
|
|
191
|
+
"\u03A6": "FORM",
|
|
192
|
+
"\u0398": "ANIMATION",
|
|
193
|
+
"\u2610": "INTERFACE",
|
|
194
|
+
"\u{1F441}": "VISUAL",
|
|
195
|
+
"\u2328": "INPUT",
|
|
196
|
+
"\u{1F9ED}": "POINTER",
|
|
197
|
+
"\u{1F6E1}": "SECURITY",
|
|
198
|
+
"\u{1F511}": "KEY",
|
|
199
|
+
"\u26A0": "RISK",
|
|
200
|
+
"\u26D4": "BLOCK",
|
|
201
|
+
"\u{1F9EA}": "SANDBOX",
|
|
202
|
+
"\u2301": "EVOLVE_BLOCK",
|
|
203
|
+
"\u27F3": "EVOLVE",
|
|
204
|
+
"\u2714": "VERIFY",
|
|
205
|
+
"\u2713": "VALID",
|
|
206
|
+
"\u2716": "INVALID",
|
|
207
|
+
"\u{1F4DC}": "LOG",
|
|
208
|
+
"\u039B": "LOGIC",
|
|
209
|
+
"\u2297": "PARALLEL_BLOCK"
|
|
210
|
+
};
|
|
211
|
+
var OPERATORS = /* @__PURE__ */ new Set(["+", "\u2212", "-", "\u2254"]);
|
|
7
212
|
function isWhitespace(ch) {
|
|
8
213
|
return ch === " " || ch === " " || ch === "\r";
|
|
9
214
|
}
|
|
@@ -167,219 +372,12 @@ function tokenize(input) {
|
|
|
167
372
|
tokens.push({ type: "EOF" /* EOF */, value: "", pos: i });
|
|
168
373
|
return tokens;
|
|
169
374
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
"use strict";
|
|
174
|
-
TokenType = /* @__PURE__ */ ((TokenType2) => {
|
|
175
|
-
TokenType2["SYMBOL"] = "SYMBOL";
|
|
176
|
-
TokenType2["IDENTIFIER"] = "IDENTIFIER";
|
|
177
|
-
TokenType2["STRING"] = "STRING";
|
|
178
|
-
TokenType2["NUMBER"] = "NUMBER";
|
|
179
|
-
TokenType2["ARROW"] = "ARROW";
|
|
180
|
-
TokenType2["LBRACE"] = "LBRACE";
|
|
181
|
-
TokenType2["RBRACE"] = "RBRACE";
|
|
182
|
-
TokenType2["COLON"] = "COLON";
|
|
183
|
-
TokenType2["COMMA"] = "COMMA";
|
|
184
|
-
TokenType2["LPAREN"] = "LPAREN";
|
|
185
|
-
TokenType2["RPAREN"] = "RPAREN";
|
|
186
|
-
TokenType2["LBRACKET"] = "LBRACKET";
|
|
187
|
-
TokenType2["RBRACKET"] = "RBRACKET";
|
|
188
|
-
TokenType2["NEWLINE"] = "NEWLINE";
|
|
189
|
-
TokenType2["COMPARATOR"] = "COMPARATOR";
|
|
190
|
-
TokenType2["OPERATOR"] = "OPERATOR";
|
|
191
|
-
TokenType2["EOF"] = "EOF";
|
|
192
|
-
return TokenType2;
|
|
193
|
-
})(TokenType || {});
|
|
194
|
-
SYMBOLS_STATE = /* @__PURE__ */ new Set([
|
|
195
|
-
"\u03A3",
|
|
196
|
-
// STATE - Estado global
|
|
197
|
-
"\u03C3",
|
|
198
|
-
// SUBSTATE - Estado local
|
|
199
|
-
"\xD8",
|
|
200
|
-
// VOID - Não-existência
|
|
201
|
-
"\u{1F512}",
|
|
202
|
-
// LOCK - Imutável
|
|
203
|
-
"\u{1F513}"
|
|
204
|
-
// UNLOCK - Mutável
|
|
205
|
-
]);
|
|
206
|
-
SYMBOLS_EXEC = /* @__PURE__ */ new Set([
|
|
207
|
-
"\u0394",
|
|
208
|
-
// ACTION - Ação/função
|
|
209
|
-
"\u0192",
|
|
210
|
-
// FUNCTION - Capacidade lógica
|
|
211
|
-
"\u21C9",
|
|
212
|
-
// PARALLEL - Execução paralela
|
|
213
|
-
"\u25B3",
|
|
214
|
-
// DEPEND - Dependência
|
|
215
|
-
"\u25CF",
|
|
216
|
-
// CORE - Núcleo
|
|
217
|
-
"\u23F3"
|
|
218
|
-
// DELAY - Espera temporal
|
|
219
|
-
]);
|
|
220
|
-
SYMBOLS_STRUCT = /* @__PURE__ */ new Set([
|
|
221
|
-
"\u03A9",
|
|
222
|
-
// OBJECT - Objeto
|
|
223
|
-
"\u25A0",
|
|
224
|
-
// OBJECT ALT - Entidade concreta
|
|
225
|
-
"\u25CB",
|
|
226
|
-
// CLASS - Classe/molde
|
|
227
|
-
"\u2B12",
|
|
228
|
-
// INHERIT - Herança
|
|
229
|
-
"\u2283",
|
|
230
|
-
// CONTAINS - Composição
|
|
231
|
-
"\u2254",
|
|
232
|
-
// ASSIGN - Atribuição
|
|
233
|
-
"\u29C9"
|
|
234
|
-
// MODULE - Módulo
|
|
235
|
-
]);
|
|
236
|
-
SYMBOLS_TIME = /* @__PURE__ */ new Set([
|
|
237
|
-
"\u26A1",
|
|
238
|
-
// CAUSE - Causa/origem
|
|
239
|
-
"\u2726",
|
|
240
|
-
// CONSEQUENCE - Resultado
|
|
241
|
-
"\u21BB",
|
|
242
|
-
// LOOP - Repetição
|
|
243
|
-
"\u25CC",
|
|
244
|
-
// EVENT - Evento
|
|
245
|
-
"\u21C4",
|
|
246
|
-
// SYNC - Sincronização
|
|
247
|
-
"\u231B"
|
|
248
|
-
// TIMEOUT - Limite temporal
|
|
249
|
-
]);
|
|
250
|
-
SYMBOLS_ENERGY = /* @__PURE__ */ new Set([
|
|
251
|
-
"\u03A8",
|
|
252
|
-
// ENERGY - Energia vital
|
|
253
|
-
"\u23EC",
|
|
254
|
-
// THROTTLE - Limitar
|
|
255
|
-
"\u23EB",
|
|
256
|
-
// BOOST - Acelerar
|
|
257
|
-
"\u20B5"
|
|
258
|
-
// COST - Custo
|
|
259
|
-
]);
|
|
260
|
-
SYMBOLS_MEMORY = /* @__PURE__ */ new Set([
|
|
261
|
-
"\u{1D4DC}",
|
|
262
|
-
// MEMORY - Memória
|
|
263
|
-
"\u267E",
|
|
264
|
-
// PERSIST - Persistência
|
|
265
|
-
"\u2302"
|
|
266
|
-
// ROOT - Raiz do sistema
|
|
267
|
-
]);
|
|
268
|
-
SYMBOLS_UI = /* @__PURE__ */ new Set([
|
|
269
|
-
"\u03A6",
|
|
270
|
-
// FORM - Form/UI
|
|
271
|
-
"\u0398",
|
|
272
|
-
// ANIMATION - Animação
|
|
273
|
-
"\u2610",
|
|
274
|
-
// INTERFACE - Interface
|
|
275
|
-
"\u{1F441}",
|
|
276
|
-
// VISUAL - Percepção visual
|
|
277
|
-
"\u2328",
|
|
278
|
-
// INPUT - Entrada
|
|
279
|
-
"\u{1F9ED}"
|
|
280
|
-
// POINTER - Ponteiro/direção
|
|
281
|
-
]);
|
|
282
|
-
SYMBOLS_SECURITY = /* @__PURE__ */ new Set([
|
|
283
|
-
"\u{1F6E1}",
|
|
284
|
-
// SECURITY - Segurança
|
|
285
|
-
"\u{1F511}",
|
|
286
|
-
// KEY - Chave/autorização
|
|
287
|
-
"\u26A0",
|
|
288
|
-
// RISK - Risco
|
|
289
|
-
"\u26D4",
|
|
290
|
-
// BLOCK - Bloqueio
|
|
291
|
-
"\u{1F9EA}"
|
|
292
|
-
// SANDBOX - Isolamento
|
|
293
|
-
]);
|
|
294
|
-
SYMBOLS_EVOLVE = /* @__PURE__ */ new Set([
|
|
295
|
-
"\u2301",
|
|
296
|
-
// EVOLVE BLOCK - Bloco de evolução
|
|
297
|
-
"\u27F3",
|
|
298
|
-
// EVOLVE - Evoluir
|
|
299
|
-
"\u2714",
|
|
300
|
-
// VERIFY - Verificar
|
|
301
|
-
"\u2713",
|
|
302
|
-
// VALID - Válido
|
|
303
|
-
"\u2716",
|
|
304
|
-
// INVALID - Inválido
|
|
305
|
-
"\u{1F4DC}"
|
|
306
|
-
// LOG - Registro
|
|
307
|
-
]);
|
|
308
|
-
SYMBOLS_LOGIC = /* @__PURE__ */ new Set([
|
|
309
|
-
"\u039B",
|
|
310
|
-
// LOGIC - Lógica condicional
|
|
311
|
-
"\u2297"
|
|
312
|
-
// PARALLEL BLOCK - Bloco paralelo
|
|
313
|
-
]);
|
|
314
|
-
SYMBOLS = /* @__PURE__ */ new Set([
|
|
315
|
-
...SYMBOLS_STATE,
|
|
316
|
-
...SYMBOLS_EXEC,
|
|
317
|
-
...SYMBOLS_STRUCT,
|
|
318
|
-
...SYMBOLS_TIME,
|
|
319
|
-
...SYMBOLS_ENERGY,
|
|
320
|
-
...SYMBOLS_MEMORY,
|
|
321
|
-
...SYMBOLS_UI,
|
|
322
|
-
...SYMBOLS_SECURITY,
|
|
323
|
-
...SYMBOLS_EVOLVE,
|
|
324
|
-
...SYMBOLS_LOGIC
|
|
325
|
-
]);
|
|
326
|
-
SYMBOL_NAMES = {
|
|
327
|
-
"\u03A3": "STATE",
|
|
328
|
-
"\u03C3": "SUBSTATE",
|
|
329
|
-
"\xD8": "VOID",
|
|
330
|
-
"\u{1F512}": "LOCK",
|
|
331
|
-
"\u{1F513}": "UNLOCK",
|
|
332
|
-
"\u0394": "ACTION",
|
|
333
|
-
"\u0192": "FUNCTION",
|
|
334
|
-
"\u21C9": "PARALLEL",
|
|
335
|
-
"\u25B3": "DEPEND",
|
|
336
|
-
"\u25CF": "CORE",
|
|
337
|
-
"\u23F3": "DELAY",
|
|
338
|
-
"\u03A9": "OBJECT",
|
|
339
|
-
"\u25A0": "OBJECT_ALT",
|
|
340
|
-
"\u25CB": "CLASS",
|
|
341
|
-
"\u2B12": "INHERIT",
|
|
342
|
-
"\u2283": "CONTAINS",
|
|
343
|
-
"\u2254": "ASSIGN",
|
|
344
|
-
"\u29C9": "MODULE",
|
|
345
|
-
"\u26A1": "CAUSE",
|
|
346
|
-
"\u2726": "CONSEQUENCE",
|
|
347
|
-
"\u21BB": "LOOP",
|
|
348
|
-
"\u25CC": "EVENT",
|
|
349
|
-
"\u21C4": "SYNC",
|
|
350
|
-
"\u231B": "TIMEOUT",
|
|
351
|
-
"\u03A8": "ENERGY",
|
|
352
|
-
"\u23EC": "THROTTLE",
|
|
353
|
-
"\u23EB": "BOOST",
|
|
354
|
-
"\u20B5": "COST",
|
|
355
|
-
"\u{1D4DC}": "MEMORY",
|
|
356
|
-
"\u267E": "PERSIST",
|
|
357
|
-
"\u2302": "ROOT",
|
|
358
|
-
"\u03A6": "FORM",
|
|
359
|
-
"\u0398": "ANIMATION",
|
|
360
|
-
"\u2610": "INTERFACE",
|
|
361
|
-
"\u{1F441}": "VISUAL",
|
|
362
|
-
"\u2328": "INPUT",
|
|
363
|
-
"\u{1F9ED}": "POINTER",
|
|
364
|
-
"\u{1F6E1}": "SECURITY",
|
|
365
|
-
"\u{1F511}": "KEY",
|
|
366
|
-
"\u26A0": "RISK",
|
|
367
|
-
"\u26D4": "BLOCK",
|
|
368
|
-
"\u{1F9EA}": "SANDBOX",
|
|
369
|
-
"\u2301": "EVOLVE_BLOCK",
|
|
370
|
-
"\u27F3": "EVOLVE",
|
|
371
|
-
"\u2714": "VERIFY",
|
|
372
|
-
"\u2713": "VALID",
|
|
373
|
-
"\u2716": "INVALID",
|
|
374
|
-
"\u{1F4DC}": "LOG",
|
|
375
|
-
"\u039B": "LOGIC",
|
|
376
|
-
"\u2297": "PARALLEL_BLOCK"
|
|
377
|
-
};
|
|
378
|
-
OPERATORS = /* @__PURE__ */ new Set(["+", "\u2212", "-", "\u2254"]);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
375
|
+
|
|
376
|
+
// src/parser.ts
|
|
377
|
+
init_esm_shims();
|
|
381
378
|
|
|
382
379
|
// src/parser/ebnfParser.ts
|
|
380
|
+
init_esm_shims();
|
|
383
381
|
function peek(cx) {
|
|
384
382
|
return cx.tokens[cx.i];
|
|
385
383
|
}
|
|
@@ -1673,19 +1671,8 @@ function parseFromCode(code, options) {
|
|
|
1673
1671
|
const tokens = tokenize(code);
|
|
1674
1672
|
return parseTokens(tokens, options);
|
|
1675
1673
|
}
|
|
1676
|
-
var init_ebnfParser = __esm({
|
|
1677
|
-
"src/parser/ebnfParser.ts"() {
|
|
1678
|
-
"use strict";
|
|
1679
|
-
init_tokenize();
|
|
1680
|
-
}
|
|
1681
|
-
});
|
|
1682
1674
|
|
|
1683
1675
|
// src/parser.ts
|
|
1684
|
-
var parser_exports = {};
|
|
1685
|
-
__export(parser_exports, {
|
|
1686
|
-
parse: () => parse,
|
|
1687
|
-
writeWithRetry: () => writeWithRetry
|
|
1688
|
-
});
|
|
1689
1676
|
async function writeWithRetry(entry, filePath, attempts = 3, delay = 1e3, onLog) {
|
|
1690
1677
|
const fsPromises = await import("fs/promises");
|
|
1691
1678
|
let attempt = 0;
|
|
@@ -1717,508 +1704,138 @@ function parse(code, options) {
|
|
|
1717
1704
|
ast.logs = ast.logs || [];
|
|
1718
1705
|
return ast;
|
|
1719
1706
|
}
|
|
1720
|
-
var init_parser = __esm({
|
|
1721
|
-
"src/parser.ts"() {
|
|
1722
|
-
"use strict";
|
|
1723
|
-
init_ebnfParser();
|
|
1724
|
-
}
|
|
1725
|
-
});
|
|
1726
1707
|
|
|
1727
|
-
// src/
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
const
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1708
|
+
// src/semantic/validate.ts
|
|
1709
|
+
init_esm_shims();
|
|
1710
|
+
function validateSemantic(ast, options) {
|
|
1711
|
+
const result = validateSemanticFull(ast, options);
|
|
1712
|
+
return result.errors;
|
|
1713
|
+
}
|
|
1714
|
+
function validateSemanticFull(ast, options) {
|
|
1715
|
+
const errors = [];
|
|
1716
|
+
const warnings = [];
|
|
1717
|
+
const pillars = {
|
|
1718
|
+
state: false,
|
|
1719
|
+
action: false,
|
|
1720
|
+
form: false,
|
|
1721
|
+
time: false,
|
|
1722
|
+
energy: false,
|
|
1723
|
+
memory: false,
|
|
1724
|
+
interface: false,
|
|
1725
|
+
security: false,
|
|
1726
|
+
evolve: false
|
|
1727
|
+
};
|
|
1728
|
+
const onLog = (e) => {
|
|
1729
|
+
const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
|
|
1730
|
+
if (options?.onLog) options.onLog(entry);
|
|
1731
|
+
};
|
|
1732
|
+
ast.functions = ast.functions || [];
|
|
1733
|
+
ast.modules = ast.modules || [];
|
|
1734
|
+
ast.objects = ast.objects || [];
|
|
1735
|
+
ast.events = ast.events || [];
|
|
1736
|
+
ast.securities = ast.securities || [];
|
|
1737
|
+
ast.memories = ast.memories || [];
|
|
1738
|
+
ast.interfaces = ast.interfaces || [];
|
|
1740
1739
|
if (ast.system) {
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
if (ast.mode) {
|
|
1745
|
-
parts.push(isESM ? `export const MODE = ${JSON.stringify(ast.mode)};` : `const MODE = ${JSON.stringify(ast.mode)};
|
|
1746
|
-
module.exports.MODE = MODE;`);
|
|
1747
|
-
}
|
|
1748
|
-
if (ast.ui) {
|
|
1749
|
-
parts.push(isESM ? `export const UI = ${JSON.stringify(ast.ui)};` : `const UI = ${JSON.stringify(ast.ui)};
|
|
1750
|
-
module.exports.UI = UI;`);
|
|
1740
|
+
pillars.state = true;
|
|
1741
|
+
} else {
|
|
1742
|
+
warnings.push("No \u03A3 SYSTEM declared - consider adding a system name");
|
|
1751
1743
|
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
const bodyLines = (fn.steps || []).map((s) => ` // ${s.raw}`);
|
|
1757
|
-
functionNames.push(fn.name);
|
|
1758
|
-
if (isESM) {
|
|
1759
|
-
const fnCode = `export function ${fn.name}(${args}) {
|
|
1760
|
-
${bodyLines.join("\n")}
|
|
1761
|
-
}`;
|
|
1762
|
-
parts.push(fnCode);
|
|
1763
|
-
} else {
|
|
1764
|
-
const fnCode = `function ${fn.name}(${args}) {
|
|
1765
|
-
${bodyLines.join("\n")}
|
|
1766
|
-
}
|
|
1767
|
-
module.exports.${fn.name} = ${fn.name};`;
|
|
1768
|
-
parts.push(fnCode);
|
|
1744
|
+
if (ast.substates?.length) {
|
|
1745
|
+
for (const sub of ast.substates) {
|
|
1746
|
+
if (sub.parent && !ast.substates.some((s) => s.name === sub.parent)) {
|
|
1747
|
+
warnings.push(`Substate '${sub.name}' references unknown parent '${sub.parent}'`);
|
|
1769
1748
|
}
|
|
1770
1749
|
}
|
|
1771
1750
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
for (const ia of ast.ias) {
|
|
1775
|
-
const body = ia.body.map((b) => ` // ${b}`).join("\n");
|
|
1776
|
-
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
1777
|
-
const constName = `IA_${name}`;
|
|
1778
|
-
iaNames.push(constName);
|
|
1779
|
-
if (isESM) {
|
|
1780
|
-
const code = `export const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
1781
|
-
${body}
|
|
1782
|
-
} };`;
|
|
1783
|
-
parts.push(code);
|
|
1784
|
-
} else {
|
|
1785
|
-
const code = `const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
1786
|
-
${body}
|
|
1787
|
-
} };
|
|
1788
|
-
module.exports.${constName} = ${constName};`;
|
|
1789
|
-
parts.push(code);
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1751
|
+
if (ast.functions.length > 0) {
|
|
1752
|
+
pillars.action = true;
|
|
1792
1753
|
}
|
|
1793
|
-
const
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
objectNames.push(o.name);
|
|
1797
|
-
parts.push(isESM ? `export const ${o.name} = ${JSON.stringify(o.props, null, 2)};` : `const ${o.name} = ${JSON.stringify(o.props, null, 2)};
|
|
1798
|
-
module.exports.${o.name} = ${o.name};`);
|
|
1799
|
-
}
|
|
1754
|
+
const fnMap = /* @__PURE__ */ new Map();
|
|
1755
|
+
for (const fn of ast.functions) {
|
|
1756
|
+
fnMap.set(fn.name, (fnMap.get(fn.name) || 0) + 1);
|
|
1800
1757
|
}
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
parts.push(isESM ? `export const ${constName} = ${JSON.stringify(f.props, null, 2)};` : `const ${constName} = ${JSON.stringify(f.props, null, 2)};
|
|
1807
|
-
module.exports.${constName} = ${constName};`);
|
|
1758
|
+
for (const [name, count] of fnMap.entries()) {
|
|
1759
|
+
if (count > 1) {
|
|
1760
|
+
const msg = `Duplicate function name: ${name}`;
|
|
1761
|
+
errors.push(msg);
|
|
1762
|
+
onLog({ level: "error", event: "parse.semantic.error", detail: { error: msg } });
|
|
1808
1763
|
}
|
|
1809
1764
|
}
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1812
|
-
for (const
|
|
1813
|
-
const
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1765
|
+
const knownFns = new Set(ast.functions.map((f) => f.name));
|
|
1766
|
+
for (const fn of ast.functions) {
|
|
1767
|
+
for (const step of fn.steps || []) {
|
|
1768
|
+
const token = step.raw.trim();
|
|
1769
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(token) && !knownFns.has(token)) {
|
|
1770
|
+
const msg = `Undefined function reference in '${fn.name}': '${token}'`;
|
|
1771
|
+
errors.push(msg);
|
|
1772
|
+
onLog({ level: "warn", event: "parse.semantic.error", detail: { error: msg } });
|
|
1773
|
+
}
|
|
1817
1774
|
}
|
|
1818
1775
|
}
|
|
1819
|
-
if (ast.
|
|
1820
|
-
|
|
1821
|
-
module.exports.BUILD_TARGETS = BUILD_TARGETS;`);
|
|
1822
|
-
}
|
|
1823
|
-
if (ast.evolve) {
|
|
1824
|
-
parts.push(isESM ? `export const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};` : `const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};
|
|
1825
|
-
module.exports.EVOLVE_STEPS = EVOLVE_STEPS;`);
|
|
1826
|
-
}
|
|
1827
|
-
if (ast.database) {
|
|
1828
|
-
parts.push(isESM ? `export const DATABASE = ${JSON.stringify(ast.database)};` : `const DATABASE = ${JSON.stringify(ast.database)};
|
|
1829
|
-
module.exports.DATABASE = DATABASE;`);
|
|
1830
|
-
}
|
|
1831
|
-
if (ast.kernel) {
|
|
1832
|
-
parts.push(isESM ? `export const KERNEL = ${JSON.stringify(ast.kernel)};` : `const KERNEL = ${JSON.stringify(ast.kernel)};
|
|
1833
|
-
module.exports.KERNEL = KERNEL;`);
|
|
1834
|
-
}
|
|
1835
|
-
if (ast.training) {
|
|
1836
|
-
parts.push(isESM ? `export const TRAINING = ${JSON.stringify(ast.training)};` : `const TRAINING = ${JSON.stringify(ast.training)};
|
|
1837
|
-
module.exports.TRAINING = TRAINING;`);
|
|
1776
|
+
if (ast.objects?.length || ast.classes?.length) {
|
|
1777
|
+
pillars.form = true;
|
|
1838
1778
|
}
|
|
1839
|
-
if (ast.
|
|
1840
|
-
|
|
1841
|
-
|
|
1779
|
+
if (ast.classes?.length) {
|
|
1780
|
+
const classNames = new Set(ast.classes.map((c) => c.name));
|
|
1781
|
+
for (const cls of ast.classes) {
|
|
1782
|
+
if (cls.extends && !classNames.has(cls.extends)) {
|
|
1783
|
+
warnings.push(`Class '${cls.name}' extends unknown class '${cls.extends}'`);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1842
1786
|
}
|
|
1843
|
-
if (ast.
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1787
|
+
if (ast.inherits?.length) {
|
|
1788
|
+
const allNames = /* @__PURE__ */ new Set([
|
|
1789
|
+
...ast.classes?.map((c) => c.name) || [],
|
|
1790
|
+
...ast.objects?.map((o) => o.name) || []
|
|
1791
|
+
]);
|
|
1792
|
+
for (const inh of ast.inherits) {
|
|
1793
|
+
if (!allNames.has(inh.parent)) {
|
|
1794
|
+
warnings.push(`Inherit: '${inh.child}' extends unknown '${inh.parent}'`);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1849
1797
|
}
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
constructor() {
|
|
1853
|
-
Object.assign(this, ${JSON.stringify(c.props)});
|
|
1798
|
+
if (ast.events?.length || ast.causes?.length || ast.loops?.length) {
|
|
1799
|
+
pillars.time = true;
|
|
1854
1800
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1801
|
+
if (ast.events?.length) {
|
|
1802
|
+
for (const evt of ast.events) {
|
|
1803
|
+
for (const handler of evt.handler || []) {
|
|
1804
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(handler) && !knownFns.has(handler)) {
|
|
1805
|
+
warnings.push(`Event '${evt.name}' handler '${handler}' is not a known function`);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1858
1808
|
}
|
|
1859
1809
|
}
|
|
1860
|
-
if (ast.
|
|
1861
|
-
|
|
1862
|
-
module.exports.LOOPS = LOOPS;`);
|
|
1810
|
+
if (ast.throttles?.length || ast.boosts?.length || ast.costs?.length) {
|
|
1811
|
+
pillars.energy = true;
|
|
1863
1812
|
}
|
|
1864
|
-
if (ast.
|
|
1865
|
-
for (const
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1813
|
+
if (ast.throttles?.length) {
|
|
1814
|
+
for (const t of ast.throttles) {
|
|
1815
|
+
if (t.limit <= 0) {
|
|
1816
|
+
errors.push(`Throttle '${t.target}' has invalid limit: ${t.limit}`);
|
|
1817
|
+
}
|
|
1869
1818
|
}
|
|
1870
1819
|
}
|
|
1871
|
-
if (ast.
|
|
1872
|
-
|
|
1873
|
-
module.exports.SYNCS = SYNCS;`);
|
|
1820
|
+
if (ast.memories?.length || ast.persists?.length || ast.database) {
|
|
1821
|
+
pillars.memory = true;
|
|
1874
1822
|
}
|
|
1875
|
-
if (ast.
|
|
1876
|
-
|
|
1877
|
-
module.exports.TIMEOUTS = TIMEOUTS;`);
|
|
1823
|
+
if (ast.forms?.length || ast.inputs?.length || ast.visuals?.length || ast.interfaces?.length) {
|
|
1824
|
+
pillars.interface = true;
|
|
1878
1825
|
}
|
|
1879
|
-
if (ast.
|
|
1880
|
-
|
|
1881
|
-
module.exports.DELAYS = DELAYS;`);
|
|
1826
|
+
if (ast.securities?.length || ast.keys?.length || ast.sandboxes?.length) {
|
|
1827
|
+
pillars.security = true;
|
|
1882
1828
|
}
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1829
|
+
const validSecurityLevels = ["low", "medium", "high", "critical"];
|
|
1830
|
+
if (ast.securities?.length) {
|
|
1831
|
+
for (const sec of ast.securities) {
|
|
1832
|
+
if (sec.level && !validSecurityLevels.includes(sec.level.toLowerCase())) {
|
|
1833
|
+
warnings.push(`Security rule has unknown level '${sec.level}' (use: low, medium, high, critical)`);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1886
1836
|
}
|
|
1887
|
-
if (ast.
|
|
1888
|
-
|
|
1889
|
-
module.exports.KEYS = KEYS;`);
|
|
1890
|
-
}
|
|
1891
|
-
if (ast.sandboxes && ast.sandboxes.length) {
|
|
1892
|
-
parts.push(isESM ? `export const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};` : `const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};
|
|
1893
|
-
module.exports.SANDBOXES = SANDBOXES;`);
|
|
1894
|
-
}
|
|
1895
|
-
if (ast.causes && ast.causes.length) {
|
|
1896
|
-
parts.push(isESM ? `export const CAUSES = ${JSON.stringify(ast.causes, null, 2)};` : `const CAUSES = ${JSON.stringify(ast.causes, null, 2)};
|
|
1897
|
-
module.exports.CAUSES = CAUSES;`);
|
|
1898
|
-
}
|
|
1899
|
-
if (ast.consequences && ast.consequences.length) {
|
|
1900
|
-
parts.push(isESM ? `export const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};` : `const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};
|
|
1901
|
-
module.exports.CONSEQUENCES = CONSEQUENCES;`);
|
|
1902
|
-
}
|
|
1903
|
-
if (ast.memories && ast.memories.length) {
|
|
1904
|
-
parts.push(isESM ? `export const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};` : `const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};
|
|
1905
|
-
module.exports.MEMORIES = MEMORIES;`);
|
|
1906
|
-
}
|
|
1907
|
-
if (ast.persists && ast.persists.length) {
|
|
1908
|
-
parts.push(isESM ? `export const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};` : `const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};
|
|
1909
|
-
module.exports.PERSISTS = PERSISTS;`);
|
|
1910
|
-
}
|
|
1911
|
-
if (ast.interfaces && ast.interfaces.length) {
|
|
1912
|
-
parts.push(isESM ? `export const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};` : `const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};
|
|
1913
|
-
module.exports.INTERFACES = INTERFACES;`);
|
|
1914
|
-
}
|
|
1915
|
-
if (ast.visuals && ast.visuals.length) {
|
|
1916
|
-
parts.push(isESM ? `export const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};` : `const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};
|
|
1917
|
-
module.exports.VISUALS = VISUALS;`);
|
|
1918
|
-
}
|
|
1919
|
-
if (ast.inputs && ast.inputs.length) {
|
|
1920
|
-
parts.push(isESM ? `export const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};` : `const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};
|
|
1921
|
-
module.exports.INPUTS = INPUTS;`);
|
|
1922
|
-
}
|
|
1923
|
-
if (ast.throttles && ast.throttles.length) {
|
|
1924
|
-
parts.push(isESM ? `export const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};` : `const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};
|
|
1925
|
-
module.exports.THROTTLES = THROTTLES;`);
|
|
1926
|
-
}
|
|
1927
|
-
if (ast.boosts && ast.boosts.length) {
|
|
1928
|
-
parts.push(isESM ? `export const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};` : `const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};
|
|
1929
|
-
module.exports.BOOSTS = BOOSTS;`);
|
|
1930
|
-
}
|
|
1931
|
-
if (ast.costs && ast.costs.length) {
|
|
1932
|
-
parts.push(isESM ? `export const COSTS = ${JSON.stringify(ast.costs, null, 2)};` : `const COSTS = ${JSON.stringify(ast.costs, null, 2)};
|
|
1933
|
-
module.exports.COSTS = COSTS;`);
|
|
1934
|
-
}
|
|
1935
|
-
if (ast.locks && ast.locks.length) {
|
|
1936
|
-
parts.push(isESM ? `export const LOCKS = ${JSON.stringify(ast.locks, null, 2)};` : `const LOCKS = ${JSON.stringify(ast.locks, null, 2)};
|
|
1937
|
-
module.exports.LOCKS = LOCKS;`);
|
|
1938
|
-
}
|
|
1939
|
-
if (ast.unlocks && ast.unlocks.length) {
|
|
1940
|
-
parts.push(isESM ? `export const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};` : `const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};
|
|
1941
|
-
module.exports.UNLOCKS = UNLOCKS;`);
|
|
1942
|
-
}
|
|
1943
|
-
if (ast.voids && ast.voids.length) {
|
|
1944
|
-
parts.push(isESM ? `export const VOIDS = ${JSON.stringify(ast.voids, null, 2)};` : `const VOIDS = ${JSON.stringify(ast.voids, null, 2)};
|
|
1945
|
-
module.exports.VOIDS = VOIDS;`);
|
|
1946
|
-
}
|
|
1947
|
-
if (ast.inherits && ast.inherits.length) {
|
|
1948
|
-
parts.push(isESM ? `export const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};` : `const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};
|
|
1949
|
-
module.exports.INHERITS = INHERITS;`);
|
|
1950
|
-
}
|
|
1951
|
-
if (ast.contains && ast.contains.length) {
|
|
1952
|
-
parts.push(isESM ? `export const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};` : `const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};
|
|
1953
|
-
module.exports.CONTAINS = CONTAINS;`);
|
|
1954
|
-
}
|
|
1955
|
-
if (ast.verifies && ast.verifies.length) {
|
|
1956
|
-
parts.push(isESM ? `export const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};` : `const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};
|
|
1957
|
-
module.exports.VERIFIES = VERIFIES;`);
|
|
1958
|
-
}
|
|
1959
|
-
if (ast.logNodes && ast.logNodes.length) {
|
|
1960
|
-
parts.push(isESM ? `export const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};` : `const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};
|
|
1961
|
-
module.exports.LOG_NODES = LOG_NODES;`);
|
|
1962
|
-
}
|
|
1963
|
-
if (isESM) {
|
|
1964
|
-
parts.push("\nexport default { SYSTEM, MODE, UI };");
|
|
1965
|
-
} else {
|
|
1966
|
-
parts.push("\nmodule.exports.default = { SYSTEM, MODE, UI };");
|
|
1967
|
-
}
|
|
1968
|
-
return parts.join("\n\n");
|
|
1969
|
-
}
|
|
1970
|
-
function transpileToDTS(ast) {
|
|
1971
|
-
const lines = [];
|
|
1972
|
-
lines.push("// Type declarations generated by enyosx-ai");
|
|
1973
|
-
lines.push("");
|
|
1974
|
-
if (ast.system) {
|
|
1975
|
-
lines.push(`export declare const SYSTEM: string;`);
|
|
1976
|
-
}
|
|
1977
|
-
if (ast.mode) {
|
|
1978
|
-
lines.push(`export declare const MODE: string;`);
|
|
1979
|
-
}
|
|
1980
|
-
if (ast.ui) {
|
|
1981
|
-
lines.push(`export declare const UI: string;`);
|
|
1982
|
-
}
|
|
1983
|
-
if (ast.functions && ast.functions.length) {
|
|
1984
|
-
for (const fn of ast.functions) {
|
|
1985
|
-
const args = (fn.args || []).map((a) => `${a}: any`).join(", ");
|
|
1986
|
-
lines.push(`export declare function ${fn.name}(${args}): void;`);
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
if (ast.ias && ast.ias.length) {
|
|
1990
|
-
for (const ia of ast.ias) {
|
|
1991
|
-
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
1992
|
-
lines.push(`export declare const IA_${name}: { name: string; run: () => void };`);
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
1995
|
-
if (ast.objects && ast.objects.length) {
|
|
1996
|
-
for (const o of ast.objects) {
|
|
1997
|
-
const propTypes = Object.keys(o.props).map((k) => `${k}: string | null`).join("; ");
|
|
1998
|
-
lines.push(`export declare const ${o.name}: { ${propTypes} };`);
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
if (ast.forms && ast.forms.length) {
|
|
2002
|
-
for (const f of ast.forms) {
|
|
2003
|
-
lines.push(`export declare const FORM_${f.name}: Record<string, any>;`);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
if (ast.animations && ast.animations.length) {
|
|
2007
|
-
for (const a of ast.animations) {
|
|
2008
|
-
const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2009
|
-
lines.push(`export declare const ${constName}: Record<string, any>;`);
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
if (ast.build) {
|
|
2013
|
-
lines.push(`export declare const BUILD_TARGETS: string[];`);
|
|
2014
|
-
}
|
|
2015
|
-
if (ast.evolve) {
|
|
2016
|
-
lines.push(`export declare const EVOLVE_STEPS: string[];`);
|
|
2017
|
-
}
|
|
2018
|
-
lines.push("");
|
|
2019
|
-
lines.push("declare const _default: { SYSTEM: string; MODE: string; UI: string };");
|
|
2020
|
-
lines.push("export default _default;");
|
|
2021
|
-
return lines.join("\n");
|
|
2022
|
-
}
|
|
2023
|
-
function transpileToWAT(ast) {
|
|
2024
|
-
const lines = [];
|
|
2025
|
-
lines.push(";; WebAssembly Text Format generated by enyosx-ai");
|
|
2026
|
-
lines.push(";; This is a stub for future WASM compilation");
|
|
2027
|
-
lines.push("");
|
|
2028
|
-
lines.push("(module");
|
|
2029
|
-
lines.push(` ;; System: ${ast.system || "unnamed"}`);
|
|
2030
|
-
lines.push(` ;; Mode: ${ast.mode || "default"}`);
|
|
2031
|
-
lines.push("");
|
|
2032
|
-
lines.push(" ;; Memory declaration");
|
|
2033
|
-
lines.push(' (memory (export "memory") 1)');
|
|
2034
|
-
lines.push("");
|
|
2035
|
-
if (ast.system) {
|
|
2036
|
-
const bytes = Array.from(new TextEncoder().encode(ast.system)).join(" ");
|
|
2037
|
-
lines.push(` ;; System name data`);
|
|
2038
|
-
lines.push(` (data (i32.const 0) "${ast.system}")`);
|
|
2039
|
-
lines.push("");
|
|
2040
|
-
}
|
|
2041
|
-
if (ast.functions && ast.functions.length) {
|
|
2042
|
-
lines.push(" ;; Function stubs");
|
|
2043
|
-
for (const fn of ast.functions) {
|
|
2044
|
-
const params = (fn.args || []).map((_, i) => `(param $arg${i} i32)`).join(" ");
|
|
2045
|
-
lines.push(` (func (export "${fn.name}") ${params} (result i32)`);
|
|
2046
|
-
lines.push(` ;; Steps: ${(fn.steps || []).map((s) => s.raw).join(" -> ")}`);
|
|
2047
|
-
lines.push(` i32.const 0 ;; placeholder return`);
|
|
2048
|
-
lines.push(` )`);
|
|
2049
|
-
lines.push("");
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
if (ast.ias && ast.ias.length) {
|
|
2053
|
-
lines.push(" ;; IA stubs (table references for future indirect calls)");
|
|
2054
|
-
for (const ia of ast.ias) {
|
|
2055
|
-
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2056
|
-
lines.push(` ;; IA: ${ia.name}`);
|
|
2057
|
-
lines.push(` (func (export "ia_${name}") (result i32)`);
|
|
2058
|
-
lines.push(` ;; Capabilities: ${ia.body.join(", ")}`);
|
|
2059
|
-
lines.push(` i32.const 1 ;; stub: IA ready`);
|
|
2060
|
-
lines.push(` )`);
|
|
2061
|
-
lines.push("");
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
lines.push(" ;; Main entry point");
|
|
2065
|
-
lines.push(' (func (export "_start")');
|
|
2066
|
-
lines.push(" ;; Initialize system");
|
|
2067
|
-
lines.push(" nop");
|
|
2068
|
-
lines.push(" )");
|
|
2069
|
-
lines.push("");
|
|
2070
|
-
if (ast.build && ast.build.targets) {
|
|
2071
|
-
lines.push(` ;; Build targets: ${ast.build.targets.join(", ")}`);
|
|
2072
|
-
}
|
|
2073
|
-
lines.push(")");
|
|
2074
|
-
lines.push("");
|
|
2075
|
-
lines.push(";; To compile this WAT to WASM:");
|
|
2076
|
-
lines.push(";; wat2wasm output.wat -o output.wasm");
|
|
2077
|
-
lines.push(";; Or use wasm-pack for Rust-based compilation");
|
|
2078
|
-
return lines.join("\n");
|
|
2079
|
-
}
|
|
2080
|
-
function hasWASMTarget(ast) {
|
|
2081
|
-
if (!ast.build || !ast.build.targets) return false;
|
|
2082
|
-
return ast.build.targets.some(
|
|
2083
|
-
(t) => t.toLowerCase() === "wasm" || t.toLowerCase() === "webassembly" || t.toLowerCase() === "wat"
|
|
2084
|
-
);
|
|
2085
|
-
}
|
|
2086
|
-
var init_transpile = __esm({
|
|
2087
|
-
"src/transpile.ts"() {
|
|
2088
|
-
"use strict";
|
|
2089
|
-
}
|
|
2090
|
-
});
|
|
2091
|
-
|
|
2092
|
-
// src/semantic/validate.ts
|
|
2093
|
-
function validateSemantic(ast, options) {
|
|
2094
|
-
const result = validateSemanticFull(ast, options);
|
|
2095
|
-
return result.errors;
|
|
2096
|
-
}
|
|
2097
|
-
function validateSemanticFull(ast, options) {
|
|
2098
|
-
const errors = [];
|
|
2099
|
-
const warnings = [];
|
|
2100
|
-
const pillars = {
|
|
2101
|
-
state: false,
|
|
2102
|
-
action: false,
|
|
2103
|
-
form: false,
|
|
2104
|
-
time: false,
|
|
2105
|
-
energy: false,
|
|
2106
|
-
memory: false,
|
|
2107
|
-
interface: false,
|
|
2108
|
-
security: false,
|
|
2109
|
-
evolve: false
|
|
2110
|
-
};
|
|
2111
|
-
const onLog = (e) => {
|
|
2112
|
-
const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
|
|
2113
|
-
if (options?.onLog) options.onLog(entry);
|
|
2114
|
-
};
|
|
2115
|
-
ast.functions = ast.functions || [];
|
|
2116
|
-
ast.modules = ast.modules || [];
|
|
2117
|
-
ast.objects = ast.objects || [];
|
|
2118
|
-
ast.events = ast.events || [];
|
|
2119
|
-
ast.securities = ast.securities || [];
|
|
2120
|
-
ast.memories = ast.memories || [];
|
|
2121
|
-
ast.interfaces = ast.interfaces || [];
|
|
2122
|
-
if (ast.system) {
|
|
2123
|
-
pillars.state = true;
|
|
2124
|
-
} else {
|
|
2125
|
-
warnings.push("No \u03A3 SYSTEM declared - consider adding a system name");
|
|
2126
|
-
}
|
|
2127
|
-
if (ast.substates?.length) {
|
|
2128
|
-
for (const sub of ast.substates) {
|
|
2129
|
-
if (sub.parent && !ast.substates.some((s) => s.name === sub.parent)) {
|
|
2130
|
-
warnings.push(`Substate '${sub.name}' references unknown parent '${sub.parent}'`);
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
if (ast.functions.length > 0) {
|
|
2135
|
-
pillars.action = true;
|
|
2136
|
-
}
|
|
2137
|
-
const fnMap = /* @__PURE__ */ new Map();
|
|
2138
|
-
for (const fn of ast.functions) {
|
|
2139
|
-
fnMap.set(fn.name, (fnMap.get(fn.name) || 0) + 1);
|
|
2140
|
-
}
|
|
2141
|
-
for (const [name, count] of fnMap.entries()) {
|
|
2142
|
-
if (count > 1) {
|
|
2143
|
-
const msg = `Duplicate function name: ${name}`;
|
|
2144
|
-
errors.push(msg);
|
|
2145
|
-
onLog({ level: "error", event: "parse.semantic.error", detail: { error: msg } });
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
const knownFns = new Set(ast.functions.map((f) => f.name));
|
|
2149
|
-
for (const fn of ast.functions) {
|
|
2150
|
-
for (const step of fn.steps || []) {
|
|
2151
|
-
const token = step.raw.trim();
|
|
2152
|
-
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(token) && !knownFns.has(token)) {
|
|
2153
|
-
const msg = `Undefined function reference in '${fn.name}': '${token}'`;
|
|
2154
|
-
errors.push(msg);
|
|
2155
|
-
onLog({ level: "warn", event: "parse.semantic.error", detail: { error: msg } });
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
if (ast.objects?.length || ast.classes?.length) {
|
|
2160
|
-
pillars.form = true;
|
|
2161
|
-
}
|
|
2162
|
-
if (ast.classes?.length) {
|
|
2163
|
-
const classNames = new Set(ast.classes.map((c) => c.name));
|
|
2164
|
-
for (const cls of ast.classes) {
|
|
2165
|
-
if (cls.extends && !classNames.has(cls.extends)) {
|
|
2166
|
-
warnings.push(`Class '${cls.name}' extends unknown class '${cls.extends}'`);
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
if (ast.inherits?.length) {
|
|
2171
|
-
const allNames = /* @__PURE__ */ new Set([
|
|
2172
|
-
...ast.classes?.map((c) => c.name) || [],
|
|
2173
|
-
...ast.objects?.map((o) => o.name) || []
|
|
2174
|
-
]);
|
|
2175
|
-
for (const inh of ast.inherits) {
|
|
2176
|
-
if (!allNames.has(inh.parent)) {
|
|
2177
|
-
warnings.push(`Inherit: '${inh.child}' extends unknown '${inh.parent}'`);
|
|
2178
|
-
}
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
if (ast.events?.length || ast.causes?.length || ast.loops?.length) {
|
|
2182
|
-
pillars.time = true;
|
|
2183
|
-
}
|
|
2184
|
-
if (ast.events?.length) {
|
|
2185
|
-
for (const evt of ast.events) {
|
|
2186
|
-
for (const handler of evt.handler || []) {
|
|
2187
|
-
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(handler) && !knownFns.has(handler)) {
|
|
2188
|
-
warnings.push(`Event '${evt.name}' handler '${handler}' is not a known function`);
|
|
2189
|
-
}
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
if (ast.throttles?.length || ast.boosts?.length || ast.costs?.length) {
|
|
2194
|
-
pillars.energy = true;
|
|
2195
|
-
}
|
|
2196
|
-
if (ast.throttles?.length) {
|
|
2197
|
-
for (const t of ast.throttles) {
|
|
2198
|
-
if (t.limit <= 0) {
|
|
2199
|
-
errors.push(`Throttle '${t.target}' has invalid limit: ${t.limit}`);
|
|
2200
|
-
}
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
if (ast.memories?.length || ast.persists?.length || ast.database) {
|
|
2204
|
-
pillars.memory = true;
|
|
2205
|
-
}
|
|
2206
|
-
if (ast.forms?.length || ast.inputs?.length || ast.visuals?.length || ast.interfaces?.length) {
|
|
2207
|
-
pillars.interface = true;
|
|
2208
|
-
}
|
|
2209
|
-
if (ast.securities?.length || ast.keys?.length || ast.sandboxes?.length) {
|
|
2210
|
-
pillars.security = true;
|
|
2211
|
-
}
|
|
2212
|
-
const validSecurityLevels = ["low", "medium", "high", "critical"];
|
|
2213
|
-
if (ast.securities?.length) {
|
|
2214
|
-
for (const sec of ast.securities) {
|
|
2215
|
-
if (sec.level && !validSecurityLevels.includes(sec.level.toLowerCase())) {
|
|
2216
|
-
warnings.push(`Security rule has unknown level '${sec.level}' (use: low, medium, high, critical)`);
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
if (ast.evolve?.steps?.length) {
|
|
2221
|
-
pillars.evolve = true;
|
|
1837
|
+
if (ast.evolve?.steps?.length) {
|
|
1838
|
+
pillars.evolve = true;
|
|
2222
1839
|
}
|
|
2223
1840
|
const activePillars = Object.values(pillars).filter(Boolean).length;
|
|
2224
1841
|
const score = Math.round(activePillars / 9 * 100);
|
|
@@ -2228,6 +1845,7 @@ function validateSemanticFull(ast, options) {
|
|
|
2228
1845
|
}
|
|
2229
1846
|
|
|
2230
1847
|
// src/evolve/stub.ts
|
|
1848
|
+
init_esm_shims();
|
|
2231
1849
|
function applyEvolve(ast, options) {
|
|
2232
1850
|
if (!ast.evolve || !ast.evolve.steps || ast.evolve.steps.length === 0) {
|
|
2233
1851
|
return { changed: false, appliedSteps: [], skippedSteps: [] };
|
|
@@ -2400,69 +2018,419 @@ function applyEvolve(ast, options) {
|
|
|
2400
2018
|
skippedSteps.push(step);
|
|
2401
2019
|
}
|
|
2402
2020
|
}
|
|
2403
|
-
if (changed && onLog) {
|
|
2404
|
-
onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.summary", detail: { appliedSteps, skippedSteps } });
|
|
2021
|
+
if (changed && onLog) {
|
|
2022
|
+
onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.summary", detail: { appliedSteps, skippedSteps } });
|
|
2023
|
+
}
|
|
2024
|
+
return { changed, appliedSteps, skippedSteps };
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
// src/runENY.ts
|
|
2028
|
+
init_esm_shims();
|
|
2029
|
+
function runENY(code, options) {
|
|
2030
|
+
const hasSystem = /Σ\s+SYSTEM/i.test(code);
|
|
2031
|
+
if (!hasSystem) {
|
|
2032
|
+
if (options?.onLog) {
|
|
2033
|
+
options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
|
|
2034
|
+
}
|
|
2035
|
+
if (options?.logFile) {
|
|
2036
|
+
const attempts = options?.logRetryAttempts ?? 3;
|
|
2037
|
+
const delay = options?.logRetryDelayMs ?? 1e3;
|
|
2038
|
+
writeWithRetry({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } }, options.logFile, attempts, delay, options?.onLog);
|
|
2039
|
+
}
|
|
2040
|
+
return { raw: code, isEny: false, logs: [] };
|
|
2041
|
+
}
|
|
2042
|
+
const userOnLog = options?.onLog;
|
|
2043
|
+
let wrappedOnLog = userOnLog;
|
|
2044
|
+
if (options?.logFile) {
|
|
2045
|
+
const attempts = options?.logRetryAttempts ?? 3;
|
|
2046
|
+
const delay = options?.logRetryDelayMs ?? 1e3;
|
|
2047
|
+
wrappedOnLog = (e) => {
|
|
2048
|
+
if (userOnLog) userOnLog(e);
|
|
2049
|
+
writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
const ast = parse(code, { ...options, onLog: wrappedOnLog });
|
|
2053
|
+
try {
|
|
2054
|
+
const errors = validateSemantic(ast, { onLog: wrappedOnLog });
|
|
2055
|
+
if (errors && errors.length > 0) {
|
|
2056
|
+
if (options?.onLog) options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "parse.semantic.summary", detail: { count: errors.length } });
|
|
2057
|
+
}
|
|
2058
|
+
} catch (err) {
|
|
2059
|
+
if (wrappedOnLog) wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.semantic.failed", detail: { error: String(err) } });
|
|
2060
|
+
}
|
|
2061
|
+
if (ast.evolve && ast.evolve.steps && ast.evolve.steps.length > 0) {
|
|
2062
|
+
try {
|
|
2063
|
+
const evolveResult = applyEvolve(ast, { onLog: wrappedOnLog });
|
|
2064
|
+
if (evolveResult.changed && wrappedOnLog) {
|
|
2065
|
+
wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.summary", detail: { changed: true, stepsApplied: ast.evolve.steps.length } });
|
|
2066
|
+
}
|
|
2067
|
+
} catch (err) {
|
|
2068
|
+
if (wrappedOnLog) wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.evolve.failed", detail: { error: String(err) } });
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
ast.isEny = true;
|
|
2072
|
+
return ast;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
// src/transpile.ts
|
|
2076
|
+
init_esm_shims();
|
|
2077
|
+
function transpileToJS(ast, options) {
|
|
2078
|
+
const parts = [];
|
|
2079
|
+
const format = options?.moduleFormat || "esm";
|
|
2080
|
+
const isESM = format === "esm";
|
|
2081
|
+
parts.push("// Generated by enyosx-ai (transpiler)");
|
|
2082
|
+
if (ast.system) {
|
|
2083
|
+
parts.push(isESM ? `export const SYSTEM = ${JSON.stringify(ast.system)};` : `const SYSTEM = ${JSON.stringify(ast.system)};
|
|
2084
|
+
module.exports.SYSTEM = SYSTEM;`);
|
|
2085
|
+
}
|
|
2086
|
+
if (ast.mode) {
|
|
2087
|
+
parts.push(isESM ? `export const MODE = ${JSON.stringify(ast.mode)};` : `const MODE = ${JSON.stringify(ast.mode)};
|
|
2088
|
+
module.exports.MODE = MODE;`);
|
|
2089
|
+
}
|
|
2090
|
+
if (ast.ui) {
|
|
2091
|
+
parts.push(isESM ? `export const UI = ${JSON.stringify(ast.ui)};` : `const UI = ${JSON.stringify(ast.ui)};
|
|
2092
|
+
module.exports.UI = UI;`);
|
|
2093
|
+
}
|
|
2094
|
+
const functionNames = [];
|
|
2095
|
+
if (ast.functions && ast.functions.length) {
|
|
2096
|
+
for (const fn of ast.functions) {
|
|
2097
|
+
const args = (fn.args || []).join(", ");
|
|
2098
|
+
const bodyLines = (fn.steps || []).map((s) => ` // ${s.raw}`);
|
|
2099
|
+
functionNames.push(fn.name);
|
|
2100
|
+
if (isESM) {
|
|
2101
|
+
const fnCode = `export function ${fn.name}(${args}) {
|
|
2102
|
+
${bodyLines.join("\n")}
|
|
2103
|
+
}`;
|
|
2104
|
+
parts.push(fnCode);
|
|
2105
|
+
} else {
|
|
2106
|
+
const fnCode = `function ${fn.name}(${args}) {
|
|
2107
|
+
${bodyLines.join("\n")}
|
|
2108
|
+
}
|
|
2109
|
+
module.exports.${fn.name} = ${fn.name};`;
|
|
2110
|
+
parts.push(fnCode);
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
const iaNames = [];
|
|
2115
|
+
if (ast.ias && ast.ias.length) {
|
|
2116
|
+
for (const ia of ast.ias) {
|
|
2117
|
+
const body = ia.body.map((b) => ` // ${b}`).join("\n");
|
|
2118
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2119
|
+
const constName = `IA_${name}`;
|
|
2120
|
+
iaNames.push(constName);
|
|
2121
|
+
if (isESM) {
|
|
2122
|
+
const code = `export const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
2123
|
+
${body}
|
|
2124
|
+
} };`;
|
|
2125
|
+
parts.push(code);
|
|
2126
|
+
} else {
|
|
2127
|
+
const code = `const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
2128
|
+
${body}
|
|
2129
|
+
} };
|
|
2130
|
+
module.exports.${constName} = ${constName};`;
|
|
2131
|
+
parts.push(code);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
const objectNames = [];
|
|
2136
|
+
if (ast.objects && ast.objects.length) {
|
|
2137
|
+
for (const o of ast.objects) {
|
|
2138
|
+
objectNames.push(o.name);
|
|
2139
|
+
parts.push(isESM ? `export const ${o.name} = ${JSON.stringify(o.props, null, 2)};` : `const ${o.name} = ${JSON.stringify(o.props, null, 2)};
|
|
2140
|
+
module.exports.${o.name} = ${o.name};`);
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
const formNames = [];
|
|
2144
|
+
if (ast.forms && ast.forms.length) {
|
|
2145
|
+
for (const f of ast.forms) {
|
|
2146
|
+
const constName = `FORM_${f.name}`;
|
|
2147
|
+
formNames.push(constName);
|
|
2148
|
+
parts.push(isESM ? `export const ${constName} = ${JSON.stringify(f.props, null, 2)};` : `const ${constName} = ${JSON.stringify(f.props, null, 2)};
|
|
2149
|
+
module.exports.${constName} = ${constName};`);
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
const animNames = [];
|
|
2153
|
+
if (ast.animations && ast.animations.length) {
|
|
2154
|
+
for (const a of ast.animations) {
|
|
2155
|
+
const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2156
|
+
animNames.push(constName);
|
|
2157
|
+
parts.push(isESM ? `export const ${constName} = ${JSON.stringify(a.props, null, 2)};` : `const ${constName} = ${JSON.stringify(a.props, null, 2)};
|
|
2158
|
+
module.exports.${constName} = ${constName};`);
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
if (ast.build) {
|
|
2162
|
+
parts.push(isESM ? `export const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};` : `const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};
|
|
2163
|
+
module.exports.BUILD_TARGETS = BUILD_TARGETS;`);
|
|
2164
|
+
}
|
|
2165
|
+
if (ast.evolve) {
|
|
2166
|
+
parts.push(isESM ? `export const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};` : `const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};
|
|
2167
|
+
module.exports.EVOLVE_STEPS = EVOLVE_STEPS;`);
|
|
2168
|
+
}
|
|
2169
|
+
if (ast.database) {
|
|
2170
|
+
parts.push(isESM ? `export const DATABASE = ${JSON.stringify(ast.database)};` : `const DATABASE = ${JSON.stringify(ast.database)};
|
|
2171
|
+
module.exports.DATABASE = DATABASE;`);
|
|
2172
|
+
}
|
|
2173
|
+
if (ast.kernel) {
|
|
2174
|
+
parts.push(isESM ? `export const KERNEL = ${JSON.stringify(ast.kernel)};` : `const KERNEL = ${JSON.stringify(ast.kernel)};
|
|
2175
|
+
module.exports.KERNEL = KERNEL;`);
|
|
2176
|
+
}
|
|
2177
|
+
if (ast.training) {
|
|
2178
|
+
parts.push(isESM ? `export const TRAINING = ${JSON.stringify(ast.training)};` : `const TRAINING = ${JSON.stringify(ast.training)};
|
|
2179
|
+
module.exports.TRAINING = TRAINING;`);
|
|
2180
|
+
}
|
|
2181
|
+
if (ast.substates && ast.substates.length) {
|
|
2182
|
+
parts.push(isESM ? `export const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};` : `const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};
|
|
2183
|
+
module.exports.SUBSTATES = SUBSTATES;`);
|
|
2184
|
+
}
|
|
2185
|
+
if (ast.classes && ast.classes.length) {
|
|
2186
|
+
for (const c of ast.classes) {
|
|
2187
|
+
const className = c.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2188
|
+
parts.push(isESM ? `export class ${className} {
|
|
2189
|
+
constructor() {
|
|
2190
|
+
Object.assign(this, ${JSON.stringify(c.props)});
|
|
2191
|
+
}
|
|
2192
|
+
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
2193
|
+
}` : `class ${className} {
|
|
2194
|
+
constructor() {
|
|
2195
|
+
Object.assign(this, ${JSON.stringify(c.props)});
|
|
2196
|
+
}
|
|
2197
|
+
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
2198
|
+
}
|
|
2199
|
+
module.exports.${className} = ${className};`);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
if (ast.loops && ast.loops.length) {
|
|
2203
|
+
parts.push(isESM ? `export const LOOPS = ${JSON.stringify(ast.loops, null, 2)};` : `const LOOPS = ${JSON.stringify(ast.loops, null, 2)};
|
|
2204
|
+
module.exports.LOOPS = LOOPS;`);
|
|
2405
2205
|
}
|
|
2406
|
-
|
|
2206
|
+
if (ast.events && ast.events.length) {
|
|
2207
|
+
for (const e of ast.events) {
|
|
2208
|
+
const eventName = `EVENT_${e.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2209
|
+
parts.push(isESM ? `export const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };` : `const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };
|
|
2210
|
+
module.exports.${eventName} = ${eventName};`);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
if (ast.syncs && ast.syncs.length) {
|
|
2214
|
+
parts.push(isESM ? `export const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};` : `const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};
|
|
2215
|
+
module.exports.SYNCS = SYNCS;`);
|
|
2216
|
+
}
|
|
2217
|
+
if (ast.timeouts && ast.timeouts.length) {
|
|
2218
|
+
parts.push(isESM ? `export const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};` : `const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};
|
|
2219
|
+
module.exports.TIMEOUTS = TIMEOUTS;`);
|
|
2220
|
+
}
|
|
2221
|
+
if (ast.delays && ast.delays.length) {
|
|
2222
|
+
parts.push(isESM ? `export const DELAYS = ${JSON.stringify(ast.delays, null, 2)};` : `const DELAYS = ${JSON.stringify(ast.delays, null, 2)};
|
|
2223
|
+
module.exports.DELAYS = DELAYS;`);
|
|
2224
|
+
}
|
|
2225
|
+
if (ast.securities && ast.securities.length) {
|
|
2226
|
+
parts.push(isESM ? `export const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};` : `const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};
|
|
2227
|
+
module.exports.SECURITY_RULES = SECURITY_RULES;`);
|
|
2228
|
+
}
|
|
2229
|
+
if (ast.keys && ast.keys.length) {
|
|
2230
|
+
parts.push(isESM ? `export const KEYS = ${JSON.stringify(ast.keys, null, 2)};` : `const KEYS = ${JSON.stringify(ast.keys, null, 2)};
|
|
2231
|
+
module.exports.KEYS = KEYS;`);
|
|
2232
|
+
}
|
|
2233
|
+
if (ast.sandboxes && ast.sandboxes.length) {
|
|
2234
|
+
parts.push(isESM ? `export const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};` : `const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};
|
|
2235
|
+
module.exports.SANDBOXES = SANDBOXES;`);
|
|
2236
|
+
}
|
|
2237
|
+
if (ast.causes && ast.causes.length) {
|
|
2238
|
+
parts.push(isESM ? `export const CAUSES = ${JSON.stringify(ast.causes, null, 2)};` : `const CAUSES = ${JSON.stringify(ast.causes, null, 2)};
|
|
2239
|
+
module.exports.CAUSES = CAUSES;`);
|
|
2240
|
+
}
|
|
2241
|
+
if (ast.consequences && ast.consequences.length) {
|
|
2242
|
+
parts.push(isESM ? `export const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};` : `const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};
|
|
2243
|
+
module.exports.CONSEQUENCES = CONSEQUENCES;`);
|
|
2244
|
+
}
|
|
2245
|
+
if (ast.memories && ast.memories.length) {
|
|
2246
|
+
parts.push(isESM ? `export const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};` : `const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};
|
|
2247
|
+
module.exports.MEMORIES = MEMORIES;`);
|
|
2248
|
+
}
|
|
2249
|
+
if (ast.persists && ast.persists.length) {
|
|
2250
|
+
parts.push(isESM ? `export const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};` : `const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};
|
|
2251
|
+
module.exports.PERSISTS = PERSISTS;`);
|
|
2252
|
+
}
|
|
2253
|
+
if (ast.interfaces && ast.interfaces.length) {
|
|
2254
|
+
parts.push(isESM ? `export const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};` : `const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};
|
|
2255
|
+
module.exports.INTERFACES = INTERFACES;`);
|
|
2256
|
+
}
|
|
2257
|
+
if (ast.visuals && ast.visuals.length) {
|
|
2258
|
+
parts.push(isESM ? `export const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};` : `const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};
|
|
2259
|
+
module.exports.VISUALS = VISUALS;`);
|
|
2260
|
+
}
|
|
2261
|
+
if (ast.inputs && ast.inputs.length) {
|
|
2262
|
+
parts.push(isESM ? `export const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};` : `const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};
|
|
2263
|
+
module.exports.INPUTS = INPUTS;`);
|
|
2264
|
+
}
|
|
2265
|
+
if (ast.throttles && ast.throttles.length) {
|
|
2266
|
+
parts.push(isESM ? `export const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};` : `const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};
|
|
2267
|
+
module.exports.THROTTLES = THROTTLES;`);
|
|
2268
|
+
}
|
|
2269
|
+
if (ast.boosts && ast.boosts.length) {
|
|
2270
|
+
parts.push(isESM ? `export const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};` : `const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};
|
|
2271
|
+
module.exports.BOOSTS = BOOSTS;`);
|
|
2272
|
+
}
|
|
2273
|
+
if (ast.costs && ast.costs.length) {
|
|
2274
|
+
parts.push(isESM ? `export const COSTS = ${JSON.stringify(ast.costs, null, 2)};` : `const COSTS = ${JSON.stringify(ast.costs, null, 2)};
|
|
2275
|
+
module.exports.COSTS = COSTS;`);
|
|
2276
|
+
}
|
|
2277
|
+
if (ast.locks && ast.locks.length) {
|
|
2278
|
+
parts.push(isESM ? `export const LOCKS = ${JSON.stringify(ast.locks, null, 2)};` : `const LOCKS = ${JSON.stringify(ast.locks, null, 2)};
|
|
2279
|
+
module.exports.LOCKS = LOCKS;`);
|
|
2280
|
+
}
|
|
2281
|
+
if (ast.unlocks && ast.unlocks.length) {
|
|
2282
|
+
parts.push(isESM ? `export const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};` : `const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};
|
|
2283
|
+
module.exports.UNLOCKS = UNLOCKS;`);
|
|
2284
|
+
}
|
|
2285
|
+
if (ast.voids && ast.voids.length) {
|
|
2286
|
+
parts.push(isESM ? `export const VOIDS = ${JSON.stringify(ast.voids, null, 2)};` : `const VOIDS = ${JSON.stringify(ast.voids, null, 2)};
|
|
2287
|
+
module.exports.VOIDS = VOIDS;`);
|
|
2288
|
+
}
|
|
2289
|
+
if (ast.inherits && ast.inherits.length) {
|
|
2290
|
+
parts.push(isESM ? `export const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};` : `const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};
|
|
2291
|
+
module.exports.INHERITS = INHERITS;`);
|
|
2292
|
+
}
|
|
2293
|
+
if (ast.contains && ast.contains.length) {
|
|
2294
|
+
parts.push(isESM ? `export const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};` : `const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};
|
|
2295
|
+
module.exports.CONTAINS = CONTAINS;`);
|
|
2296
|
+
}
|
|
2297
|
+
if (ast.verifies && ast.verifies.length) {
|
|
2298
|
+
parts.push(isESM ? `export const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};` : `const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};
|
|
2299
|
+
module.exports.VERIFIES = VERIFIES;`);
|
|
2300
|
+
}
|
|
2301
|
+
if (ast.logNodes && ast.logNodes.length) {
|
|
2302
|
+
parts.push(isESM ? `export const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};` : `const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};
|
|
2303
|
+
module.exports.LOG_NODES = LOG_NODES;`);
|
|
2304
|
+
}
|
|
2305
|
+
if (isESM) {
|
|
2306
|
+
parts.push("\nexport default { SYSTEM, MODE, UI };");
|
|
2307
|
+
} else {
|
|
2308
|
+
parts.push("\nmodule.exports.default = { SYSTEM, MODE, UI };");
|
|
2309
|
+
}
|
|
2310
|
+
return parts.join("\n\n");
|
|
2407
2311
|
}
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2312
|
+
function transpileToDTS(ast) {
|
|
2313
|
+
const lines = [];
|
|
2314
|
+
lines.push("// Type declarations generated by enyosx-ai");
|
|
2315
|
+
lines.push("");
|
|
2316
|
+
if (ast.system) {
|
|
2317
|
+
lines.push(`export declare const SYSTEM: string;`);
|
|
2318
|
+
}
|
|
2319
|
+
if (ast.mode) {
|
|
2320
|
+
lines.push(`export declare const MODE: string;`);
|
|
2321
|
+
}
|
|
2322
|
+
if (ast.ui) {
|
|
2323
|
+
lines.push(`export declare const UI: string;`);
|
|
2324
|
+
}
|
|
2325
|
+
if (ast.functions && ast.functions.length) {
|
|
2326
|
+
for (const fn of ast.functions) {
|
|
2327
|
+
const args = (fn.args || []).map((a) => `${a}: any`).join(", ");
|
|
2328
|
+
lines.push(`export declare function ${fn.name}(${args}): void;`);
|
|
2417
2329
|
}
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2330
|
+
}
|
|
2331
|
+
if (ast.ias && ast.ias.length) {
|
|
2332
|
+
for (const ia of ast.ias) {
|
|
2333
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2334
|
+
lines.push(`export declare const IA_${name}: { name: string; run: () => void };`);
|
|
2422
2335
|
}
|
|
2423
|
-
return { raw: code, isEny: false, logs: [] };
|
|
2424
2336
|
}
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
wrappedOnLog = (e) => {
|
|
2431
|
-
if (userOnLog) userOnLog(e);
|
|
2432
|
-
writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
|
|
2433
|
-
};
|
|
2337
|
+
if (ast.objects && ast.objects.length) {
|
|
2338
|
+
for (const o of ast.objects) {
|
|
2339
|
+
const propTypes = Object.keys(o.props).map((k) => `${k}: string | null`).join("; ");
|
|
2340
|
+
lines.push(`export declare const ${o.name}: { ${propTypes} };`);
|
|
2341
|
+
}
|
|
2434
2342
|
}
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
if (errors && errors.length > 0) {
|
|
2439
|
-
if (options?.onLog) options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "parse.semantic.summary", detail: { count: errors.length } });
|
|
2343
|
+
if (ast.forms && ast.forms.length) {
|
|
2344
|
+
for (const f of ast.forms) {
|
|
2345
|
+
lines.push(`export declare const FORM_${f.name}: Record<string, any>;`);
|
|
2440
2346
|
}
|
|
2441
|
-
} catch (err) {
|
|
2442
|
-
if (wrappedOnLog) wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.semantic.failed", detail: { error: String(err) } });
|
|
2443
2347
|
}
|
|
2444
|
-
if (ast.
|
|
2445
|
-
|
|
2446
|
-
const
|
|
2447
|
-
|
|
2448
|
-
wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.summary", detail: { changed: true, stepsApplied: ast.evolve.steps.length } });
|
|
2449
|
-
}
|
|
2450
|
-
} catch (err) {
|
|
2451
|
-
if (wrappedOnLog) wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.evolve.failed", detail: { error: String(err) } });
|
|
2348
|
+
if (ast.animations && ast.animations.length) {
|
|
2349
|
+
for (const a of ast.animations) {
|
|
2350
|
+
const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2351
|
+
lines.push(`export declare const ${constName}: Record<string, any>;`);
|
|
2452
2352
|
}
|
|
2453
2353
|
}
|
|
2454
|
-
ast.
|
|
2455
|
-
|
|
2354
|
+
if (ast.build) {
|
|
2355
|
+
lines.push(`export declare const BUILD_TARGETS: string[];`);
|
|
2356
|
+
}
|
|
2357
|
+
if (ast.evolve) {
|
|
2358
|
+
lines.push(`export declare const EVOLVE_STEPS: string[];`);
|
|
2359
|
+
}
|
|
2360
|
+
lines.push("");
|
|
2361
|
+
lines.push("declare const _default: { SYSTEM: string; MODE: string; UI: string };");
|
|
2362
|
+
lines.push("export default _default;");
|
|
2363
|
+
return lines.join("\n");
|
|
2364
|
+
}
|
|
2365
|
+
function transpileToWAT(ast) {
|
|
2366
|
+
const lines = [];
|
|
2367
|
+
lines.push(";; WebAssembly Text Format generated by enyosx-ai");
|
|
2368
|
+
lines.push(";; This is a stub for future WASM compilation");
|
|
2369
|
+
lines.push("");
|
|
2370
|
+
lines.push("(module");
|
|
2371
|
+
lines.push(` ;; System: ${ast.system || "unnamed"}`);
|
|
2372
|
+
lines.push(` ;; Mode: ${ast.mode || "default"}`);
|
|
2373
|
+
lines.push("");
|
|
2374
|
+
lines.push(" ;; Memory declaration");
|
|
2375
|
+
lines.push(' (memory (export "memory") 1)');
|
|
2376
|
+
lines.push("");
|
|
2377
|
+
if (ast.system) {
|
|
2378
|
+
const bytes = Array.from(new TextEncoder().encode(ast.system)).join(" ");
|
|
2379
|
+
lines.push(` ;; System name data`);
|
|
2380
|
+
lines.push(` (data (i32.const 0) "${ast.system}")`);
|
|
2381
|
+
lines.push("");
|
|
2382
|
+
}
|
|
2383
|
+
if (ast.functions && ast.functions.length) {
|
|
2384
|
+
lines.push(" ;; Function stubs");
|
|
2385
|
+
for (const fn of ast.functions) {
|
|
2386
|
+
const params = (fn.args || []).map((_, i) => `(param $arg${i} i32)`).join(" ");
|
|
2387
|
+
lines.push(` (func (export "${fn.name}") ${params} (result i32)`);
|
|
2388
|
+
lines.push(` ;; Steps: ${(fn.steps || []).map((s) => s.raw).join(" -> ")}`);
|
|
2389
|
+
lines.push(` i32.const 0 ;; placeholder return`);
|
|
2390
|
+
lines.push(` )`);
|
|
2391
|
+
lines.push("");
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
if (ast.ias && ast.ias.length) {
|
|
2395
|
+
lines.push(" ;; IA stubs (table references for future indirect calls)");
|
|
2396
|
+
for (const ia of ast.ias) {
|
|
2397
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2398
|
+
lines.push(` ;; IA: ${ia.name}`);
|
|
2399
|
+
lines.push(` (func (export "ia_${name}") (result i32)`);
|
|
2400
|
+
lines.push(` ;; Capabilities: ${ia.body.join(", ")}`);
|
|
2401
|
+
lines.push(` i32.const 1 ;; stub: IA ready`);
|
|
2402
|
+
lines.push(` )`);
|
|
2403
|
+
lines.push("");
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
lines.push(" ;; Main entry point");
|
|
2407
|
+
lines.push(' (func (export "_start")');
|
|
2408
|
+
lines.push(" ;; Initialize system");
|
|
2409
|
+
lines.push(" nop");
|
|
2410
|
+
lines.push(" )");
|
|
2411
|
+
lines.push("");
|
|
2412
|
+
if (ast.build && ast.build.targets) {
|
|
2413
|
+
lines.push(` ;; Build targets: ${ast.build.targets.join(", ")}`);
|
|
2414
|
+
}
|
|
2415
|
+
lines.push(")");
|
|
2416
|
+
lines.push("");
|
|
2417
|
+
lines.push(";; To compile this WAT to WASM:");
|
|
2418
|
+
lines.push(";; wat2wasm output.wat -o output.wasm");
|
|
2419
|
+
lines.push(";; Or use wasm-pack for Rust-based compilation");
|
|
2420
|
+
return lines.join("\n");
|
|
2421
|
+
}
|
|
2422
|
+
function hasWASMTarget(ast) {
|
|
2423
|
+
if (!ast.build || !ast.build.targets) return false;
|
|
2424
|
+
return ast.build.targets.some(
|
|
2425
|
+
(t) => t.toLowerCase() === "wasm" || t.toLowerCase() === "webassembly" || t.toLowerCase() === "wat"
|
|
2426
|
+
);
|
|
2456
2427
|
}
|
|
2457
2428
|
|
|
2458
2429
|
export {
|
|
2459
2430
|
TokenType,
|
|
2460
2431
|
SYMBOL_NAMES,
|
|
2461
2432
|
tokenize,
|
|
2462
|
-
init_tokenize,
|
|
2463
2433
|
parse,
|
|
2464
|
-
parser_exports,
|
|
2465
|
-
init_parser,
|
|
2466
2434
|
validateSemantic,
|
|
2467
2435
|
validateSemanticFull,
|
|
2468
2436
|
applyEvolve,
|
|
@@ -2470,7 +2438,5 @@ export {
|
|
|
2470
2438
|
transpileToJS,
|
|
2471
2439
|
transpileToDTS,
|
|
2472
2440
|
transpileToWAT,
|
|
2473
|
-
hasWASMTarget
|
|
2474
|
-
transpile_exports,
|
|
2475
|
-
init_transpile
|
|
2441
|
+
hasWASMTarget
|
|
2476
2442
|
};
|