xbintsc 0.3.35 → 0.3.49
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/AGENTS.md +95 -0
- package/README.md +31 -3
- package/README.zh-CN.md +23 -0
- package/dist/src/cli/hints.d.ts +54 -0
- package/dist/src/cli/hints.js +165 -0
- package/dist/src/cli/hints.js.map +1 -0
- package/dist/src/cli/main.js +73 -9
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/module.js +10 -0
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +4 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +26 -0
- package/dist/src/codegen/generator/tables.js +64 -12
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +22 -0
- package/dist/src/diagnostics/source-text.js +76 -0
- package/dist/src/diagnostics/source-text.js.map +1 -0
- package/dist/src/driver/bundler/graph.js +2 -1
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/compiler.js +3 -2
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/lexer/scanner/strings.js +16 -3
- package/dist/src/lexer/scanner/strings.js.map +1 -1
- package/dist/tests/cli/hints.test.d.ts +9 -0
- package/dist/tests/cli/hints.test.js +143 -0
- package/dist/tests/cli/hints.test.js.map +1 -0
- package/dist/tests/cli/main.test.js +6 -4
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +17 -2
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/e2e/gc.test.d.ts +1 -0
- package/dist/tests/e2e/gc.test.js +168 -0
- package/dist/tests/e2e/gc.test.js.map +1 -0
- package/dist/tests/e2e/harness.d.ts +2 -0
- package/dist/tests/e2e/harness.js +1 -0
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/helpers.js +3 -2
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/lexer/strings.test.js +14 -2
- package/dist/tests/lexer/strings.test.js.map +1 -1
- package/doc/DESIGN.md +117 -0
- package/doc/ai/README.md +63 -0
- package/doc/ai/build-recipe.md +137 -0
- package/doc/ai/cli.md +142 -0
- package/doc/ai/contributing.md +196 -0
- package/doc/ai/extensions.md +148 -0
- package/doc/ai/language-support.md +152 -0
- package/doc/ai/troubleshooting.md +163 -0
- package/doc/ai/zh-CN/README.md +56 -0
- package/doc/ai/zh-CN/build-recipe.md +132 -0
- package/doc/ai/zh-CN/cli.md +127 -0
- package/doc/ai/zh-CN/contributing.md +173 -0
- package/doc/ai/zh-CN/extensions.md +139 -0
- package/doc/ai/zh-CN/language-support.md +147 -0
- package/doc/ai/zh-CN/troubleshooting.md +150 -0
- package/doc/gui-scripts.md +350 -0
- package/doc/gui.md +646 -0
- package/doc/icon.md +265 -0
- package/doc/implemented.md +373 -0
- package/doc/node-implemented.md +588 -0
- package/doc/node-unimplemented.md +167 -0
- package/doc/post/announce.md +43 -0
- package/doc/requirements.md +145 -0
- package/doc/unimplemented.md +286 -0
- package/doc/xbintsc.config.schema.json +67 -0
- package/doc/zh-CN/DESIGN.md +104 -0
- package/doc/zh-CN/gui-scripts.md +329 -0
- package/doc/zh-CN/gui.md +588 -0
- package/doc/zh-CN/icon.md +241 -0
- package/doc/zh-CN/implemented.md +365 -0
- package/doc/zh-CN/node-implemented.md +533 -0
- package/doc/zh-CN/node-unimplemented.md +141 -0
- package/doc/zh-CN/plan-require-node-modules.md +284 -0
- package/doc/zh-CN/post/announce.md +47 -0
- package/doc/zh-CN/requirements.md +134 -0
- package/doc/zh-CN/unimplemented.md +247 -0
- package/llms.txt +45 -0
- package/package.json +6 -2
- package/runtime/ext_gui/dom_api_proto.cpp +5 -0
- package/runtime/ext_gui/gui.cpp +3 -1
- package/runtime/ext_gui/renderer.cpp +13 -11
- package/runtime/ext_gui/renderer_image.cpp +12 -8
- package/runtime/ext_gui/renderer_shaders.h +131 -4
- package/runtime/ext_gui/renderer_shaders_data.h +1809 -0
- package/runtime/ext_gui/renderer_text.cpp +12 -8
- package/runtime/ext_gui/shaders.hlsl +98 -0
- package/runtime/ext_gui/spirv/fill.frag +19 -0
- package/runtime/ext_gui/spirv/fill.vert +42 -0
- package/runtime/ext_gui/spirv/image.frag +16 -0
- package/runtime/ext_gui/spirv/quad.vert +30 -0
- package/runtime/ext_gui/spirv/text.frag +16 -0
- package/runtime/ext_gui/window.cpp +1 -0
- package/runtime/ext_node/buffer/parts/prototype.inc +1 -0
- package/runtime/ext_node/dgram/dgram.c +1 -0
- package/runtime/ext_node/events/events.c +1 -0
- package/runtime/ext_node/fs/fs_ops.c +10 -25
- package/runtime/ext_node/fs/glob.c +13 -30
- package/runtime/ext_node/fs/promises.c +1 -0
- package/runtime/ext_node/http/parts/prototypes.inc +5 -0
- package/runtime/ext_node/net/parts/prototypes.inc +2 -0
- package/runtime/ext_node/process/process.c +9 -7
- package/runtime/ext_node/stream/stream.c +1 -0
- package/runtime/ext_node/util/util.c +6 -6
- package/runtime/rt.h +10 -0
- package/runtime/rt_internal.h +63 -2
- package/runtime/xt_alloc.c +442 -5
- package/runtime/xt_generator.c +95 -1
- package/runtime/xt_loop.c +35 -1
- package/runtime/xt_promise.c +46 -0
- package/runtime/xt_stdlib2/error.inc +1 -0
- package/runtime/xt_stdlib2/regexp-match.inc +8 -7
- package/runtime/xt_symbol.c +2 -0
- package/runtime/xt_typed_array/construction.inc +142 -0
- package/runtime/xt_typed_array/elements.inc +92 -0
- package/runtime/xt_typed_array/methods.inc +329 -0
- package/runtime/xt_typed_array.c +6 -548
- package/runtime/xt_values/number-format.inc +26 -0
- package/scripts/build-gui-shaders.mjs +204 -0
- package/scripts/build-gui.ts +35 -0
- package/scripts/check-file-length.ts +89 -0
- package/src/cli/hints.ts +194 -0
- package/src/cli/main.ts +82 -9
- package/src/codegen/generator/module.ts +10 -0
- package/src/codegen/generator/state.ts +4 -0
- package/src/codegen/generator/tables.ts +60 -14
- package/src/diagnostics/source-text.ts +78 -0
- package/src/driver/bundler/graph.ts +2 -1
- package/src/driver/compiler.ts +3 -2
- package/src/lexer/scanner/strings.ts +16 -3
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Extensions: Node modules, GUI, C++/Rust libraries
|
|
2
|
+
|
|
3
|
+
The compiler core is platform-agnostic. Anything platform-specific — Node's
|
|
4
|
+
`fs`, an HTML/CSS renderer, your own C++ library — arrives as an **extension**
|
|
5
|
+
that contributes module bindings plus the C/C++ sources or objects to link.
|
|
6
|
+
|
|
7
|
+
## The rule that trips people up
|
|
8
|
+
|
|
9
|
+
**An import of an extension-provided module fails until the extension is
|
|
10
|
+
enabled.** xbintsc knows the module exists and says exactly what to pass:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
$ xbintsc run app.ts # app.ts: import { readFileSync } from "fs";
|
|
14
|
+
error TS6001: module 'fs' is provided by the 'node' extension; pass --ext node
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
xbintsc run app.ts --ext node
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Enable several at once with a comma-separated list: `--ext node,gui`. In a
|
|
22
|
+
project, put them in `xbintsc.config.json` so no flag is needed:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{ "entry": "src/app.ts", "outDir": "build", "extensions": ["node"] }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Bundled extensions
|
|
29
|
+
|
|
30
|
+
### `node` — Node built-in modules
|
|
31
|
+
|
|
32
|
+
Enable with `--ext node`. A module is importable by its bare name or the
|
|
33
|
+
`node:` prefix (`import { readFileSync } from "node:fs"`), and both spellings
|
|
34
|
+
resolve to the same implementation.
|
|
35
|
+
|
|
36
|
+
| Module | Notes |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `fs` | **synchronous API only** (`readFileSync`, `writeFileSync`, …); `fs/promises` is separate |
|
|
39
|
+
| `fs/promises` | promise-based file APIs |
|
|
40
|
+
| `path` | also hooks namespace dispatch, so `path.join(...)` works |
|
|
41
|
+
| `os` | |
|
|
42
|
+
| `process` | `process.cwd()`, `argv`, `env`, …; namespace dispatch too |
|
|
43
|
+
| `buffer` | |
|
|
44
|
+
| `crypto` | |
|
|
45
|
+
| `stream`, `stream/promises` | |
|
|
46
|
+
| `events` | |
|
|
47
|
+
| `net`, `dgram`, `http` | sockets and servers on the xbintsc event loop (see the async caveat below) |
|
|
48
|
+
| `child_process` | |
|
|
49
|
+
| `worker_threads` | |
|
|
50
|
+
| `util`, `querystring`, `url`, `assert`, `test`, `zlib` | |
|
|
51
|
+
|
|
52
|
+
Coverage per module (exact functions and options) is in
|
|
53
|
+
[../node-implemented.md](../node-implemented.md); what is missing is in
|
|
54
|
+
[../node-unimplemented.md](../node-unimplemented.md).
|
|
55
|
+
|
|
56
|
+
Remember the runtime model before building on `net`/`http`: the event loop runs
|
|
57
|
+
**after** the program body, and `async`/`await` is a synchronous microtask
|
|
58
|
+
model. See [language-support.md](./language-support.md).
|
|
59
|
+
|
|
60
|
+
### `gui` — HTML/CSS window
|
|
61
|
+
|
|
62
|
+
Enable with `--ext gui` and import the `gui` module:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { createWindow, run } from "gui";
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
It is a self-contained GPU-accelerated renderer (own HTML parser, CSS cascade,
|
|
69
|
+
layout and compositor) — not a system WebView. It ships as a per-platform
|
|
70
|
+
prebuilt `gui.a`/`gui.lib` because it is C++. If that archive is missing for
|
|
71
|
+
your platform, the build fails with an actionable message; design and roadmap
|
|
72
|
+
live in [../gui.md](../gui.md), and the scripting surface in
|
|
73
|
+
[../gui-scripts.md](../gui-scripts.md).
|
|
74
|
+
|
|
75
|
+
## Third-party npm packages
|
|
76
|
+
|
|
77
|
+
Bare specifiers that no enabled extension claims are looked up in `node_modules`
|
|
78
|
+
and bundled **as source**. A package that is not plain ESM TypeScript/JavaScript
|
|
79
|
+
— or that relies on CommonJS, `require`, `__dirname`, or circular dependencies —
|
|
80
|
+
will not work. `require()` is rejected with a hint to convert to `import`.
|
|
81
|
+
|
|
82
|
+
Practical consequence: for a Node program, enabling `--ext node` is usually the
|
|
83
|
+
right answer; reach for an npm dependency only when you must.
|
|
84
|
+
|
|
85
|
+
## Native extensions (C++ / Rust, no compiler changes)
|
|
86
|
+
|
|
87
|
+
Any code that exposes `extern "C"` entry points with the runtime ABI can be
|
|
88
|
+
linked in:
|
|
89
|
+
|
|
90
|
+
```c
|
|
91
|
+
xt_value my_fn(int32_t argc, xt_value *argv);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Build it with an **external** toolchain (clang++ or cargo), describe the
|
|
95
|
+
artifacts in a JSON manifest, and pass the manifest:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
xbintsc build demo.ts --ext-native ./xbintsc.manifest.json
|
|
99
|
+
xbintsc build demo.ts --ext-native a.json,b.json # several
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```jsonc
|
|
103
|
+
{
|
|
104
|
+
"name": "mathx-cpp", // required, unique
|
|
105
|
+
"objects": ["build/mathx.o"], // .o / .a / .lib, relative to this file
|
|
106
|
+
"linkerFlagsByPlatform": { // C++/Rust runtimes
|
|
107
|
+
"linux": ["-lstdc++", "-lm"],
|
|
108
|
+
"darwin": ["-lc++"],
|
|
109
|
+
"win32": ["-lmsvcprt"]
|
|
110
|
+
},
|
|
111
|
+
"builtins": { "cppClamp": { "symbol": "mathx_clamp" } }, // no import needed
|
|
112
|
+
"modules": {
|
|
113
|
+
"mathx": { "exports": { "add": { "symbol": "mathx_add" } } }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`import { add } from "mathx"` then lowers to the native symbol exactly like a C
|
|
119
|
+
runtime binding; `builtins` are globally callable without importing.
|
|
120
|
+
|
|
121
|
+
Authoring helpers: `runtime/xt_ext.h` (C/C++) and `runtime/xt_ext.rs` (Rust) —
|
|
122
|
+
they wrap the argument and value helpers. Key ABI facts: values are 64-bit
|
|
123
|
+
NaN-boxed words; strings are **not** NUL-terminated, so pair `xt_string_data`
|
|
124
|
+
with `xt_string_length_value`; the runtime never moves or frees memory it handed
|
|
125
|
+
out. Build with the same clang/ABI that xbintsc resolves (`xbintsc doctor`
|
|
126
|
+
prints it), and on Windows build inside an **x64/ARM64 Native Tools Command
|
|
127
|
+
Prompt**.
|
|
128
|
+
|
|
129
|
+
Working projects to copy: [`examples/extensions/cpp`](../../examples/extensions/cpp)
|
|
130
|
+
and [`examples/extensions/rust`](../../examples/extensions/rust); the full guide
|
|
131
|
+
is [../../examples/extensions/README.md](../../examples/extensions/README.md).
|
|
132
|
+
|
|
133
|
+
## Programmatic registration
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { build, createDefaultRegistry, nativeExtensionFromManifest, nodeExtension } from "xbintsc";
|
|
137
|
+
|
|
138
|
+
const extensions = createDefaultRegistry()
|
|
139
|
+
.register(nodeExtension)
|
|
140
|
+
.register(nativeExtensionFromManifest("./xbintsc.manifest.json"));
|
|
141
|
+
|
|
142
|
+
build("demo.ts", { extensions });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The registry is also how a host tool hints at a disabled extension, which is what
|
|
146
|
+
produces the "pass `--ext node`" message instead of a confusing downstream error
|
|
147
|
+
([../../src/extensions/catalog.ts](../../src/extensions/catalog.ts)). The list of
|
|
148
|
+
bundled extensions is `bundledExtensions()`.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Language support: what compiles, what behaves differently
|
|
2
|
+
|
|
3
|
+
xbintsc compiles a **practical subset** of TypeScript. Use this page to decide
|
|
4
|
+
what you can write; follow the links for exact wording.
|
|
5
|
+
|
|
6
|
+
Canonical detail (always current, much longer):
|
|
7
|
+
|
|
8
|
+
- [../implemented.md](../implemented.md) — everything that works, by compiler stage
|
|
9
|
+
- [../unimplemented.md](../unimplemented.md) — unsupported syntax, deviations, quick reference
|
|
10
|
+
- [../node-implemented.md](../node-implemented.md) / [../node-unimplemented.md](../node-unimplemented.md) — the Node extension
|
|
11
|
+
|
|
12
|
+
> Chinese: [../zh-CN/implemented.md](../zh-CN/implemented.md), [../zh-CN/unimplemented.md](../zh-CN/unimplemented.md)
|
|
13
|
+
|
|
14
|
+
## Legend
|
|
15
|
+
|
|
16
|
+
| Mark | Meaning |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| ✅ | Works as in Node/TypeScript |
|
|
19
|
+
| ⚠️ | Works but deviates from the standard |
|
|
20
|
+
| 🚫 | Rejected — parse error or `UnsupportedFeature` |
|
|
21
|
+
| — | Parsed and erased, with no runtime effect |
|
|
22
|
+
|
|
23
|
+
## Statements and declarations
|
|
24
|
+
|
|
25
|
+
| Feature | Status | Notes |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| `var` / `let` / `const`, blocks, `if`, `for`, `for...of`, `for...in`, `while`, `do...while` | ✅ | `for...in` enumerates own keys only (no prototype chain) |
|
|
28
|
+
| `switch`, `break`, `continue`, labels | ✅ | labeled `break`/`continue` included |
|
|
29
|
+
| `try` / `catch` / `finally`, `throw` | ✅ | `finally` runs on early `return`/`break`/`continue` |
|
|
30
|
+
| `function`, arrow functions, default/rest parameters | ✅ | |
|
|
31
|
+
| `return`, `throw` as expressions' operands | ✅ | |
|
|
32
|
+
| `namespace` / `module` declaration | 🚫 | parse ✓, codegen ✗ |
|
|
33
|
+
| `with`, `debugger` | 🚫 | not supported |
|
|
34
|
+
| Top-level `await` | 🚫 | wrap it in an `async` function |
|
|
35
|
+
|
|
36
|
+
## Expressions and operators
|
|
37
|
+
|
|
38
|
+
| Feature | Status | Notes |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| Arithmetic, bitwise, logical, comparison, assignment operators | ✅ | ES `ToPrimitive` / `+` coercion match Node |
|
|
41
|
+
| `===` / `!==` / `==` / `!=` | ✅ | loose equality matches Node |
|
|
42
|
+
| Optional chaining `?.`, nullish `??`, logical assignment `??=` | ✅ | whole-chain short-circuit implemented |
|
|
43
|
+
| Template literals, tagged templates | ✅ | tagged templates have `raw` + `String.raw` |
|
|
44
|
+
| Spread / rest in calls, arrays and object literals | ✅ | |
|
|
45
|
+
| Destructuring (bindings, parameters, nested) | ✅ | defaults + rest supported |
|
|
46
|
+
| `delete`, `in`, `instanceof`, `typeof` | ✅ | |
|
|
47
|
+
| Comma operator, `void` | ✅ | |
|
|
48
|
+
| `new.target` | 🚫 | not implemented |
|
|
49
|
+
| `import.meta` | 🚫 | parsed but has no value |
|
|
50
|
+
| `super` | ⚠️ | single-level inheritance correct; depth > 1 may be inaccurate |
|
|
51
|
+
|
|
52
|
+
## Functions, classes, objects
|
|
53
|
+
|
|
54
|
+
| Feature | Status | Notes |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| Closures (capture by reference through boxes) | ✅ | one ABI for direct and closure calls |
|
|
57
|
+
| `this`, method calls, arrow lexical `this` | ✅ | arrow functions get their own `arguments`, unlike JS |
|
|
58
|
+
| `call` / `apply` / `bind`, `fn.name` / `fn.length` | ✅ | a bound closure does not track partial-argument `length` |
|
|
59
|
+
| First-class built-in methods (`arr.map` as a value) | ✅ | exposed as *unbound* method values; a detached call throws like JS |
|
|
60
|
+
| `fn.toString()` | ⚠️ | returns `function name() { [native code] }`, not the source text |
|
|
61
|
+
| Classes: fields, methods, statics, getters/setters, `extends`/`super`, `instanceof` | ✅ | |
|
|
62
|
+
| Constructor parameter properties `constructor(public x: T)` | ✅ | |
|
|
63
|
+
| `#private` fields / methods / statics | ⚠️ | stored under a literal `#x` key; no access enforcement; parent/child name collisions may alias |
|
|
64
|
+
| `enum` / `const enum` | ✅ | forward + reverse mapping |
|
|
65
|
+
| `private` / `protected` / `public` / `readonly` / `abstract` / `implements` | — | erased, no access control |
|
|
66
|
+
| Generators `function*`, `yield`, `yield*` | ✅ | `async` generators are not supported |
|
|
67
|
+
| `arguments` object | ✅ | implicit; arrows see their own parameters |
|
|
68
|
+
| Argument-count validation | 🚫 | never checked, though `fn.length` reports declared arity |
|
|
69
|
+
|
|
70
|
+
## Async, Promises, event loop
|
|
71
|
+
|
|
72
|
+
| Feature | Status | Notes |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| `async` / `await`, `Promise`, `Promise.all` | ⚠️ | **synchronous microtask model** — `await` on a settled promise continues synchronously |
|
|
75
|
+
| `setTimeout` and callbacks | ⚠️ | the event loop runs **after** the program body, so a promise settled from a timer cannot be awaited |
|
|
76
|
+
| Sockets / servers (`http`, `net`, `dgram`) | ⚠️ | same model: callbacks run on the event loop after the program body |
|
|
77
|
+
| A real async event loop, worker threads | 🚫 | not implemented |
|
|
78
|
+
|
|
79
|
+
## Types: parsed, then erased
|
|
80
|
+
|
|
81
|
+
**No type checking happens.** Type syntax is parsed into the AST and erased
|
|
82
|
+
during binding/codegen:
|
|
83
|
+
|
|
84
|
+
| Construct | Status |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| Type annotations, return types, type aliases, interfaces | — parsed, erased, never checked |
|
|
87
|
+
| Generic type parameters and constraints | — no runtime instantiation |
|
|
88
|
+
| `as`, `satisfies`, non-null `!` | — erased, no assertion semantics |
|
|
89
|
+
| Optional-chaining type narrowing | 🚫 |
|
|
90
|
+
| Diagnostics `TS4001`–`TS4004` (`TypeMismatch`, `NotCallable`, `PropertyNotFound`, `ArgumentCountMismatch`) | 🚫 defined but never emitted |
|
|
91
|
+
|
|
92
|
+
A type error in your source is therefore not a compile error — only runtime
|
|
93
|
+
behaviour is checked. Write the runtime code you mean.
|
|
94
|
+
|
|
95
|
+
## Standard library
|
|
96
|
+
|
|
97
|
+
Implemented: `Math`, `JSON`, `Date`, `RegExp`, `Map`, `Set`, `WeakMap`/`WeakSet`,
|
|
98
|
+
`Symbol`, `Error` family, `BigInt`, `Array`/`String`/`Number`/`Object` methods,
|
|
99
|
+
typed arrays, `String.prototype.match`/`split`/`replace` with capture groups,
|
|
100
|
+
immutable array helpers (`toReversed`, `toSorted`, `toSpliced`, `with`), global
|
|
101
|
+
URI functions.
|
|
102
|
+
|
|
103
|
+
| Missing or different | Status |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `String.prototype.normalize`, `structuredClone` | 🚫 |
|
|
106
|
+
| `Error.stack` capture | 🚫 (not captured) |
|
|
107
|
+
| `Object.getPrototypeOf({})` | ⚠️ returns `undefined`, not `Object.prototype` |
|
|
108
|
+
| Global RegExp `lastIndex` | ⚠️ `test`/`exec` ignore it for `/g` and `/y` |
|
|
109
|
+
| Sparse array holes, array out-of-bounds | ⚠️ holes are not tracked distinctly; out-of-bounds reads give `undefined` |
|
|
110
|
+
|
|
111
|
+
See section 3 of [../unimplemented.md](../unimplemented.md) for the full list.
|
|
112
|
+
|
|
113
|
+
## Modules
|
|
114
|
+
|
|
115
|
+
| Feature | Status | Notes |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| ESM `import` / `export` | ✅ | |
|
|
118
|
+
| Relative multi-file bundling | ✅ | a `./helper.js` specifier resolves to `helper.ts` |
|
|
119
|
+
| `import * as ns`, default and named imports | ✅ | |
|
|
120
|
+
| Node built-in modules | ✅ | only with `--ext node` — see [extensions.md](./extensions.md) |
|
|
121
|
+
| Bare third-party npm packages | 🚫 | `node_modules` ESM packages are bundled as source only when no extension claims the specifier |
|
|
122
|
+
| `require()` / CommonJS | 🚫 | rejected with a hint to use `import` |
|
|
123
|
+
| Circular dependencies | 🚫 | |
|
|
124
|
+
| Live bindings | ⚠️ | imports and namespace members are snapshots |
|
|
125
|
+
| `import.meta`, `__dirname`, `__filename` | 🚫 | |
|
|
126
|
+
|
|
127
|
+
## Strings, numbers, memory
|
|
128
|
+
|
|
129
|
+
| Item | Behaviour |
|
|
130
|
+
| --- | --- |
|
|
131
|
+
| `String.prototype.length` | ⚠️ **UTF-8 bytes**, not UTF-16 units: `"é".length === 1`, `"😀".length === 4`; `codePointAt` differs accordingly |
|
|
132
|
+
| Number formatting and coercion | ✅ matches Node (`toFixed`, `toPrecision`, hex/octal/binary parsing) |
|
|
133
|
+
| `BigInt` | ✅ implemented |
|
|
134
|
+
| Garbage collection | ✅ non-moving mark-sweep; explicit roots plus a conservative C-stack scan; single-threaded and stop-the-world; no weak references |
|
|
135
|
+
| Threads | 🚫 single-threaded; `worker_threads` exists in the Node extension only |
|
|
136
|
+
|
|
137
|
+
## Platform
|
|
138
|
+
|
|
139
|
+
Builds target macOS, Linux and Windows on x64 and arm64. On Windows the target
|
|
140
|
+
is the **MSVC ABI**, so clang needs the MSVC/SDK environment — see
|
|
141
|
+
[../requirements.md](../requirements.md). clang **16 or newer** is required.
|
|
142
|
+
|
|
143
|
+
## Before you write a large program
|
|
144
|
+
|
|
145
|
+
1. Skim the table for the features you plan to use; open
|
|
146
|
+
[../unimplemented.md](../unimplemented.md) for anything marked ⚠️ or 🚫.
|
|
147
|
+
2. Prototype with `xbintsc emit app.ts` — the cheapest way to learn whether a
|
|
148
|
+
construct is supported, since it needs no clang.
|
|
149
|
+
3. Run the real thing with `xbintsc run app.ts`. If a build fails, go to
|
|
150
|
+
[troubleshooting.md](./troubleshooting.md).
|
|
151
|
+
4. When exact Node behaviour matters, run the same program under Node and
|
|
152
|
+
compare output; the project's own test suite does this differential check.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
Start with the command that shows what xbintsc actually resolved:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
xbintsc doctor
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It prints the platform, the toolchain it will use (and where it came from), the
|
|
10
|
+
compiler version, the runtime directory, the runtime library directory and the
|
|
11
|
+
icon resource compiler. Most "it doesn't work" reports are answered here.
|
|
12
|
+
|
|
13
|
+
## Before anything else: is clang new enough?
|
|
14
|
+
|
|
15
|
+
**clang/LLVM 16 or newer is required.** Older clang rejects the emitted IR with a
|
|
16
|
+
typed-pointer error:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
D:\...\build\app.ll:382:37: error: '@.str.0' defined with type '[6 x i8]*' but expected 'i8*'
|
|
20
|
+
%r0 = call i64 @xt_string_new(i8* @.str.0, i64 5)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The compiler emits LLVM IR that relies on opaque pointers; typed pointers were
|
|
24
|
+
removed in LLVM 16 ([LLVM release notes](https://github.com/llvm/llvm-project/blob/release/15.x/llvm/docs/ReleaseNotes.rst#changes-to-the-llvm-ir)).
|
|
25
|
+
Confirm with `clang --version`; if the machine has an old system clang, install a
|
|
26
|
+
newer LLVM and point xbintsc at it:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
export xbintsc_CLANG=/usr/lib/llvm-18/bin/clang # PowerShell: $env:xbintsc_CLANG = "C:\Program Files\LLVM\bin\clang.exe"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Note that front-end-only work (`xbintsc emit`) never needs clang, so it keeps
|
|
33
|
+
working on an old toolchain.
|
|
34
|
+
|
|
35
|
+
## Error messages and what they mean
|
|
36
|
+
|
|
37
|
+
### `module '…' is provided by the 'node' extension; pass --ext node`
|
|
38
|
+
|
|
39
|
+
The program imports a Node module but the extension is off. Add the flag, or put
|
|
40
|
+
it in `xbintsc.config.json` so it is always on:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
xbintsc run app.ts --ext node
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### `module '<pkg>' is not supported: xbintsc can import built-in platform modules, relative '.ts' files and ESM packages under node_modules; CommonJS packages are not supported`
|
|
47
|
+
|
|
48
|
+
A bare third-party import that nothing can link. Either the package is CommonJS
|
|
49
|
+
(unsupported), or it is an ESM package that failed to bundle. Prefer a Node
|
|
50
|
+
built-in from the `node` extension; see [extensions.md](./extensions.md) for
|
|
51
|
+
what can actually be bundled.
|
|
52
|
+
|
|
53
|
+
### ``CommonJS `require()` is not supported``
|
|
54
|
+
|
|
55
|
+
Convert to ESM: `const fs = require("fs")` becomes `import fs from "fs"` (plus
|
|
56
|
+
`--ext node`). `require` inside `node_modules` packages *is* handled by the
|
|
57
|
+
bundler; it is only rejected in your own source. `require(<non-literal>)` is
|
|
58
|
+
never supported.
|
|
59
|
+
|
|
60
|
+
### `error TS4005: xbintsc does not yet support this <construct>`
|
|
61
|
+
|
|
62
|
+
The syntax is parsed but codegen does not implement it. Check
|
|
63
|
+
[language-support.md](./language-support.md) and
|
|
64
|
+
[../unimplemented.md](../unimplemented.md), then rewrite the construct (or
|
|
65
|
+
contribute support). `namespace` declarations and `new.target` are the common
|
|
66
|
+
ones.
|
|
67
|
+
|
|
68
|
+
### `error TS2xxx` (parser) or `error TS1xxx` (lexer)
|
|
69
|
+
|
|
70
|
+
A syntax error in the source. The diagnostic prints the file, line, column, the
|
|
71
|
+
offending line and a caret. Note that xbintsc's parser accepts most TypeScript,
|
|
72
|
+
so a parse error usually means genuinely broken syntax rather than an
|
|
73
|
+
unsupported feature.
|
|
74
|
+
|
|
75
|
+
### `error TS6001: Cannot resolve module './x' from '<file>'` / `Cannot find module`
|
|
76
|
+
|
|
77
|
+
A relative import that does not resolve. A `./helper.js` specifier maps to
|
|
78
|
+
`helper.ts`, so import the runtime path you actually wrote in TypeScript.
|
|
79
|
+
|
|
80
|
+
### `Cannot resolve module '…' required from '<file>'`
|
|
81
|
+
|
|
82
|
+
A `require(...)` inside a bundled `node_modules` package that could not be
|
|
83
|
+
resolved. The package is not usable as-is; prefer the built-in or a different
|
|
84
|
+
dependency.
|
|
85
|
+
|
|
86
|
+
### `xbintsc: <config path>: invalid JSON (…)` / `Unable to read …`
|
|
87
|
+
|
|
88
|
+
The project config or a native extension manifest is malformed or missing. Fix
|
|
89
|
+
the JSON, or bypass discovery with `--no-config` / `--config <path>`.
|
|
90
|
+
|
|
91
|
+
### `error TS6003` / `Command failed (N): clang …`
|
|
92
|
+
|
|
93
|
+
clang itself failed. The thrown message includes the full clang command and its
|
|
94
|
+
stderr — read the stderr, not just the first line. Frequent causes:
|
|
95
|
+
|
|
96
|
+
- the toolchain is too old (see above);
|
|
97
|
+
- on Windows, clang cannot find the MSVC/SDK headers or libraries because the
|
|
98
|
+
environment was not imported. Run from an **x64 Native Tools Command Prompt
|
|
99
|
+
for VS 2022** (or **ARM64 Native Tools** on Windows on ARM), or import it
|
|
100
|
+
first:
|
|
101
|
+
```powershell
|
|
102
|
+
& "$env:ProgramFiles\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
|
|
103
|
+
```
|
|
104
|
+
- the linker is wrong on Linux — set `xbintsc_CLANG` and/or pass
|
|
105
|
+
`xbintsc_LINKER_ARGS=-fuse-ld=lld`;
|
|
106
|
+
- `No C compiler found. Set xbintsc_CLANG to a clang binary.` — no clang on
|
|
107
|
+
`PATH` at all.
|
|
108
|
+
|
|
109
|
+
### `GUI native library not found at …`
|
|
110
|
+
|
|
111
|
+
The `gui` extension needs its per-platform prebuilt `gui.a`/`gui.lib`, which is
|
|
112
|
+
not built in a plain source checkout. Drop `--ext gui`, or build the archive as
|
|
113
|
+
described in [../gui.md](../gui.md).
|
|
114
|
+
|
|
115
|
+
### `Icon file not found` / icon tools missing
|
|
116
|
+
|
|
117
|
+
`--icon`/`app.icon` paths resolve against the config file's directory. On
|
|
118
|
+
Windows, embedding a PE icon needs `llvm-rc` or `windres`; `doctor` reports which
|
|
119
|
+
one was found, and a missing one is only fatal when an icon was requested.
|
|
120
|
+
|
|
121
|
+
## Build behaviour that looks wrong but is not
|
|
122
|
+
|
|
123
|
+
### The build printed `(cached)` and did nothing
|
|
124
|
+
|
|
125
|
+
The incremental cache matched: same source hash, compiler version, options,
|
|
126
|
+
platform and extension set, with every output still present. That is the feature
|
|
127
|
+
working. Force a rebuild with `--force`.
|
|
128
|
+
|
|
129
|
+
### Stale output after changing a flag
|
|
130
|
+
|
|
131
|
+
The object cache key deliberately excludes compiler flags, which is why scripts
|
|
132
|
+
that change flags (such as runtime coverage) use a separate
|
|
133
|
+
`xbintsc_CACHE_DIR`. If you suspect a stale artefact, pass `--force` or delete
|
|
134
|
+
`.xbintsc/`.
|
|
135
|
+
|
|
136
|
+
### `run` exits with a non-zero status but there is no error message
|
|
137
|
+
|
|
138
|
+
`run` propagates the **program's** exit status; the compiler succeeded. Run it
|
|
139
|
+
directly (`./build/app`) to see the program's own output.
|
|
140
|
+
|
|
141
|
+
### `xbintsc: run requires --emit exe`
|
|
142
|
+
|
|
143
|
+
`run` only executes executables. Use `build --emit ir` or `emit` to inspect IR.
|
|
144
|
+
|
|
145
|
+
### Program output appears in an unexpected order
|
|
146
|
+
|
|
147
|
+
`async`/`await` is a synchronous microtask model and the event loop only runs
|
|
148
|
+
after the program body. Timer and socket callbacks therefore fire late; see
|
|
149
|
+
[language-support.md](./language-support.md).
|
|
150
|
+
|
|
151
|
+
## Where to look in the code
|
|
152
|
+
|
|
153
|
+
| Symptom | Source |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| A diagnostic message or code | [../../src/diagnostics/diagnostic.ts](../../src/diagnostics/diagnostic.ts), emit sites under `src/` |
|
|
156
|
+
| A missing feature | [../../src/codegen/](../../src/codegen/) — `UnsupportedFeature` is raised there |
|
|
157
|
+
| An import that will not resolve | [../../src/driver/bundler/](../../src/driver/bundler/) |
|
|
158
|
+
| clang invocation, linker flags | [../../src/driver/toolchain.ts](../../src/driver/toolchain.ts), [../../src/driver/toolchain-provider.ts](../../src/driver/toolchain-provider.ts) |
|
|
159
|
+
| Cache behaviour | [../../src/driver/cache.ts](../../src/driver/cache.ts) |
|
|
160
|
+
| Runtime crashes, GC, values | `runtime/*.c`, `runtime/rt.h` |
|
|
161
|
+
|
|
162
|
+
If you are changing the compiler rather than using it, read
|
|
163
|
+
[contributing.md](./contributing.md) next.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# 面向 AI 的 xbintsc 使用指南
|
|
2
|
+
|
|
3
|
+
**xbintsc 把 TypeScript 的一个子集直接编译成原生二进制。** 它自己解析
|
|
4
|
+
TypeScript,把程序降级为 LLVM IR 文本,再调用 `clang` 链接一个小型 C 运行时
|
|
5
|
+
(`runtime/`)产出独立可执行文件。产物里没有 Node.js,也没有 TypeScript 编译器。
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
source.ts --词法分析--> tokens --语法分析--> AST --绑定--> 绑定后的 AST
|
|
9
|
+
--代码生成--> module.ll --clang--> module.o --链接--> 可执行文件
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
本目录是**面向 AI、按任务组织**的文档层:刻意写得短,并指向更权威的文档。
|
|
13
|
+
请只读你当前任务需要的那一篇,不要通读整个目录。
|
|
14
|
+
|
|
15
|
+
| 页面 | 什么时候读 |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| [build-recipe.md](./build-recipe.md) | 要编译或运行一个程序,需要确切的命令形状 |
|
|
18
|
+
| [cli.md](./cli.md) | 需要完整参数表、项目配置或编程 API |
|
|
19
|
+
| [language-support.md](./language-support.md) | 必须确认某个语法/API 是否存在,或是否与 Node 一致 |
|
|
20
|
+
| [extensions.md](./extensions.md) | 需要 `fs`/`http`/…、GUI,或 C++/Rust 库 |
|
|
21
|
+
| [troubleshooting.md](./troubleshooting.md) | 报错了,要定位原因并修好 |
|
|
22
|
+
|
|
23
|
+
如果你要改的是**这个仓库本身**(而不是用它编译程序),先读
|
|
24
|
+
[../../AGENTS.md](../../../AGENTS.md):那里讲了目录结构、构建门禁与改动规则。
|
|
25
|
+
|
|
26
|
+
## 三个决定一切的事实
|
|
27
|
+
|
|
28
|
+
1. **只有 TypeScript 的一个子集能编译。** 不支持的语法会被直接拒绝,而不是
|
|
29
|
+
近似实现。动手写大段代码之前先确认。
|
|
30
|
+
2. **类型全部被擦除,从不做类型检查。** 类型注解、接口、泛型、`as`/`satisfies`、
|
|
31
|
+
非空断言 `!` 在运行时没有任何作用,也没有类型检查器会跑。只有真实的运行时
|
|
32
|
+
行为才算数。
|
|
33
|
+
3. **Node 兼容是可选且不完整的。** Node 模块由 `node` 扩展提供(`--ext node`);
|
|
34
|
+
不支持直接 import 第三方 npm 包。
|
|
35
|
+
|
|
36
|
+
## 选一条命令
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# 直接运行程序(先编译成临时二进制,再执行)
|
|
40
|
+
xbintsc run app.ts
|
|
41
|
+
|
|
42
|
+
# 产出独立二进制
|
|
43
|
+
xbintsc build app.ts --out build # -> build/app[.exe]
|
|
44
|
+
|
|
45
|
+
# 查看会被编译的 LLVM IR
|
|
46
|
+
xbintsc emit app.ts
|
|
47
|
+
|
|
48
|
+
# 查看 xbintsc 解析到的工具链
|
|
49
|
+
xbintsc doctor
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
在源码检出里,把 `xbintsc` 换成 `npx tsx src/cli/main.ts`(或
|
|
53
|
+
`npm run xbintsc --`)。发布压缩包里的二进制不需要 Node.js。
|
|
54
|
+
|
|
55
|
+
下一步:要命令就[build-recipe.md](./build-recipe.md),要写正经程序就先看
|
|
56
|
+
[language-support.md](./language-support.md)。
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# 构建配方
|
|
2
|
+
|
|
3
|
+
常见任务的可直接复制命令,以及让构建成功的关键前提。完整参数见
|
|
4
|
+
[cli.md](./cli.md);命令报错见 [troubleshooting.md](./troubleshooting.md)。
|
|
5
|
+
|
|
6
|
+
## 调用编译器
|
|
7
|
+
|
|
8
|
+
| 场景 | 调用方式 |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| 已发布的独立压缩包 | `xbintsc …`(`bin/xbintsc[.exe]` 在 `PATH` 上) |
|
|
11
|
+
| 源码检出,已编译 | `node dist/src/cli/main.js …` |
|
|
12
|
+
| 源码检出,直接跑 TypeScript | `npx tsx src/cli/main.ts …` |
|
|
13
|
+
| 源码检出,npm 脚本 | `npm run xbintsc -- …` |
|
|
14
|
+
| 源码检出,bin 启动器 | `node bin/xbintsc.js …`(会自动回退到 `tsx`) |
|
|
15
|
+
|
|
16
|
+
下文为简洁统一写作 `xbintsc`。
|
|
17
|
+
|
|
18
|
+
## 运行程序
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
xbintsc run app.ts
|
|
22
|
+
xbintsc run app.ts -- --flag value # -- 之后的所有参数传给被运行的程序
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`run` 先把程序编译成可执行文件,再以继承 stdio 的方式启动它。它要求
|
|
26
|
+
`--emit exe`;`xbintsc run app.ts --emit ir` 是错误用法。`run` 的退出码就是被运行
|
|
27
|
+
程序的退出码。
|
|
28
|
+
|
|
29
|
+
## 构建独立二进制
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
xbintsc build app.ts # -> build/app(Windows 上是 build/app.exe)
|
|
33
|
+
xbintsc build app.ts --out build/app # 指定输出目录
|
|
34
|
+
xbintsc build app.ts -o app.bin # 或指定确切输出路径
|
|
35
|
+
xbintsc build app.ts -O0 # 优化级别:-O0 .. -O3(默认 -O2)
|
|
36
|
+
xbintsc build app.ts --force # 忽略增量缓存
|
|
37
|
+
xbintsc build app.ts --verbose # 输出进度
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`build` 会打印产出的文件;如果增量缓存让本次构建无需干活,会额外打印
|
|
41
|
+
`(cached)`:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
xbintsc: wrote /abs/path/build/app
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
其他产出类型用于检查:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
xbintsc build app.ts --emit ir # 写出 app.ll
|
|
51
|
+
xbintsc build app.ts --emit obj # 写出 app.o
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 查看 LLVM IR
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
xbintsc emit app.ts > app.ll # IR 输出到 stdout,不写任何文件
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`emit` 不需要 clang,也不需要运行时库——它是确认"编译器到底理解了什么"最便宜
|
|
61
|
+
的手段,也是不确定某个语法是否被支持时最快的反馈回路。
|
|
62
|
+
|
|
63
|
+
## 能编译的程序形态
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// app.ts —— ESM,不用 require()
|
|
67
|
+
import { readFileSync } from "fs"; // 需要 `--ext node`
|
|
68
|
+
|
|
69
|
+
function main(): void {
|
|
70
|
+
const text = readFileSync("package.json", "utf8");
|
|
71
|
+
console.log(text.length);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main(); // 顶层代码按顺序执行
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- 使用 `import`/`export`;`require()` 会被拒绝。
|
|
78
|
+
- 相对导入会被打包(`import { helper } from "./helper.js"` 会解析到
|
|
79
|
+
`helper.ts`)。
|
|
80
|
+
- Node 内置模块用裸名(`fs`、`path`、`node:fs`),并且需要开启 `node` 扩展。
|
|
81
|
+
|
|
82
|
+
## 项目配置:不带参数即可构建
|
|
83
|
+
|
|
84
|
+
`xbintsc.config.json`(从入口文件所在目录向上查找,或用 `--config <path>` 指定,
|
|
85
|
+
用 `--no-config` 关闭)承载构建选项,因此只敲 `xbintsc build` 就能工作。配置里的
|
|
86
|
+
路径相对该配置文件解析,任何命令行参数都会覆盖对应字段。
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"entry": "src/app.ts",
|
|
91
|
+
"outDir": "build",
|
|
92
|
+
"optimize": "2",
|
|
93
|
+
"extensions": ["node"],
|
|
94
|
+
"app": { "name": "Demo", "icon": "assets/app.png" }
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
机器可读的 schema 见 [../xbintsc.config.schema.json](../../xbintsc.config.schema.json);
|
|
99
|
+
完整字段表见 [cli.md](./cli.md)。
|
|
100
|
+
|
|
101
|
+
## 带扩展编译
|
|
102
|
+
|
|
103
|
+
只要 import 了 Node 模块,就必须开启对应扩展,否则编译失败。可一次开多个,用逗号
|
|
104
|
+
分隔:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
xbintsc run app.ts --ext node
|
|
108
|
+
xbintsc run app.ts --ext node,gui
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
C++/Rust 库改用清单注册:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
xbintsc run app.ts --ext-native ./mathx.manifest.json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
两种扩展的编写方式都在 [extensions.md](./extensions.md)。
|
|
118
|
+
|
|
119
|
+
## 编程 API
|
|
120
|
+
|
|
121
|
+
写工具而不是写程序时:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { build, compileString } from "xbintsc";
|
|
125
|
+
|
|
126
|
+
const { ir } = compileString("console.log(1 + 1);"); // IR 文本,不需要 clang
|
|
127
|
+
const result = build("program.ts", { emit: "exe", outDir: "build" });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`build` 返回 `{ outputPath, irPath?, cached, diagnostics, bundlePath? }`,可恢复的
|
|
131
|
+
问题通过 `diagnostics` 报告;但工具链失败会**抛异常**。子路径导出
|
|
132
|
+
`xbintsc/driver` 暴露驱动内部能力。
|