ic10c-node 2.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ ## 2026/06/25
4
+
5
+ - [1.0.0]: publish version 1.0.0
6
+
7
+ ## 2026/06/29
8
+
9
+ - [1.0.1]: Fix the issue of crashing when importing the module with VSCode
10
+ - [1.0.2]: Hide debug output
package/README.md ADDED
@@ -0,0 +1,300 @@
1
+ # ic10c-node
2
+
3
+ [![npm version](https://badge.fury.io/js/ic10c_node.svg)](https://badge.fury.io/js/ic10c_node)
4
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D16.0.0-brightgreen)](https://nodejs.org/)
5
+ [![C++23](https://img.shields.io/badge/C%2B%2B-23-blue)](https://isocpp.org/)
6
+ [![License: CC BY-NC-SA](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
7
+
8
+ [中文](./README.zh.md)
9
+
10
+ ## Overview
11
+
12
+ `ic10c-node` is the Node.js native binding module for the **IC10 Compiler**, providing lexical analysis, syntax analysis, and semantic analysis capabilities for IC10 assembly language code.
13
+
14
+ IC10 is an assembly-style programming language used in the game [Stationeers](https://store.steampowered.com/app/544550/Stationeers/) to control computers and devices in the game. This module allows developers to use all core features of the IC10 compiler in the Node.js environment.
15
+
16
+ ## Features
17
+
18
+ - **Lexer** – tokenizes IC10 source code (supports registers, devices, numbers, strings, comments, keywords)
19
+ - **Parser** – builds an Abstract Syntax Tree (AST) for all IC10 instructions (nullary to senary)
20
+ - **Semantic Analyser** – performs symbol resolution and type checking using a `Promise`/`Future` based asynchronous symbol table
21
+ - **Error Reporting** – rich error messages with source location, internationalization support (English / Simplified Chinese)
22
+ - **Async Coroutine Infrastructure** – custom `Task<T>`, `Promise<T>`, `Future<T>` and coroutine state management
23
+ - **Cross‑Platform** – builds on Linux (GCC/Clang) and Windows (MSVC)
24
+
25
+ ## Installation
26
+
27
+ ### Prerequisites
28
+
29
+ - Node.js >= 16.0.0 (Node.js 26.x recommended)
30
+ - C++ compiler (GCC 13+ / Clang 16+ / MSVC 2022)
31
+ - CMake >= 3.28.1
32
+
33
+ ### Install from npm
34
+
35
+ ```bash
36
+ npm install ic10c-node
37
+ ```
38
+
39
+ ### Build from Source
40
+
41
+ ```bash
42
+ # Clone repository
43
+ git clone https://github.com/edoCsItahW/Stationeers.git
44
+ cd Stationeers/code/IC10/backend/compiler
45
+
46
+ # Install dependencies
47
+ npm install
48
+
49
+ # Download Node.js headers
50
+ npx node-gyp install
51
+
52
+ # Build native module
53
+ npm run build
54
+ ```
55
+
56
+ ## Quick Start
57
+
58
+ ### Basic Usage
59
+
60
+ ```typescript
61
+ import * as ic10 from 'ic10c-node';
62
+
63
+ // Set language (optional, default English)
64
+ ic10.IC10Local.setLanguage('zh-hans');
65
+
66
+ // IC10 source code
67
+ const source = `
68
+ alias disp d0
69
+ main:
70
+ move r0 42
71
+ yield
72
+ jal main
73
+ `;
74
+
75
+ // 1. Lexical analysis
76
+ const tokens = ic10.Lexer.tokenize(source);
77
+ console.log(`Generated ${tokens.length} Tokens`);
78
+
79
+ // 2. Syntax analysis
80
+ const parser = new ic10.Parser(tokens);
81
+ const program = parser.parse();
82
+
83
+ // 3. Semantic analysis
84
+ const analyser = new ic10.Analyser();
85
+ await analyser.visit(program);
86
+
87
+ // 4. Get results
88
+ const symbolTable = analyser.symbolTable;
89
+ console.log(symbolTable.toJSON());
90
+ ```
91
+
92
+ ### Using Static Methods
93
+
94
+ ```typescript
95
+ import { Lexer, Parser, Analyser } from 'ic10c-node';
96
+
97
+ // Lexical analysis
98
+ const tokens = Lexer.tokenize('add r0 r1 r2');
99
+
100
+ // Syntax analysis
101
+ const program = Parser.parse(tokens);
102
+
103
+ // Access AST
104
+ const json = JSON.parse(program.toJSON());
105
+ console.log(json.statements[0].type); // "addInstruction"
106
+ ```
107
+
108
+ ## API Reference
109
+
110
+ ### Classes
111
+
112
+ | Class | Description |
113
+ |:------|:------------|
114
+ | `IC10Local` | Localization settings |
115
+ | `Pos` | Position information |
116
+ | `Token` | Lexical token |
117
+ | `Lexer` | Lexical analyzer |
118
+ | `Program` | AST root node |
119
+ | `Parser` | Syntax analyzer |
120
+ | `Analyser` | Semantic analyzer |
121
+ | `SymbolTable` | Symbol table for variables and labels |
122
+
123
+ ### IC10Local
124
+
125
+ ```typescript
126
+ import { IC10Local } from 'ic10c-node';
127
+
128
+ // Set language
129
+ IC10Local.setLanguage('zh-hans'); // Simplified Chinese
130
+ IC10Local.setLanguage('en-us'); // English
131
+
132
+ // Get current language
133
+ const lang = IC10Local.getLanguage();
134
+ ```
135
+
136
+ ### Lexer
137
+
138
+ ```typescript
139
+ import { Lexer } from 'ic10c-node';
140
+
141
+ // Static method
142
+ const tokens = Lexer.tokenize('alias ic d0');
143
+
144
+ // Instance method
145
+ const lexer = new Lexer('move r0 42');
146
+ const result = lexer.scan();
147
+ ```
148
+
149
+ ### Parser
150
+
151
+ ```typescript
152
+ import { Lexer, Parser } from 'ic10c-node';
153
+
154
+ const tokens = Lexer.tokenize(source);
155
+ const parser = new Parser(tokens);
156
+ const program = parser.parse();
157
+
158
+ console.log('Statement count:', program.statements.length);
159
+ console.log('AST:', program.toJSON());
160
+ ```
161
+
162
+ ### Analyser
163
+
164
+ ```typescript
165
+ import { Lexer, Parser, Analyser } from 'ic10c-node';
166
+
167
+ const tokens = Lexer.tokenize(source);
168
+ const program = Parser.parse(tokens);
169
+ const analyser = new Analyser();
170
+
171
+ await analyser.visit(program);
172
+
173
+ const symbolTable = analyser.symbolTable;
174
+ console.log('Symbol table:', symbolTable.toJSON());
175
+ ```
176
+
177
+ ## IC10 Instruction Examples
178
+
179
+ ### Nullary Instructions
180
+
181
+ ```ic10
182
+ yield
183
+ sleep
184
+ pause
185
+ break
186
+ ```
187
+
188
+ ### Binary Instructions
189
+
190
+ ```ic10
191
+ move r0 r1
192
+ not r0 r1
193
+ ```
194
+
195
+ ### Ternary Instructions
196
+
197
+ ```ic10
198
+ add r0 r1 r2
199
+ sub r0 r1 r2
200
+ ```
201
+
202
+ ## Error Handling
203
+
204
+ ```typescript
205
+ import { Lexer, Parser } from 'ic10c-node';
206
+
207
+ const source = 'move r0'; // Missing operand
208
+ const tokens = Lexer.tokenize(source);
209
+ const program = Parser.parse(tokens);
210
+
211
+ // Check errors
212
+ if (program.errors && program.errors.length > 0) {
213
+ for (const err of program.errors) {
214
+ console.log(`Error: ${err.message}`);
215
+ console.log(`Position: Line ${err.pos.line}, Column ${err.pos.column}`);
216
+ }
217
+ }
218
+ ```
219
+
220
+ ## TypeScript
221
+
222
+ This module includes complete TypeScript type definitions.
223
+
224
+ ```typescript
225
+ import * as ic10 from 'ic10c-node';
226
+
227
+ // Fully type-safe
228
+ const token: ic10.Token = new ic10.Token(1, new ic10.Pos(), 'a', 3);
229
+ ```
230
+
231
+ ## Build Instructions
232
+
233
+ ### Requirements
234
+
235
+ - **Node.js**: 16.0.0+
236
+ - **CMake**: 3.28.1+
237
+ - **C++ Compiler**:
238
+ - Linux: GCC 13+ or Clang 16+
239
+ - Windows: MSVC 2022
240
+
241
+ ### Build Steps
242
+
243
+ ```bash
244
+ # 1. Install Node.js dependencies
245
+ npm install
246
+
247
+ # 2. Download Node.js headers
248
+ npx node-gyp install
249
+
250
+ # 3. Configure CMake
251
+ cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
252
+
253
+ # 4. Build
254
+ cmake --build build --parallel 4
255
+
256
+ # 5. Copy generated .node file
257
+ cp build/ic10c-node.node src/
258
+ ```
259
+
260
+ ## Project Structure
261
+
262
+ ```
263
+ ic10c_node/
264
+ ├── src/
265
+ │ ├── index.d.ts # TypeScript type definitions
266
+ │ └── ic10c-node.node # Native module (built)
267
+ ├── include/ # C++ headers
268
+ ├── test/ # Test files
269
+ ├── package.json
270
+ └── README.md
271
+ ```
272
+
273
+ ## License
274
+
275
+ This project is licensed under **CC BY-NC-SA 4.0** (Creative Commons Attribution-NonCommercial-ShareAlike 4.0).
276
+
277
+ [![License: CC BY-NC-SA](https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
278
+
279
+ ## Contributing
280
+
281
+ Contributions are welcome! Please feel free to submit a Pull Request.
282
+
283
+ 1. Fork the repository
284
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
285
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
286
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
287
+ 5. Open a Pull Request
288
+
289
+ ## Contact
290
+
291
+ - **Author**: Xiao Songtao
292
+ - **Email**: 2207150234@st.sziit.edu.cn
293
+ - **Repository**: [https://github.com/edoCsItahW/Stationeers](https://github.com/edoCsItahW/Stationeers)
294
+
295
+ ## Related Links
296
+
297
+ - [IC10 Compiler Core Documentation](https://github.com/edoCsItahW/Stationeers)
298
+ - [Stationeers Official Website](https://store.steampowered.com/app/544550/Stationeers/)
299
+ - [Node.js N-API Documentation](https://nodejs.org/api/n-api.html)
300
+ - [node-addon-api Documentation](https://github.com/nodejs/node-addon-api)
package/README.zh.md ADDED
@@ -0,0 +1,300 @@
1
+ # ic10c_node
2
+
3
+ [![npm 版本](https://badge.fury.io/js/ic10c-node.svg)](https://badge.fury.io/js/ic10c_node)
4
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D16.0.0-brightgreen)](https://nodejs.org/)
5
+ [![C++23](https://img.shields.io/badge/C%2B%2B-23-blue)](https://isocpp.org/)
6
+ [![许可证: CC BY-NC-SA](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
7
+
8
+ [English](README.md)
9
+
10
+ ## 简介
11
+
12
+ `ic10c-node` 是 **IC10 编译器** 的 Node.js 原生绑定模块,提供了对 IC10 汇编语言代码的词法分析、语法分析和语义分析能力。
13
+
14
+ IC10 是一种用于 [Stationeers](https://store.steampowered.com/app/544550/Stationeers/) 游戏的汇编式编程语言,用于控制游戏中的计算机和设备。本模块允许开发者在 Node.js 环境中使用 IC10 编译器的全部核心功能。
15
+
16
+ ## 特性
17
+
18
+ - **词法分析 (Lexer)** - 词符化 IC10 源代码,支持寄存器、设备号、数字、字符串、注释和关键字
19
+ - **语法分析 (Parser)** - 构建抽象语法树 (AST),覆盖所有 IC10 指令(一元至六元)
20
+ - **语义分析 (Analyser)** - 执行符号解析和类型检查,基于 `Promise`/`Future` 的异步符号表
21
+ - **错误报告** - 丰富的错误信息,包含源代码位置,支持国际化(中/英)
22
+ - **异步协程基础设施** - 自定义的 `Task<T>`、`Promise<T>`、`Future<T>` 和协程状态管理
23
+ - **跨平台** - 支持 Linux (GCC/Clang) 和 Windows (MSVC)
24
+
25
+ ## 安装
26
+
27
+ ### 前提条件
28
+
29
+ - Node.js >= 16.0.0(推荐 Node.js 26.x)
30
+ - C++ 编译器 (GCC 13+ / Clang 16+ / MSVC 2022)
31
+ - CMake >= 3.28.1
32
+
33
+ ### 从 npm 安装
34
+
35
+ ```bash
36
+ npm install ic10c-node
37
+ ```
38
+
39
+ ### 从源码构建
40
+
41
+ ```bash
42
+ # 克隆仓库
43
+ git clone https://github.com/edoCsItahW/Stationeers.git
44
+ cd Stationeers/code/IC10/backend/compiler
45
+
46
+ # 安装依赖
47
+ npm install
48
+
49
+ # 下载 Node.js 头文件
50
+ npx node-gyp install
51
+
52
+ # 构建原生模块
53
+ npm run build
54
+ ```
55
+
56
+ ## 快速开始
57
+
58
+ ### 基本用法
59
+
60
+ ```typescript
61
+ import * as ic10 from 'ic10c-node';
62
+
63
+ // 设置语言(可选,默认英文)
64
+ ic10.IC10Local.setLanguage('zh-hans');
65
+
66
+ // IC10 源代码
67
+ const source = `
68
+ alias disp d0
69
+ main:
70
+ move r0 42
71
+ yield
72
+ jal main
73
+ `;
74
+
75
+ // 1. 词法分析
76
+ const tokens = ic10.Lexer.tokenize(source);
77
+ console.log(`生成了 ${tokens.length} 个 Token`);
78
+
79
+ // 2. 语法分析
80
+ const parser = new ic10.Parser(tokens);
81
+ const program = parser.parse();
82
+
83
+ // 3. 语义分析
84
+ const analyser = new ic10.Analyser();
85
+ await analyser.visit(program);
86
+
87
+ // 4. 获取结果
88
+ const symbolTable = analyser.symbolTable;
89
+ console.log(symbolTable.toJSON());
90
+ ```
91
+
92
+ ### 使用静态方法
93
+
94
+ ```typescript
95
+ import { Lexer, Parser, Analyser } from 'ic10c-node';
96
+
97
+ // 词法分析
98
+ const tokens = Lexer.tokenize('add r0 r1 r2');
99
+
100
+ // 语法分析
101
+ const program = Parser.parse(tokens);
102
+
103
+ // 访问 AST
104
+ const json = JSON.parse(program.toJSON());
105
+ console.log(json.statements[0].type); // "addInstruction"
106
+ ```
107
+
108
+ ## API 文档
109
+
110
+ ### 类
111
+
112
+ | 类 | 说明 |
113
+ |:---|:---|
114
+ | `IC10Local` | 本地化设置 |
115
+ | `Pos` | 位置信息 |
116
+ | `Token` | 词法标记 |
117
+ | `Lexer` | 词法分析器 |
118
+ | `Program` | AST 根节点 |
119
+ | `Parser` | 语法分析器 |
120
+ | `Analyser` | 语义分析器 |
121
+ | `SymbolTable` | 符号表(存储变量和标签) |
122
+
123
+ ### IC10Local
124
+
125
+ ```typescript
126
+ import { IC10Local } from 'ic10c-node';
127
+
128
+ // 设置语言
129
+ IC10Local.setLanguage('zh-hans'); // 简体中文
130
+ IC10Local.setLanguage('en-us'); // 英文
131
+
132
+ // 获取当前语言
133
+ const lang = IC10Local.getLanguage();
134
+ ```
135
+
136
+ ### Lexer
137
+
138
+ ```typescript
139
+ import { Lexer } from 'ic10c-node';
140
+
141
+ // 静态方法
142
+ const tokens = Lexer.tokenize('alias ic d0');
143
+
144
+ // 实例方法
145
+ const lexer = new Lexer('move r0 42');
146
+ const result = lexer.scan();
147
+ ```
148
+
149
+ ### Parser
150
+
151
+ ```typescript
152
+ import { Lexer, Parser } from 'ic10c-node';
153
+
154
+ const tokens = Lexer.tokenize(source);
155
+ const parser = new Parser(tokens);
156
+ const program = parser.parse();
157
+
158
+ console.log('语句数量:', program.statements.length);
159
+ console.log('AST:', program.toJSON());
160
+ ```
161
+
162
+ ### Analyser
163
+
164
+ ```typescript
165
+ import { Lexer, Parser, Analyser } from 'ic10c-node';
166
+
167
+ const tokens = Lexer.tokenize(source);
168
+ const program = Parser.parse(tokens);
169
+ const analyser = new Analyser();
170
+
171
+ await analyser.visit(program);
172
+
173
+ const symbolTable = analyser.symbolTable;
174
+ console.log('符号表:', symbolTable.toJSON());
175
+ ```
176
+
177
+ ## IC10 指令示例
178
+
179
+ ### 一元指令 (Nullary)
180
+
181
+ ```ic10
182
+ yield
183
+ sleep
184
+ pause
185
+ break
186
+ ```
187
+
188
+ ### 二元指令 (Binary)
189
+
190
+ ```ic10
191
+ move r0 r1
192
+ not r0 r1
193
+ ```
194
+
195
+ ### 三元指令 (Ternary)
196
+
197
+ ```ic10
198
+ add r0 r1 r2
199
+ sub r0 r1 r2
200
+ ```
201
+
202
+ ## 错误处理
203
+
204
+ ```typescript
205
+ import { Lexer, Parser } from 'ic10c-node';
206
+
207
+ const source = 'move r0'; // 缺少操作数
208
+ const tokens = Lexer.tokenize(source);
209
+ const program = Parser.parse(tokens);
210
+
211
+ // 检查错误
212
+ if (program.errors && program.errors.length > 0) {
213
+ for (const err of program.errors) {
214
+ console.log(`错误: ${err.message}`);
215
+ console.log(`位置: 行 ${err.pos.line}, 列 ${err.pos.column}`);
216
+ }
217
+ }
218
+ ```
219
+
220
+ ## TypeScript
221
+
222
+ 本模块附带完整的 TypeScript 类型定义,无需额外安装 `@types` 包。
223
+
224
+ ```typescript
225
+ import * as ic10 from 'ic10c-node';
226
+
227
+ // 完全类型安全
228
+ const token: ic10.Token = new ic10.Token(1, new ic10.Pos(), 'a', 3);
229
+ ```
230
+
231
+ ## 构建说明
232
+
233
+ ### 环境要求
234
+
235
+ - **Node.js**: 16.0.0+
236
+ - **CMake**: 3.28.1+
237
+ - **C++ 编译器**:
238
+ - Linux: GCC 13+ 或 Clang 16+
239
+ - Windows: MSVC 2022
240
+
241
+ ### 构建步骤
242
+
243
+ ```bash
244
+ # 1. 安装 Node.js 依赖
245
+ npm install
246
+
247
+ # 2. 下载 Node.js 头文件
248
+ npx node-gyp install
249
+
250
+ # 3. 配置 CMake
251
+ cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
252
+
253
+ # 4. 编译
254
+ cmake --build build --parallel 4
255
+
256
+ # 5. 复制生成的 .node 文件
257
+ cp build/ic10c-node.node src/
258
+ ```
259
+
260
+ ## 项目结构
261
+
262
+ ```
263
+ ic10c-node/
264
+ ├── src/
265
+ │ ├── index.d.ts # TypeScript 类型定义
266
+ │ └── ic10c-node.node # 原生模块(编译生成)
267
+ ├── include/ # C++ 头文件
268
+ ├── test/ # 测试文件
269
+ ├── package.json
270
+ └── README.md
271
+ ```
272
+
273
+ ## 许可证
274
+
275
+ 本项目采用 **CC BY-NC-SA 4.0** (Creative Commons Attribution-NonCommercial-ShareAlike 4.0) 许可证。
276
+
277
+ [![License: CC BY-NC-SA](https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
278
+
279
+ ## 贡献
280
+
281
+ 欢迎提交 Issue 和 Pull Request!
282
+
283
+ 1. Fork 本仓库
284
+ 2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
285
+ 3. 提交更改 (`git commit -m 'Add amazing feature'`)
286
+ 4. 推送到分支 (`git push origin feature/amazing-feature`)
287
+ 5. 创建 Pull Request
288
+
289
+ ## 联系方式
290
+
291
+ - **作者**: Xiao Songtao
292
+ - **邮箱**: 2207150234@st.sziit.edu.cn
293
+ - **仓库**: [https://github.com/edoCsItahW/Stationeers](https://github.com/edoCsItahW/Stationeers)
294
+
295
+ ## 相关链接
296
+
297
+ - [IC10 编译器核心文档](https://github.com/edoCsItahW/Stationeers)
298
+ - [Stationeers 官方网站](https://store.steampowered.com/app/544550/Stationeers/)
299
+ - [Node.js N-API 文档](https://nodejs.org/api/n-api.html)
300
+ - [node-addon-api 文档](https://github.com/nodejs/node-addon-api)
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "ic10c-node",
3
+ "version": "2.6.6",
4
+ "description": "IC10 Compiler Node.js Native Bindings - Lexer, Parser, and Semantic Analyser | IC10 编译器 Node.js 原生绑定 - 提供词法分析、语法分析和语义分析功能",
5
+ "main": "src/ic10c-node.node",
6
+ "types": "types/index.d.ts",
7
+ "files": [
8
+ "src/",
9
+ "types/",
10
+ "static/",
11
+ "tsconfig.json",
12
+ "CHANGELOG.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=16.0.0"
16
+ },
17
+ "scripts": {
18
+ "test": "echo \"Error: no test specified\" && exit 1"
19
+ },
20
+ "keywords": [
21
+ "ic10",
22
+ "stationeers",
23
+ "compiler",
24
+ "lexer",
25
+ "parser",
26
+ "ast",
27
+ "semantic-analysis",
28
+ "native-addon",
29
+ "node-addon-api",
30
+ "n-api"
31
+ ],
32
+ "author": "edocsitahw <edocsitahw@qq.com>",
33
+ "contributors": [
34
+ "edocsitahw"
35
+ ],
36
+ "license": "CC BY-NC-SA",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/edoCsItahW/Stationeers.git",
40
+ "directory": "code/IC10/backend/compiler/publish/node"
41
+ },
42
+ "homepage": "https://github.com/edoCsItahW/Stationeers/blob/main/README.md",
43
+ "bugs": {
44
+ "url": "https://github.com/edoCsItahW/Stationeers/issues",
45
+ "email": "2257699870@qq.com"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^26.1.1"
49
+ }
50
+ }
Binary file