xbintsc 0.1.1 → 0.1.6

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 (47) hide show
  1. package/README.md +29 -15
  2. package/dist/src/cli/main.js +1 -1
  3. package/dist/src/cli/main.js.map +1 -1
  4. package/dist/src/codegen/llvm.js +422 -44
  5. package/dist/src/codegen/llvm.js.map +1 -1
  6. package/dist/src/extensions/node/fs/index.d.ts +5 -0
  7. package/dist/src/extensions/node/fs/index.js +11 -0
  8. package/dist/src/extensions/node/fs/index.js.map +1 -0
  9. package/dist/src/extensions/node/fs/read-file.d.ts +8 -0
  10. package/dist/src/extensions/node/fs/read-file.js +11 -0
  11. package/dist/src/extensions/node/fs/read-file.js.map +1 -0
  12. package/dist/src/extensions/node/index.d.ts +11 -0
  13. package/dist/src/extensions/node/index.js +24 -0
  14. package/dist/src/extensions/node/index.js.map +1 -0
  15. package/dist/src/extensions/node/module.d.ts +17 -0
  16. package/dist/src/extensions/node/module.js +13 -0
  17. package/dist/src/extensions/node/module.js.map +1 -0
  18. package/dist/src/index.d.ts +2 -1
  19. package/dist/src/index.js +1 -1
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/parser/parser.js +4 -0
  22. package/dist/src/parser/parser.js.map +1 -1
  23. package/dist/tests/codegen/llvm.test.js +1 -1
  24. package/dist/tests/codegen/llvm.test.js.map +1 -1
  25. package/dist/tests/e2e/compile.test.js +123 -3
  26. package/dist/tests/e2e/compile.test.js.map +1 -1
  27. package/dist/tests/extensions/registry.test.js +2 -2
  28. package/dist/tests/extensions/registry.test.js.map +1 -1
  29. package/dist/tests/parser/parser.test.js +9 -1
  30. package/dist/tests/parser/parser.test.js.map +1 -1
  31. package/package.json +1 -1
  32. package/runtime/{ext_node.c → ext_node/fs/read_file.c} +4 -3
  33. package/runtime/rt.h +32 -0
  34. package/runtime/xt_runtime.c +696 -6
  35. package/scripts/build-runtime.mjs +1 -1
  36. package/src/cli/main.ts +1 -1
  37. package/src/codegen/llvm.ts +458 -43
  38. package/src/extensions/node/fs/index.ts +13 -0
  39. package/src/extensions/node/fs/read-file.ts +13 -0
  40. package/src/extensions/node/index.ts +27 -0
  41. package/src/extensions/node/module.ts +24 -0
  42. package/src/index.ts +2 -1
  43. package/src/parser/parser.ts +4 -0
  44. package/dist/src/extensions/node.d.ts +0 -9
  45. package/dist/src/extensions/node.js +0 -20
  46. package/dist/src/extensions/node.js.map +0 -1
  47. package/src/extensions/node.ts +0 -23
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Node's `fs` module: text file reads backed by `runtime/ext_node/fs`.
3
+ */
4
+
5
+ import type { NodeModule } from "../module.js";
6
+ import { resolveFrom } from "../module.js";
7
+ import { readFileBuiltins } from "./read-file.js";
8
+
9
+ export const fsModule: NodeModule = {
10
+ name: "fs",
11
+ runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/fs/read_file.c")],
12
+ builtins: () => readFileBuiltins,
13
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Concrete builtins for Node's `fs` module.
3
+ *
4
+ * Both names map to the same C symbol because the compiler only distinguishes
5
+ * globals, not the namespaces they come from.
6
+ */
7
+
8
+ import type { BuiltinFunction } from "../../registry.js";
9
+
10
+ export const readFileBuiltins: Readonly<Record<string, BuiltinFunction>> = {
11
+ readFileSync: { symbol: "xt_node_read_text_file" },
12
+ readTextFile: { symbol: "xt_node_read_text_file" },
13
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Node.js compatibility extension.
3
+ *
4
+ * Registering it links the C sources under `runtime/ext_node/` and exposes the
5
+ * builtins each module implements, so `readFileSync("...")` in TypeScript
6
+ * resolves to the C implementation without the core compiler knowing anything
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/`.
9
+ */
10
+
11
+ import type { BuiltinFunction, Extension } from "../registry.js";
12
+ import type { NodeModule } from "./module.js";
13
+ import { fsModule } from "./fs/index.js";
14
+
15
+ /** Every Node module the extension currently provides. */
16
+ const modules: readonly NodeModule[] = [fsModule];
17
+
18
+ export const nodeExtension: Extension = {
19
+ name: "node",
20
+ description: "Node.js host APIs (fs, ...)",
21
+ runtimeSources: () => modules.flatMap((module) => module.runtimeSources()),
22
+ builtins: () => {
23
+ const merged: Record<string, BuiltinFunction> = {};
24
+ for (const module of modules) Object.assign(merged, module.builtins());
25
+ return merged;
26
+ },
27
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A single Node.js module contributed by the `node` extension.
3
+ *
4
+ * Each module lives in its own folder (e.g. `node/fs`) and pairs the globally
5
+ * visible builtins it exposes with the C runtime sources that implement them.
6
+ */
7
+
8
+ import { dirname, resolve } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import type { BuiltinFunction } from "../registry.js";
11
+
12
+ export interface NodeModule {
13
+ /** Module name, e.g. `fs`. */
14
+ readonly name: string;
15
+ /** C sources compiled and linked for this module. */
16
+ runtimeSources(): readonly string[];
17
+ /** Global identifiers that resolve to this module's runtime symbols. */
18
+ builtins(): Readonly<Record<string, BuiltinFunction>>;
19
+ }
20
+
21
+ /** Resolve a path relative to the folder of the module that calls this. */
22
+ export function resolveFrom(importMetaUrl: string, relative: string): string {
23
+ return resolve(dirname(fileURLToPath(importMetaUrl)), relative);
24
+ }
package/src/index.ts CHANGED
@@ -29,5 +29,6 @@ export {
29
29
  booleanLiteral,
30
30
  } from "./codegen/values.js";
31
31
  export { ExtensionRegistry, createDefaultRegistry, coreExtension, type Extension } from "./extensions/registry.js";
32
- export { nodeExtension } from "./extensions/node.js";
32
+ export { nodeExtension } from "./extensions/node/index.js";
33
+ export type { NodeModule } from "./extensions/node/module.js";
33
34
  export * from "./driver/index.js";
@@ -394,6 +394,10 @@ export class Parser {
394
394
 
395
395
  private parseStatementWithModifiers(modifiers: Modifier[]): Statement {
396
396
  switch (this.token.kind) {
397
+ case TokenKind.VarKeyword:
398
+ case TokenKind.LetKeyword:
399
+ case TokenKind.ConstKeyword:
400
+ return this.parseVariableStatement(modifiers);
397
401
  case TokenKind.FunctionKeyword:
398
402
  return this.parseFunctionDeclaration(modifiers);
399
403
  case TokenKind.ClassKeyword:
@@ -1,9 +0,0 @@
1
- /**
2
- * Node.js compatibility extension.
3
- *
4
- * Registering it links `runtime/ext_node.c` and exposes the builtins it
5
- * implements, so `readFileSync("...")` in TypeScript resolves to the C
6
- * implementation without the core compiler knowing anything about Node.
7
- */
8
- import type { Extension } from "./registry.js";
9
- export declare const nodeExtension: Extension;
@@ -1,20 +0,0 @@
1
- /**
2
- * Node.js compatibility extension.
3
- *
4
- * Registering it links `runtime/ext_node.c` and exposes the builtins it
5
- * implements, so `readFileSync("...")` in TypeScript resolves to the C
6
- * implementation without the core compiler knowing anything about Node.
7
- */
8
- import { fileURLToPath } from "node:url";
9
- import { dirname, resolve } from "node:path";
10
- const here = dirname(fileURLToPath(import.meta.url));
11
- export const nodeExtension = {
12
- name: "node",
13
- description: "Node.js host APIs (readFileSync, ...)",
14
- runtimeSources: () => [resolve(here, "../../runtime/ext_node.c")],
15
- builtins: () => ({
16
- readFileSync: { symbol: "xt_node_read_text_file" },
17
- readTextFile: { symbol: "xt_node_read_text_file" },
18
- }),
19
- };
20
- //# sourceMappingURL=node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/extensions/node.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,uCAAuC;IACpD,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;IACjE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;QACf,YAAY,EAAE,EAAE,MAAM,EAAE,wBAAwB,EAAE;QAClD,YAAY,EAAE,EAAE,MAAM,EAAE,wBAAwB,EAAE;KACnD,CAAC;CACH,CAAC"}
@@ -1,23 +0,0 @@
1
- /**
2
- * Node.js compatibility extension.
3
- *
4
- * Registering it links `runtime/ext_node.c` and exposes the builtins it
5
- * implements, so `readFileSync("...")` in TypeScript resolves to the C
6
- * implementation without the core compiler knowing anything about Node.
7
- */
8
-
9
- import { fileURLToPath } from "node:url";
10
- import { dirname, resolve } from "node:path";
11
- import type { Extension } from "./registry.js";
12
-
13
- const here = dirname(fileURLToPath(import.meta.url));
14
-
15
- export const nodeExtension: Extension = {
16
- name: "node",
17
- description: "Node.js host APIs (readFileSync, ...)",
18
- runtimeSources: () => [resolve(here, "../../runtime/ext_node.c")],
19
- builtins: () => ({
20
- readFileSync: { symbol: "xt_node_read_text_file" },
21
- readTextFile: { symbol: "xt_node_read_text_file" },
22
- }),
23
- };