xbintsc 0.1.9 → 0.1.10

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 (57) hide show
  1. package/README.md +12 -7
  2. package/dist/src/codegen/generator/calls.js +11 -1
  3. package/dist/src/codegen/generator/calls.js.map +1 -1
  4. package/dist/src/codegen/generator/module.js +1 -0
  5. package/dist/src/codegen/generator/module.js.map +1 -1
  6. package/dist/src/codegen/generator/state.js +5 -0
  7. package/dist/src/codegen/generator/state.js.map +1 -1
  8. package/dist/src/codegen/generator/tables.d.ts +2 -0
  9. package/dist/src/codegen/generator/tables.js +7 -0
  10. package/dist/src/codegen/generator/tables.js.map +1 -1
  11. package/dist/src/extensions/node/fs/fs-ops.d.ts +6 -0
  12. package/dist/src/extensions/node/fs/fs-ops.js +18 -0
  13. package/dist/src/extensions/node/fs/fs-ops.js.map +1 -0
  14. package/dist/src/extensions/node/fs/index.d.ts +3 -1
  15. package/dist/src/extensions/node/fs/index.js +11 -3
  16. package/dist/src/extensions/node/fs/index.js.map +1 -1
  17. package/dist/src/extensions/node/fs/write-file.d.ts +5 -0
  18. package/dist/src/extensions/node/fs/write-file.js +8 -0
  19. package/dist/src/extensions/node/fs/write-file.js.map +1 -0
  20. package/dist/src/extensions/node/index.d.ts +2 -1
  21. package/dist/src/extensions/node/index.js +7 -3
  22. package/dist/src/extensions/node/index.js.map +1 -1
  23. package/dist/src/extensions/node/os/index.d.ts +9 -0
  24. package/dist/src/extensions/node/os/index.js +14 -0
  25. package/dist/src/extensions/node/os/index.js.map +1 -0
  26. package/dist/src/extensions/node/path/index.d.ts +10 -0
  27. package/dist/src/extensions/node/path/index.js +15 -0
  28. package/dist/src/extensions/node/path/index.js.map +1 -0
  29. package/dist/src/extensions/node/process/index.d.ts +10 -0
  30. package/dist/src/extensions/node/process/index.js +15 -0
  31. package/dist/src/extensions/node/process/index.js.map +1 -0
  32. package/dist/tests/e2e/compile.test.js +55 -0
  33. package/dist/tests/e2e/compile.test.js.map +1 -1
  34. package/dist/tests/extensions/registry.test.js +9 -3
  35. package/dist/tests/extensions/registry.test.js.map +1 -1
  36. package/package.json +1 -1
  37. package/runtime/ext_node/fs/fs_common.h +166 -0
  38. package/runtime/ext_node/fs/fs_ops.c +342 -0
  39. package/runtime/ext_node/fs/read_file.c +12 -6
  40. package/runtime/ext_node/fs/write_file.c +47 -0
  41. package/runtime/ext_node/os/os.c +165 -0
  42. package/runtime/ext_node/path/path.c +324 -0
  43. package/runtime/ext_node/process/process.c +137 -0
  44. package/runtime/rt.h +6 -0
  45. package/runtime/xt_io.c +9 -0
  46. package/scripts/build-runtime.mjs +5 -0
  47. package/src/codegen/generator/calls.ts +13 -0
  48. package/src/codegen/generator/module.ts +1 -0
  49. package/src/codegen/generator/state.ts +5 -0
  50. package/src/codegen/generator/tables.ts +8 -0
  51. package/src/extensions/node/fs/fs-ops.ts +20 -0
  52. package/src/extensions/node/fs/index.ts +11 -3
  53. package/src/extensions/node/fs/write-file.ts +10 -0
  54. package/src/extensions/node/index.ts +7 -3
  55. package/src/extensions/node/os/index.ts +16 -0
  56. package/src/extensions/node/path/index.ts +17 -0
  57. package/src/extensions/node/process/index.ts +17 -0
@@ -77,6 +77,10 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
77
77
  "declare i64 @xt_number_static(i64, i32, i64*)",
78
78
  "declare i64 @xt_string_static(i64, i32, i64*)",
