B编程语言编译器
Compiler for the B Programming Language

原始链接: https://github.com/tsoding/b

Strawberry 🍓 编译器提供了一个用 Rust 编写的 B 编程语言实现,使用 fasm 作为后端。虽然 WarningCompiler 功能尚不完整,但该项目包含一个编译器 `b`,可以执行 B 程序(例如,`./build/b -run ./examples/hello_world.b`)。更多示例请参见 `./examples/` 目录。 `btest` 实用程序简化了测试过程。它从 `./tests/` 编译并运行针对支持目标的测试,生成一个测试状态矩阵报告。运行 `make` 命令可以构建编译器和 `btest`。 可以使用标志自定义测试:`-t` 指定目标平台(例如,`./build/btest -t fasm-x86_64-linux`),`-c` 选择特定的测试用例(例如,`./build/btest -c upper`)。可以组合使用 `-c` 和 `-t` 来进行更细粒度的控制(例如,`./build/btest -c upper -c vector -t fasm-x86_64-linux -t uxn`)。`btest` 可以优雅地处理错误,并为每个测试编译状态报告。

Hacker News 上的一个帖子讨论了 tsoding 使用自定义的 Rust 子集/方言“Crust”实现的 B 语言编译器。“Crust”通过使用不安全代码、指针而非引用、直接 `rustc` 编译以及避免使用标准库来追求简洁性。评论者们就该项目选择 Rust(或 Crust)展开了辩论,一些人建议 Zig 可能是更好的替代方案。tsoding 的项目被一些人视为简单系统示例。其他人分享了他们自己的 B 语言实现,并且一位用户因其可能对 tsoding 的工作不够了解而被幽默地指了出来,因为 Crust 明确偏离了惯用的 Rust 风格。该帖子强调了该项目对裸机编程的关注以及对过于复杂的构建系统的拒绝。
相关文章

原文

Warning

Compiler is not fully implemented yet.

Logo by Strawberry 🍓

Compiler for the B Programming Language implemented in Crust

  • Rust - the compiler is written in it;
  • fasm - used as the compiler backend;
$ make
$ ./build/b -run ./examples/hello_world.b

Also check out more examples at ./examples/.

The project comes with btest utility which tests the B compiler. It is built automatically along with the B compiler when you do make.

When you run it, it just builds and runs all the tests from the ./tests/ folder on all the supported targets and generates a matrix report. Give it a try to see it for yourself:

It doesn't crash when it encounters errors, it just collects the statuses of the tests on all the platforms to give an overview of the current state of the compiler.

If you want to test only on a specific platform you can supply the flag -t

$ ./build/btest -t fasm-x86_64-linux

You can supply several platforms

$ ./build/btest -t fasm-x86_64-linux -t uxn

If you want to run a specific test case you can supply flag -c

You can do several tests

$ ./build/btest -c upper -c vector

And of course you can combine both -c and -t flags to slice the Test Matrix however you want

$ ./build/btest -c upper -c vector -t fasm-x86_64-linux -t uxn
联系我们 contact @ memedata.com