jebc-install 2.0.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 +33 -0
- package/README.md +7 -0
- package/docs/JEBC_Technical_Manual_EN.txt +302 -0
- package/docs/JEBC_Technical_Manual_JP.txt +298 -0
- package/examples/demo.jebc +22 -0
- package/jebc.exe +0 -0
- package/package.json +12 -0
- package/scripts/postinstall.js +7 -0
- package/setup.bat +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 JEBC Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
MIT ライセンス
|
|
26
|
+
|
|
27
|
+
Copyright (c) 2026 JEBC Contributors
|
|
28
|
+
|
|
29
|
+
本ソフトウェアおよび関連文書のファイルの複製を取得するすべての人に対し、
|
|
30
|
+
ソフトウェアを無制限に扱うことを無償で許可します。
|
|
31
|
+
上記の著作権表示および本許諾表示を、ソフトウェアのすべての複製
|
|
32
|
+
または重要な部分に記載するものとします。
|
|
33
|
+
ソフトウェアは「現状のまま」で、何らの保証もなく提供されます。
|
package/README.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# JEBC V2 Technical Manual
|
|
2
|
+
|
|
3
|
+
> JEBC — JavaScript/TypeScript + Emscripten Bundled Compiler
|
|
4
|
+
> Version 2.0 | Platform: Windows
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
1. Overview
|
|
11
|
+
2. Requirements
|
|
12
|
+
3. Installation
|
|
13
|
+
4. Input File Format (.jebc)
|
|
14
|
+
5. Language Blocks
|
|
15
|
+
6. File Inclusion (call directive)
|
|
16
|
+
7. @jebc-sync (Struct Synchronization)
|
|
17
|
+
8. Build Pipeline
|
|
18
|
+
9. Output Structure
|
|
19
|
+
10. WASM Runtime API
|
|
20
|
+
11. Error Reference
|
|
21
|
+
12. Examples
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 1. Overview
|
|
26
|
+
|
|
27
|
+
JEBC is a single-command build tool that compiles C/C++ and JS/TS/TSX from
|
|
28
|
+
a unified `.jebc` source file into a deployable web application with WebAssembly.
|
|
29
|
+
|
|
30
|
+
V2 adds: unified `.jebc` extension, mixed JS/TS/TSX blocks, `call` directive
|
|
31
|
+
for file splitting, `lang.css`/`lang.html` blocks, and `@jebc-sync` for
|
|
32
|
+
automatic C struct <-> TS class synchronization.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 2. Requirements
|
|
37
|
+
|
|
38
|
+
| Tool | Purpose | Install |
|
|
39
|
+
|---------------------|---------------------------|----------------------------------|
|
|
40
|
+
| Node.js + npm | Install JEBC & esbuild | https://nodejs.org/ |
|
|
41
|
+
| Emscripten (emcc) | C/C++ -> WASM | https://emscripten.org/ |
|
|
42
|
+
| esbuild | JS/TS bundling | Auto-installed via npm |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 3. Installation
|
|
47
|
+
|
|
48
|
+
### Via npm (recommended)
|
|
49
|
+
|
|
50
|
+
npm install -g jebc
|
|
51
|
+
|
|
52
|
+
This installs `jebc` globally and auto-installs esbuild.
|
|
53
|
+
For Emscripten, run `setup.bat` or install manually.
|
|
54
|
+
|
|
55
|
+
### Manual
|
|
56
|
+
|
|
57
|
+
Download `jebc.exe` from GitHub and add to PATH.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 4. Input File Format (.jebc)
|
|
62
|
+
|
|
63
|
+
JEBC source files use `lang.X { ... }` blocks to embed multiple languages.
|
|
64
|
+
|
|
65
|
+
Supported extensions: `.jebc` (V2, recommended), `.jsbc`, `.tsbc`, `.tsxbc` (legacy)
|
|
66
|
+
|
|
67
|
+
### Syntax
|
|
68
|
+
|
|
69
|
+
lang.c {
|
|
70
|
+
// C/C++ code -> compiled to WASM
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
lang.js {
|
|
74
|
+
// JavaScript code
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
lang.ts {
|
|
78
|
+
// TypeScript code
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
lang.tsx {
|
|
82
|
+
// TSX code
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
lang.css {
|
|
86
|
+
// CSS -> injected into <style> in index.html
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
lang.html {
|
|
90
|
+
// HTML -> injected into <body> in index.html
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
### Rules
|
|
94
|
+
|
|
95
|
+
- Multiple blocks of the same type are concatenated in order
|
|
96
|
+
- `.jebc` files allow JS/TS/TSX blocks to coexist (auto-detect mode)
|
|
97
|
+
- Compile mode is determined by highest-priority block: TSX > TS > JS
|
|
98
|
+
- Comments and strings inside code are correctly ignored by the parser
|
|
99
|
+
- Every file must have at least one `lang.c` block and one script block
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 5. Language Blocks
|
|
104
|
+
|
|
105
|
+
| Block | Language | Output |
|
|
106
|
+
|------------|-------------|-------------------------------|
|
|
107
|
+
| `lang.c` | C/C++ | dist/native.wasm (via emcc) |
|
|
108
|
+
| `lang.js` | JavaScript | dist/bundle.js (via esbuild) |
|
|
109
|
+
| `lang.ts` | TypeScript | dist/bundle.js (via esbuild) |
|
|
110
|
+
| `lang.tsx` | TSX | dist/bundle.js (via esbuild) |
|
|
111
|
+
| `lang.css` | CSS | dist/index.html <style> |
|
|
112
|
+
| `lang.html`| HTML | dist/index.html <body> |
|
|
113
|
+
|
|
114
|
+
### Mixed Blocks (.jebc)
|
|
115
|
+
|
|
116
|
+
In `.jebc` files, all script blocks (js/ts/tsx) are concatenated in source
|
|
117
|
+
order and compiled together. This allows:
|
|
118
|
+
|
|
119
|
+
lang.js {
|
|
120
|
+
const data = [1, 2, 3];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
lang.ts {
|
|
124
|
+
// Can reference 'data' from the js block above
|
|
125
|
+
console.log(data.length);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 6. File Inclusion (call directive)
|
|
131
|
+
|
|
132
|
+
Split large projects into multiple files using `call`:
|
|
133
|
+
|
|
134
|
+
// main.jebc
|
|
135
|
+
call "components/math.jebc"
|
|
136
|
+
call "components/ui.jebc"
|
|
137
|
+
|
|
138
|
+
lang.c { ... }
|
|
139
|
+
lang.ts { ... }
|
|
140
|
+
|
|
141
|
+
### Behavior
|
|
142
|
+
- `call "path"` inlines the target file's contents before parsing
|
|
143
|
+
- Paths are relative to the calling file's directory
|
|
144
|
+
- Recursive: called files can also use `call`
|
|
145
|
+
- Circular reference detection prevents infinite loops
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## 7. @jebc-sync (Struct Synchronization)
|
|
150
|
+
|
|
151
|
+
Annotate C structs with `// @jebc-sync` to auto-generate:
|
|
152
|
+
- C accessor functions (getter/setter for each field)
|
|
153
|
+
- TS wrapper class with properties mapped to C memory
|
|
154
|
+
|
|
155
|
+
### C Side
|
|
156
|
+
|
|
157
|
+
// @jebc-sync
|
|
158
|
+
struct Vector2 {
|
|
159
|
+
float x;
|
|
160
|
+
float y;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
extern "C" {
|
|
164
|
+
float Vector2_length(Vector2* self) {
|
|
165
|
+
return sqrtf(self->x * self->x + self->y * self->y);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
### Auto-generated TS (available in all script blocks)
|
|
170
|
+
|
|
171
|
+
const v = new Vector2();
|
|
172
|
+
v.x = 3.0;
|
|
173
|
+
v.y = 4.0;
|
|
174
|
+
console.log(v.length()); // Calls C function via WASM
|
|
175
|
+
|
|
176
|
+
### Method Convention
|
|
177
|
+
- Define methods as: `ReturnType StructName_methodName(StructName* self, ...)`
|
|
178
|
+
- JEBC auto-detects and wraps them in the TS class
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 8. Build Pipeline
|
|
183
|
+
|
|
184
|
+
jebc app.jebc
|
|
185
|
+
|
|
186
|
+
1. **Preprocess** — Expand `call` directives (recursive file inclusion)
|
|
187
|
+
2. **Parse** — Extract all `lang.X { ... }` blocks
|
|
188
|
+
3. **Mode Detection** — Determine JS/TS/TSX from blocks present
|
|
189
|
+
4. **@jebc-sync** — Parse annotated structs, generate accessors + classes
|
|
190
|
+
5. **Write Intermediates** — `.bc_build/core.cpp` + `.bc_build/entry.X`
|
|
191
|
+
6. **WASM Compile** — `emcc core.cpp -O3 -s SIDE_MODULE=1 --no-entry`
|
|
192
|
+
7. **JS Bundle** — `esbuild entry.X --bundle --minify --format=esm`
|
|
193
|
+
8. **HTML Generate** — Create `index.html` with CSS/HTML injection
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 9. Output Structure
|
|
198
|
+
|
|
199
|
+
project/
|
|
200
|
+
├── app.jebc # Source file
|
|
201
|
+
├── .bc_build/ # Intermediate build files
|
|
202
|
+
│ ├── core.cpp # Extracted C code + sync accessors
|
|
203
|
+
│ ├── entry.tsx # Glue code + sync classes + script blocks
|
|
204
|
+
│ ├── emcc.stderr.log
|
|
205
|
+
│ └── esbuild.stderr.log
|
|
206
|
+
└── dist/ # Deploy this directory
|
|
207
|
+
├── native.wasm # C -> WASM
|
|
208
|
+
├── bundle.js # Bundled JS/TS (ESM)
|
|
209
|
+
└── index.html # HTML with CSS + markup
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 10. WASM Runtime API
|
|
214
|
+
|
|
215
|
+
| Global | Type | Description |
|
|
216
|
+
|----------------|--------------------|------------------------------------|
|
|
217
|
+
| `native` | Object | All extern "C" functions from WASM |
|
|
218
|
+
| `sharedBuffer` | SharedArrayBuffer | 16 MB shared buffer for data |
|
|
219
|
+
| `sharedMemory` | WebAssembly.Memory | Shared linear memory (256 pages) |
|
|
220
|
+
|
|
221
|
+
const result = native.add(21, 21); // Call C function
|
|
222
|
+
const view = new Uint8Array(sharedBuffer); // Direct memory access
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 11. Error Reference
|
|
227
|
+
|
|
228
|
+
| Error | Solution |
|
|
229
|
+
|---------------------------------|---------------------------------------|
|
|
230
|
+
| Unsupported file extension | Use .jebc, .jsbc, .tsbc, or .tsxbc |
|
|
231
|
+
| No lang.c section found | Add a lang.c { } block |
|
|
232
|
+
| No script section found | Add lang.js/ts/tsx { } block |
|
|
233
|
+
| emcc not found in PATH | Run setup.bat or install Emscripten |
|
|
234
|
+
| esbuild not found in PATH | Run: npm i -g esbuild |
|
|
235
|
+
| Circular call detected | Check call directives for loops |
|
|
236
|
+
| Failed to read call target | Verify the file path in call "..." |
|
|
237
|
+
| emcc build failed | Check C code; see .bc_build/*.log |
|
|
238
|
+
| esbuild bundle failed | Check script code; see .bc_build/*.log|
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## 12. Examples
|
|
243
|
+
|
|
244
|
+
### Minimal Example
|
|
245
|
+
|
|
246
|
+
lang.c {
|
|
247
|
+
extern "C" { int add(int a, int b) { return a + b; } }
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
lang.js {
|
|
251
|
+
document.body.textContent = 'add(2,3) = ' + native.add(2, 3);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
### Full V2 Example (CSS + HTML + mixed scripts + call)
|
|
255
|
+
|
|
256
|
+
call "math.jebc"
|
|
257
|
+
|
|
258
|
+
lang.c {
|
|
259
|
+
extern "C" { int square(int x) { return x * x; } }
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
lang.css {
|
|
263
|
+
body { background: #0f0f23; color: #eee; font-family: monospace; }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
lang.html {
|
|
267
|
+
<div id="app"></div>
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
lang.js {
|
|
271
|
+
const el = document.getElementById('app');
|
|
272
|
+
el.textContent = 'square(7) = ' + native.square(7);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
### @jebc-sync Example
|
|
276
|
+
|
|
277
|
+
lang.c {
|
|
278
|
+
#include <math.h>
|
|
279
|
+
|
|
280
|
+
// @jebc-sync
|
|
281
|
+
struct Circle {
|
|
282
|
+
float x;
|
|
283
|
+
float y;
|
|
284
|
+
float radius;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
extern "C" {
|
|
288
|
+
float Circle_area(Circle* self) {
|
|
289
|
+
return 3.14159f * self->radius * self->radius;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
lang.ts {
|
|
295
|
+
const c = new Circle();
|
|
296
|
+
c.x = 100; c.y = 200; c.radius = 50;
|
|
297
|
+
console.log('Area:', c.area());
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
> JEBC V2 — C and JS in one file. Ship to the web.
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# JEBC V2 技術マニュアル
|
|
2
|
+
|
|
3
|
+
> JEBC — JavaScript/TypeScript + Emscripten Bundled Compiler
|
|
4
|
+
> バージョン 2.0 | 対応: Windows
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 目次
|
|
9
|
+
|
|
10
|
+
1. 概要
|
|
11
|
+
2. 必要環境
|
|
12
|
+
3. インストール
|
|
13
|
+
4. 入力ファイル形式 (.jebc)
|
|
14
|
+
5. 言語ブロック
|
|
15
|
+
6. ファイル分割 (call ディレクティブ)
|
|
16
|
+
7. @jebc-sync (構造体同期)
|
|
17
|
+
8. ビルドパイプライン
|
|
18
|
+
9. 出力構成
|
|
19
|
+
10. WASM ランタイム API
|
|
20
|
+
11. エラーリファレンス
|
|
21
|
+
12. サンプルコード集
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 1. 概要
|
|
26
|
+
|
|
27
|
+
JEBC は C/C++ と JS/TS/TSX を一つの `.jebc` ファイルにまとめ、
|
|
28
|
+
コマンド一発で WebAssembly を活用した Web アプリケーションを生成するビルドツールです。
|
|
29
|
+
|
|
30
|
+
V2 の新機能:
|
|
31
|
+
- `.jebc` 拡張子に統一(JS/TS/TSX 混在可能)
|
|
32
|
+
- `call` ディレクティブでファイル分割
|
|
33
|
+
- `lang.css` / `lang.html` ブロック対応
|
|
34
|
+
- `@jebc-sync` による C構造体 ↔ TSクラス 自動同期
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 2. 必要環境
|
|
39
|
+
|
|
40
|
+
| ツール | 用途 | インストール |
|
|
41
|
+
|--------------------|---------------------------|---------------------------------|
|
|
42
|
+
| Node.js + npm | JEBC と esbuild のインストール | https://nodejs.org/ |
|
|
43
|
+
| Emscripten (emcc) | C/C++ → WASM コンパイル | https://emscripten.org/ |
|
|
44
|
+
| esbuild | JS/TS バンドル | npm で自動インストール |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 3. インストール
|
|
49
|
+
|
|
50
|
+
### npm 経由(推奨)
|
|
51
|
+
|
|
52
|
+
npm install -g jebc
|
|
53
|
+
|
|
54
|
+
グローバルに `jebc` コマンドがインストールされ、esbuild も自動導入されます。
|
|
55
|
+
Emscripten は `setup.bat` を実行するか手動でインストールしてください。
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 4. 入力ファイル形式 (.jebc)
|
|
60
|
+
|
|
61
|
+
`lang.X { ... }` ブロックで複数言語のコードを記述します。
|
|
62
|
+
|
|
63
|
+
対応拡張子: `.jebc`(V2推奨)、`.jsbc`、`.tsbc`、`.tsxbc`(レガシー)
|
|
64
|
+
|
|
65
|
+
### 構文
|
|
66
|
+
|
|
67
|
+
lang.c {
|
|
68
|
+
// C/C++ コード → WASM にコンパイル
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
lang.js {
|
|
72
|
+
// JavaScript コード
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
lang.ts {
|
|
76
|
+
// TypeScript コード
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
lang.tsx {
|
|
80
|
+
// TSX コード
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
lang.css {
|
|
84
|
+
// CSS → index.html の <style> に注入
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
lang.html {
|
|
88
|
+
// HTML → index.html の <body> に注入
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
### ルール
|
|
92
|
+
|
|
93
|
+
- 同じ言語のブロックが複数ある場合、出現順に連結
|
|
94
|
+
- `.jebc` ファイルでは JS/TS/TSX を自由に混在可能
|
|
95
|
+
- コンパイルモードは最高優先ブロックから自動判定: TSX > TS > JS
|
|
96
|
+
- コメントや文字列リテラル内のブロックは無視される
|
|
97
|
+
- 最低1つの `lang.c` ブロックと1つのスクリプトブロックが必要
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 5. 言語ブロック
|
|
102
|
+
|
|
103
|
+
| ブロック | 言語 | 出力先 |
|
|
104
|
+
|------------|-------------|---------------------------------|
|
|
105
|
+
| `lang.c` | C/C++ | dist/native.wasm (emcc経由) |
|
|
106
|
+
| `lang.js` | JavaScript | dist/bundle.js (esbuild経由) |
|
|
107
|
+
| `lang.ts` | TypeScript | dist/bundle.js (esbuild経由) |
|
|
108
|
+
| `lang.tsx` | TSX | dist/bundle.js (esbuild経由) |
|
|
109
|
+
| `lang.css` | CSS | dist/index.html の <style> |
|
|
110
|
+
| `lang.html`| HTML | dist/index.html の <body> |
|
|
111
|
+
|
|
112
|
+
### 混在対応 (.jebc)
|
|
113
|
+
|
|
114
|
+
`.jebc` ファイルでは全スクリプトブロックが出現順に連結されます:
|
|
115
|
+
|
|
116
|
+
lang.js {
|
|
117
|
+
const data = [1, 2, 3];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
lang.ts {
|
|
121
|
+
// 上の js ブロックの data を参照可能
|
|
122
|
+
console.log(data.length);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 6. ファイル分割 (call ディレクティブ)
|
|
128
|
+
|
|
129
|
+
大きなプロジェクトを複数ファイルに分割:
|
|
130
|
+
|
|
131
|
+
// main.jebc
|
|
132
|
+
call "components/math.jebc"
|
|
133
|
+
call "components/ui.jebc"
|
|
134
|
+
|
|
135
|
+
lang.c { ... }
|
|
136
|
+
lang.ts { ... }
|
|
137
|
+
|
|
138
|
+
### 動作
|
|
139
|
+
- `call "パス"` は対象ファイルの内容をその場に展開
|
|
140
|
+
- パスは呼び出し元ファイルからの相対パス
|
|
141
|
+
- 再帰対応(call の中に call も可)
|
|
142
|
+
- 循環参照の自動検出
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 7. @jebc-sync (構造体同期)
|
|
147
|
+
|
|
148
|
+
C構造体に `// @jebc-sync` を付けると自動生成:
|
|
149
|
+
- C側: インスタンスプール + getter/setter 関数
|
|
150
|
+
- TS側: 同名のラッパークラス(プロパティ + メソッド)
|
|
151
|
+
|
|
152
|
+
### C側の記述
|
|
153
|
+
|
|
154
|
+
// @jebc-sync
|
|
155
|
+
struct Vector2 {
|
|
156
|
+
float x;
|
|
157
|
+
float y;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
extern "C" {
|
|
161
|
+
float Vector2_length(Vector2* self) {
|
|
162
|
+
return sqrtf(self->x * self->x + self->y * self->y);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
### TS側で自動的に使える
|
|
167
|
+
|
|
168
|
+
const v = new Vector2();
|
|
169
|
+
v.x = 3.0;
|
|
170
|
+
v.y = 4.0;
|
|
171
|
+
console.log(v.length()); // C関数をWASM経由で呼び出し
|
|
172
|
+
|
|
173
|
+
### メソッドの規約
|
|
174
|
+
- `戻り値型 構造体名_メソッド名(構造体名* self, ...)` の形式で定義
|
|
175
|
+
- JEBC がパターンを検出し、TSクラスに自動ラップ
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 8. ビルドパイプライン
|
|
180
|
+
|
|
181
|
+
jebc app.jebc
|
|
182
|
+
|
|
183
|
+
1. **プリプロセス** — `call` ディレクティブを再帰的に展開
|
|
184
|
+
2. **パース** — 全 `lang.X { ... }` ブロックを抽出
|
|
185
|
+
3. **モード判定** — 存在するブロックから JS/TS/TSX を自動選択
|
|
186
|
+
4. **@jebc-sync** — 構造体解析、アクセサ関数 + TSクラス生成
|
|
187
|
+
5. **中間ファイル書き出し** — `.bc_build/core.cpp` + `.bc_build/entry.X`
|
|
188
|
+
6. **WASM コンパイル** — `emcc core.cpp -O3 -s SIDE_MODULE=1 --no-entry`
|
|
189
|
+
7. **JS バンドル** — `esbuild entry.X --bundle --minify --format=esm`
|
|
190
|
+
8. **HTML 生成** — CSS/HTML を注入した `index.html` を出力
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 9. 出力構成
|
|
195
|
+
|
|
196
|
+
project/
|
|
197
|
+
├── app.jebc # ソースファイル
|
|
198
|
+
├── .bc_build/ # 中間ビルドファイル
|
|
199
|
+
│ ├── core.cpp # Cコード + sync アクセサ
|
|
200
|
+
│ ├── entry.tsx # グルーコード + sync クラス + スクリプト
|
|
201
|
+
│ ├── emcc.stderr.log
|
|
202
|
+
│ └── esbuild.stderr.log
|
|
203
|
+
└── dist/ # このディレクトリを配信
|
|
204
|
+
├── native.wasm
|
|
205
|
+
├── bundle.js
|
|
206
|
+
└── index.html # CSS + HTML 注入済み
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## 10. WASM ランタイム API
|
|
211
|
+
|
|
212
|
+
| グローバル変数 | 型 | 説明 |
|
|
213
|
+
|----------------|--------------------|------------------------------------|
|
|
214
|
+
| `native` | Object | extern "C" 関数がプロパティとして利用可能 |
|
|
215
|
+
| `sharedBuffer` | SharedArrayBuffer | 16MB 共有バッファ |
|
|
216
|
+
| `sharedMemory` | WebAssembly.Memory | 共有リニアメモリ (256ページ) |
|
|
217
|
+
|
|
218
|
+
const result = native.add(21, 21);
|
|
219
|
+
const view = new Uint8Array(sharedBuffer);
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 11. エラーリファレンス
|
|
224
|
+
|
|
225
|
+
| エラーメッセージ | 対処法 |
|
|
226
|
+
|-------------------------------|---------------------------------------|
|
|
227
|
+
| Unsupported file extension | .jebc / .jsbc / .tsbc / .tsxbc を使用 |
|
|
228
|
+
| No lang.c section found | lang.c { } ブロックを追加 |
|
|
229
|
+
| No script section found | lang.js/ts/tsx { } ブロックを追加 |
|
|
230
|
+
| emcc not found in PATH | setup.bat を実行 or emcc をインストール|
|
|
231
|
+
| esbuild not found in PATH | npm i -g esbuild を実行 |
|
|
232
|
+
| Circular call detected | call の循環参照を確認 |
|
|
233
|
+
| Failed to read call target | call "..." のファイルパスを確認 |
|
|
234
|
+
| emcc build failed | Cコードを確認。.bc_build/*.log 参照 |
|
|
235
|
+
| esbuild bundle failed | スクリプトを確認。.bc_build/*.log 参照|
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 12. サンプルコード集
|
|
240
|
+
|
|
241
|
+
### 最小サンプル
|
|
242
|
+
|
|
243
|
+
lang.c {
|
|
244
|
+
extern "C" { int add(int a, int b) { return a + b; } }
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
lang.js {
|
|
248
|
+
document.body.textContent = 'add(2,3) = ' + native.add(2, 3);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
### V2 フルサンプル (CSS + HTML + 混在 + call)
|
|
252
|
+
|
|
253
|
+
call "math.jebc"
|
|
254
|
+
|
|
255
|
+
lang.c {
|
|
256
|
+
extern "C" { int square(int x) { return x * x; } }
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
lang.css {
|
|
260
|
+
body { background: #0f0f23; color: #eee; font-family: monospace; }
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
lang.html {
|
|
264
|
+
<div id="app"></div>
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
lang.js {
|
|
268
|
+
document.getElementById('app').textContent = 'square(7) = ' + native.square(7);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
### @jebc-sync サンプル
|
|
272
|
+
|
|
273
|
+
lang.c {
|
|
274
|
+
#include <math.h>
|
|
275
|
+
|
|
276
|
+
// @jebc-sync
|
|
277
|
+
struct Circle {
|
|
278
|
+
float x;
|
|
279
|
+
float y;
|
|
280
|
+
float radius;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
extern "C" {
|
|
284
|
+
float Circle_area(Circle* self) {
|
|
285
|
+
return 3.14159f * self->radius * self->radius;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
lang.ts {
|
|
291
|
+
const c = new Circle();
|
|
292
|
+
c.x = 100; c.y = 200; c.radius = 50;
|
|
293
|
+
console.log('Area:', c.area());
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
> JEBC V2 — CとJSを一つのファイルに。Webへ出荷。
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
call "math.jebc"
|
|
2
|
+
|
|
3
|
+
lang.c {
|
|
4
|
+
extern "C" {
|
|
5
|
+
int add(int a, int b) { return a + b; }
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
lang.css {
|
|
10
|
+
body { background: #0f0f23; color: #ccc; font-family: monospace; padding: 2rem; }
|
|
11
|
+
h1 { color: #00cc96; }
|
|
12
|
+
pre { background: #1a1a2e; padding: 1.5rem; border-radius: 8px; border: 1px solid #333; }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
lang.html {
|
|
16
|
+
<h1>JEBC V2 Demo</h1>
|
|
17
|
+
<pre id="output">Loading WASM...</pre>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
lang.js {
|
|
21
|
+
document.getElementById('output').textContent = 'add(21, 21) = ' + native.add(21, 21);
|
|
22
|
+
}
|
package/jebc.exe
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jebc-install",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "JEBC - Write C++ and JS/TS in one .jebc file, build to WebAssembly in one command",
|
|
5
|
+
"bin": { "jebc": "jebc.exe" },
|
|
6
|
+
"os": ["win32"],
|
|
7
|
+
"scripts": { "postinstall": "node scripts/postinstall.js" },
|
|
8
|
+
"keywords": ["webassembly","wasm","emscripten","esbuild","compiler","typescript","cpp"],
|
|
9
|
+
"author": "userkunngakkou",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": { "type": "git", "url": "https://github.com/userkunngakkou/jebc" }
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
console.log('[JEBC] Checking dependencies...');
|
|
3
|
+
try { execSync('esbuild --version', { stdio: 'ignore' }); console.log('[JEBC] esbuild OK'); }
|
|
4
|
+
catch { try { execSync('npm install -g esbuild', { stdio: 'inherit' }); } catch { console.warn('[JEBC] Please run: npm i -g esbuild'); } }
|
|
5
|
+
try { execSync('emcc --version', { stdio: 'ignore' }); console.log('[JEBC] emcc OK'); }
|
|
6
|
+
catch { console.log('[JEBC] emcc not found. Run setup.bat or install from https://emscripten.org/'); }
|
|
7
|
+
console.log('[JEBC] Ready! Run: jebc your_app.jebc');
|
package/setup.bat
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
echo [JEBC] Emscripten Setup
|
|
4
|
+
where emcc >nul 2>nul
|
|
5
|
+
if !ERRORLEVEL! neq 0 (
|
|
6
|
+
where git >nul 2>nul
|
|
7
|
+
if !ERRORLEVEL! neq 0 ( echo [ERROR] git required. & exit /b 1 )
|
|
8
|
+
if not exist "emsdk" ( git clone https://github.com/emscripten-core/emsdk.git emsdk )
|
|
9
|
+
pushd emsdk & call emsdk install latest & call emsdk activate latest & call emsdk_env.bat & popd
|
|
10
|
+
) else ( echo [OK] emcc available. )
|
|
11
|
+
echo Done!
|
|
12
|
+
endlocal
|