79
79
  "declare i64 @xt_date_static(i64, i32, i64*)",
80
+ "declare i64 @xt_path_static(i64, i32, i64*)",
81
+ "declare i64 @xt_os_static(i64, i32, i64*)",
82
+ "declare i64 @xt_process_call(i64, i32, i64*)",
83
+ "declare i64 @xt_process_get(i64)",
80
84
  "declare i64 @xt_map_ctor(i32, i64*)",
81
85
  "declare i64 @xt_set_ctor(i32, i64*)",
82
86
  "declare i64 @xt_date_ctor(i32, i64*)",
@@ -147,6 +151,7 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
147
151
  "declare i64 @xt_in(i64, i64)",
148
152
  "declare i64 @xt_delete(i64, i64)",
149
153
  "declare i64 @xt_rest_args(i32, i64*, i32)",
154
+ "declare void @xt_set_program_args(i32, i8**)",
150
155
  "declare i64 @xt_array_new(i32, i64*)",
151
156
  "declare i64 @xt_array_push(i64, i64)",
152
157
  "declare i64 @xt_array_length(i64)",
@@ -89,6 +89,14 @@ export const NAMESPACE_STATICS: Record<string, string> = {
89
89
  String: "xt_string_static",
90
90
  Date: "xt_date_static",
91
91
  Promise: "xt_promise_static",
92
+ path: "xt_path_static",
93
+ os: "xt_os_static",
94
+ process: "xt_process_call",
95
+ };
96
+
97
+ /** Namespace identifiers whose property access maps to a runtime getter. */
98
+ export const NAMESPACE_PROPERTIES: Record<string, string> = {
99
+ process: "xt_process_get",
92
100
  };
93
101
 
94
102
  /** Global constructors called as `new X(...)` (all have signature `(i32, i64*)`). */
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Builtins for the filesystem operations in Node's `fs` module
3
+ * (`existsSync`, directory handling, rename/copy, `statSync`, ...).
4
+ */
5
+
6
+ import type { BuiltinFunction } from "../../registry.js";
7
+
8
+ export const fsOpsBuiltins: Readonly<Record<string, BuiltinFunction>> = {
9
+ existsSync: { symbol: "xt_node_exists" },
10
+ readdirSync: { symbol: "xt_node_read_dir" },
11
+ mkdirSync: { symbol: "xt_node_mkdir" },
12
+ rmSync: { symbol: "xt_node_rm" },
13
+ unlinkSync: { symbol: "xt_node_unlink" },
14
+ rmdirSync: { symbol: "xt_node_rmdir" },
15
+ renameSync: { symbol: "xt_node_rename" },
16
+ copyFileSync: { symbol: "xt_node_copy_file" },
17
+ realpathSync: { symbol: "xt_node_realpath" },
18
+ statSync: { symbol: "xt_node_stat" },
19
+ lstatSync: { symbol: "xt_node_lstat" },
20
+ };
@@ -1,13 +1,21 @@
1
1
  /**
2
- * Node's `fs` module: text file reads backed by `runtime/ext_node/fs`.
2
+ * Node's `fs` module: synchronous file and directory operations backed by
3
+ * `runtime/ext_node/fs`. Asynchronous callbacks are not supported (xbintsc has
4
+ * no event loop), so only the `*Sync` API is exposed.
3
5
  */
4
6
 
5
7
  import type { NodeModule } from "../module.js";
6
8
  import { resolveFrom } from "../module.js";
7
9
  import { readFileBuiltins } from "./read-file.js";
10
+ import { writeFileBuiltins } from "./write-file.js";
11
+ import { fsOpsBuiltins } from "./fs-ops.js";
8
12
 
9
13
  export const fsModule: NodeModule = {
10
14
  name: "fs",
11
- runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/fs/read_file.c")],
12
- builtins: () => readFileBuiltins,
15
+ runtimeSources: () => [
16
+ resolveFrom(import.meta.url, "../../../../runtime/ext_node/fs/read_file.c"),
17
+ resolveFrom(import.meta.url, "../../../../runtime/ext_node/fs/write_file.c"),
18
+ resolveFrom(import.meta.url, "../../../../runtime/ext_node/fs/fs_ops.c"),
19
+ ],
20
+ builtins: () => ({ ...readFileBuiltins, ...writeFileBuiltins, ...fsOpsBuiltins }),
13
21
  };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Builtins for Node's `fs` write/append APIs.
