xbintsc 0.1.0
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/LICENSE +21 -0
- package/README.md +191 -0
- package/bin/xbintsc.js +26 -0
- package/dist/src/ast/factory.d.ts +11 -0
- package/dist/src/ast/factory.js +36 -0
- package/dist/src/ast/factory.js.map +1 -0
- package/dist/src/ast/nodes.d.ts +848 -0
- package/dist/src/ast/nodes.js +247 -0
- package/dist/src/ast/nodes.js.map +1 -0
- package/dist/src/ast/visitor.d.ts +18 -0
- package/dist/src/ast/visitor.js +52 -0
- package/dist/src/ast/visitor.js.map +1 -0
- package/dist/src/binder/binder.d.ts +82 -0
- package/dist/src/binder/binder.js +443 -0
- package/dist/src/binder/binder.js.map +1 -0
- package/dist/src/cli/main.d.ts +16 -0
- package/dist/src/cli/main.js +191 -0
- package/dist/src/cli/main.js.map +1 -0
- package/dist/src/codegen/llvm.d.ts +31 -0
- package/dist/src/codegen/llvm.js +1178 -0
- package/dist/src/codegen/llvm.js.map +1 -0
- package/dist/src/codegen/values.d.ts +23 -0
- package/dist/src/codegen/values.js +32 -0
- package/dist/src/codegen/values.js.map +1 -0
- package/dist/src/diagnostics/diagnostic.d.ts +69 -0
- package/dist/src/diagnostics/diagnostic.js +104 -0
- package/dist/src/diagnostics/diagnostic.js.map +1 -0
- package/dist/src/diagnostics/source.d.ts +43 -0
- package/dist/src/diagnostics/source.js +73 -0
- package/dist/src/diagnostics/source.js.map +1 -0
- package/dist/src/driver/cache.d.ts +37 -0
- package/dist/src/driver/cache.js +82 -0
- package/dist/src/driver/cache.js.map +1 -0
- package/dist/src/driver/compiler.d.ts +41 -0
- package/dist/src/driver/compiler.js +128 -0
- package/dist/src/driver/compiler.js.map +1 -0
- package/dist/src/driver/index.d.ts +4 -0
- package/dist/src/driver/index.js +5 -0
- package/dist/src/driver/index.js.map +1 -0
- package/dist/src/driver/paths.d.ts +4 -0
- package/dist/src/driver/paths.js +22 -0
- package/dist/src/driver/paths.js.map +1 -0
- package/dist/src/driver/toolchain.d.ts +43 -0
- package/dist/src/driver/toolchain.js +76 -0
- package/dist/src/driver/toolchain.js.map +1 -0
- package/dist/src/extensions/node.d.ts +9 -0
- package/dist/src/extensions/node.js +20 -0
- package/dist/src/extensions/node.js.map +1 -0
- package/dist/src/extensions/registry.d.ts +45 -0
- package/dist/src/extensions/registry.js +76 -0
- package/dist/src/extensions/registry.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.js +19 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lexer/scanner.d.ts +48 -0
- package/dist/src/lexer/scanner.js +650 -0
- package/dist/src/lexer/scanner.js.map +1 -0
- package/dist/src/lexer/token.d.ts +170 -0
- package/dist/src/lexer/token.js +250 -0
- package/dist/src/lexer/token.js.map +1 -0
- package/dist/src/parser/parser.d.ts +127 -0
- package/dist/src/parser/parser.js +2334 -0
- package/dist/src/parser/parser.js.map +1 -0
- package/dist/tests/binder/binder.test.d.ts +1 -0
- package/dist/tests/binder/binder.test.js +89 -0
- package/dist/tests/binder/binder.test.js.map +1 -0
- package/dist/tests/cli/main.test.d.ts +1 -0
- package/dist/tests/cli/main.test.js +68 -0
- package/dist/tests/cli/main.test.js.map +1 -0
- package/dist/tests/cli/process.test.d.ts +9 -0
- package/dist/tests/cli/process.test.js +57 -0
- package/dist/tests/cli/process.test.js.map +1 -0
- package/dist/tests/codegen/llvm.test.d.ts +1 -0
- package/dist/tests/codegen/llvm.test.js +93 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -0
- package/dist/tests/driver/cache.test.d.ts +1 -0
- package/dist/tests/driver/cache.test.js +66 -0
- package/dist/tests/driver/cache.test.js.map +1 -0
- package/dist/tests/driver/compiler.test.d.ts +1 -0
- package/dist/tests/driver/compiler.test.js +80 -0
- package/dist/tests/driver/compiler.test.js.map +1 -0
- package/dist/tests/driver/toolchain.test.d.ts +1 -0
- package/dist/tests/driver/toolchain.test.js +60 -0
- package/dist/tests/driver/toolchain.test.js.map +1 -0
- package/dist/tests/e2e/compile.test.d.ts +5 -0
- package/dist/tests/e2e/compile.test.js +93 -0
- package/dist/tests/e2e/compile.test.js.map +1 -0
- package/dist/tests/extensions/registry.test.d.ts +1 -0
- package/dist/tests/extensions/registry.test.js +47 -0
- package/dist/tests/extensions/registry.test.js.map +1 -0
- package/dist/tests/helpers.d.ts +23 -0
- package/dist/tests/helpers.js +41 -0
- package/dist/tests/helpers.js.map +1 -0
- package/dist/tests/lexer/scanner.test.d.ts +1 -0
- package/dist/tests/lexer/scanner.test.js +95 -0
- package/dist/tests/lexer/scanner.test.js.map +1 -0
- package/dist/tests/parser/parser.test.d.ts +1 -0
- package/dist/tests/parser/parser.test.js +137 -0
- package/dist/tests/parser/parser.test.js.map +1 -0
- package/package.json +49 -0
- package/runtime/ext_node.c +42 -0
- package/runtime/rt.h +177 -0
- package/runtime/xt_runtime.c +682 -0
- package/scripts/build-runtime.mjs +34 -0
- package/src/ast/factory.ts +37 -0
- package/src/ast/nodes.ts +1111 -0
- package/src/ast/visitor.ts +60 -0
- package/src/binder/binder.ts +549 -0
- package/src/cli/main.ts +210 -0
- package/src/codegen/llvm.ts +1324 -0
- package/src/codegen/values.ts +36 -0
- package/src/diagnostics/diagnostic.ts +132 -0
- package/src/diagnostics/source.ts +97 -0
- package/src/driver/cache.ts +96 -0
- package/src/driver/compiler.ts +197 -0
- package/src/driver/index.ts +4 -0
- package/src/driver/paths.ts +24 -0
- package/src/driver/toolchain.ts +103 -0
- package/src/extensions/node.ts +23 -0
- package/src/extensions/registry.ts +101 -0
- package/src/index.ts +33 -0
- package/src/lexer/scanner.ts +650 -0
- package/src/lexer/token.ts +266 -0
- package/src/parser/parser.ts +2396 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { parse } from "../helpers.js";
|
|
3
|
+
import { SyntaxKind } from "../../src/ast/nodes.js";
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
function first(text) {
|
|
6
|
+
const { file, diagnostics } = parse(text);
|
|
7
|
+
expect(diagnostics.filter((d) => d.category === "error")).toHaveLength(0);
|
|
8
|
+
return file.statements[0];
|
|
9
|
+
}
|
|
10
|
+
function errors(text) {
|
|
11
|
+
return parse(text).diagnostics.filter((d) => d.category === "error");
|
|
12
|
+
}
|
|
13
|
+
function kindsOf(text) {
|
|
14
|
+
return parse(text).file.statements.map((statement) => statement.kind);
|
|
15
|
+
}
|
|
16
|
+
describe("parser", () => {
|
|
17
|
+
it("parses variable declarations with all modifier kinds", () => {
|
|
18
|
+
const statement = first("const answer = 42;");
|
|
19
|
+
expect(statement.kind).toBe(SyntaxKind.VariableStatement);
|
|
20
|
+
expect(statement.declarationList.declarations[0].name.text).toBe("answer");
|
|
21
|
+
expect(statement.declarationList.declarations[0].initializer.kind).toBe(SyntaxKind.NumericLiteral);
|
|
22
|
+
});
|
|
23
|
+
it("parses function declarations with types and defaults", () => {
|
|
24
|
+
const fn = first("function add(a: number, b: number = 2): number { return a + b; }");
|
|
25
|
+
expect(fn.kind).toBe(SyntaxKind.FunctionDeclaration);
|
|
26
|
+
expect(fn.name.text).toBe("add");
|
|
27
|
+
expect(fn.parameters).toHaveLength(2);
|
|
28
|
+
expect(fn.parameters[0].name.text).toBe("a");
|
|
29
|
+
expect(fn.parameters[1].initializer.kind).toBe(SyntaxKind.NumericLiteral);
|
|
30
|
+
expect(fn.returnType.kind).toBe(SyntaxKind.NumberKeywordType);
|
|
31
|
+
expect(fn.body.kind).toBe(SyntaxKind.Block);
|
|
32
|
+
expect(fn.body.statements[0].kind).toBe(SyntaxKind.ReturnStatement);
|
|
33
|
+
});
|
|
34
|
+
it("parses arrow functions with expression and block bodies", () => {
|
|
35
|
+
const withExpr = first("const f = (x) => x + 1;");
|
|
36
|
+
const arrow = withExpr.declarationList.declarations[0].initializer;
|
|
37
|
+
expect(arrow.kind).toBe(SyntaxKind.ArrowFunction);
|
|
38
|
+
expect(arrow.body.kind).toBe(SyntaxKind.BinaryExpression);
|
|
39
|
+
const withBlock = first("const g = () => { return 1; };");
|
|
40
|
+
expect(withBlock.declarationList.declarations[0].initializer.body.kind).toBe(SyntaxKind.Block);
|
|
41
|
+
});
|
|
42
|
+
it("respects operator precedence and associativity", () => {
|
|
43
|
+
const statement = first("const v = 1 + 2 * 3;");
|
|
44
|
+
const binary = statement.declarationList.declarations[0].initializer;
|
|
45
|
+
expect(binary.kind).toBe(SyntaxKind.BinaryExpression);
|
|
46
|
+
expect(binary.operator).toBe("+");
|
|
47
|
+
expect(binary.right.kind).toBe(SyntaxKind.BinaryExpression);
|
|
48
|
+
expect(binary.right.operator).toBe("*");
|
|
49
|
+
});
|
|
50
|
+
it("parses control flow statements", () => {
|
|
51
|
+
expect(kindsOf("if (a) b(); else c();")).toEqual([SyntaxKind.IfStatement]);
|
|
52
|
+
expect(kindsOf("while (a) b();")).toEqual([SyntaxKind.WhileStatement]);
|
|
53
|
+
expect(kindsOf("do b(); while (a);")).toEqual([SyntaxKind.DoStatement]);
|
|
54
|
+
expect(kindsOf("for (;;) break;")).toEqual([SyntaxKind.ForStatement]);
|
|
55
|
+
expect(kindsOf("for (const x of xs) x;")).toEqual([SyntaxKind.ForOfStatement]);
|
|
56
|
+
expect(kindsOf("for (const k in obj) k;")).toEqual([SyntaxKind.ForInStatement]);
|
|
57
|
+
expect(kindsOf("switch (a) { case 1: break; default: break; }")).toEqual([SyntaxKind.SwitchStatement]);
|
|
58
|
+
});
|
|
59
|
+
it("parses for loops whose condition contains `<` without confusion", () => {
|
|
60
|
+
const statement = first("for (let i = 0; i < 5; i++) { }");
|
|
61
|
+
expect(statement.kind).toBe(SyntaxKind.ForStatement);
|
|
62
|
+
expect(statement.condition.kind).toBe(SyntaxKind.BinaryExpression);
|
|
63
|
+
expect(statement.condition.operator).toBe("<");
|
|
64
|
+
});
|
|
65
|
+
it("parses object and array literals", () => {
|
|
66
|
+
const object = first("const o = { a: 1, b: 2, c };").declarationList.declarations[0].initializer;
|
|
67
|
+
expect(object.kind).toBe(SyntaxKind.ObjectLiteralExpression);
|
|
68
|
+
expect(object.properties.map((p) => p.kind)).toEqual([
|
|
69
|
+
SyntaxKind.PropertyAssignment,
|
|
70
|
+
SyntaxKind.PropertyAssignment,
|
|
71
|
+
SyntaxKind.ShorthandPropertyAssignment,
|
|
72
|
+
]);
|
|
73
|
+
const array = first("const a = [1, 2, ...rest];").declarationList.declarations[0].initializer;
|
|
74
|
+
expect(array.kind).toBe(SyntaxKind.ArrayLiteralExpression);
|
|
75
|
+
expect(array.elements.map((e) => e.kind)).toEqual([
|
|
76
|
+
SyntaxKind.NumericLiteral,
|
|
77
|
+
SyntaxKind.NumericLiteral,
|
|
78
|
+
SyntaxKind.SpreadElement,
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
it("parses member access, calls and new expressions", () => {
|
|
82
|
+
const call = first("console.log(a.b[0]);").expression;
|
|
83
|
+
expect(call.kind).toBe(SyntaxKind.CallExpression);
|
|
84
|
+
expect(call.expression.kind).toBe(SyntaxKind.PropertyAccessExpression);
|
|
85
|
+
expect(call.arguments[0].kind).toBe(SyntaxKind.ElementAccessExpression);
|
|
86
|
+
const constructed = first("new Foo(1);").expression;
|
|
87
|
+
expect(constructed.kind).toBe(SyntaxKind.NewExpression);
|
|
88
|
+
expect(constructed.arguments).toHaveLength(1);
|
|
89
|
+
});
|
|
90
|
+
it("parses template literals with substitutions", () => {
|
|
91
|
+
const statement = first("const s = `a${x}b${y}c`;");
|
|
92
|
+
const template = statement.declarationList.declarations[0].initializer;
|
|
93
|
+
expect(template.kind).toBe(SyntaxKind.TemplateLiteral);
|
|
94
|
+
expect(template.spans).toHaveLength(2);
|
|
95
|
+
expect(template.spans[0].expression.kind).toBe(SyntaxKind.Identifier);
|
|
96
|
+
});
|
|
97
|
+
it("parses type-only declarations", () => {
|
|
98
|
+
expect(kindsOf("interface Point { x: number; y: number; }")).toEqual([SyntaxKind.InterfaceDeclaration]);
|
|
99
|
+
expect(kindsOf("type Id = string | number;")).toEqual([SyntaxKind.TypeAliasDeclaration]);
|
|
100
|
+
expect(kindsOf("enum Color { Red, Green }")).toEqual([SyntaxKind.EnumDeclaration]);
|
|
101
|
+
expect(kindsOf("class Box { value = 1; get() { return this.value; } }")).toEqual([
|
|
102
|
+
SyntaxKind.ClassDeclaration,
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
it("parses imports and exports", () => {
|
|
106
|
+
expect(kindsOf("import { a, b } from './m';")).toEqual([SyntaxKind.ImportDeclaration]);
|
|
107
|
+
expect(kindsOf("export function f() {}")).toEqual([SyntaxKind.FunctionDeclaration]);
|
|
108
|
+
expect(kindsOf("export default 1;")).toEqual([SyntaxKind.ExportAssignment]);
|
|
109
|
+
});
|
|
110
|
+
it("parses generic calls without consuming comparison operators", () => {
|
|
111
|
+
const statement = first("const r = identity<number>(1);");
|
|
112
|
+
const call = statement.declarationList.declarations[0].initializer;
|
|
113
|
+
expect(call.kind).toBe(SyntaxKind.CallExpression);
|
|
114
|
+
expect(call.typeArguments).toHaveLength(1);
|
|
115
|
+
});
|
|
116
|
+
it("parses nested generic types", () => {
|
|
117
|
+
const fn = first("function f(m: Map<string, Array<number>>): void {}");
|
|
118
|
+
expect(fn.parameters[0].type.kind).toBe(SyntaxKind.TypeReference);
|
|
119
|
+
});
|
|
120
|
+
it("parses conditional, mapped and function types", () => {
|
|
121
|
+
expect(kindsOf("type A = T extends string ? 1 : 2;")).toEqual([SyntaxKind.TypeAliasDeclaration]);
|
|
122
|
+
expect(kindsOf("type B = { [K in keyof T]: T[K] };")).toEqual([SyntaxKind.TypeAliasDeclaration]);
|
|
123
|
+
expect(kindsOf("type C = (a: number) => string;")).toEqual([SyntaxKind.TypeAliasDeclaration]);
|
|
124
|
+
});
|
|
125
|
+
it("applies automatic semicolon insertion", () => {
|
|
126
|
+
const statements = kindsOf("const a = 1\nconst b = 2\n");
|
|
127
|
+
expect(statements).toEqual([SyntaxKind.VariableStatement, SyntaxKind.VariableStatement]);
|
|
128
|
+
});
|
|
129
|
+
it("recovers from a stray token with a diagnostic", () => {
|
|
130
|
+
expect(errors("const = ;").length).toBeGreaterThan(0);
|
|
131
|
+
});
|
|
132
|
+
it("does not emit phantom diagnostics for valid arrow with as-expression", () => {
|
|
133
|
+
const { diagnostics } = parse("const f = (x: unknown) => (x as number) + 1;");
|
|
134
|
+
expect(diagnostics.filter((d) => d.category === "error")).toHaveLength(0);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=parser.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.test.js","sourceRoot":"","sources":["../../../tests/parser/parser.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAa,MAAM,wBAAwB,CAAC;AAE/D,uDAAuD;AACvD,SAAS,KAAK,CAAC,IAAY;IACzB,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,KAAK,CAAC,IAA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,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sEAAsE,EAAE,GAAG,EAAE;QAC9E,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAC9E,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xbintsc",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "xbintsc - a TypeScript binary compiler (TypeScript -> LLVM IR -> native binary)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"xbintsc": "./bin/xbintsc.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/src/index.d.ts",
|
|
13
|
+
"import": "./dist/src/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./driver": {
|
|
16
|
+
"types": "./dist/src/driver/index.d.ts",
|
|
17
|
+
"import": "./dist/src/driver/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"dist",
|
|
23
|
+
"runtime",
|
|
24
|
+
"scripts",
|
|
25
|
+
"bin",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"prepublishOnly": "npm run build",
|
|
31
|
+
"runtime": "node scripts/build-runtime.mjs",
|
|
32
|
+
"runtime:clean": "node -e \"require('fs').rmSync('build/runtime',{recursive:true,force:true})\"",
|
|
33
|
+
"xbintsc": "tsx src/cli/main.ts",
|
|
34
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"test:e2e": "vitest run tests/e2e",
|
|
38
|
+
"coverage": "vitest run --coverage"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.10.2",
|
|
42
|
+
"tsx": "^4.19.2",
|
|
43
|
+
"typescript": "^5.7.2",
|
|
44
|
+
"vitest": "^2.1.8"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Node.js compatibility extension for xbintsc.
|
|
3
|
+
*
|
|
4
|
+
* Compiled and linked only when the `node` extension is registered. Each
|
|
5
|
+
* builtin follows the runtime calling convention: (int32_t argc, xt_value *argv).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include "rt.h"
|
|
9
|
+
|
|
10
|
+
#include <stdio.h>
|
|
11
|
+
#include <stdlib.h>
|
|
12
|
+
|
|
13
|
+
xt_value xt_node_read_text_file(int32_t argc, xt_value *argv) {
|
|
14
|
+
if (argc < 1) return xt_undefined();
|
|
15
|
+
xt_value pathValue = xt_to_string(argv[0]);
|
|
16
|
+
const char *path = xt_string_data(pathValue);
|
|
17
|
+
if (!path) return xt_undefined();
|
|
18
|
+
|
|
19
|
+
FILE *file = fopen(path, "rb");
|
|
20
|
+
if (!file) {
|
|
21
|
+
fprintf(stderr, "xbintsc: cannot open '%s'\n", path);
|
|
22
|
+
return xt_undefined();
|
|
23
|
+
}
|
|
24
|
+
fseek(file, 0, SEEK_END);
|
|
25
|
+
long size = ftell(file);
|
|
26
|
+
fseek(file, 0, SEEK_SET);
|
|
27
|
+
if (size < 0) {
|
|
28
|
+
fclose(file);
|
|
29
|
+
return xt_undefined();
|
|
30
|
+
}
|
|
31
|
+
char *buffer = (char *)malloc((size_t)size + 1);
|
|
32
|
+
if (!buffer) {
|
|
33
|
+
fclose(file);
|
|
34
|
+
return xt_undefined();
|
|
35
|
+
}
|
|
36
|
+
size_t read = fread(buffer, 1, (size_t)size, file);
|
|
37
|
+
fclose(file);
|
|
38
|
+
buffer[read] = '\0';
|
|
39
|
+
xt_value result = xt_string_new(buffer, read);
|
|
40
|
+
free(buffer);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
package/runtime/rt.h
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime ABI.
|
|
3
|
+
*
|
|
4
|
+
* The runtime is the boundary between generated LLVM IR and the operating
|
|
5
|
+
* system. Every JavaScript value that flows through generated code is an
|
|
6
|
+
* `xt_value` (a 64-bit NaN-boxed word). The compiler emits calls into the
|
|
7
|
+
* functions declared here; linking `libxtrt.a` (or the object file) provides
|
|
8
|
+
* their implementations.
|
|
9
|
+
*
|
|
10
|
+
* Keeping the ABI in a single header lets the compiler, the runtime and any
|
|
11
|
+
* extension module (node/bun shims, ...) agree on representation without
|
|
12
|
+
* sharing implementation details.
|
|
13
|
+
*/
|
|
14
|
+
#ifndef xbintsc_RUNTIME_H
|
|
15
|
+
#define xbintsc_RUNTIME_H
|
|
16
|
+
|
|
17
|
+
#include <stddef.h>
|
|
18
|
+
#include <stdint.h>
|
|
19
|
+
|
|
20
|
+
#ifdef __cplusplus
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
typedef uint64_t xt_value;
|
|
25
|
+
|
|
26
|
+
/* Tag layout (top 16 bits). Values whose tag bits are not 0xFFF8.. are
|
|
27
|
+
* doubles, so ordinary numbers travel unboxed. */
|
|
28
|
+
#define XT_TAG_MASK 0xFFFF000000000000ULL
|
|
29
|
+
#define XT_NUMBER_MASK 0xFFF8000000000000ULL
|
|
30
|
+
|
|
31
|
+
#define XT_TAG_UNDEFINED 0xFFF8000000000000ULL
|
|
32
|
+
#define XT_TAG_NULL 0xFFF9000000000000ULL
|
|
33
|
+
#define XT_TAG_FALSE 0xFFFA000000000000ULL
|
|
34
|
+
#define XT_TAG_TRUE 0xFFFB000000000000ULL
|
|
35
|
+
#define XT_TAG_STRING 0xFFFC000000000000ULL
|
|
36
|
+
#define XT_TAG_OBJECT 0xFFFD000000000000ULL
|
|
37
|
+
#define XT_TAG_ARRAY 0xFFFE000000000000ULL
|
|
38
|
+
#define XT_TAG_FUNCTION 0xFFFF000000000000ULL
|
|
39
|
+
|
|
40
|
+
#define XT_PAYLOAD_MASK 0x0000FFFFFFFFFFFFULL
|
|
41
|
+
|
|
42
|
+
#define XT_IS_NUMBER(v) (((v) & XT_NUMBER_MASK) != XT_NUMBER_MASK)
|
|
43
|
+
#define XT_IS_TAGGED(v, tag) (((v) & XT_TAG_MASK) == (tag))
|
|
44
|
+
#define XT_IS_UNDEFINED(v) ((v) == XT_TAG_UNDEFINED)
|
|
45
|
+
#define XT_IS_NULL(v) ((v) == XT_TAG_NULL)
|
|
46
|
+
#define XT_IS_BOOL(v) (((v) & ~0x1ULL) == XT_TAG_FALSE)
|
|
47
|
+
#define XT_IS_STRING(v) XT_IS_TAGGED(v, XT_TAG_STRING)
|
|
48
|
+
#define XT_IS_OBJECT(v) XT_IS_TAGGED(v, XT_TAG_OBJECT)
|
|
49
|
+
#define XT_IS_ARRAY(v) XT_IS_TAGGED(v, XT_TAG_ARRAY)
|
|
50
|
+
#define XT_IS_FUNCTION(v) XT_IS_TAGGED(v, XT_TAG_FUNCTION)
|
|
51
|
+
#define XT_IS_HEAP(v) (((v) & XT_NUMBER_MASK) == XT_NUMBER_MASK)
|
|
52
|
+
|
|
53
|
+
#define XT_GET_PTR(v) ((void *)(uintptr_t)((v) & XT_PAYLOAD_MASK))
|
|
54
|
+
#define XT_FROM_PTR(tag, p) ((xt_value)((tag) | ((uintptr_t)(p) & XT_PAYLOAD_MASK)))
|
|
55
|
+
|
|
56
|
+
#define XT_UNDEFINED XT_TAG_UNDEFINED
|
|
57
|
+
#define XT_NULL XT_TAG_NULL
|
|
58
|
+
#define XT_FALSE XT_TAG_FALSE
|
|
59
|
+
#define XT_TRUE XT_TAG_TRUE
|
|
60
|
+
|
|
61
|
+
/* Double <-> value helpers. */
|
|
62
|
+
static inline xt_value xt_from_double(double d) {
|
|
63
|
+
xt_value v;
|
|
64
|
+
__builtin_memcpy(&v, &d, sizeof(v));
|
|
65
|
+
/* Canonicalise NaNs so they never collide with the tag space. */
|
|
66
|
+
if (!XT_IS_NUMBER(v)) {
|
|
67
|
+
double nan = 0.0 / 0.0;
|
|
68
|
+
__builtin_memcpy(&v, &nan, sizeof(v));
|
|
69
|
+
}
|
|
70
|
+
return v;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static inline double xt_to_double(xt_value v) {
|
|
74
|
+
double d;
|
|
75
|
+
__builtin_memcpy(&d, &v, sizeof(d));
|
|
76
|
+
return d;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* -- constructors -------------------------------------------------------- */
|
|
80
|
+
xt_value xt_undefined(void);
|
|
81
|
+
xt_value xt_null(void);
|
|
82
|
+
xt_value xt_bool(int b);
|
|
83
|
+
xt_value xt_number(double d);
|
|
84
|
+
xt_value xt_string_new(const char *data, size_t len);
|
|
85
|
+
xt_value xt_string_from_cstr(const char *data);
|
|
86
|
+
/** Raw UTF-8 bytes of a string value (NULL for non-strings); not NUL-safe. */
|
|
87
|
+
const char *xt_string_data(xt_value value);
|
|
88
|
+
int32_t xt_string_length_value(xt_value value);
|
|
89
|
+
|
|
90
|
+
/* -- function calling convention ----------------------------------------- */
|
|
91
|
+
/* Every compiled function has the signature:
|
|
92
|
+
* xt_value fn(xt_value env, int32_t argc, xt_value *argv);
|
|
93
|
+
* `env` carries captured values for closures (XT_UNDEFINED when there are
|
|
94
|
+
* none) and `argv` carries the actual arguments. */
|
|
95
|
+
typedef xt_value (*xt_code_fn)(xt_value env, int32_t argc, xt_value *argv);
|
|
96
|
+
|
|
97
|
+
xt_value xt_arg(int32_t argc, xt_value *argv, int32_t index);
|
|
98
|
+
xt_value xt_closure_new(void *fn, int32_t env_count, xt_value *env);
|
|
99
|
+
xt_value xt_closure_call(xt_value fn, int32_t argc, xt_value *argv);
|
|
100
|
+
xt_value xt_closure_env(xt_value fn, int32_t index);
|
|
101
|
+
int32_t xt_closure_arity(xt_value fn);
|
|
102
|
+
|
|
103
|
+
/* -- conversions ---------------------------------------------------------- */
|
|
104
|
+
int xt_truthy(xt_value v);
|
|
105
|
+
double xt_to_number(xt_value v);
|
|
106
|
+
xt_value xt_to_string(xt_value v);
|
|
107
|
+
xt_value xt_typeof(xt_value v);
|
|
108
|
+
|
|
109
|
+
/* -- arithmetic ----------------------------------------------------------- */
|
|
110
|
+
xt_value xt_add(xt_value a, xt_value b);
|
|
111
|
+
xt_value xt_sub(xt_value a, xt_value b);
|
|
112
|
+
xt_value xt_mul(xt_value a, xt_value b);
|
|
113
|
+
xt_value xt_div(xt_value a, xt_value b);
|
|
114
|
+
xt_value xt_mod(xt_value a, xt_value b);
|
|
115
|
+
xt_value xt_pow(xt_value a, xt_value b);
|
|
116
|
+
xt_value xt_neg(xt_value a);
|
|
117
|
+
xt_value xt_pos(xt_value a);
|
|
118
|
+
xt_value xt_bit_and(xt_value a, xt_value b);
|
|
119
|
+
xt_value xt_bit_or(xt_value a, xt_value b);
|
|
120
|
+
xt_value xt_bit_xor(xt_value a, xt_value b);
|
|
121
|
+
xt_value xt_bit_not(xt_value a);
|
|
122
|
+
xt_value xt_shl(xt_value a, xt_value b);
|
|
123
|
+
xt_value xt_shr(xt_value a, xt_value b);
|
|
124
|
+
xt_value xt_ushr(xt_value a, xt_value b);
|
|
125
|
+
|
|
126
|
+
/* -- comparison (returns a boolean value) --------------------------------- */
|
|
127
|
+
xt_value xt_lt(xt_value a, xt_value b);
|
|
128
|
+
xt_value xt_le(xt_value a, xt_value b);
|
|
129
|
+
xt_value xt_gt(xt_value a, xt_value b);
|
|
130
|
+
xt_value xt_ge(xt_value a, xt_value b);
|
|
131
|
+
xt_value xt_eq(xt_value a, xt_value b);
|
|
132
|
+
xt_value xt_ne(xt_value a, xt_value b);
|
|
133
|
+
xt_value xt_seq(xt_value a, xt_value b);
|
|
134
|
+
xt_value xt_sne(xt_value a, xt_value b);
|
|
135
|
+
xt_value xt_not(xt_value a);
|
|
136
|
+
|
|
137
|
+
/* -- objects -------------------------------------------------------------- */
|
|
138
|
+
xt_value xt_object_new(void);
|
|
139
|
+
xt_value xt_object_get(xt_value obj, xt_value key);
|
|
140
|
+
xt_value xt_object_get_cstr(xt_value obj, const char *key);
|
|
141
|
+
xt_value xt_object_set(xt_value obj, xt_value key, xt_value value);
|
|
142
|
+
xt_value xt_object_has(xt_value obj, xt_value key);
|
|
143
|
+
xt_value xt_object_keys(xt_value obj);
|
|
144
|
+
|
|
145
|
+
/* -- arrays --------------------------------------------------------------- */
|
|
146
|
+
xt_value xt_array_new(int32_t count, xt_value *items);
|
|
147
|
+
xt_value xt_array_get(xt_value arr, xt_value index);
|
|
148
|
+
xt_value xt_array_set(xt_value arr, xt_value index, xt_value value);
|
|
149
|
+
xt_value xt_array_push(xt_value arr, xt_value value);
|
|
150
|
+
xt_value xt_array_length(xt_value arr);
|
|
151
|
+
xt_value xt_array_spread(xt_value target, xt_value source);
|
|
152
|
+
|
|
153
|
+
/* -- generic member access ------------------------------------------------ */
|
|
154
|
+
xt_value xt_get(xt_value target, xt_value key);
|
|
155
|
+
xt_value xt_set(xt_value target, xt_value key, xt_value value);
|
|
156
|
+
|
|
157
|
+
/* -- boxes (used for captured variables) ---------------------------------- */
|
|
158
|
+
xt_value xt_box_new(xt_value value);
|
|
159
|
+
xt_value xt_box_get(xt_value box);
|
|
160
|
+
xt_value xt_box_set(xt_value box, xt_value value);
|
|
161
|
+
xt_value xt_is_nullish(xt_value value);
|
|
162
|
+
|
|
163
|
+
/* -- exceptions / output -------------------------------------------------- */
|
|
164
|
+
void xt_throw(xt_value v);
|
|
165
|
+
void xt_console_log(int32_t argc, xt_value *argv);
|
|
166
|
+
void xt_print(xt_value v);
|
|
167
|
+
void xt_println(xt_value v);
|
|
168
|
+
|
|
169
|
+
/* -- diagnostics ---------------------------------------------------------- */
|
|
170
|
+
size_t xt_heap_bytes(void);
|
|
171
|
+
size_t xt_heap_allocations(void);
|
|
172
|
+
|
|
173
|
+
#ifdef __cplusplus
|
|
174
|
+
}
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
#endif /* xbintsc_RUNTIME_H */
|