Nimony: The next version of Nim
Nimony: The next version of Nim
Nimony Efficient, expressive, elegant Get the nightly toolchain Built every day from nimony’s master branch. Linux x86_64 · tar.xz Linux ARM64 · tar.xz macOS Apple silicon · tar.xz Windows x86_64 · zip Unpack, put bin/ on your PATH, done — and with nimony n you do not even need a C compiler. Download page · Build from source · Tools
Nimony 高效、富有表现力且优雅。获取每日构建的工具链,该工具链每天从 nimony 的 master 分支构建。Linux x86_64 · tar.xz Linux ARM64 · tar.xz macOS Apple silicon · tar.xz Windows x86_64 · zip。解压后将 bin/ 放入您的 PATH 即可使用——而且使用 nimony n,您甚至不需要 C 编译器。下载页面 · 从源码构建 · 工具
Nimony is a new compiler for Nim and the home of the Nim 3 language: borrow checking, explicit nilability, sum types, checked generics and more, with incremental and parallel builds from the start. For how it relates to Nim 2, see the FAQ.
Nimony 是 Nim 的新编译器,也是 Nim 3 语言的家园:它从一开始就具备借用检查、显式可空性、和类型(sum types)、已检查泛型等特性,并支持增量和并行构建。关于它与 Nim 2 的关系,请参阅常见问题解答。
Nimony for… Embedded Games Full stack Compiler devs
Nimony 适用于……嵌入式、游戏、全栈、编译器开发。
Embedded development Native code generation for x86_64, ARM64, ARM32, AVR and RISC-V — independent of LLVM and GCC, so there are fewer surprises from the implicit assumptions about C’s undefined behavior that plague these toolchains. A runtime hardened against heap exhaustion: running out of memory is a condition you handle, not a crash. A structured, typesafe inline assembler that uses Nim’s own syntax. Memory safe thanks to optimized automatic reference counting and a variant of borrow checking that is easy to understand. Provable absence of out-of-bounds indexing. Indexing into arrays, seqs and strings is a requires contract checked at the call site: an index that is provably out of range is a compile-time error, and a module with {.feature: “staticContracts”.} must prove every access in bounds — no buffer overruns and no run-time checks left in the binary. Your own routines state their preconditions the same way.
嵌入式开发:为 x86_64、ARM64、ARM32、AVR 和 RISC-V 生成原生代码——独立于 LLVM 和 GCC,因此减少了因 C 语言未定义行为的隐式假设而带来的意外,这些假设曾困扰着上述工具链。运行时针对堆耗尽进行了加固:内存不足是一种您可以处理的状态,而不是导致崩溃的原因。提供使用 Nim 自身语法的结构化、类型安全的内联汇编器。得益于优化的自动引用计数和易于理解的借用检查变体,实现了内存安全。可证明不存在越界索引。对数组、序列(seqs)和字符串的索引是调用点检查的契约要求:可证明超出范围的索引会引发编译时错误,且带有 {.feature: “staticContracts”.} 的模块必须证明每次访问都在边界内——没有缓冲区溢出,二进制文件中也不会残留运行时检查。您自己的例程也以同样的方式声明其前置条件。
Game development Standalone binaries optimized for your target architecture. .passive procs turn linear code into state machines — ideal for splitting game logic across frames. Mutable state is well supported, not an afterthought. Short feedback loops. Incremental and parallel builds keep the edit–compile–fix cycle fast.
游戏开发:为您的目标架构优化独立二进制文件。.passive 过程将线性代码转换为状态机——非常适合跨帧拆分游戏逻辑。可变状态得到良好支持,而非事后补救。反馈循环短。增量和并行构建使“编辑-编译-修复”周期保持快速。
Full stack development A single language for the full stack. No matter how low level or high level your tasks are: get familiar with Nimony and end up with readable, maintainable code. The same code base compiles to C, to native code, to JavaScript and to WebAssembly — from microcontrollers to the browser. Batteries included. The standard library ships what applications need: linear-time regular expressions, sockets with a TLS 1.3 client written in Nim, an HTTP client and server, JSON and a math library. The compiler as a reviewer. Generics are type checked where they are defined, sum types are matched exhaustively, and the borrow checker rejects mutation under active borrows. Whole classes of plausible-looking mistakes become compile errors, pointing at the line that caused them. Little ceremony. Nim’s concise, indentation-based syntax means less code to write and less code to review.
全栈开发:全栈使用单一语言。无论您的任务是底层还是高层:熟悉 Nimony,最终都能获得可读、可维护的代码。同一代码库可编译为 C、原生代码、JavaScript 和 WebAssembly——从微控制器到浏览器皆可。内置功能丰富。标准库提供了应用程序所需的一切:线性时间正则表达式、使用 Nim 编写的带有 TLS 1.3 客户端的套接字、HTTP 客户端和服务器、JSON 以及数学库。编译器即审查员。泛型在定义处进行类型检查,和类型进行穷尽匹配,借用检查器拒绝在活跃借用下的修改。整类看似合理的错误都会变成编译错误,并指出导致错误的代码行。仪式感少。Nim 简洁的、基于缩进的语法意味着编写的代码更少,需要审查的代码也更少。
Compiler and tool developers Built around NIF, an interchange format that every stage of the pipeline reads and writes. You can inspect, diff and transform the output of any stage — and it is what makes incremental and parallel builds possible. Plugins go far beyond what a macro system can accomplish easily: Custom validators that look for possible deadlocks, race conditions or risky recursion (embedded targets often have very small stacks). Custom code generators that compile a subset of Nim to GPUs or target FPGAs. Custom DSLs, supported more cleanly than in Nim today — for example lexer and parser generators.
编译器和工具开发者:围绕 NIF 构建,这是一种流水线每个阶段都能读写的交换格式。您可以检查、对比并转换任何阶段的输出——这正是实现增量和并行构建的基础。插件的功能远超宏系统所能轻易实现的范畴:自定义验证器可查找潜在的死锁、竞态条件或危险递归(嵌入式目标通常堆栈很小)。自定义代码生成器可将 Nim 的子集编译到 GPU 或目标 FPGA。自定义 DSL 的支持比现在的 Nim 更简洁——例如词法分析器和解析器生成器。
Here is a taste of the language. Sum types (algebraic data types)Variant objects no longer need a separate discriminator enum: tags live in the case section, and case value of Tag(fields): pattern matching binds the fields for that arm — like expressions you’d write in ML-family languages, checked for exhaustiveness.
以下是该语言的概览。和类型(代数数据类型):变体对象不再需要单独的判别枚举:标签位于 case 部分,case value of Tag(fields): 模式匹配会绑定该分支的字段——就像您在 ML 家族语言中编写的表达式一样,并会进行穷尽性检查。
type Expr = ref object case of Lit: value: int of Add, Sub: left, right: Expr proc eval(e: Expr): int = case e of Lit(value): result = value of Add(left, right): result = eval(left) + eval(right) of Sub(left, right): result = eval(left) - eval(right) echo eval(Add(left: Lit(value: 10), right: Lit(value: 32))) # 42
(代码示例:定义 Expr 类型,包含 Lit、Add、Sub 分支,并实现 eval 函数进行递归求值。)
Shared fields can live outside the case, variants can nest (seq[Tree] in a branch), and grouped matchers like {Add, Sub}(left, right) appear where multiple tags share the same shape — see Case in object in the manual.
共享字段可以位于 case 之外,变体可以嵌套(分支中包含 seq[Tree]),并且当多个标签共享相同形状时,可以使用像 {Add, Sub}(left, right) 这样的分组匹配器——请参阅手册中的“Case in object”。
Borrow checking — iterator safety and aliasing Nimony rejects classic footguns at compile time: proc grow(s: var seq[int]; use: int) = s.add use var s = @[1, 2, 3] # for v in s: # grow(s, v) # Error: s is borrowed during iteration — no realloc under active borrows This follows prefix exclusion: while s (or s.elements) is borrowed, that path cannot be mutated until the borrow ends — sibling fields can still be updated.
借用检查——迭代器安全与别名:Nimony 在编译时拒绝了经典的“坑”:(代码示例展示了在迭代过程中修改序列导致的错误)。这遵循前缀排除原则:当 s(或其元素)被借用时,该路径在借用结束前不能被修改——但同级字段仍可更新。
Type checked generics By default generics are type checked: the code is checked when the generic is defined, not only when it is instantiated! Duck typing is still available, you get it via the {.untyped.} pragma. The required operations are described via concepts: type Comparable = concept proc <(a, b: Self): bool proc min[T: Comparable](a, b: T): T = if a < b: a else: b echo min(3, 7) echo min(“b”, “a”) Container-style concepts (e.g. Findable[T]) work the same way with iterators and indexed access — see Concepts and Generics in the manual.
类型检查泛型:默认情况下,泛型是经过类型检查的:代码在定义泛型时就会被检查,而不仅仅是在实例化时!鸭子类型仍然可用,您可以通过 {.untyped.} 编译指示来使用它。所需的操作通过概念(concepts)描述:(代码示例展示了 Comparable 概念及 min 函数)。容器风格的概念(例如 Findable[T])在迭代器和索引访问方面以同样的方式工作——请参阅手册中的“Concepts and Generics”。
Latest news 2026-09-08 Nimony 0.6.2 has been released. It ships with a guest report from a user who spent a year porting real projects over. A Vulkan visualiser, a web framework, an embedded server: Nim, one year in. Older entries, including the 0.2 release, live on the News page.
最新消息:2026-09-08 Nimony 0.6.2 发布。随附一位用户花费一年时间将真实项目移植过来的客座报告。包括 Vulkan 可视化工具、Web 框架、嵌入式服务器:Nim,一年回顾。旧条目(包括 0.2 版本)位于新闻页面。