cobolx-2 1.2.3

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 (284) hide show
  1. package/.github/pull_request_template.md +9 -0
  2. package/.github/workflows/ci.yml +18 -0
  3. package/.vscode/launch.json +19 -0
  4. package/.vscode/tasks.json +14 -0
  5. package/CHANGELOG.md +16 -0
  6. package/CONTRIBUTING.md +23 -0
  7. package/CargoX.lock +2 -0
  8. package/LICENSE +21 -0
  9. package/README.md +164 -0
  10. package/api-demo/CargoX.lock +1 -0
  11. package/api-demo/README.md +3 -0
  12. package/api-demo/benchmarks/arith.cbx +6 -0
  13. package/api-demo/cobolx.toml +6 -0
  14. package/api-demo/docs-output/index.html +1 -0
  15. package/api-demo/generated/LEGACYDEMO.cbx +5 -0
  16. package/api-demo/generated/client-types.ts +2 -0
  17. package/api-demo/generated/deploy.json +12 -0
  18. package/api-demo/generated/flowchart.mmd +4 -0
  19. package/api-demo/migrations/20260411215238_init.sql +1 -0
  20. package/api-demo/src/main.cbx +5 -0
  21. package/api-demo/tests/smoke.cbx +6 -0
  22. package/benchmarks/arithmetic.cbx +6 -0
  23. package/cargox/package.json +11 -0
  24. package/cargox/src/index.d.ts +4 -0
  25. package/cargox/src/index.js +5 -0
  26. package/cargox/src/index.js.map +1 -0
  27. package/cargox/src/index.ts +4 -0
  28. package/cargox/src/lockfile/index.d.ts +1 -0
  29. package/cargox/src/lockfile/index.js +9 -0
  30. package/cargox/src/lockfile/index.js.map +1 -0
  31. package/cargox/src/lockfile/index.ts +9 -0
  32. package/cargox/src/manifest.d.ts +10 -0
  33. package/cargox/src/manifest.js +49 -0
  34. package/cargox/src/manifest.js.map +1 -0
  35. package/cargox/src/manifest.ts +58 -0
  36. package/cargox/src/registry/index.d.ts +4 -0
  37. package/cargox/src/registry/index.js +13 -0
  38. package/cargox/src/registry/index.js.map +1 -0
  39. package/cargox/src/registry/index.ts +13 -0
  40. package/cargox/src/resolver/index.d.ts +5 -0
  41. package/cargox/src/resolver/index.js +4 -0
  42. package/cargox/src/resolver/index.js.map +1 -0
  43. package/cargox/src/resolver/index.ts +8 -0
  44. package/cargox/tsconfig.json +7 -0
  45. package/cli/cobolx-cli/package.json +23 -0
  46. package/cli/cobolx-cli/src/commands/add.ts +18 -0
  47. package/cli/cobolx-cli/src/commands/bench.ts +47 -0
  48. package/cli/cobolx-cli/src/commands/build.ts +74 -0
  49. package/cli/cobolx-cli/src/commands/check.ts +24 -0
  50. package/cli/cobolx-cli/src/commands/debug.ts +15 -0
  51. package/cli/cobolx-cli/src/commands/debug_rewind.ts +16 -0
  52. package/cli/cobolx-cli/src/commands/deploy.ts +18 -0
  53. package/cli/cobolx-cli/src/commands/dev.ts +24 -0
  54. package/cli/cobolx-cli/src/commands/doc.ts +19 -0
  55. package/cli/cobolx-cli/src/commands/fmt.ts +14 -0
  56. package/cli/cobolx-cli/src/commands/fuzz.ts +24 -0
  57. package/cli/cobolx-cli/src/commands/generate.ts +38 -0
  58. package/cli/cobolx-cli/src/commands/install.ts +25 -0
  59. package/cli/cobolx-cli/src/commands/legacy.ts +17 -0
  60. package/cli/cobolx-cli/src/commands/lint.ts +17 -0
  61. package/cli/cobolx-cli/src/commands/migrate.ts +27 -0
  62. package/cli/cobolx-cli/src/commands/new.ts +20 -0
  63. package/cli/cobolx-cli/src/commands/profile.ts +8 -0
  64. package/cli/cobolx-cli/src/commands/publish.ts +16 -0
  65. package/cli/cobolx-cli/src/commands/repl.ts +30 -0
  66. package/cli/cobolx-cli/src/commands/run.ts +22 -0
  67. package/cli/cobolx-cli/src/commands/task.ts +27 -0
  68. package/cli/cobolx-cli/src/commands/test.ts +44 -0
  69. package/cli/cobolx-cli/src/commands/update.ts +30 -0
  70. package/cli/cobolx-cli/src/commands/visualize.ts +25 -0
  71. package/cli/cobolx-cli/src/index.ts +101 -0
  72. package/cli/cobolx-cli/src/project.ts +74 -0
  73. package/cli/cobolx-cli/tsconfig.json +7 -0
  74. package/cobolx.toml +7 -0
  75. package/compiler/package.json +14 -0
  76. package/compiler/src/ast/types.d.ts +87 -0
  77. package/compiler/src/ast/types.js +2 -0
  78. package/compiler/src/ast/types.js.map +1 -0
  79. package/compiler/src/ast/types.ts +329 -0
  80. package/compiler/src/backend/custom.d.ts +8 -0
  81. package/compiler/src/backend/custom.js +12 -0
  82. package/compiler/src/backend/custom.js.map +1 -0
  83. package/compiler/src/backend/custom.ts +21 -0
  84. package/compiler/src/borrow_checker/checker.d.ts +3 -0
  85. package/compiler/src/borrow_checker/checker.js +82 -0
  86. package/compiler/src/borrow_checker/checker.js.map +1 -0
  87. package/compiler/src/borrow_checker/checker.ts +100 -0
  88. package/compiler/src/codegen/javascript.d.ts +2 -0
  89. package/compiler/src/codegen/javascript.js +89 -0
  90. package/compiler/src/codegen/javascript.js.map +1 -0
  91. package/compiler/src/codegen/javascript.ts +175 -0
  92. package/compiler/src/const_eval/evaluator.ts +58 -0
  93. package/compiler/src/diagnostics.d.ts +11 -0
  94. package/compiler/src/diagnostics.js +14 -0
  95. package/compiler/src/diagnostics.js.map +1 -0
  96. package/compiler/src/diagnostics.ts +20 -0
  97. package/compiler/src/hir/lower.d.ts +7 -0
  98. package/compiler/src/hir/lower.js +44 -0
  99. package/compiler/src/hir/lower.js.map +1 -0
  100. package/compiler/src/hir/lower.ts +60 -0
  101. package/compiler/src/hir/types.d.ts +21 -0
  102. package/compiler/src/hir/types.js +2 -0
  103. package/compiler/src/hir/types.js.map +1 -0
  104. package/compiler/src/hir/types.ts +26 -0
  105. package/compiler/src/index.d.ts +22 -0
  106. package/compiler/src/index.js +84 -0
  107. package/compiler/src/index.js.map +1 -0
  108. package/compiler/src/index.ts +122 -0
  109. package/compiler/src/lexer/lexer.d.ts +21 -0
  110. package/compiler/src/lexer/lexer.js +207 -0
  111. package/compiler/src/lexer/lexer.js.map +1 -0
  112. package/compiler/src/lexer/lexer.ts +274 -0
  113. package/compiler/src/lexer/tokens.d.ts +8 -0
  114. package/compiler/src/lexer/tokens.js +18 -0
  115. package/compiler/src/lexer/tokens.js.map +1 -0
  116. package/compiler/src/lexer/tokens.ts +126 -0
  117. package/compiler/src/macros/expand.ts +75 -0
  118. package/compiler/src/main.ts +4 -0
  119. package/compiler/src/mir/lower.d.ts +3 -0
  120. package/compiler/src/mir/lower.js +10 -0
  121. package/compiler/src/mir/lower.js.map +1 -0
  122. package/compiler/src/mir/lower.ts +12 -0
  123. package/compiler/src/mir/types.d.ts +13 -0
  124. package/compiler/src/mir/types.js +2 -0
  125. package/compiler/src/mir/types.js.map +1 -0
  126. package/compiler/src/mir/types.ts +16 -0
  127. package/compiler/src/optimizer/constantFold.d.ts +2 -0
  128. package/compiler/src/optimizer/constantFold.js +61 -0
  129. package/compiler/src/optimizer/constantFold.js.map +1 -0
  130. package/compiler/src/optimizer/constantFold.ts +109 -0
  131. package/compiler/src/parser/parser.d.ts +33 -0
  132. package/compiler/src/parser/parser.js +323 -0
  133. package/compiler/src/parser/parser.js.map +1 -0
  134. package/compiler/src/parser/parser.ts +710 -0
  135. package/compiler/src/plugins/api.ts +8 -0
  136. package/compiler/src/plugins/loader.ts +21 -0
  137. package/compiler/src/semantic/analyzer.d.ts +12 -0
  138. package/compiler/src/semantic/analyzer.js +144 -0
  139. package/compiler/src/semantic/analyzer.js.map +1 -0
  140. package/compiler/src/semantic/analyzer.ts +277 -0
  141. package/compiler/src/type_system/checker.d.ts +7 -0
  142. package/compiler/src/type_system/checker.js +84 -0
  143. package/compiler/src/type_system/checker.js.map +1 -0
  144. package/compiler/src/type_system/checker.ts +108 -0
  145. package/compiler/tsconfig.json +7 -0
  146. package/debugger/package.json +11 -0
  147. package/debugger/src/index.d.ts +1 -0
  148. package/debugger/src/index.js +9 -0
  149. package/debugger/src/index.js.map +1 -0
  150. package/debugger/src/index.ts +9 -0
  151. package/debugger/tsconfig.json +7 -0
  152. package/docs/CHANGELOG.md +11 -0
  153. package/docs/CONTRIBUTING.md +15 -0
  154. package/docs/LICENSE +21 -0
  155. package/docs/architecture.md +29 -0
  156. package/docs/cli.md +58 -0
  157. package/docs/language-spec.md +49 -0
  158. package/docs/packages.md +19 -0
  159. package/docs/platform-systems.md +31 -0
  160. package/docs/release-validation.md +22 -0
  161. package/docs/runtime.md +10 -0
  162. package/docs/tooling.md +17 -0
  163. package/docs/vscode-extension.md +40 -0
  164. package/enterprise-demo/CargoX.lock +2 -0
  165. package/enterprise-demo/README.md +3 -0
  166. package/enterprise-demo/benchmarks/arith.cbx +6 -0
  167. package/enterprise-demo/cobolx.toml +7 -0
  168. package/enterprise-demo/src/main.cbx +5 -0
  169. package/enterprise-demo/tests/smoke.cbx +6 -0
  170. package/examples/README.md +20 -0
  171. package/examples/actors-and-flags.md +8 -0
  172. package/examples/api-server/README.md +9 -0
  173. package/examples/api-server/cobolx.toml +6 -0
  174. package/examples/api-server/src/main.cbx +8 -0
  175. package/examples/debug-replay.md +7 -0
  176. package/examples/debugging-demo/README.md +3 -0
  177. package/examples/debugging-demo/cobolx.toml +6 -0
  178. package/examples/debugging-demo/src/main.cbx +7 -0
  179. package/examples/distributed-service.md +12 -0
  180. package/examples/distributed-system/README.md +3 -0
  181. package/examples/distributed-system/cobolx.toml +6 -0
  182. package/examples/distributed-system/generated/deploy.json +12 -0
  183. package/examples/distributed-system/src/main.cbx +6 -0
  184. package/examples/event-driven.md +5 -0
  185. package/examples/event-system/README.md +3 -0
  186. package/examples/event-system/cobolx.toml +6 -0
  187. package/examples/event-system/src/main.cbx +11 -0
  188. package/examples/functions.cbx +10 -0
  189. package/examples/functions.mjs +12 -0
  190. package/examples/hello.cbx +5 -0
  191. package/examples/hello.mjs +7 -0
  192. package/examples/legacy-sample.cob +5 -0
  193. package/examples/parallel-processing/README.md +3 -0
  194. package/examples/parallel-processing/cobolx.toml +6 -0
  195. package/examples/parallel-processing/src/main.cbx +6 -0
  196. package/examples/parallel-processing.md +8 -0
  197. package/examples/platform-features.cbx +32 -0
  198. package/examples/platform-features.mjs +35 -0
  199. package/examples/service.cbx +10 -0
  200. package/examples/workflow-engine/README.md +3 -0
  201. package/examples/workflow-engine/cobolx.toml +6 -0
  202. package/examples/workflow-engine/generated/flowchart.mmd +8 -0
  203. package/examples/workflow-engine/src/main.cbx +13 -0
  204. package/examples/workflow-engine.md +5 -0
  205. package/formatter/package.json +14 -0
  206. package/formatter/src/index.d.ts +1 -0
  207. package/formatter/src/index.js +59 -0
  208. package/formatter/src/index.js.map +1 -0
  209. package/formatter/src/index.ts +103 -0
  210. package/formatter/tsconfig.json +7 -0
  211. package/generated/LEGACYDEMO.cbx +5 -0
  212. package/install.ps1 +4 -0
  213. package/install.sh +5 -0
  214. package/linter/package.json +14 -0
  215. package/linter/src/index.d.ts +2 -0
  216. package/linter/src/index.js +18 -0
  217. package/linter/src/index.js.map +1 -0
  218. package/linter/src/index.ts +19 -0
  219. package/linter/tsconfig.json +7 -0
  220. package/lsp/server/package.json +16 -0
  221. package/lsp/server/src/index.ts +168 -0
  222. package/lsp/server/tsconfig.json +7 -0
  223. package/package.json +30 -0
  224. package/profiler/package.json +11 -0
  225. package/profiler/src/index.d.ts +5 -0
  226. package/profiler/src/index.js +11 -0
  227. package/profiler/src/index.js.map +1 -0
  228. package/profiler/src/index.ts +11 -0
  229. package/profiler/tsconfig.json +7 -0
  230. package/release.json +10 -0
  231. package/runtime/package.json +14 -0
  232. package/runtime/src/actors/index.ts +27 -0
  233. package/runtime/src/async/futures.ts +11 -0
  234. package/runtime/src/code_as_data/index.ts +5 -0
  235. package/runtime/src/config/index.ts +17 -0
  236. package/runtime/src/distributed/index.ts +13 -0
  237. package/runtime/src/events/index.ts +21 -0
  238. package/runtime/src/feature_flags/index.ts +9 -0
  239. package/runtime/src/gc_or_arc/index.ts +1 -0
  240. package/runtime/src/healing/index.ts +26 -0
  241. package/runtime/src/index.ts +20 -0
  242. package/runtime/src/intents/index.ts +9 -0
  243. package/runtime/src/iterators/index.ts +23 -0
  244. package/runtime/src/memory/arc.ts +22 -0
  245. package/runtime/src/observability/index.ts +23 -0
  246. package/runtime/src/repl/context.ts +7 -0
  247. package/runtime/src/scheduler/taskScheduler.ts +11 -0
  248. package/runtime/src/security/capabilities.ts +15 -0
  249. package/runtime/src/security/secrets.ts +13 -0
  250. package/runtime/src/state/versioned.ts +31 -0
  251. package/runtime/src/std_hooks/audit.ts +23 -0
  252. package/runtime/src/time_travel/index.ts +54 -0
  253. package/runtime/src/workflows/index.ts +35 -0
  254. package/runtime/tsconfig.json +7 -0
  255. package/sample-payroll/README.md +3 -0
  256. package/sample-payroll/cobolx.toml +3 -0
  257. package/sample-payroll/src/main.cbx +5 -0
  258. package/stdlib/business/index.js +15 -0
  259. package/stdlib/core/README.md +8 -0
  260. package/stdlib/core/runtime.js +191 -0
  261. package/stdlib/crypto/index.js +5 -0
  262. package/stdlib/datetime/index.js +3 -0
  263. package/stdlib/fs/index.js +9 -0
  264. package/stdlib/http/index.js +7 -0
  265. package/stdlib/io/index.js +1 -0
  266. package/stdlib/json/index.js +7 -0
  267. package/stdlib/net/index.js +4 -0
  268. package/tests/macros.cbx +10 -0
  269. package/tests/pattern_match.cbx +16 -0
  270. package/tests/smoke.cbx +7 -0
  271. package/tests/validate-release.mjs +54 -0
  272. package/tsconfig.base.json +24 -0
  273. package/vscode-extension/LICENSE +21 -0
  274. package/vscode-extension/README.md +47 -0
  275. package/vscode-extension/cobolx-1.2.0.vsix +0 -0
  276. package/vscode-extension/icon.png +0 -0
  277. package/vscode-extension/icon.svg +15 -0
  278. package/vscode-extension/language-configuration.json +17 -0
  279. package/vscode-extension/package.json +148 -0
  280. package/vscode-extension/snippets/cobolx.code-snippets +49 -0
  281. package/vscode-extension/src/extension.ts +283 -0
  282. package/vscode-extension/syntaxes/cobolx.tmLanguage.json +75 -0
  283. package/vscode-extension/tests/test.cbl +3 -0
  284. package/vscode-extension/tsconfig.json +7 -0
