lumos-language 1.1.2 → 2.0.2
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/.github/FUNDING.yml +1 -0
- package/.npmrc.ci-backup +3 -0
- package/LICENSE +0 -29
- package/Lumos.png +0 -0
- package/README.md +284 -126
- package/STRUCTURE.md +216 -0
- package/examples/hello.lumos +5 -0
- package/index.cjs +125 -125
- package/index.html +120 -274
- package/package.json +20 -10
- package/src/backends/assembly/arm.js +39 -0
- package/src/backends/assembly/wasm.js +39 -0
- package/src/backends/assembly/x86.js +39 -0
- package/src/backends/compiled/c.js +39 -0
- package/src/backends/compiled/cpp.js +39 -0
- package/src/backends/compiled/csharp.js +39 -0
- package/src/backends/compiled/go.js +39 -0
- package/src/backends/compiled/java.js +39 -0
- package/src/backends/compiled/rust.js +39 -0
- package/src/backends/compiled/swift.js +39 -0
- package/src/backends/database/mongodb.js +39 -0
- package/src/backends/database/mysql.js +39 -0
- package/src/backends/database/postgresql.js +39 -0
- package/src/backends/database/sql.js +39 -0
- package/src/backends/database/sqlite.js +39 -0
- package/src/backends/functional/clojure.js +39 -0
- package/src/backends/functional/elixir.js +39 -0
- package/src/backends/functional/erlang.js +39 -0
- package/src/backends/functional/fsharp.js +39 -0
- package/src/backends/functional/haskell.js +39 -0
- package/src/backends/functional/scala.js +39 -0
- package/src/backends/interpreted/lua.js +39 -0
- package/src/backends/interpreted/perl.js +39 -0
- package/src/backends/interpreted/php.js +39 -0
- package/src/backends/interpreted/python.js +356 -0
- package/src/backends/interpreted/ruby.js +222 -0
- package/src/backends/scripting/bash.js +39 -0
- package/src/backends/scripting/javascript.js +39 -0
- package/src/backends/scripting/powershell.js +39 -0
- package/src/backends/scripting/typescript.js +39 -0
- package/src/backends/scripting/vbscript.js +39 -0
- package/src/backends/specialized/ada.js +39 -0
- package/src/backends/specialized/cobol.js +39 -0
- package/src/backends/specialized/fortran.js +39 -0
- package/src/backends/specialized/lisp.js +39 -0
- package/src/backends/specialized/mlang.js +39 -0
- package/src/backends/specialized/prolog.js +39 -0
- package/src/backends/web/css.js +39 -0
- package/src/backends/web/html.js +39 -0
- package/src/backends/web/jsx.js +39 -0
- package/src/backends/web/vue.js +39 -0
- package/src/cli/fileRunner.js +82 -0
- package/src/cli/repl.js +244 -0
- package/src/compiler/core/compiler.js +1350 -0
- package/src/compiler/framework-integrator.js +846 -0
- package/src/compiler/generators/dynamic-languages.js +620 -0
- package/src/compiler/generators/system-languages.js +1184 -0
- package/src/core/compiler.js +181 -0
- package/src/core/evaluator.js +408 -0
- package/src/core/lexer.js +251 -0
- package/src/core/parser.js +452 -0
- package/src/core/runtime.js +173 -0
- package/tests/run-tests.js +243 -0
package/src/cli/repl.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
const readline = require("readline");
|
|
2
|
+
|
|
3
|
+
class REPL {
|
|
4
|
+
constructor(engine) {
|
|
5
|
+
this.engine = engine;
|
|
6
|
+
this.history = [];
|
|
7
|
+
this.multilineBuffer = '';
|
|
8
|
+
this.inMultilineMode = false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
start() {
|
|
12
|
+
this.rl = readline.createInterface({
|
|
13
|
+
input: process.stdin,
|
|
14
|
+
output: process.stdout,
|
|
15
|
+
prompt: "lumos> ",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
console.log("Lumos Language Enhanced REPL");
|
|
19
|
+
console.log("Multi-target compiler supporting 100+ languages");
|
|
20
|
+
console.log("Type '.help' for commands, '.exit' to quit\n");
|
|
21
|
+
|
|
22
|
+
this.rl.prompt();
|
|
23
|
+
|
|
24
|
+
this.rl.on("line", (line) => {
|
|
25
|
+
this.handleLine(line.trim());
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
this.rl.on("close", () => {
|
|
29
|
+
console.log("\nGoodbye!");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
handleLine(line) {
|
|
35
|
+
if (line === "") {
|
|
36
|
+
this.rl.prompt();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (line.startsWith(".")) {
|
|
41
|
+
this.handleCommand(line);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.inMultilineMode) {
|
|
46
|
+
if (line === "end" || line === "}") {
|
|
47
|
+
this.multilineBuffer += "\n" + line;
|
|
48
|
+
this.executeCode(this.multilineBuffer);
|
|
49
|
+
this.multilineBuffer = '';
|
|
50
|
+
this.inMultilineMode = false;
|
|
51
|
+
} else {
|
|
52
|
+
this.multilineBuffer += "\n" + line;
|
|
53
|
+
this.rl.setPrompt("... ");
|
|
54
|
+
this.rl.prompt();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
if (line.endsWith("{") || line.startsWith("def ") || line.startsWith("class ")) {
|
|
59
|
+
this.multilineBuffer = line;
|
|
60
|
+
this.inMultilineMode = true;
|
|
61
|
+
this.rl.setPrompt("... ");
|
|
62
|
+
this.rl.prompt();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.executeCode(line);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.rl.setPrompt("lumos> ");
|
|
70
|
+
this.rl.prompt();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
executeCode(code) {
|
|
74
|
+
try {
|
|
75
|
+
this.history.push(code);
|
|
76
|
+
const result = this.engine.execute(code);
|
|
77
|
+
if (result !== null && result !== undefined) {
|
|
78
|
+
console.log("=> " + this.formatOutput(result));
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("Error: " + error.message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
handleCommand(cmd) {
|
|
86
|
+
const parts = cmd.split(" ");
|
|
87
|
+
const command = parts[0];
|
|
88
|
+
const args = parts.slice(1);
|
|
89
|
+
|
|
90
|
+
switch (command) {
|
|
91
|
+
case ".exit":
|
|
92
|
+
case ".quit":
|
|
93
|
+
this.rl.close();
|
|
94
|
+
break;
|
|
95
|
+
|
|
96
|
+
case ".help":
|
|
97
|
+
this.showHelp();
|
|
98
|
+
break;
|
|
99
|
+
|
|
100
|
+
case ".history":
|
|
101
|
+
this.showHistory();
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case ".clear":
|
|
105
|
+
console.clear();
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case ".compile":
|
|
109
|
+
this.handleCompile(args);
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
case ".targets":
|
|
113
|
+
this.showTargets();
|
|
114
|
+
break;
|
|
115
|
+
|
|
116
|
+
case ".vars":
|
|
117
|
+
this.showVariables();
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case ".reset":
|
|
121
|
+
this.engine.runtime = new (require("./runtime"))();
|
|
122
|
+
console.log("Runtime reset");
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
default:
|
|
126
|
+
console.log(`Unknown command: ${command}`);
|
|
127
|
+
console.log("Type '.help' for available commands");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.rl.prompt();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
showHelp() {
|
|
134
|
+
console.log(`
|
|
135
|
+
Available Commands:
|
|
136
|
+
.help Show this help message
|
|
137
|
+
.exit, .quit Exit the REPL
|
|
138
|
+
.clear Clear the console
|
|
139
|
+
.history Show command history
|
|
140
|
+
.compile [target] Compile last expression to target language
|
|
141
|
+
.targets Show available compilation targets
|
|
142
|
+
.vars Show current variables
|
|
143
|
+
.reset Reset the runtime environment
|
|
144
|
+
|
|
145
|
+
Examples:
|
|
146
|
+
let x = 42
|
|
147
|
+
def greet(name) { print("Hello, " + name) }
|
|
148
|
+
.compile python
|
|
149
|
+
.compile rust
|
|
150
|
+
`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
showHistory() {
|
|
154
|
+
console.log("\nCommand History:");
|
|
155
|
+
this.history.forEach((cmd, index) => {
|
|
156
|
+
console.log(`${index + 1}: ${cmd}`);
|
|
157
|
+
});
|
|
158
|
+
console.log();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
handleCompile(args) {
|
|
162
|
+
if (args.length === 0) {
|
|
163
|
+
console.log("Usage: .compile [target]");
|
|
164
|
+
console.log("Example: .compile python");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const target = args[0];
|
|
169
|
+
const lastCode = this.history[this.history.length - 1];
|
|
170
|
+
|
|
171
|
+
if (!lastCode) {
|
|
172
|
+
console.log("No code to compile. Execute some code first.");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
const compiled = this.engine.compileToTarget(lastCode, target);
|
|
178
|
+
console.log(`\nCompiled to ${target}:`);
|
|
179
|
+
console.log("---");
|
|
180
|
+
console.log(compiled);
|
|
181
|
+
console.log("---\n");
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(`Compilation error: ${error.message}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
showTargets() {
|
|
188
|
+
const targets = this.engine.compiler.getSupportedTargets();
|
|
189
|
+
console.log("\nAvailable Compilation Targets:");
|
|
190
|
+
|
|
191
|
+
const categories = {
|
|
192
|
+
assembly: [],
|
|
193
|
+
compiled: [],
|
|
194
|
+
interpreted: [],
|
|
195
|
+
scripting: [],
|
|
196
|
+
functional: [],
|
|
197
|
+
web: [],
|
|
198
|
+
database: [],
|
|
199
|
+
specialized: []
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
targets.forEach(target => {
|
|
203
|
+
const type = this.engine.compiler.getTargetType(target);
|
|
204
|
+
if (categories[type]) {
|
|
205
|
+
categories[type].push(target);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
Object.entries(categories).forEach(([category, langs]) => {
|
|
210
|
+
if (langs.length > 0) {
|
|
211
|
+
console.log(`\n${category.charAt(0).toUpperCase() + category.slice(1)}:`);
|
|
212
|
+
console.log(` ${langs.join(', ')}`);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
console.log();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
showVariables() {
|
|
220
|
+
const vars = this.engine.evaluator.currentScope;
|
|
221
|
+
console.log("\nCurrent Variables:");
|
|
222
|
+
Object.entries(vars).forEach(([name, value]) => {
|
|
223
|
+
console.log(` ${name} = ${this.formatOutput(value)}`);
|
|
224
|
+
});
|
|
225
|
+
console.log();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
formatOutput(value) {
|
|
229
|
+
if (value === null) return 'null';
|
|
230
|
+
if (value === undefined) return 'undefined';
|
|
231
|
+
if (typeof value === 'string') return `"${value}"`;
|
|
232
|
+
if (typeof value === 'function') return '[Function]';
|
|
233
|
+
if (typeof value === 'object') {
|
|
234
|
+
try {
|
|
235
|
+
return JSON.stringify(value, null, 2);
|
|
236
|
+
} catch {
|
|
237
|
+
return '[Object]';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return String(value);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
module.exports = REPL;
|