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.
Files changed (63) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/.npmrc.ci-backup +3 -0
  3. package/LICENSE +0 -29
  4. package/Lumos.png +0 -0
  5. package/README.md +284 -126
  6. package/STRUCTURE.md +216 -0
  7. package/examples/hello.lumos +5 -0
  8. package/index.cjs +125 -125
  9. package/index.html +120 -274
  10. package/package.json +20 -10
  11. package/src/backends/assembly/arm.js +39 -0
  12. package/src/backends/assembly/wasm.js +39 -0
  13. package/src/backends/assembly/x86.js +39 -0
  14. package/src/backends/compiled/c.js +39 -0
  15. package/src/backends/compiled/cpp.js +39 -0
  16. package/src/backends/compiled/csharp.js +39 -0
  17. package/src/backends/compiled/go.js +39 -0
  18. package/src/backends/compiled/java.js +39 -0
  19. package/src/backends/compiled/rust.js +39 -0
  20. package/src/backends/compiled/swift.js +39 -0
  21. package/src/backends/database/mongodb.js +39 -0
  22. package/src/backends/database/mysql.js +39 -0
  23. package/src/backends/database/postgresql.js +39 -0
  24. package/src/backends/database/sql.js +39 -0
  25. package/src/backends/database/sqlite.js +39 -0
  26. package/src/backends/functional/clojure.js +39 -0
  27. package/src/backends/functional/elixir.js +39 -0
  28. package/src/backends/functional/erlang.js +39 -0
  29. package/src/backends/functional/fsharp.js +39 -0
  30. package/src/backends/functional/haskell.js +39 -0
  31. package/src/backends/functional/scala.js +39 -0
  32. package/src/backends/interpreted/lua.js +39 -0
  33. package/src/backends/interpreted/perl.js +39 -0
  34. package/src/backends/interpreted/php.js +39 -0
  35. package/src/backends/interpreted/python.js +356 -0
  36. package/src/backends/interpreted/ruby.js +222 -0
  37. package/src/backends/scripting/bash.js +39 -0
  38. package/src/backends/scripting/javascript.js +39 -0
  39. package/src/backends/scripting/powershell.js +39 -0
  40. package/src/backends/scripting/typescript.js +39 -0
  41. package/src/backends/scripting/vbscript.js +39 -0
  42. package/src/backends/specialized/ada.js +39 -0
  43. package/src/backends/specialized/cobol.js +39 -0
  44. package/src/backends/specialized/fortran.js +39 -0
  45. package/src/backends/specialized/lisp.js +39 -0
  46. package/src/backends/specialized/mlang.js +39 -0
  47. package/src/backends/specialized/prolog.js +39 -0
  48. package/src/backends/web/css.js +39 -0
  49. package/src/backends/web/html.js +39 -0
  50. package/src/backends/web/jsx.js +39 -0
  51. package/src/backends/web/vue.js +39 -0
  52. package/src/cli/fileRunner.js +82 -0
  53. package/src/cli/repl.js +244 -0
  54. package/src/compiler/core/compiler.js +1350 -0
  55. package/src/compiler/framework-integrator.js +846 -0
  56. package/src/compiler/generators/dynamic-languages.js +620 -0
  57. package/src/compiler/generators/system-languages.js +1184 -0
  58. package/src/core/compiler.js +181 -0
  59. package/src/core/evaluator.js +408 -0
  60. package/src/core/lexer.js +251 -0
  61. package/src/core/parser.js +452 -0
  62. package/src/core/runtime.js +173 -0
  63. 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 vars = {};
7
- const functions = {};
8
-
9
- function evaluateExpression(expr, scope = vars) {
10
- expr = expr.trim();
11
- if (/^".*"$/.test(expr)) return expr.slice(1, -1);
12
- if (expr in scope) return scope[expr];
13
- if (!isNaN(expr)) return Number(expr);
14
-
15
- let m;
16
-
17
- if ((m = expr.match(/^(.+?)\s*(==|!=|<=|>=|<|>)\s*(.+)$/))) {
18
- const a = evaluateExpression(m[1], scope);
19
- const b = evaluateExpression(m[3], scope);
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
- if ((m = expr.match(/^(.+?)\s*([+\-*/%])\s*(.+)$/))) {
31
- const a = evaluateExpression(m[1], scope);
32
- const b = evaluateExpression(m[3], scope);
33
- switch (m[2]) {
34
- case "+": return a + b;
35
- case "-": return a - b;
36
- case "*": return a * b;
37
- case "/": return a / b;
38
- case "%": return a % b;
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
- throw new Error("Invalid expression: " + expr);
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
- function interpret(cmd) {
46
- let m;
50
+ runFile(filepath) {
51
+ const runner = new FileRunner(this);
52
+ return runner.run(filepath);
53
+ }
47
54
 
48
- if ((m = cmd.match(/^let\s+(\w+)\s*=\s*(.+)$/))) {
49
- const name = m[1], value = evaluateExpression(m[2]);
50
- vars[name] = value;
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 ((m = cmd.match(/^def\s+(\w+)\(([^)]*)\)\s*{([\s\S]+)}$/))) {
55
- const name = m[1];
56
- const params = m[2].split(",").map(s => s.trim()).filter(Boolean);
57
- const body = m[3].trim();
58
- functions[name] = { params, body };
59
- return `Function ${name} defined.`;
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
- if ((m = cmd.match(/^(\w+)\((.*)\)$/)) && functions[m[1]]) {
63
- const func = functions[m[1]];
64
- const args = m[2] ? m[2].split(",").map(s => s.trim()) : [];
65
- const localScope = { ...vars };
66
- func.params.forEach((p, i) => {
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 ((m = cmd.match(/^for\s+(\w+)\s*=\s*(\d+)\s+to\s+(\d+)\s*{([\s\S]+)}$/))) {
77
- const [_, v, s, e, body] = m;
78
- for (let i = +s; i <= +e; i++) {
79
- vars[v] = i;
80
- interpret(body.trim());
81
- }
82
- return `Looped ${v} from ${s} to ${e}`;
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 ((m = cmd.match(/^while\s*\((.+?)\)\s*{([\s\S]+)}$/))) {
86
- const cond = m[1], body = m[2].trim();
87
- let count = 0;
88
- while (evaluateExpression(cond)) {
89
- interpret(body);
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
- if ((m = cmd.match(/^if\s*\((.+?)\)\s*{([\s\S]+?)}(?:\s*elsif\s*\((.+?)\)\s*{([\s\S]+?)})?(?:\s*else\s*{([\s\S]+?)})?$/))) {
96
- if (evaluateExpression(m[1])) return interpret(m[2].trim());
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
- if ((m = cmd.match(/^(\d+)\.times\s+do\s+\|(\w+)\|\s*{([\s\S]+)}\s*end$/))) {
103
- const [_, n, v, body] = m;
104
- let out = [];
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
- if (vars.hasOwnProperty(cmd)) {
113
- return vars[cmd];
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
- throw new Error("Unrecognized command: " + cmd);
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
- function runFile(fn) {
120
- const lines = fs.readFileSync(fn, "utf8").split(/\r?\n/);
121
- lines.filter(line => line.trim()).forEach(line => {
122
- const res = interpret(line.trim());
123
- console.log("> " + res);
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
- function startREPL() {
128
- const rl = readline.createInterface({
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
- const args = process.argv.slice(2);
156
- if (args.length) runFile(args[0]);
157
- else startREPL();
157
+ module.exports = LumosEngine;