Zinc:一个系统编程语言原型
~oconnor0/zinc
the zinc systems programming language
12e74d9 pelleas: further api design.
~oconnor0 pushed to ~oconnor0/zinc-proto git
21 hours ago
606cfda proto: explore app.h
~oconnor0 pushed to ~oconnor0/zinc-proto git
21 hours ago
View project feed RSS
#Zinc, a systems programming language prototype
Zinc 是我尝试构建的一个底层系统编程语言原型。我发现了一个名为 Owl 的解析器(镜像版本在这里),它可以为 visibly pushdown languages 生成解析器。Visibly pushdown languages 要求到其他语法产生式的递归必须由只能用于该目的的 tokens 保护。虽然有一定的限制,但这最终意味着所有可以“包含”其他产生式的语法产生式都被包装在特定的 tokens 中,因此该语言在视觉上更容易解析,并且它以线性时间运行。
mut i = 0
def n = 10
while 0 <= i < n {
def x = call rndi()
if i = 0 {
; verify that the fixed seed rng is working as expected
assert "rndi() = 13109595": x = 13109595
}
call puti(x)
call putc(10)
set i = i + 1
}
return i
#特性!
- 所有语句都以关键字开头,除了以大括号开始和结束的代码块。
- 像数学中那样的范围条件判断:
0 <= i < 100
- 内置的
assert
语法——包含在所有编译模式中。确保事情符合你的预期。 - 通过在
lib/prelude.h
中定义函数来添加新函数。 if
和while
语句的条件判断不需要圆括号。- 可变变量和不可变绑定。
- 分号用于注释掉该行的剩余部分。
- 该语言将有副作用的代码与无副作用的代码分开。或者说,一旦函数和子程序被实现就会这样。子程序可以有副作用,函数不能。表达式只能应用函数,不能调用子程序。这就像 Haskell,但更好。
- 没有包管理器来分散你的注意力。
- 简单的类型系统。目前,是一种 unityped 语言——除了可选的
assert
消息之外,一切都是 int。 - 无需编写函数。
.zn
文件中的顶层代码在包含该文件时执行。 - 尚未实现包/文件/模块导入。我曾想过将每个文件编译成一个结构体,但只有一个还是多个结构体尚未决定。而且总是存在关于模块加载时如何处理副作用的问题。
- 没有 nil。也没有指针或引用。我想知道在这种模型下我能走多远,也许使用数组、结构体、arena 或静态分配或其他什么。
#状态
虽然我梦想着将它与一些 2D 图形或瓦片引擎集成,并玩玩老式游戏开发,但我遇到了其设计的一些限制。例如,用我自己编写的语言编写一个 Raptor: Call of the Shadows 的克隆版有多酷? 我打算将其编写为单遍编译器,直接从语法树编译并以 C 为目标,通过 TCC 使其能够快速运行并在任何平台上运行。不幸的是,我还设计了一种具有顶层执行和嵌套函数的语言——如果我想保留编译器的单遍、无 AST、无 IR 设计,我就无法为这两种语言提出一个好的编译模型。当然可能存在一种模型,但我的思考无法弄清楚。 现实情况是,我整个职业生涯都是用 GC 语言编程的(如果你忽略我做 C++ 和 Verilog 的 5 年),这就是我的思维所在,所以编写一种底层有限的语言,嗯,限制了我的发挥。
#更早的笔记
#目标
- 跨平台——无需安装 Unix 即可在 Windows 上进行编译。不依赖于平台特定的工具。
- 交叉编译——轻松编译到其他目标——操作系统和架构。
- 单个可执行文件(可选),包含编译器、汇编器、链接器。
- 可以在没有操作系统的情况下运行。
- 标准库是可选的,但相当大。
- 核心库是无动态分配的。
- 底层且比 C 更容易编程。
- 没有魔法——隐式转换,大量零成本抽象的优化。
- 优先考虑简洁——但编译器或开发者呢?
- 成为我想用其编写代码的语言。
- 成为应用程序的实现语言以及稍后出现的脚本编程语言。
- 合理的 C 互操作性,并且可能,初始编译为 C。
- 包系统,如果开发出来,不应支持传递依赖。
- 最终支持一个简单、跨平台的 graphics.h 或 MODE 13h 风格的图形库。
- 包含一个 console.h/TUI 风格的库。
- 内联汇编器。
- 小型、干净且理智的语言。
- 某种模块系统。
- 任意的或有原则的限制。
- 内置 SIMD?
#非目标
- 垃圾回收。
- 对任何人有用。
- 完整的内存安全,我想。
- 高级优化。
#未解决的问题
- 模块和类型如何交互?
- 运行时和编译时如何分离?它们如何交互?
- 多态性适合在哪里?参数化?单态化?
- 语句和表达式之间的关系是什么?
#灵感来源
- https://briancallahan.net/blog/archive.html
- https://drewdevault.com/
- https://jcs.org/
- http://cowlark.com/
- http://cowlark.com/cowgol/
- https://www.youtube.com/watch?v=iUarU8Fhvug
- https://www.pastraiser.com/cpu/i8080/i8080_opcodes.html
- https://zsmith.co/intel.php
- https://github.com/ianh/owl
- https://mansfield-devine.com/speculatrix/
- https://blog.waleedkhan.name/union-vs-sum-types/
- https://github.com/mattiasgustavsson/libs Mattias Gustavsson's single-file libraries
- https://github.com/nothings/stb/ Nothings' (Sean T Barrett's) single-file libraries
- https://github.com/gingerBill/gb Ginger Bill's single-file libraries
- https://github.com/antirez/sds Antirez's C string library
- https://github.com/floooh/sokol Sokol single header libraries
- https://github.com/sheredom/subprocess.h single header process launching solution for C
- https://github.com/jondgoodwin/cone/blob/master/PLAN.md a language plan table
tail
to specify tail calls?- https://github.com/r-lyeh/single_file_libs
- https://github.com/libunwind/libunwind
- https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
- https://github.com/Dexter9313/C-stacktrace
- https://github.com/iboB/b_stacktrace
- https://github.com/scottt/debugbreak
- https://github.com/wc-duck/dbgtools
- https://github.com/edubart/minicoro/
- https://ccodearchive.net/list.html
- https://github.com/clibs/clib/wiki/Packages
- https://github.com/clibs/commander
- https://github.com/clibs/flag
- https://github.com/clibs/buffer
- https://nemequ.github.io/hedley/api-reference.html#HEDLEY_NO_RETURN
- https://github.com/rxi/kit
- https://github.com/erkkah/tigr
- https://github.com/martincohen/Punity
- https://ldtk.io/
- https://monocypher.org/
- https://opensource.org/license/UPL
- https://oss.oracle.com/licenses/upl/
What you are I once was. What I am you will become.