All Projects → brain-labs → Brain

brain-labs / Brain

Licence: gpl-3.0
An esoteric programming language compiler on top of LLVM based on Brainfuck

Programming Languages

language
365 projects

Projects that are alternatives of or similar to Brain

Akilang
A compiler for a simple language, built with Python and LLVM
Stars: ✭ 71 (-36.61%)
Mutual labels:  compiler, llvm, repl
Red
Red is a next-generation programming language strongly inspired by Rebol, but with a broader field of usage thanks to its native-code compiler, from system programming to high-level scripting and cross-platform reactive GUI, while providing modern support for concurrency, all in a zero-install, zero-config, single 1MB file!
Stars: ✭ 4,725 (+4118.75%)
Mutual labels:  compiler, interpreter, repl
Mond
A scripting language for .NET Core
Stars: ✭ 237 (+111.61%)
Mutual labels:  compiler, interpreter, repl
Bic
A C interpreter and API explorer.
Stars: ✭ 719 (+541.96%)
Mutual labels:  compiler, interpreter, repl
Rascal
The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
Stars: ✭ 284 (+153.57%)
Mutual labels:  compiler, interpreter, repl
Cfl
a Compileable statically typed Functional programming Language
Stars: ✭ 7 (-93.75%)
Mutual labels:  compiler, llvm, interpreter
Flashforth
FlashForth development
Stars: ✭ 60 (-46.43%)
Mutual labels:  compiler, interpreter
Kai
An expressive low level programming language
Stars: ✭ 68 (-39.29%)
Mutual labels:  compiler, llvm
Seeless
C IDE for iOS
Stars: ✭ 71 (-36.61%)
Mutual labels:  compiler, llvm
Ghdl
VHDL 2008/93/87 simulator
Stars: ✭ 1,285 (+1047.32%)
Mutual labels:  compiler, llvm
Cymbal
Yet another Rust implementation of the Monkey language from "Writing an Interpreter in Go" and "Writing a Compiler in Go"
Stars: ✭ 49 (-56.25%)
Mutual labels:  compiler, interpreter
Mini Interpreter
A Simple Scripting Language
Stars: ✭ 72 (-35.71%)
Mutual labels:  compiler, interpreter
Quickjs
The official repo is at bellard/quickjs.
Stars: ✭ 1,429 (+1175.89%)
Mutual labels:  compiler, interpreter
Tiny Lisp
A tiny lisp compiler written in JS
Stars: ✭ 58 (-48.21%)
Mutual labels:  compiler, interpreter
I8086.js
16bit Intel 8086 / 80186 + X87 emulator written in TypeScript with REPL assembly compiler and tiny C compiler
Stars: ✭ 54 (-51.79%)
Mutual labels:  compiler, repl
Mir
A light-weight JIT compiler based on MIR (Medium Internal Representation)
Stars: ✭ 1,075 (+859.82%)
Mutual labels:  compiler, interpreter
Goto
Goto is an interpreted programming language written in go.
Stars: ✭ 79 (-29.46%)
Mutual labels:  interpreter, repl
Wasm Forth
A Forth implementation compiling to WebAssembly.
Stars: ✭ 92 (-17.86%)
Mutual labels:  compiler, interpreter
Enzyme.jl
Julia bindings for the Enzyme automatic differentiator
Stars: ✭ 90 (-19.64%)
Mutual labels:  compiler, llvm
Numba Scipy
numba_scipy extends Numba to make it aware of SciPy
Stars: ✭ 98 (-12.5%)
Mutual labels:  compiler, llvm

Logo

Brain

Build Status

A computer language based on Brainfuck.

Table of Contents

About

Brain wants to improve the performance of the Brainfuck programming language and extend it as well, as Brainfuck itself has a lack of flexibility and does not perform great control over complex computations. Brain is open to new model represetantion and allows programmers to extend its capability by attaching LLVM IR to its code.

One of the main ideas of Brain is saving some operations in machine language, creating an instruction optmizer due to the excess of instructions that Brainfuck would generate. Brain aims to implement it by using current technology (LLVM).

In spite of implementing new commands and features, Brain is completely compatible with Brainfuck (but the opposite is not true).

Install

Arch Linux via AUR

yaourt -S brain

Docker

docker pull luizperes/brain:1.0
docker run -it luizperes/brain:1.0

Documentation

You can check this repository documentation on https://brain-labs.github.io/brain/docs/html/index.html

Current Status

Brain is stable on its tag version 1.0

Obs.: To use Project Status (the "Kanban" below), please visit:https://github.com/luizperes/status-projects/blob/master/README.md and http://luizperes.github.io/status-projects/

