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/index.cjs
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
4
5
|
const readline = require("readline");
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
switch (m[2]) {
|
|
21
|
-
case "==": return a == b;
|
|
22
|
-
case "!=": return a != b;
|
|
23
|
-
case "<=": return a <= b;
|
|
24
|
-
case ">=": return a >= b;
|
|
25
|
-
case "<": return a < b;
|
|
26
|
-
case ">": return a > b;
|
|
27
|
-
}
|
|
7
|
+
const Lexer = require("./src/core/lexer");
|
|
8
|
+
const Parser = require("./src/core/parser");
|
|
9
|
+
const Evaluator = require("./src/core/evaluator");
|
|
10
|
+
const Compiler = require("./src/core/compiler");
|
|
11
|
+
const Runtime = require("./src/core/runtime");
|
|
12
|
+
const REPL = require("./src/cli/repl");
|
|
13
|
+
const FileRunner = require("./src/cli/fileRunner");
|
|
14
|
+
|
|
15
|
+
class LumosEngine {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.runtime = new Runtime();
|
|
18
|
+
this.compiler = new Compiler();
|
|
19
|
+
this.evaluator = new Evaluator(this.runtime);
|
|
20
|
+
this.version = "2.0.0";
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
execute(code, options = {}) {
|
|
24
|
+
try {
|
|
25
|
+
const lexer = new Lexer(code);
|
|
26
|
+
const tokens = lexer.tokenize();
|
|
27
|
+
|
|
28
|
+
const parser = new Parser(tokens);
|
|
29
|
+
const ast = parser.parse();
|
|
30
|
+
|
|
31
|
+
if (options.compile) {
|
|
32
|
+
return this.compiler.compile(ast, options.target || "javascript");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return this.evaluator.evaluate(ast);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw new Error(`Lumos Execution Error: ${error.message}`);
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
compileToTarget(code, target) {
|
|
42
|
+
const lexer = new Lexer(code);
|
|
43
|
+
const tokens = lexer.tokenize();
|
|
44
|
+
const parser = new Parser(tokens);
|
|
45
|
+
const ast = parser.parse();
|
|
46
|
+
|
|
47
|
+
return this.compiler.compile(ast, target);
|
|
48
|
+
}
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
runFile(filepath) {
|
|
51
|
+
const runner = new FileRunner(this);
|
|
52
|
+
return runner.run(filepath);
|
|
53
|
+
}
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
return `${name} = ${value}`;
|
|
55
|
+
startREPL() {
|
|
56
|
+
const repl = new REPL(this);
|
|
57
|
+
repl.start();
|
|
52
58
|
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function main() {
|
|
62
|
+
const args = process.argv.slice(2);
|
|
63
|
+
const engine = new LumosEngine();
|
|
53
64
|
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
65
|
+
if (args.length === 0) {
|
|
66
|
+
console.log(`Lumos Language v${engine.version}`);
|
|
67
|
+
console.log("Enhanced Multi-Target Compiler & Interpreter");
|
|
68
|
+
console.log("Type 'exit' to quit, 'help' for commands\n");
|
|
69
|
+
engine.startREPL();
|
|
70
|
+
return;
|
|
60
71
|
}
|
|
61
72
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
localScope[p] = evaluateExpression(args[i], vars);
|
|
68
|
-
});
|
|
69
|
-
const letm = func.body.match(/^let\s+(\w+)\s*=\s*(.+)$/);
|
|
70
|
-
if (!letm) throw new Error("Invalid function body");
|
|
71
|
-
const res = evaluateExpression(letm[2], localScope);
|
|
72
|
-
vars[letm[1]] = res;
|
|
73
|
-
return `${letm[1]} = ${res}`;
|
|
73
|
+
const command = args[0];
|
|
74
|
+
|
|
75
|
+
if (command === "--version" || command === "-v") {
|
|
76
|
+
console.log(`Lumos Language v${engine.version}`);
|
|
77
|
+
return;
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
if (command === "--help" || command === "-h") {
|
|
81
|
+
console.log(`
|
|
82
|
+
Lumos Language - Multi-Target Compiler & Interpreter
|
|
83
|
+
|
|
84
|
+
Usage:
|
|
85
|
+
lumos [file.lumos] Run a Lumos file
|
|
86
|
+
lumos compile [file.lumos] [target] Compile to target language
|
|
87
|
+
lumos --version Show version
|
|
88
|
+
lumos --help Show this help
|
|
89
|
+
|
|
90
|
+
Compilation Targets:
|
|
91
|
+
Assembly: x86, arm, wasm
|
|
92
|
+
Compiled: c, cpp, rust, go, java, csharp, swift, ada, d, fortran
|
|
93
|
+
Interpreted: python, ruby, php, perl, lua, javascript, typescript
|
|
94
|
+
Functional: haskell, scala, elixir, erlang, fsharp, clojure, lisp
|
|
95
|
+
Web: html, jsx, vue, react, nextjs
|
|
96
|
+
Database: sql, postgresql, mysql, sqlite, mongodb
|
|
97
|
+
Frameworks: laravel, django, fastapi, express, nestjs, phoenix
|
|
98
|
+
Specialized: cobol, matlab, vhdl, mql4, vba, gas
|
|
99
|
+
|
|
100
|
+
Examples:
|
|
101
|
+
lumos script.lumos
|
|
102
|
+
lumos compile script.lumos python
|
|
103
|
+
lumos compile script.lumos rust --optimize
|
|
104
|
+
`);
|
|
105
|
+
return;
|
|
83
106
|
}
|
|
84
107
|
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (++count > 10000) throw new Error("Infinite loop detected");
|
|
108
|
+
if (command === "compile") {
|
|
109
|
+
if (args.length < 3) {
|
|
110
|
+
console.error("Error: Missing file or target");
|
|
111
|
+
console.error("Usage: lumos compile [file.lumos] [target]");
|
|
112
|
+
process.exit(1);
|
|
91
113
|
}
|
|
92
|
-
return "While loop executed.";
|
|
93
|
-
}
|
|
94
114
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
else if (m[3] && evaluateExpression(m[3])) return interpret(m[4].trim());
|
|
98
|
-
else if (m[5]) return interpret(m[5].trim());
|
|
99
|
-
return "If condition was false.";
|
|
100
|
-
}
|
|
115
|
+
const filepath = args[1];
|
|
116
|
+
const target = args[2];
|
|
101
117
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
for (let i = 0; i < +n; i++) {
|
|
106
|
-
vars[v] = i;
|
|
107
|
-
out.push(interpret(body.trim()));
|
|
118
|
+
if (!fs.existsSync(filepath)) {
|
|
119
|
+
console.error(`Error: File not found: ${filepath}`);
|
|
120
|
+
process.exit(1);
|
|
108
121
|
}
|
|
109
|
-
return out.join("\n");
|
|
110
|
-
}
|
|
111
122
|
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
try {
|
|
124
|
+
const code = fs.readFileSync(filepath, "utf8");
|
|
125
|
+
const compiled = engine.compileToTarget(code, target);
|
|
126
|
+
|
|
127
|
+
const ext = engine.compiler.getExtension(target);
|
|
128
|
+
const outputPath = filepath.replace(/\.lumos$/, ext);
|
|
129
|
+
|
|
130
|
+
fs.writeFileSync(outputPath, compiled);
|
|
131
|
+
console.log(`Successfully compiled to ${target}: ${outputPath}`);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error(`Compilation Error: ${error.message}`);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
114
137
|
}
|
|
115
138
|
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
const filepath = args[0];
|
|
140
|
+
if (!fs.existsSync(filepath)) {
|
|
141
|
+
console.error(`Error: File not found: ${filepath}`);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
118
144
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
145
|
+
try {
|
|
146
|
+
engine.runFile(filepath);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.error(`Runtime Error: ${error.message}`);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
125
151
|
}
|
|
126
152
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
input: process.stdin,
|
|
130
|
-
output: process.stdout,
|
|
131
|
-
prompt: "Lumos> ",
|
|
132
|
-
});
|
|
133
|
-
console.log("Welcome to Lumos CLI (type exit)");
|
|
134
|
-
rl.prompt();
|
|
135
|
-
|
|
136
|
-
rl.on("line", line => {
|
|
137
|
-
if (line.trim() === "exit") return rl.close();
|
|
138
|
-
if (line.trim()) {
|
|
139
|
-
try {
|
|
140
|
-
const res = interpret(line.trim());
|
|
141
|
-
console.log("> " + res);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
console.error("! " + e.message);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
rl.prompt();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
rl.on("close", () => {
|
|
150
|
-
console.log("Goodbye!");
|
|
151
|
-
process.exit(0);
|
|
152
|
-
});
|
|
153
|
+
if (require.main === module) {
|
|
154
|
+
main();
|
|
153
155
|
}
|
|
154
156
|
|
|
155
|
-
|
|
156
|
-
if (args.length) runFile(args[0]);
|
|
157
|
-
else startREPL();
|
|
157
|
+
module.exports = LumosEngine;
|