3
+ */
4
+
5
+ import type { BuiltinFunction } from "../../registry.js";
6
+
7
+ export const writeFileBuiltins: Readonly<Record<string, BuiltinFunction>> = {
8
+ writeFileSync: { symbol: "xt_node_write_file" },
9
+ appendFileSync: { symbol: "xt_node_append_file" },
10
+ };
@@ -5,19 +5,23 @@
5
5
  * builtins each module implements, so `readFileSync("...")` in TypeScript
6
6
  * resolves to the C implementation without the core compiler knowing anything
7
7
  * about Node. Every Node module lives in its own subfolder next to this file
8
- * (currently `fs/`), with the runtime counterpart under `runtime/ext_node/`.
8
+ * (`fs/`, `path/`, `os/`, `process/`), with the runtime counterpart under
9
+ * `runtime/ext_node/`.
9
10
  */
10
11
 
11
12
  import type { BuiltinFunction, Extension } from "../registry.js";
12
13
  import type { NodeModule } from "./module.js";
13
14
  import { fsModule } from "./fs/index.js";
15
+ import { pathModule } from "./path/index.js";
16
+ import { osModule } from "./os/index.js";
17
+ import { processModule } from "./process/index.js";
14
18
 
15
19
  /** Every Node module the extension currently provides. */
16
- const modules: readonly NodeModule[] = [fsModule];
20
+ const modules: readonly NodeModule[] = [fsModule, pathModule, osModule, processModule];
17
21
 
18
22
  export const nodeExtension: Extension = {
19
23
  name: "node",
20
- description: "Node.js host APIs (fs, ...)",
24
+ description: "Node.js host APIs (fs, path, os, process)",
21
25
  runtimeSources: () => modules.flatMap((module) => module.runtimeSources()),
22
26
  builtins: () => {
23
27
  const merged: Record<string, BuiltinFunction> = {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Node's `os` module: host information backed by `runtime/ext_node/os`.
3
+ *
4
+ * `os` contributes no global builtins; the compiler lowers `os.<name>(...)` to
5
+ * `xt_os_static(<name>, argc, argv)` (see `NAMESPACE_STATICS` in
6
+ * `src/codegen/generator/tables.ts`). This module only links the C source.
7
+ */
8
+
9
+ import type { NodeModule } from "../module.js";
10
+ import { resolveFrom } from "../module.js";
11
+
12
+ export const osModule: NodeModule = {
13
+ name: "os",
14
+ runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/os/os.c")],
15
+ builtins: () => ({}),
16
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Node's `path` module: POSIX-style path helpers backed by
3
+ * `runtime/ext_node/path`.
4
+ *
5
+ * `path` contributes no global builtins; the compiler lowers `path.<name>(...)`
6
+ * to `xt_path_static(<name>, argc, argv)` (see `NAMESPACE_STATICS` in
7
+ * `src/codegen/generator/tables.ts`). This module only links the C source.
8
+ */
9
+
10
+ import type { NodeModule } from "../module.js";
11
+ import { resolveFrom } from "../module.js";
12
+
13
+ export const pathModule: NodeModule = {
14
+ name: "path",
15
+ runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/path/path.c")],
16
+ builtins: () => ({}),
17
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Node's `process` object backed by `runtime/ext_node/process`.
3
+ *
4
+ * The compiler lowers `process.<method>(...)` to
5
+ * `xt_process_call(<method>, argc, argv)` and `process.<property>` to
6
+ * `xt_process_get(<property>)` (see `NAMESPACE_STATICS` / `NAMESPACE_PROPERTIES`
7
+ * in `src/codegen/generator/tables.ts`). This module only links the C source.
8
+ */
9
+
10
+ import type { NodeModule } from "../module.js";
11
+ import { resolveFrom } from "../module.js";
12
+
13
+ export const processModule: NodeModule = {
14
+ name: "process",
15
+ runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/process/process.c")],
16
+ builtins: () => ({}),
17
+ };