# Next-Inrerpreter **Repository Path**: Next-Development-Group/Next-Interpreter ## Basic Information - **Project Name**: Next-Inrerpreter - **Description**: 用C++写的Next解释器 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-05 - **Last Updated**: 2026-09-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: Cpp, cmake, Interpreter ## README # Next1.3 解释器 用 **C++20** 编写的轻量级动态解释器,是 Next 语言系列的第三代实现。 Next1.3 提供字节码虚拟机、标记-清除垃圾回收、 异步调度、泛型、模式匹配、运算符重载等能力,内置 **101 个函数(含 4 常量)**,其中 **`define` —— 定义函数的函数** 是核心元编程能力。 ## 特性亮点 - **C++20 字节码虚拟机**:AST → 字节码编译 + 栈式 VM + 内联缓存(IC)优化。 - **标记-清除 GC**:自动内存回收,支持闭包/类/实例/模块等复杂引用图。 - **完整面向对象**:类、单继承(`is`)、`self`/`super`、`pub`/`priv`、运算符重载(`__add__`)。 - **现代语言特性**:泛型 ``、`struct`、`enum` + `match` 模式匹配、管道 `|>`、字符串插值、切片、推导式、多返回值。 - **异步并发**:`async fn` + `await` + `gather` + `create_task`,协程式调度。 - **异常体系**:15 种内置异常类 + `try/catch/finally` + `raise ... with cause=`。 - **模块系统**:内置 `math` `string` `io` 模块 + `import`/`export`。 - **元编程**:`define`(定义函数的函数)、`eval`(源码求值)。 - **`.next` 文件格式**:UTF-8 源文件,扩展名 `.next`。 ## 目录结构 ``` Next1.3/ ├── CMakeLists.txt 顶层构建脚本(C++20) ├── src/ │ ├── main.cpp 入口(REPL + 文件执行) │ ├── lexer/ 词法分析器 │ ├── parser/ 递归下降语法分析器 │ ├── ast/ 抽象语法树 │ ├── bytecode/ 字节码编译器 │ ├── vm/ 虚拟机 + GC + 对象模型 │ ├── runtime/ 内置函数 / 模块 / 类型方法 │ └── async/ 异步调度器 ├── docs/ 文档 │ ├── 90-builtins.md 内置函数清单 │ └── file-format.md .next 文件格式规范 └── examples/ 示例脚本(.next) ``` ## 构建 1. 配置好 C++20 与 CMake(≥3.16)环境。 2. 打开终端进入源码根目录: ```bash mkdir build && cd build cmake .. cmake --build . ``` 3. 编译成功后,产物位于 `bin/` 目录(Windows 为 `next1.3.exe`,Linux/macOS 为 `next1.3`)。 ## 使用 ```bash # 启动交互式 REPL ./next1.3 # 执行 .next 脚本 ./next1.3 examples/next13_showcase.next # 省略扩展名自动补全 .next ./next1.3 examples/next13_showcase ``` ## 快速示例 ```next // 定义函数的函数 define("square", ["x"], "x * x") write square(4) // 16 // 类与运算符重载 class Vec2 { let x: float let y: float pub fn new(x: float, y: float) { self.x = x; self.y = y } pub fn __add__(self, o: Vec2) -> Vec2 { return new Vec2(self.x + o.x, self.y + o.y) } pub fn __str__(self) -> str { return "({self.x}, {self.y})" } } write new Vec2(1, 2) + new Vec2(3, 4) // (4, 6) // 模式匹配 + 管道 let data = [1, 2, 3, 4, 5] write data |> filter((x) => x % 2 == 1) |> map((x) => x * 10) // [10, 30, 50] ``` ## 内置函数 共 **101 个内置函数 + 4 常量 + 15 异常类**,详见 [`docs/90-builtins.md`](docs/90-builtins.md)。 `.next` 文件格式见 [`docs/file-format.md`](docs/file-format.md)。 ## 许可 MIT License(继承自 Next1.0.1 / Next1.2 系列)。