on-internet
← Community

[分享创造] Egg:没有 GC、不写生命周期标注,但内存安全的小语言,编译成 C99

V2EX ·

最近 Matz 合并了我给 Spinel 的一个 PR,顺便介绍一下我在做的语言 Egg: https://github.com/femto/egg 一句话:编译成可移植 C99,没有 GC,但释放后使用、重复释放、内存泄漏都是编译错误,而且不用写生命周期标注。 几个设计重点 单一所有者。 每个缓冲区只有一个所有者,借用在最后一次使用时结束,不需要写 'a。 没有未定义行为。 整数溢出、除以零、数组越界都会 panic,不会悄悄回绕或踩坏内存。 能力写在签名里。 语言核心不能做 IO,也不能分配内存。文件要先声明 uses io, alloc,再由 main 把这些值往下传,看函数签名就知道它能碰什么。 线程之间不共享数据。 有所有者的值通过 channel 在线程之间转移。 长什么样 uses alloc, io fn greet(io: Io, a: Allocator, name: str) void { const msg = a.concat("hello, ", name) defer a.free(msg) io.print(msg) } fn main(io: Io, a: Allocator) void { greet(io, a, "egg") } 忘了写 defer a.free(msg),编译不过: hello.egg:4:11: error[E135]:

Comments

Sign in or sign up to comment and upvote.

No comments yet.