An optimising Brainf*ck to x86-64 assembly compiler written in Rust

Overview

brainfrsk 2

An optimising Brainf*ck to x86-64 assembly compiler.

This compiler can produce optimised binaries for macOS (Sytem V calling convention) by outputting AMD64 asm (similar to my other project).

Speed

I've written several Brainf*ck projects over the years.

Here's a comparison of the execution time for a "Hello world!" program in each:

Project Implementation Time Ratio
brainfJSk JS Interpreter 0.073s 1x
brainGoop Go Interpreter 0.009s 8x
brainfrsk 1 Rust Interpreter 0.008s 9x
brainfrsk 2 Rust Compiler 0.002s 36x faster 🤯

Try it yourself

git clone https://github.com/adamsoutar/brainfrsk-2
cd brainfrsk-2
./compile.sh

This (assuming you're on macOS) will produce and run an output binary at ./output.

Optimisations

More than just writing it in pure assembly code, the compiler makes your code faster by batching repeated operations into one.

For example, +++++ is re-written as add 5.

Tape size & limits

The tape is automatically expanded (it's "unlimited"). Cells are 64-bit integers.

Memory is automatically allocated on the stack. This technically means the tape is limited by the stack size. On macOS that is 8mb, a.k.a 1 million cells.


by Adam Soutar
You might also like...
A compiler for a language representing plonk circuits

Plang A language representing PLONK circuits. Compiler This repository contains a compiler for a language representing PLONK circuits. It allows circu

A fusion of OTP lib/dialyzer + lib/compiler for regular Erlang with type inference

Typed ERLC The Problem I have a dream, that one day there will be an Erlang compiler, which will generate high quality type-correct code from deduced

JIT compiler and runtime for a toy language, using Cranelift

Hello! This is a simple demo that JIT-compiles a toy language, using Cranelift. It uses the new JIT interface in development here. JIT takes care of m

Compiler from a lisp-like language to mlog

slimlog slimlog compiles a lisp-like language to mlog Architecture slimlog is divided into three distinct parts Parser Parses the source file Compiler

Compiler & Interpreter for the (rather new and very experimental) Y programming language.

Y Lang Why would anyone build a new (and rather experimental) language with no real world use case. Design Y (pronounced as why) is based on the idea

A transpiler/compiler for CrabRave, a version of BrainFuck with sea-life emojis.
A transpiler/compiler for CrabRave, a version of BrainFuck with sea-life emojis.

CrabRave Programming Language CrabRave is a fun and unique programming language based on Brainfuck, which utilizes crab and sea-life emojis as its syn

A highly modular Bitcoin Lightning library written in Rust. Its Rust-Lightning, not Rusty's Lightning!

Rust-Lightning is a Bitcoin Lightning library written in Rust. The main crate, lightning, does not handle networking, persistence, or any other I/O. Thus, it is runtime-agnostic, but users must implement basic networking logic, chain interactions, and disk storage. More information is available in the About section.

A language server for lua written in rust

lua-analyzer lua-analyzer is a lsp server for lua. This is mostly for me to learn the lsp protocol and language analysis so suggestions are helpful. T

Opensource diagnostic software for Daimler vehicles, inspired by Xentry and DAS, written in Rust

OPENSTAR An opensource diagnostic application for Daimler vehicles inspired by DAS and Xentry. Some of the work here is based on OpenVehicleDiag If yo

Owner
Adam Soutar
Games / Compilers / Emulators / Apps / Web
Adam Soutar
A Brainf** interpreter written in rust 🦀

Brainf Interpreter An interpreter for the esoteric programming language Brainfuck written in rust ?? Compilation NOTE: To compile the project, you nee

Chitram Dasgupta 2 Sep 12, 2022
Brainf - A brainfuck interpreter written in Rust 🦀

brainf A brainfuck interpreter written in Rust ?? . Do not I wrote this in my spare time... but still its good! Run Locally Clone the project git cl

Nav 3 Oct 8, 2022
🤯 A brainf*ck-style programming language, but readable

?? Brainease Brainease is a brainf*ck-style programming language, but readable. $ cargo install brainease # brainease -f examples/hello.bz save 'H

Arthur Fiorette 11 Sep 30, 2022
Risc-V assembly interpreter built with pure Rust

Risc-V Interpreter Interpreter for Risc-V assembly built with Rust Report bug · Request feature Table of contents Quick start Exemple Program Instruct

null 2 Aug 24, 2022
dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle!

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle (such as rewriting/refactroing your DM code).

SS220 20 Dec 13, 2022
Use explicit container types with Scrypto! Leverage the Rust compiler's type checking to increase security and productivity when developing Radix blueprints.

Scrypto Static Types Use explicit container types with Scrypto! Leverage the Rust compiler's type checking to increase security and productivity when

null 7 Aug 5, 2022
The official zeta compiler

Torq What makes Torq the goto language for creating CLI's? Smaller Executables Inbuilt argument and flag parser Your code will work anywhere in any OS

ZetaLang 2 Nov 24, 2021
The nightly_crimes!{} macro commits horrible crimes to allow you to enable nightly features on the stable compiler.

The nightly_crimes!{} macro commits horrible crimes to allow you to enable nightly features on the stable compiler.

Mara Bos 151 Dec 16, 2022
A compiler for the esoteric language â„‚.

The â„‚ Programming Language It's a language where the only types are "complex number" and "matrix of complex numbers". In particular, this means you ca

Eleanor McMurtry 24 Jul 15, 2022
Solidity-Compiler Version Manager

Solidity Compiler Version Manager

Rohit Narurkar 114 Jan 2, 2023