Project Name Status Technology Priority Deadline
Brain 1.0 Progress C/C++/LLVM Low
Brain 1.1 Progress C/C++/LLVM Low
To Do In Progress Done
PostIt PostIt PostIt PostIt
PostItPostIt
PostItPostIt
PostItPostIt
PostIt

TODO List

If you want to check the micro TODO list, please see this issue.

How to build LLVM

Brain runs on the top of LLVM, thus, you are required to install the lastest versions of LLVM. You can do that by following this http://llvm.org/releases/download.html

How to install pre-commit

This project uses pre-commit to help us to check our commits in order to minimize bugs and other problems on the project, therefore is strongly recommended that you use it, if you are intending to contribute to the project. For that, you can install by:

if you have pip installed:

Mac

brew install pre-commit

Linux

sudo pip install pre-commit

After that, go to where Brain lives:

$ cd /path/to/brain
$ pre-commit install

More information about that here

How to build Brain and run files

To build it, after installing LLVM, execute:

$ cd /path/to/brain/src
$ make
$ make install

Brain will try to run on clang and clang++ automatically. However you can change your CC with the commands:

  • make build-3.8 or make build-3.9 for LLVM 3.8 and 3.9
  • make CC=clang++-3.7 LLVM_CONFIG=clang++-3.7 for older versions (3.7 in this case)

And you can do the same for installing it and running tests:

  • make install C=clang-3.7
  • make tests C=clang-3.7

After running make and make install on it, you can execute:./brain your_brain_file.b. Please check the current status of the project.

How it has been built

Brain is based on previous work https://github.com/luizperes/BrainfuckInterpreter and https://github.com/Lisapple/BF-Compiler-Tutorial-with-LLVM, now trying to make something more serious: Turing Complete, faster, more features/commands and different types.

Technical Information

Brain is now a Turing Complete language. You can now extend the tape size by using the flag --size=<tape size>.

Commands

Implemented

  • > increment the data pointer (to point to the next cell to the righ.
  • < decrement the data pointer (to point to the next cell to the left).
  • + increment (increase by one) the value at the data pointer.
  • - decrement (decrease by one) the value at the data pointer.
  • . output the value at the data pointer.
  • , accept one value of input, storing its value in the value at the data pointer.
  • [ if the value at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command.
  • ] jump to its correspondent [ .
  • * multiply *ptr with *(ptr-1). Store result in *ptr // format: 2 3 *
  • / divide *ptr with *(ptr-1). Store the result in *ptr // format: 2 3 /
  • % divide *ptr with *(ptr-1). Store the remainder in *ptr // format: 2 3 %
  • # prints out the current debug information.
  • { (for loop) iterates 'value-at-the-data-pointer' times and needs to be closed with a matching } command. It does not decrease the value at the data pointer. It will only work for positive values.
  • } jump to its correspondent { .
  • ! (break) jumps to the end of a loop ([ ] or { })
  • ? if the value at the data pointer is zero , jumps to the block with : or ; and executes the commands one by one up to its correlative ;, otherwise, it executes the code until it finds a : or ;.
  • : it works as an otherwise (or else) for ?.
  • ; ends a statement.
  • $ prints out the value at the data pointer divided by 100.
  • ^ move the data pointer (jump) on the tape. Ex.: ++++++++++^ // the data pointer will jump to cell 10.

Not Implemented

  • @ calls a function according to the value at the data pointer.

Example of the instructions above:

  • if-then: ? +++ ; // if (*ptr) { *ptr += 3; }
  • if-else: ? +++ : --- ; // if (*ptr) { *ptr += 3; } else { *ptr -= 3; }
  • for: ++++ { commands } // makes four iterations 4 through 0 (excluded)
  • float numbers: ++>+********$ cell 0[2] cell 1[256] // '$' prints out 256 / 100
  • break loop: +[+++++!] // *ptr = 1; while(*ptr) { *ptr += 5; break; }

Compiler Options

  • --code=<"inline code"> Sets inline brain code
  • --io=repl Sets the IO module to REPLs style
  • --out=<filename> Sets the output filename
  • --size=<number> Sets the number of cells used by the interpreter
  • --size-cell=<number> Sets the cell width (8, 16, 32, 64 bits) of each cell
  • --version Shows the current version of Brain
  • -emit-llvm Emits LLVM IR code for the given input
  • -emit-ast Emits the AST for the given input
  • -emit-code Emits an optimized code for the given input
  • -c Generates object file
  • -S Generates assembly file
  • -v Uses verbose mode for the output
  • -O0 Generates output code with no optmizations
  • -O1 Optimizes Brain generated output code (Default)

Applications on real life

  • Artificial Intelligence/ Machine Learning
  • Send commands to Arduino
  • Easy support to primitive processors

Help

Feel free to send your pull requests. :)

LICENSE

This project extends GNU GPL v. 3, so be aware of that, regarding copying, modifying and (re)destributing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].