@geastack/compiler 1.0.18 → 1.0.19

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/README.md CHANGED
@@ -1,36 +1,68 @@
1
1
  # geatsc
2
2
 
3
- The geastack TypeScript-to-C++ compiler.
4
-
5
- It is a clean-room rewrite. The design goal is the second constraint below: a
6
- statically typed value that reaches a dynamic carrier is a defect. The earlier
7
- implementation could not be driven to zero of them, because boxing was
8
- load-bearing in its emitter and removing it anywhere broke it somewhere else.
9
- Starting from a tree where the carrier algebra is closed and fail-closed from
10
- the first commit is what makes "no boxing" a property rather than an aspiration.
11
-
12
- See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the pipeline, the layering
13
- and the constraints, and `CLAUDE.md` for the code conventions.
3
+ geatsc compiles TypeScript ahead of time to C++. The output contains no
4
+ JavaScript engine or interpreter. A C++ toolchain builds it into a native
5
+ binary for the target: ESP32 or RP2350 firmware, a macOS, iOS, Linux or Windows
6
+ app, an Xbox game, or a server executable.
7
+
8
+ The input is an ordinary TypeScript program, type-checked by the TypeScript
9
+ compiler. geatsc uses those types to pick native C++ representations: classes
10
+ become structs, numbers become native numeric types, and typed arrays, maps and
11
+ records become typed containers. This is what lets the same TypeScript run on a
12
+ microcontroller, and lets a compiled server use a fraction of the memory the
13
+ same code needs under Node.
14
+
15
+ ## Where it fits in GeaStack
16
+
17
+ geatsc is the compiler for [GeaStack](https://github.com/geastack), a framework
18
+ for writing apps in TypeScript and JSX and running them natively on embedded
19
+ boards, desktop, mobile and consoles. The other repositories plug into it:
20
+
21
+ - [`core`](https://github.com/geastack/core) — the Gea framework (app API,
22
+ reactivity, rendering engine, host services) and `geatsc-plugin-gea`, the
23
+ plugin that teaches geatsc about Gea components and JSX.
24
+ - [`cli`](https://github.com/geastack/cli) — the `gea` command. `gea build`
25
+ runs vite, and core's `build-gea-vite-geatsc.mjs` hands the module graph to
26
+ `geatsc compile-module-graph`. The target's toolchain then builds the
27
+ generated C++.
28
+ - [`targets`](https://github.com/geastack/targets),
29
+ [`apple`](https://github.com/geastack/apple),
30
+ [`linux`](https://github.com/geastack/linux),
31
+ [`windows`](https://github.com/geastack/windows) — the platform projects that
32
+ compile and link the generated C++. `apple` also ships a geatsc plugin for the
33
+ Apple SDK bindings.
34
+ - Xbox — the Xbox target is not open source; it is available commercially.
35
+ Contact [contact@geastack.com](mailto:contact@geastack.com).
36
+ - [`node-compat`](https://github.com/geastack/node-compat) — the Node.js
37
+ runtime and geatsc plugin for compiling Node servers (`node:http`, Hono) to
38
+ native executables. It is a dependency of this package: running `geatsc`
39
+ with no input file inside a Node project builds each of the project's entry
40
+ points through node-compat into `dist/`.
41
+
42
+ The Gea and Apple plugins are peer dependencies. Other plugins are loaded with
43
+ `--plugin`; see [docs/CLI-PLUGINS.md](docs/CLI-PLUGINS.md).
44
+
45
+ [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) describes the pipeline, the
46
+ layering and the constraints. `CLAUDE.md` has the code conventions.
14
47
 
15
48
  ## Layering
16
49
 
17
50
  ```
18
51
  identity/ canonical IDs
19
- semantics/ the target-neutral frontend: regions, structural types,
20
- operations, edges, coverage. The frontend/backend boundary.
21
- representation/ physical carriers, the sealed plan, and fail-closed guards
52
+ semantics/ target-neutral frontend: regions, structural types,
53
+ operations, edges, coverage
54
+ representation/ physical carriers, the sealed plan, fail-closed guards
22
55
  conversion/ the closed dynamic-conversion capability algebra
23
56
  preflight/ whole-pipeline capability census and certificate
24
57
  ir/ typed IR: verified operations and SSA values
25
- targets/cpp/ emission; consumes typed IR only
58
+ targets/cpp/ C++ emission; consumes typed IR only
26
59
  diagnostics/ authority-component sweep, deterministic ordering
27
60
  ```
28
61
 
29
- Nothing after `semantics/` may import `typescript` or touch a TypeScript AST.
30
- That boundary is what stops two layers from answering the same question
31
- differently.
62
+ `semantics/` is the frontend/backend boundary. Nothing after it may import
63
+ `typescript` or touch a TypeScript AST.
32
64
 
33
- ## Absolute constraints
65
+ ## Constraints
34
66
 
35
67
  1. **No source-shaped authority.** No decision may depend on a file name,
36
68
  path, source offset, `.pos`/`.end`/`getStart()` compared to a literal,
@@ -38,68 +70,74 @@ differently.
38
70
  C++ text. Identity is a checker symbol/declaration, a sealed semantic ID,
39
71
  or a versioned protocol identity.
40
72
  2. **No boxing.** A value with a static type never gets the dynamic carrier.
41
- `Representation.dynamic` is admissible only for the four declared
42
- `DynamicReason` values in `src/representation/model.ts`.
43
- 3. **Fail closed.** A guard firing is always correct; the defect is upstream.
44
- Never relax a guard, never downgrade an `unresolved`, never default when a
45
- fact is missing. `unresolved` is lattice bottom, not an answer.
73
+ `Representation.dynamic` is allowed only for the four `DynamicReason`
74
+ values declared in `src/representation/model.ts`.
75
+ 3. **Fail closed.** When a guard fires, the defect is upstream. Do not relax a
76
+ guard, downgrade an `unresolved`, or substitute a default for a missing
77
+ fact. `unresolved` is lattice bottom, not an answer.
46
78
 
47
79
  ## Architecture gate
48
80
 
49
- `scripts/architecture.mjs` enforces the layering over `src/**/*.ts`: file and
50
- directory size maximums, and zero-tolerance checks for RegExp literals under
51
- `src/targets/cpp/`, source-position literal comparisons, `typescript` imports
52
- outside `src/semantics/`, source-shaped discriminants, unclassified
53
- `Authority`/`Admission`/`Proof` contracts, class declarations under
54
- `src/targets/`, and `any`. It collects every violation before failing, so one
55
- run reports everything wrong rather than one thing at a time.
81
+ `scripts/architecture.mjs` checks `src/**/*.ts` for:
82
+
83
+ - file and directory size limits
84
+ - RegExp literals under `src/targets/cpp/`
85
+ - source-position literal comparisons
86
+ - `typescript` imports outside `src/semantics/`
87
+ - source-shaped discriminants
88
+ - unclassified `Authority`/`Admission`/`Proof` contracts
89
+ - class declarations under `src/targets/`
90
+ - `any`
91
+
92
+ It reports every violation in one run.
56
93
 
57
- ## Looking at what it does
94
+ ## Diagnostics
58
95
 
59
96
  ```bash
60
97
  node dist/cli.js test/fixtures/spread.ts
61
98
  ```
62
99
 
63
- runs the whole pipeline and prints the complete diagnostic set — never a top-N —
64
- exiting non-zero when no capability certificate was minted. Add `--preflight` for
65
- the full obligation census as canonical NDJSON.
100
+ Runs the full pipeline and prints every diagnostic. Exits non-zero when no
101
+ capability certificate was minted. `--preflight` prints the obligation census
102
+ as canonical NDJSON.
103
+
104
+ ### Coverage
66
105
 
67
106
  ```bash
68
107
  node dist/cli.js coverage app/index.ts --plugin ../node-compat/plugin/v2.mjs
69
108
  ```
70
109
 
71
- answers the porting question the diagnostics do not: **which lines of my file
72
- are the problem, and what kind of problem is each?** It joins every layer's
73
- outcome by source position and prints one row per statement with a stable
74
- code, a status and a one-line reason, then a summary and a by-code count. A
75
- carrier that BOXED is a row too -- the program compiles and runs slower than it
76
- says, and no other view places that on a line. Exit 0 iff a certificate was
77
- minted and nothing refused at lowering or emission.
110
+ Prints one row per statement with a code, a status and a one-line reason,
111
+ followed by a summary and a count per code. Boxed carriers are reported as
112
+ rows too. Exits 0 only if a certificate was minted and nothing was refused
113
+ during lowering or emission.
78
114
 
79
115
  | Code | Layer |
80
116
  | ------- | -------------------------------------------------------------- |
81
- | `G1xxx` | the TypeScript checker's own errors |
117
+ | `G1xxx` | TypeScript checker errors |
82
118
  | `G2xxx` | census blocker: a language primitive family the compiler lacks |
83
119
  | `G3xxx` | representation guard violation |
84
120
  | `G4xxx` | preflight obligation missing/unsupported, by obligation kind |
85
121
  | `G5xxx` | IR lowering blocker |
86
- | `G6xxx` | emission refusal, by the emitter's category |
122
+ | `G6xxx` | emission refusal, by emitter category |
87
123
  | `G7xxx` | calling-convention (ABI) projection blocker |
88
124
  | `G8xxx` | boxed carrier (`gea::Value`), by reason |
89
125
 
90
- The trailing digits index fixed tables in `src/cli-coverage.ts`, never a hash
91
- of a message, so rewording a diagnostic keeps its code; `x999` means the table
92
- lacks a row. Options: `--project`/`--no-project`, `--plugin`, `--plugin-option`,
93
- `--json` (rows + summary as one object), `--no-derived` (roots only),
94
- `--no-boxed` (refusals only).
126
+ The trailing digits index fixed tables in `src/cli-coverage.ts`, so rewording a
127
+ message does not change its code. `x999` means the table has no row for it.
128
+
129
+ Options: `--project`/`--no-project`, `--plugin`, `--plugin-option`, `--json`
130
+ (rows and summary as one object), `--no-derived` (roots only), `--no-boxed`
131
+ (refusals only).
132
+
133
+ ### Carriers
95
134
 
96
135
  ```bash
97
136
  node scripts/probe-carriers.mjs test/fixtures/language.ts
98
137
  ```
99
138
 
100
- prints the carrier and C++ spelling selected for every declaration, and counts
101
- unresolved and boxed carriers. It is the view of the structural mapper and
102
- carrier selection, which nothing else exercises directly.
139
+ Prints the carrier and C++ spelling chosen for every declaration, and counts
140
+ unresolved and boxed carriers.
103
141
 
104
142
  ## Emitting C++
105
143
 
@@ -107,43 +145,46 @@ carrier selection, which nothing else exercises directly.
107
145
  node dist/cli.js compile app/index.ts --out-dir build/generated
108
146
  ```
109
147
 
110
- is the command the gea build pipeline drives (`build-gea-vite-geatsc.mjs`
111
- passes it through `--geatsc-bin`). It writes the C++ into `--out-dir` together
112
- with `gea_runtime.h`, `generated_support.hpp`, whatever the installed hosts
113
- require beside the unit, `geatsc-sources.txt` -- the list of `.cpp` files the
114
- build compiles -- and, for the per-file layout, `geatsc-header.txt` naming the
115
- shared header the build should precompile. Options:
116
-
117
- | Option | Meaning |
118
- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
119
- | `--project <tsconfig.json>` | The project the input compiles under. Default: the nearest one; a `.js` bundle has none. |
120
- | `--entry-symbol <name>` | The C++ function the target starts the program at. Default `__gea_top_level`, which `core/gea_app_entry.cpp` calls. |
121
- | `--dynamic-fallback` | Opt in to boxed C++ runtime dispatch for supported dynamic features. No JavaScript engine. See [coverage and limits](docs/DYNAMIC-FALLBACK.md). |
122
- | `--isolate-symbols` | This program is one of several a resident build links: everything it defines is private to it, and a program that cannot be isolated is refused. |
123
- | `--translation-units single \| per-file \| balanced` | How many C++ files the program becomes. `single` (default) is one unit. `per-file` is one unit per source file plus a shared `<stem>.hpp` and a program unit, for parallel and incremental C++ builds. `balanced` groups the small units. See [`docs/TRANSLATION-UNITS.md`](docs/TRANSLATION-UNITS.md). |
124
- | `--plugin <module>` | Load an external compiler plugin; repeat for multiple plugins. See [CLI plugins](docs/CLI-PLUGINS.md) for exports, compatibility and precedence. |
125
- | `--plugin-option <lib.key>=<value>` | Delivered verbatim to the library whose prefix names it (`gea.cpp-prelude=...`). |
126
-
127
- `compile-module-graph <gea-module-graph.json> --entry <file>` is the same
128
- command over vite's module graph instead of files on disk, and is the path every
129
- real application build takes; it accepts the same options.
148
+ The gea build pipeline runs this command (`build-gea-vite-geatsc.mjs` passes it
149
+ through `--geatsc-bin`). It writes to `--out-dir`:
150
+
151
+ - the generated C++
152
+ - `gea_runtime.h` and `generated_support.hpp`
153
+ - any files the installed hosts need beside the unit
154
+ - `geatsc-sources.txt`, the list of `.cpp` files to compile
155
+ - `geatsc-header.txt` (per-file layout only), the shared header to precompile
156
+
157
+ | Option | Meaning |
158
+ | ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
159
+ | `--project <tsconfig.json>` | Project to compile the input under. Default: the nearest one. A `.js` bundle has none. |
160
+ | `--entry-symbol <name>` | C++ function the program starts at. Default `__gea_top_level`, called by `core/gea_app_entry.cpp`. |
161
+ | `--dynamic-fallback` | Allow boxed C++ runtime dispatch for supported dynamic features. No JavaScript engine is involved. See [docs/DYNAMIC-FALLBACK.md](docs/DYNAMIC-FALLBACK.md). |
162
+ | `--isolate-symbols` | Make every definition private to this program, for builds that link several programs into one binary. Programs that cannot be isolated are refused. |
163
+ | `--translation-units single \| per-file \| balanced` | `single` (default): one C++ file. `per-file`: one file per source file, plus a shared `<stem>.hpp` and a program unit. `balanced`: per-file with small units grouped. See [docs/TRANSLATION-UNITS.md](docs/TRANSLATION-UNITS.md). |
164
+ | `--plugin <module>` | Load a compiler plugin. Repeatable. See [docs/CLI-PLUGINS.md](docs/CLI-PLUGINS.md). |
165
+ | `--plugin-option <lib.key>=<value>` | Passed unchanged to the library named by the prefix, e.g. `gea.cpp-prelude=...`. |
166
+
167
+ `compile-module-graph <gea-module-graph.json> --entry <file>` does the same
168
+ from vite's module graph instead of files on disk. Application builds use this
169
+ form. It takes the same options.
130
170
 
131
171
  ## npm scripts
132
172
 
133
- | Script | Purpose |
134
- | -------------- | --------------------------------------------------------- |
135
- | `architecture` | Run the architecture gate. |
136
- | `typecheck` | `tsc -p tsconfig.json --noEmit`. |
137
- | `build` | Run the architecture gate, then compile to `dist/`. |
138
- | `format` | `prettier --write .`. |
139
- | `format:check` | `prettier --check .`. |
140
- | `check` | Architecture gate, typecheck, and format check, in order. |
173
+ | Script | Purpose |
174
+ | -------------- | --------------------------------------------- |
175
+ | `architecture` | Run the architecture gate |
176
+ | `typecheck` | `tsc -p tsconfig.json --noEmit` |
177
+ | `build` | Architecture gate, then compile to `dist/` |
178
+ | `format` | `prettier --write .` |
179
+ | `format:check` | `prettier --check .` |
180
+ | `check` | Architecture gate, typecheck and format check |
141
181
 
142
182
  ## License
143
183
 
144
- Apache-2.0 (see `LICENSE`), the compiler and the runtime it combines into
145
- generated programs alike. Programs you compile with geatsc are yours; their
146
- license is decided only by what they link. The GeaStack framework and the
147
- desktop, mobile and web targets are Apache-2.0 as well; the embedded board
148
- support (`targets`, `@geastack/chips`) is GPL-3.0-only and needs a commercial
149
- license for closed-source firmware. Contact [contact@geastack.com](mailto:contact@geastack.com) for commercial terms.
184
+ The compiler and the runtime it links into generated programs are Apache-2.0
185
+ (see `LICENSE`). Programs you compile with geatsc are yours; their license
186
+ depends only on what they link. The GeaStack framework and the desktop, mobile
187
+ and web targets are also Apache-2.0. The embedded board support (`targets`,
188
+ `@geastack/chips`) is GPL-3.0-only; closed-source firmware needs a commercial
189
+ license. Contact [contact@geastack.com](mailto:contact@geastack.com) for
190
+ commercial terms.
@@ -727,7 +727,7 @@ export const jsonCallText = (ctx, member, operation) => {
727
727
  throw createCppEmitBlockedError('host-member-call:JSON.parse', `JSON.parse cannot decode natively into this asserted type: ${reason}`);
728
728
  const textArgument = operandText(ctx, operation.arguments[0]);
729
729
  const resultType = cppTypeOf(resultRepresentation);
730
- return `[&]() { const std::string& gea_json_text = ${textArgument}; gea::json::Reader gea_json_reader(gea_json_text); ${resultType} gea_json_result{}; gea_json_read(gea_json_reader, gea_json_result); return gea_json_result; }()`;
730
+ return `[&]() { const std::string& gea_json_text = ${textArgument}; gea::json::Reader gea_json_reader(gea_json_text); ${resultType} gea_json_result{}; gea_json_read(gea_json_reader, gea_json_result); gea_json_reader.finish(); return gea_json_result; }()`;
731
731
  };
732
732
  /**
733
733
  * `JSON.stringify(v)` written straight into the cell that receives it, as
@@ -260,10 +260,11 @@ const emitObjectPropEntries = (ctx, lines, operation, node, key, value) => {
260
260
  // ahead of the apply, which the capture list then names. Scoped by the
261
261
  // node's own variable, which is unique within the body, so two elements'
262
262
  // tables cannot collide.
263
+ const initializers = [];
263
264
  let thunk = computed.thunk;
264
265
  if (!isPlainName(thunk)) {
265
266
  thunk = `gea_class_thunk_${node}_${named++}`;
266
- blocks.push(`const auto ${thunk} = ${computed.thunk};`);
267
+ initializers.push(`const auto ${thunk} = ${computed.thunk};`);
267
268
  }
268
269
  // Numeric dictionaries retain canonical PropertyKey text as their safe
269
270
  // physical key, so NaN and infinities never enter an ordered double map.
@@ -271,7 +272,7 @@ const emitObjectPropEntries = (ctx, lines, operation, node, key, value) => {
271
272
  const call = `${thunk}.call()`;
272
273
  const written = alignedValueText(ctx, 'emit-jsx.ts:276', computed.origin.representation, value.value, call) ?? call;
273
274
  const write = `[${table}, ${thunk}]() { ${subscript}[${entryKey}] = ${written}; }`;
274
- blocks.push(...reactiveApplyBlock(`gea::jsx::reactiveObjectPropApply(${node}, ${key}, ${table}, ${write})`, computed.subscriptions));
275
+ blocks.push(...reactiveApplyBlock(`gea::jsx::reactiveObjectPropApply(${node}, ${key}, ${table}, ${write})`, computed.subscriptions, initializers));
275
276
  }
276
277
  // No reactive entry means nothing here has anything to say about this prop,
277
278
  // and it takes the path it always took.
@@ -450,8 +451,11 @@ const subscriptionOwnerText = (ctx, dependency) => {
450
451
  const reference = bindingReference(ctx, dependency.source.declaration, 'a reactive subscription');
451
452
  return reference.boxed ? null : reference.name;
452
453
  };
453
- const reactiveApplyBlock = (open, subscriptions) => [
454
+ // Every initialized local belongs inside the block: control-flow labels outside
455
+ // it must remain reachable without jumping over a C++ variable initialization.
456
+ const reactiveApplyBlock = (open, subscriptions, initializers = []) => [
454
457
  '{',
458
+ ...initializers.map((line) => ` ${line}`),
455
459
  ` const auto gea_apply = ${open};`,
456
460
  ...subscriptions.map((line) => ` ${line}`),
457
461
  '}'
@@ -217,7 +217,7 @@ export const hostJsonMemberValueText = (member, representation) => {
217
217
  if (!jsonRuntimeDeclaredCarrier(abi.result))
218
218
  return null;
219
219
  return (`[&]() { gea::json::Reader gea_json_reader(${only}); ${cppTypeOf(abi.result)} gea_json_result{}; ` +
220
- `gea_json_read(gea_json_reader, gea_json_result); return gea_json_result; }()`);
220
+ `gea_json_read(gea_json_reader, gea_json_result); gea_json_reader.finish(); return gea_json_result; }()`);
221
221
  }
222
222
  const argument = abi.parameters[0];
223
223
  if (argument === undefined || !jsonRuntimeDeclaredCarrier(argument.value))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/compiler",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -46,6 +46,7 @@
46
46
  "scripts": {
47
47
  "test:cli-plugins": "node --test test/cli-plugins.mjs",
48
48
  "test:allocation-runtime": "node test/allocation-runtime.mjs",
49
+ "test:compact-runtime": "node test/compact-runtime.mjs",
49
50
  "test:stored-listener-native-flow": "node test/stored-listener-native-flow.mjs",
50
51
  "test:native-typed-field-read": "node test/native-typed-field-read.mjs",
51
52
  "test:native-method-overrides": "node test/native-method-overrides.mjs",
@@ -64,7 +65,9 @@
64
65
  "format": "prettier --write .",
65
66
  "format:check": "prettier --check .",
66
67
  "check": "npm run architecture && npm run typecheck && npm run format:check",
67
- "check:contracts": "npm run build && node test/contracts.mjs"
68
+ "check:contracts": "npm run build && node test/contracts.mjs",
69
+ "test": "npm run build && node test/run.mjs",
70
+ "test:node-project": "node test/node-project.mjs"
68
71
  },
69
72
  "dependencies": {
70
73
  "@geastack/node-compat": "^1.0.12",
@@ -74,7 +77,16 @@
74
77
  "@types/node": "^22.15.3",
75
78
  "fastify": "^5.0.0",
76
79
  "find-my-way": "9.6.0",
77
- "prettier": "^3.8.3"
80
+ "prettier": "^3.8.3",
81
+ "@geastack/core": "0.1.23",
82
+ "@geastack/host": "0.1.8",
83
+ "@geastack/engine": "0.1.6",
84
+ "@geastack/elements": "0.1.2",
85
+ "@geastack/geaos": "0.1.3",
86
+ "@geastack/apple": "0.2.8",
87
+ "@geastack/geatsc-plugin-gea": "0.1.6",
88
+ "@geastack/geatsc-plugin-apple-native": "0.1.3",
89
+ "@geastack/native-webgl-angle": "0.1.6"
78
90
  },
79
91
  "peerDependencies": {
80
92
  "@geastack/apple": ">=0.2.8",