Brainfuck with jit, llvm c api as backend
- add optimizations at byte code level
- peephole
- too many to be listed
- add llvm c api backend to jit it
- add better error handling, currently there is none besides panicking
use brainfuck::{machine::create_default_machine, source_file::UcSourceFile};
fn main() {
let mut machine = create_default_machine();
let src_file = UcSourceFile::new("tests/artifacts/hello_world_1.bf").unwrap();
machine.eval_source_file(&src_file); // OUTPUT: Hello World!
let byte_codes = src_file.to_byte_codes().unwrap();
machine.eval_byte_codes(&byte_codes); // OUTPUT: Hello World!
}
$ cargo build --release
$ target/release/bfi tests/artifacts/hello_world_1.bf
Hello World!
End to end, doesn't do anything indirectly, encapsule no objects. Interpreting source file takes
$ /usr/bin/time ./target/release/bfi tests/artifacts/mandelbrot.bf
46.71user 0.00system 0:46.71elapsed 99%CPU (0avgtext+0avgdata 2852maxresident)k
0inputs+0outputs (0major+301minor)pagefaults 0swaps
With interpreting source file directly, eval time is
Evaluating byte codes, eval time down to
With "compressed" byte codes, byte codes eval time down to >>>>
to something like 4>
.
Change UnicodeChar
from storing source file index to SmolStr
, by doing this, we don't need to do slicing each time to get tokens.
- Source file evaluation time down to
$\textcolor{green}{\textsf{78}}$ seconds - Byte code evaluation time down to
$\textcolor{yellow}{\textsf{10}}$ seconds
By changing the iterator to a more direct call to &UnicodeChars::IntoIter
,
- Source file evaluation time down to
$\textcolor{green}{\textsf{66}}$ seconds - Byte code evaluation time down to
$\textcolor{yellow}{\textsf{9}}$ seconds
- Source file evaluation time grows up to
$\textcolor{green}{\textsf{80}}$ seconds - Adding tests for it make the evaluation time down to
$\textcolor{green}{\textsf{76}}$ seconds. Could be one of those machine code alignment things
- This makes everything slower, source file evaluations time grows up to
$\textcolor{gree}{\textsf{82}}$ seconds - Byte code evaluation time grows up to
$\textcolor{yellow}{\textsf{10}}$ seconds, but I think it is within the margin of error