Newshot

Nimony:Nim 的下一个版本

Translation(model translation, not the source's own text)

Nimony

高效、富有表现力、优雅

获取每日构建工具链

每天从 nimony 的 master 分支构建。

解压,将 bin/ 放到你的 PATH 中,完成——而且使用 nimony n 时你甚至不需要 C 编译器。下载页面 · 从源码构建 · 工具

Nimony 是 Nim 的新编译器,也是 Nim 3 语言的大本营:借用检查、显式可空性、和类型、受检查的泛型等等,并且从一开始就支持增量与并行构建。关于它与 Nim 2 的关系,请参阅 FAQ。

嵌入式开发

  • 为 x86

        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
      

共享字段可以放在 case 之外,变体可以嵌套(分支中的 seq[Tree]),像 {Add, Sub}(left, right) 这样的分组匹配器会出现在多个标签共享同一形状的地方——参见手册中的 Case in object。

Borrow checking — iterator safety and aliasing

Nimony 在编译期拒绝经典的陷阱:


        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
      

这遵循 prefix exclusion:当 s(或 s.elements)被借用时,该路径在借用结束前不能被修改——兄弟字段仍然可以更新。

Type checked generics

默认情况下泛型是类型检查的:代码在定义泛型时就被检查,而不只是在实例化时!鸭子类型仍然可用,你可以通过 {.untyped.} pragma 获得它。

所需操作通过 concept 描述:


        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")
      

容器风格的 concept(例如 Findable[T])以相同方式配合迭代器和索引访问工作——参见手册中的 Concepts and Generics。

Latest news

2026-09-08 Nimony 0.6.2 已发布。它附带了一份来自用户的客座报告,这位用户花了一年时间移植真实项目。一个 Vulkan 可视化工具、一个 Web 框架、一个嵌入式服务器:Nim,一年之后。

更早的条目(包括 0.2 版本)见 News 页面。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