@@ -0,0 +1,30 @@
1
+ import { readManifest, writeManifest } from "@cobolx/cargox";
2
+ import { manifestPath } from "../project.js";
3
+ import { runInstallCommand } from "./install.js";
4
+
5
+ function bumpPatch(version: string): string {
6
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version.trim());
7
+ if (!match) return version;
8
+ const [, major, minor, patch] = match;
9
+ return `${major}.${minor}.${Number(patch) + 1}`;
10
+ }
11
+
12
+ export function runUpdateCommand(projectDir: string): number {
13
+ const manifestFile = manifestPath(projectDir);
14
+ const manifest = readManifest(manifestFile);
15
+ const updated: string[] = [];
16
+
17
+ for (const [name, version] of Object.entries(manifest.dependencies)) {
18
+ const nextVersion = bumpPatch(version);
19
+ manifest.dependencies[name] = nextVersion;
20
+ if (nextVersion !== version) {
21
+ updated.push(`${name}: ${version} -> ${nextVersion}`);
22
+ }
23
+ }
24
+
25
+ writeManifest(manifestFile, manifest);
26
+ const installExitCode = runInstallCommand(projectDir);
27
+ if (installExitCode !== 0) return installExitCode;
28
+ console.log(updated.length > 0 ? `Updated dependencies:\n${updated.join("\n")}` : "Dependencies already up to date");
29
+ return 0;
30
+ }
@@ -0,0 +1,25 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { parseSource } from "@cobolx/compiler";
4
+ import { readManifest, manifestPath } from "../project.js";
5
+
6
+ export function runVisualizeCommand(projectDir: string): number {
7
+ const manifest = readManifest(manifestPath(projectDir));
8
+ const sourcePath = path.join(projectDir, manifest.package.entry);
9
+ const program = parseSource(fs.readFileSync(sourcePath, "utf8"));
10
+ const output = path.join(projectDir, "generated", "flowchart.mmd");
11
+ fs.mkdirSync(path.dirname(output), { recursive: true });
12
+
13
+ const lines = ["flowchart TD", ` A[Program ${program.name}]`];
14
+ let previous = "A";
15
+ program.body.forEach((statement, index) => {
16
+ const node = `N${index}`;
17
+ lines.push(` ${node}[${statement.kind}]`);
18
+ lines.push(` ${previous} --> ${node}`);
19
+ previous = node;
20
+ });
21
+
22
+ fs.writeFileSync(output, `${lines.join("\n")}\n`, "utf8");
23
+ console.log(`Generated visualization ${output}`);
24
+ return 0;
25
+ }
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ import { runAddCommand } from "./commands/add.js";
3
+ import { runBenchCommand } from "./commands/bench.js";
4
+ import { runBuildCommand } from "./commands/build.js";
5
+ import { runCheckCommand } from "./commands/check.js";
6
+ import { runDevCommand } from "./commands/dev.js";
7
+ import { runDebugCommand } from "./commands/debug.js";
8
+ import { runDocCommand } from "./commands/doc.js";
9
+ import { runDeployCommand } from "./commands/deploy.js";
10
+ import { runFmtCommand } from "./commands/fmt.js";
11
+ import { runFuzzCommand } from "./commands/fuzz.js";
12
+ import { runGenerateCommand } from "./commands/generate.js";
13
+ import { runInstallCommand } from "./commands/install.js";
14
+ import { runLegacyConvertCommand } from "./commands/legacy.js";
15
+ import { runLintCommand } from "./commands/lint.js";
16
+ import { runMigrateCreateCommand, runMigrateRunCommand } from "./commands/migrate.js";
17
+ import { runNewCommand } from "./commands/new.js";
18
+ import { runProfileCommand } from "./commands/profile.js";
19
+ import { runPublishCommand } from "./commands/publish.js";
20
+ import { runReplCommand } from "./commands/repl.js";
21
+ import { runRunCommand } from "./commands/run.js";
22
+ import { runTaskCommand } from "./commands/task.js";
23
+ import { runTestCommand } from "./commands/test.js";
24
+ import { runUpdateCommand } from "./commands/update.js";
25
+ import { runVisualizeCommand } from "./commands/visualize.js";
26
+
27
+ function usage(): void {
28
+ console.log("COBOL-X CLI");
29
+ console.log("Usage: cobolx <new|build|run|check|test|bench|add|install|update|publish|fmt|lint|debug|profile|dev|migrate|generate|fuzz|repl|doc|task|legacy|visualize|deploy> [args]");
30
+ }
31
+
32
+ async function main(argv: string[]): Promise<number> {
33
+ const [command, ...rest] = argv;
34
+ const projectDir = process.cwd();
35
+ const release = rest.includes("--release");
36
+ const targetIndex = rest.indexOf("--target");
37
+ const target = targetIndex >= 0 ? rest[targetIndex + 1] : undefined;
38
+
39
+ switch (command) {
40
+ case "new":
41
+ return runNewCommand(rest[0], rest[1]);
42
+ case "build":
43
+ return runBuildCommand(projectDir, { release, target });
44
+ case "run":
45
+ return runRunCommand(projectDir, { release, target });
46
+ case "check":
47
+ return runCheckCommand(projectDir);
48
+ case "test":
49
+ return runTestCommand(projectDir);
50
+ case "bench":
51
+ return await runBenchCommand(projectDir);
52
+ case "add":
53
+ return runAddCommand(projectDir, rest[0], rest[1]);
54
+ case "install":
55
+ return runInstallCommand(projectDir);
56
+ case "update":
57
+ return runUpdateCommand(projectDir);
58
+ case "publish":
59
+ return runPublishCommand(projectDir);
60
+ case "fmt":
61
+ return runFmtCommand(projectDir);
62
+ case "lint":
63
+ return runLintCommand(projectDir);
64
+ case "debug":
65
+ return runDebugCommand(projectDir, rest.includes("--rewind"));
66
+ case "profile":
67
+ return await runProfileCommand(projectDir);
68
+ case "dev":
69
+ return runDevCommand(projectDir);
70
+ case "migrate":
71
+ if (rest[0] === "create") return runMigrateCreateCommand(projectDir, rest[1]);
72
+ if (rest[0] === "run") return runMigrateRunCommand(projectDir);
73
+ usage();
74
+ return 1;
75
+ case "generate":
76
+ return runGenerateCommand(projectDir, rest[0], rest[1]);
77
+ case "fuzz":
78
+ return runFuzzCommand(projectDir, rest[0]);
79
+ case "repl":
80
+ return await runReplCommand();
81
+ case "doc":
82
+ return runDocCommand(projectDir);
83
+ case "task":
84
+ return runTaskCommand(projectDir, rest[0]);
85
+ case "legacy":
86
+ return runLegacyConvertCommand(projectDir, rest[0]);
87
+ case "visualize":
88
+ return runVisualizeCommand(projectDir);
89
+ case "deploy":
90
+ return runDeployCommand(projectDir);
91
+ case undefined:
92
+ usage();
93
+ return 0;
94
+ default:
95
+ console.error(`Unknown command: ${command}`);
96
+ usage();
97
+ return 1;
98
+ }
99
+ }
100
+
101
+ process.exit(await main(process.argv.slice(2)));
@@ -0,0 +1,74 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { readManifest, writeManifest, writeLockfile } from "@cobolx/cargox";
4
+
5
+ export { readManifest };
6
+
7
+ export function manifestPath(projectDir: string): string {
8
+ return path.join(projectDir, "cobolx.toml");
9
+ }
10
+
11
+ export function lockfilePath(projectDir: string): string {
12
+ return path.join(projectDir, "CargoX.lock");
13
+ }
14
+
15
+ export function scaffoldProject(targetDir: string, projectName: string, template = "default"): void {
16
+ const srcDir = path.join(targetDir, "src");
17
+ const testsDir = path.join(targetDir, "tests");
18
+ const benchmarksDir = path.join(targetDir, "benchmarks");
19
+ const migrationsDir = path.join(targetDir, "migrations");
20
+ const generatedDir = path.join(targetDir, "generated");
21
+ fs.mkdirSync(srcDir, { recursive: true });
22
+ fs.mkdirSync(testsDir, { recursive: true });
23
+ fs.mkdirSync(benchmarksDir, { recursive: true });
24
+ fs.mkdirSync(migrationsDir, { recursive: true });
25
+ fs.mkdirSync(generatedDir, { recursive: true });
26
+
27
+ writeManifest(manifestPath(targetDir), {
28
+ package: {
29
+ name: projectName,
30
+ version: "0.1.0",
31
+ entry: "src/main.cbx"
32
+ },
33
+ dependencies: {}
34
+ });
35
+ writeLockfile(lockfilePath(targetDir), projectName, {});
36
+
37
+ fs.writeFileSync(path.join(targetDir, "README.md"), `# ${projectName}\n\nGenerated with COBOL-X template \`${template}\`.\n`, "utf8");
38
+ fs.writeFileSync(path.join(targetDir, ".env.example"), "DATABASE_URL=\nCOBOLX_SECRET_TOKEN=\n", "utf8");
39
+ fs.writeFileSync(path.join(targetDir, "cobolx.tasks.json"), JSON.stringify({
40
+ build: ["check", "test"],
41
+ release: ["build --release", "doc"]
42
+ }, null, 2), "utf8");
43
+
44
+ const mainSource = templateSource(projectName, template);
45
+ fs.writeFileSync(
46
+ path.join(srcDir, "main.cbx"),
47
+ mainSource,
48
+ "utf8"
49
+ );
50
+ fs.writeFileSync(
51
+ path.join(testsDir, "smoke.cbx"),
52
+ `PROGRAM Smoke\n\nBEGIN\nSET total = 1 + 2\nDISPLAY total\nEND\n`,
53
+ "utf8"
54
+ );
55
+ fs.writeFileSync(
56
+ path.join(benchmarksDir, "arith.cbx"),
57
+ `PROGRAM Bench\n\nBEGIN\nSET value = 1000 * 1000\nDISPLAY value\nEND\n`,
58
+ "utf8"
59
+ );
60
+ }
61
+
62
+ function templateSource(projectName: string, template: string): string {
63
+ const programName = projectName.replace(/[^A-Za-z0-9_]/g, "") || "Main";
64
+ switch (template) {
65
+ case "api":
66
+ return `PROGRAM ${programName}\n\nCONST API_VERSION = "v1"\n\nBEGIN\nDISPLAY "API template ${projectName}"\nEND\n`;
67
+ case "microservice":
68
+ return `PROGRAM ${programName}\n\nBEGIN\nDISPLAY "Microservice booting"\nEND\n`;
69
+ case "cli":
70
+ return `PROGRAM ${programName}\n\nBEGIN\nDISPLAY "CLI ready"\nEND\n`;
71
+ default:
72
+ return `PROGRAM ${programName}\n\nBEGIN\nDISPLAY "Hello from COBOL-X"\nEND\n`;
73
+ }
74
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src/**/*.ts"]
7
+ }
package/cobolx.toml ADDED
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "cobolx"
3
+ version = "0.2.0"
4
+ entry = "examples/hello.cbx"
5
+
6
+ [dependencies]
7
+ ledger = "1.2.3"
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@cobolx/compiler",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "bin": {
7
+ "cobolxc": "./dist/main.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc -p tsconfig.json",
11
+ "check": "tsc -p tsconfig.json --noEmit",
12
+ "clean": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }"
13
+ }
14
+ }
@@ -0,0 +1,87 @@
1
+ export interface SourceLocation {
2
+ line: number;
3
+ column: number;
4
+ offset: number;
5
+ }
6
+ export interface SourceRange {
7
+ start: SourceLocation;
8
+ end: SourceLocation;
9
+ }
10
+ export interface BaseNode {
11
+ kind: string;
12
+ range: SourceRange;
13
+ }
14
+ export interface ProgramNode extends BaseNode {
15
+ kind: "Program";
16
+ name: string;
17
+ functions: FunctionDeclarationNode[];
18
+ body: StatementNode[];
19
+ }
20
+ export interface FunctionDeclarationNode extends BaseNode {
21
+ kind: "FunctionDeclaration";
22
+ name: string;
23
+ params: string[];
24
+ body: StatementNode[];
25
+ }
26
+ export type StatementNode = SetStatementNode | DisplayStatementNode | InputStatementNode | IfStatementNode | ReturnStatementNode | ExpressionStatementNode;
27
+ export interface SetStatementNode extends BaseNode {
28
+ kind: "SetStatement";
29
+ name: string;
30
+ expression: ExpressionNode;
31
+ }
32
+ export interface DisplayStatementNode extends BaseNode {
33
+ kind: "DisplayStatement";
34
+ expression: ExpressionNode;
35
+ }
36
+ export interface InputStatementNode extends BaseNode {
37
+ kind: "InputStatement";
38
+ name: string;
39
+ prompt?: ExpressionNode;
40
+ }
41
+ export interface IfStatementNode extends BaseNode {
42
+ kind: "IfStatement";
43
+ condition: ExpressionNode;
44
+ thenBranch: StatementNode[];
45
+ elseBranch: StatementNode[];
46
+ }
47
+ export interface ReturnStatementNode extends BaseNode {
48
+ kind: "ReturnStatement";
49
+ expression: ExpressionNode;
50
+ }
51
+ export interface ExpressionStatementNode extends BaseNode {
52
+ kind: "ExpressionStatement";
53
+ expression: ExpressionNode;
54
+ }
55
+ export type ExpressionNode = NumberLiteralNode | StringLiteralNode | BooleanLiteralNode | IdentifierNode | BinaryExpressionNode | UnaryExpressionNode | CallExpressionNode;
56
+ export interface NumberLiteralNode extends BaseNode {
57
+ kind: "NumberLiteral";
58
+ value: number;
59
+ }
60
+ export interface StringLiteralNode extends BaseNode {
61
+ kind: "StringLiteral";
62
+ value: string;
63
+ }
64
+ export interface BooleanLiteralNode extends BaseNode {
65
+ kind: "BooleanLiteral";
66
+ value: boolean;
67
+ }
68
+ export interface IdentifierNode extends BaseNode {
69
+ kind: "Identifier";
70
+ name: string;
71
+ }
72
+ export interface BinaryExpressionNode extends BaseNode {
73
+ kind: "BinaryExpression";
74
+ operator: string;
75
+ left: ExpressionNode;
76
+ right: ExpressionNode;
77
+ }
78
+ export interface UnaryExpressionNode extends BaseNode {
79
+ kind: "UnaryExpression";
80
+ operator: string;
81
+ operand: ExpressionNode;
82
+ }
83
+ export interface CallExpressionNode extends BaseNode {
84
+ kind: "CallExpression";
85
+ callee: string;
86
+ args: ExpressionNode[];
87
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,329 @@
1
+ export interface SourceLocation {
2
+ line: number;
3
+ column: number;
4
+ offset: number;
5
+ }
6
+
7
+ export interface SourceRange {
8
+ start: SourceLocation;
9
+ end: SourceLocation;
10
+ }
11
+
12
+ export interface BaseNode {
13
+ kind: string;
14
+ range: SourceRange;
15
+ docs?: string[];
16
+ }
17
+
18
+ export interface ProgramNode extends BaseNode {
19
+ kind: "Program";
20
+ name: string;
21
+ imports: ImportDeclarationNode[];
22
+ exports: ExportDeclarationNode[];
23
+ plugins: PluginUseNode[];
24
+ consts: ConstDeclarationNode[];
25
+ enums: EnumDeclarationNode[];
26
+ traits: TraitDeclarationNode[];
27
+ impls: ImplDeclarationNode[];
28
+ macros: MacroDeclarationNode[];
29
+ modules: ModuleDeclarationNode[];
30
+ functions: FunctionDeclarationNode[];
31
+ tests: TestDeclarationNode[];
32
+ body: StatementNode[];
33
+ }
34
+
35
+ export interface GenericParam {
36
+ name: string;
37
+ bound?: string;
38
+ lifetime?: string;
39
+ }
40
+
41
+ export interface TypedName {
42
+ name: string;
43
+ typeName?: string;
44
+ lifetime?: string;
45
+ mutable?: boolean;
46
+ }
47
+
48
+ export interface ImportDeclarationNode extends BaseNode {
49
+ kind: "ImportDeclaration";
50
+ modulePath: string;
51
+ importedName: string;
52
+ alias?: string;
53
+ }
54
+
55
+ export interface ExportDeclarationNode extends BaseNode {
56
+ kind: "ExportDeclaration";
57
+ name: string;
58
+ }
59
+
60
+ export interface PluginUseNode extends BaseNode {
61
+ kind: "PluginUse";
62
+ pluginPath: string;
63
+ }
64
+
65
+ export interface ConstDeclarationNode extends BaseNode {
66
+ kind: "ConstDeclaration";
67
+ name: string;
68
+ expression: ExpressionNode;
69
+ }
70
+
71
+ export interface EnumVariantNode extends BaseNode {
72
+ kind: "EnumVariant";
73
+ name: string;
74
+ fields: TypedName[];
75
+ }
76
+
77
+ export interface EnumDeclarationNode extends BaseNode {
78
+ kind: "EnumDeclaration";
79
+ name: string;
80
+ variants: EnumVariantNode[];
81
+ }
82
+
83
+ export interface FunctionSignatureNode extends BaseNode {
84
+ kind: "FunctionSignature";
85
+ name: string;
86
+ genericParams: GenericParam[];
87
+ params: TypedName[];
88
+ returnType?: string;
89
+ returnLifetime?: string;
90
+ isAsync?: boolean;
91
+ isConst?: boolean;
92
+ traitBound?: string;
93
+ }
94
+
95
+ export interface FunctionDeclarationNode extends BaseNode {
96
+ kind: "FunctionDeclaration";
97
+ signature: FunctionSignatureNode;
98
+ body: StatementNode[];
99
+ }
100
+
101
+ export interface TraitDeclarationNode extends BaseNode {
102
+ kind: "TraitDeclaration";
103
+ name: string;
104
+ composedTraits: string[];
105
+ methods: FunctionDeclarationNode[];
106
+ }
107
+
108
+ export interface ImplDeclarationNode extends BaseNode {
109
+ kind: "ImplDeclaration";
110
+ traitName?: string;
111
+ targetType: string;
112
+ methods: FunctionDeclarationNode[];
113
+ }
114
+
115
+ export interface MacroDeclarationNode extends BaseNode {
116
+ kind: "MacroDeclaration";
117
+ name: string;
118
+ params: string[];
119
+ body: StatementNode[];
120
+ }
121
+
122
+ export interface ModuleDeclarationNode extends BaseNode {
123
+ kind: "ModuleDeclaration";
124
+ name: string;
125
+ exports: ExportDeclarationNode[];
126
+ consts: ConstDeclarationNode[];
127
+ enums: EnumDeclarationNode[];
128
+ traits: TraitDeclarationNode[];
129
+ impls: ImplDeclarationNode[];
130
+ macros: MacroDeclarationNode[];
131
+ functions: FunctionDeclarationNode[];
132
+ }
133
+
134
+ export interface TestDeclarationNode extends BaseNode {
135
+ kind: "TestDeclaration";
136
+ name: string;
137
+ body: StatementNode[];
138
+ }
139
+
140
+ export type StatementNode =
141
+ | SetStatementNode
142
+ | LetStatementNode
143
+ | DisplayStatementNode
144
+ | InputStatementNode
145
+ | IfStatementNode
146
+ | MatchStatementNode
147
+ | ReturnStatementNode
148
+ | ExpressionStatementNode
149
+ | UnsafeBlockNode
150
+ | AssertStatementNode
151
+ | SpawnStatementNode
152
+ | BlockStatementNode;
153
+
154
+ export interface LetStatementNode extends BaseNode {
155
+ kind: "LetStatement";
156
+ binding: TypedName;
157
+ expression: ExpressionNode;
158
+ isMutable: boolean;
159
+ }
160
+
161
+ export interface SetStatementNode extends BaseNode {
162
+ kind: "SetStatement";
163
+ name: string;
164
+ expression: ExpressionNode;
165
+ }
166
+
167
+ export interface DisplayStatementNode extends BaseNode {
168
+ kind: "DisplayStatement";
169
+ expression: ExpressionNode;
170
+ }
171
+
172
+ export interface InputStatementNode extends BaseNode {
173
+ kind: "InputStatement";
174
+ name: string;
175
+ prompt?: ExpressionNode;
176
+ }
177
+
178
+ export interface IfStatementNode extends BaseNode {
179
+ kind: "IfStatement";
180
+ condition: ExpressionNode;
181
+ thenBranch: StatementNode[];
182
+ elseBranch: StatementNode[];
183
+ }
184
+
185
+ export interface MatchArmNode extends BaseNode {
186
+ kind: "MatchArm";
187
+ pattern: PatternNode;
188
+ body: StatementNode[];
189
+ }
190
+
191
+ export interface MatchStatementNode extends BaseNode {
192
+ kind: "MatchStatement";
193
+ expression: ExpressionNode;
194
+ arms: MatchArmNode[];
195
+ }
196
+
197
+ export interface UnsafeBlockNode extends BaseNode {
198
+ kind: "UnsafeBlock";
199
+ body: StatementNode[];
200
+ }
201
+
202
+ export interface AssertStatementNode extends BaseNode {
203
+ kind: "AssertStatement";
204
+ expression: ExpressionNode;
205
+ }
206
+
207
+ export interface SpawnStatementNode extends BaseNode {
208
+ kind: "SpawnStatement";
209
+ expression: ExpressionNode;
210
+ }
211
+
212
+ export interface BlockStatementNode extends BaseNode {
213
+ kind: "BlockStatement";
214
+ body: StatementNode[];
215
+ }
216
+
217
+ export interface ReturnStatementNode extends BaseNode {
218
+ kind: "ReturnStatement";
219
+ expression: ExpressionNode;
220
+ }
221
+
222
+ export interface ExpressionStatementNode extends BaseNode {
223
+ kind: "ExpressionStatement";
224
+ expression: ExpressionNode;
225
+ }
226
+
227
+ export type PatternNode = WildcardPatternNode | IdentifierPatternNode | VariantPatternNode | LiteralPatternNode;
228
+
229
+ export interface WildcardPatternNode extends BaseNode {
230
+ kind: "WildcardPattern";
231
+ }
232
+
233
+ export interface IdentifierPatternNode extends BaseNode {
234
+ kind: "IdentifierPattern";
235
+ name: string;
236
+ }
237
+
238
+ export interface VariantPatternNode extends BaseNode {
239
+ kind: "VariantPattern";
240
+ variantName: string;
241
+ bindings: string[];
242
+ }
243
+
244
+ export interface LiteralPatternNode extends BaseNode {
245
+ kind: "LiteralPattern";
246
+ expression: ExpressionNode;
247
+ }
248
+
249
+ export type ExpressionNode =
250
+ | NumberLiteralNode
251
+ | StringLiteralNode
252
+ | BooleanLiteralNode
253
+ | IdentifierNode
254
+ | BinaryExpressionNode
255
+ | UnaryExpressionNode
256
+ | CallExpressionNode
257
+ | MacroInvocationNode
258
+ | TryExpressionNode
259
+ | MemberExpressionNode
260
+ | EnumConstructorExpressionNode
261
+ | ArrayLiteralNode;
262
+
263
+ export interface NumberLiteralNode extends BaseNode {
264
+ kind: "NumberLiteral";
265
+ value: number;
266
+ }
267
+
268
+ export interface StringLiteralNode extends BaseNode {
269
+ kind: "StringLiteral";
270
+ value: string;
271
+ }
272
+
273
+ export interface BooleanLiteralNode extends BaseNode {
274
+ kind: "BooleanLiteral";
275
+ value: boolean;
276
+ }
277
+
278
+ export interface IdentifierNode extends BaseNode {
279
+ kind: "Identifier";
280
+ name: string;
281
+ }
282
+
283
+ export interface ArrayLiteralNode extends BaseNode {
284
+ kind: "ArrayLiteral";
285
+ items: ExpressionNode[];
286
+ }
287
+
288
+ export interface BinaryExpressionNode extends BaseNode {
289
+ kind: "BinaryExpression";
290
+ operator: string;
291
+ left: ExpressionNode;
292
+ right: ExpressionNode;
293
+ }
294
+
295
+ export interface UnaryExpressionNode extends BaseNode {
296
+ kind: "UnaryExpression";
297
+ operator: string;
298
+ operand: ExpressionNode;
299
+ }
300
+
301
+ export interface CallExpressionNode extends BaseNode {
302
+ kind: "CallExpression";
303
+ callee: ExpressionNode;
304
+ args: ExpressionNode[];
305
+ }
306
+
307
+ export interface MacroInvocationNode extends BaseNode {
308
+ kind: "MacroInvocation";
309
+ name: string;
310
+ args: ExpressionNode[];
311
+ }
312
+
313
+ export interface TryExpressionNode extends BaseNode {
314
+ kind: "TryExpression";
315
+ expression: ExpressionNode;
316
+ }
317
+
318
+ export interface MemberExpressionNode extends BaseNode {
319
+ kind: "MemberExpression";
320
+ object: ExpressionNode;
321
+ property: string;
322
+ }
323
+
324
+ export interface EnumConstructorExpressionNode extends BaseNode {
325
+ kind: "EnumConstructorExpression";
326
+ enumName?: string;
327
+ variantName: string;
328
+ fields: ExpressionNode[];
329
+ }
@@ -0,0 +1,8 @@
1
+ import type { MIRProgram } from "../mir/types.js";
2
+ import type { ProgramNode } from "../ast/types.js";
3
+ export interface BackendOutput {
4
+ target: "js-custom-backend";
5
+ code: string;
6
+ instructionCount: number;
7
+ }
8
+ export declare function emitCustomBackend(program: ProgramNode, mir: MIRProgram, outputFilePath: string, stdlibDir: string): BackendOutput;