Crates.io | brainoxide |
lib.rs | brainoxide |
version | 0.1.2 |
source | src |
created_at | 2023-02-03 18:28:12.644399 |
updated_at | 2023-08-27 10:05:12.248342 |
description | An optimizing Brainfuck compiler/interpreter |
homepage | |
repository | https://github.com/VorpalBlade/brainoxide |
max_upload_size | |
id | 775807 |
size | 177,959 |
[ On crates.io ]
An optimizing Brainfuck interpreter/compiler-to-C in Rust.
Made as a project to learn Rust. Code is for sure not idiomatic and quite messy in places.
Features:
Does the world need yet another BF implementation? Not really. Did I have fun making it, and did I learn things? Yes.
BrainOxide performs the following optimisations:
[>]
, [>>]
, ... → various seeksBrainOxide internally differentiates between balanced and unbalanced code
sections. This refers to the amount of >
vs <
. In a balanced code sections
we know all offsets, and are thus able to optimise better. In unbalanced
sections we have very limited abilities to optimise.
For balanced code sections BrainOxide builds a directed acyclic graph (DAG) and performs the optimisation on the DAG.
Partial evaluation until first input instruction:
This could potentially constant fold large programs into a single fputs()
call.
It would have to be opt-in. Additionally, it only makes sense for code gen mode.
Better equation handling:
Right now the lowering of loops into equations is fairly
limited and simplistic. The code cannot lower loops already containing equations for
example, and only a loop index stride of -1
is supported.
Loop/If unrolling:
Unroll loops when we know the iteration count statically, if it makes sense. A heuristic would be needed.
This code base does not have a stable API. It is not meant to be used as a library. The command line flags are not stable either, as there are some changes I'd like to make to allow more flexible logging options.
This software has only been tested on an up-to-date install of Arch Linux x86-64. If it happens to work on non-Linux, that is a happy accident.
YMMV. It works on rustc 1.67.0 as of writing. It should continue working on the latest stable Rust (except fuzz testing that needs nightly). I will not test on older versions than whatever happens to be the latest stable when I make a change.
So in summary: There is no MSRV policy.
BrainOxide is released under GPL 3.0 (only, not "or later").