matslina/awib Usage Optimizations Requirements Environment License

Google ChromeFirefoxdownload GitHub Desktopdownload GitHub Desktopdownload Xcodedownload the GitHub extension for Visual Studio







Skip to content








Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.




<!-- -->

Learn more



























  • Watch

    12







  • Star


    297







  • Fork


    7



matslina/awib

















a brainfuck compiler written in brainfuck











  • 136

    commits





  • 1

    branch







  • 0

    releases






  • Fetching contributors







  • GPL-3.0





Brainfuck
Roff
Python
C
Assembly
Shell
Makefile





  1. Brainfuck
    34.2%





  2. Roff
    29.6%





  3. Python
    29.3%





  4. C
    2.3%





  5. Assembly
    2.1%





  6. Shell
    2.1%





  7. Makefile
    0.4%





Branch:
master






Find File






Clone or download















@matslina





matslina





more succinct head



Latest commit

eaf1d79

Sep 3, 2016






Permalink































































Type Name Latest commit message Commit time
Failed to load latest commit information.


386_linux


pad memory areas to survive MUL w overreaching offset


Oct 21, 2015


formats


format for 0.3


Oct 3, 2010


frontend


adds target lang_java (with backend skeleton)


Apr 4, 2014


lang_c


pad memory areas to survive MUL w overreaching offset


Oct 21, 2015


lang_generic


remove redundant dummy backend


Oct 31, 2015


lang_java


pad memory areas to survive MUL w overreaching offset


Oct 21, 2015


systest


file modes: +x and -x


Sep 8, 2014


test


pad memory areas to survive MUL w overreaching offset


Oct 21, 2015


util


report line and column on suspected infinite or unbalanced loop


Feb 16, 2014


COPYING


add GPLv3 license text


Oct 19, 2008


DEVEL


mention lang_java index in docs


Oct 22, 2015


Makefile


dont depend on dummy.b coz it no longer exists


Nov 1, 2015


README.md


more succinct head


Sep 3, 2016


awib-skeleton.b


remove redundant dummy backend


Oct 31, 2015








README.md











Awib is a brainfuck compiler entirely written in brainfuck.


  • Awib implements several optimization strategies and its compiled
    output outperforms that of many other brainfuck compilers

  • Awib is itself a 4-language polyglot and can be run/compiled
    as brainfuck, Tcl, C and bash

  • Awib has 6 separate backends and is capable of
    compiling brainfuck source code to Linux executables (i386) and
    five programming languages: C, Tcl, Go, Ruby and Java


Usage


Feed awib brainfuck source code as input and the compiled program
will be written as output.


Awib is a cross-compiler. The supported target platforms are
listed below. By default, the target "lang_c" is chosen.


To specify a target platform, insert a line on the form "@TARGET"
(without the quotation marks and with "TARGET" suitably replaced)
at the very beginning of the source code you wish to compile.
Awib will then produce output accordingly.


386_linux - Linux executables for i386
lang_c - C code
lang_ruby - Ruby code
lang_go - Go code
lang_tcl - Tcl code
lang_java - Java code

For instance, the following input would produce an executable hello
world-program for Linux:


@386_linux
++++++[->++++++++++++<]>.----[--<+++>]<-.+++++++..+++.[--->+<]>-----.--
-[-<+++>]<.---[--->++++<]>-.+++.------.--------.-[---<+>]<.[--->+<]>-.

The following would produce a hello world-program in Ruby:


@lang_ruby
++++++[->++++++++++++<]>.----[--<+++>]<-.+++++++..+++.[--->+<]>-----.--
-[-<+++>]<.---[--->++++<]>-.+++.------.--------.-[---<+>]<.[--->+<]>-.

And this file would give you the hello world-program in C:


@lang_c
++++++[->++++++++++++<]>.----[--<+++>]<-.+++++++..+++.[--->+<]>-----.--
-[-<+++>]<.---[--->++++<]>-.+++.------.--------.-[---<+>]<.[--->+<]>-.


Optimizations


Awib is an optimizing compiler:


  • Sequences of '-','>','<' and '+' are contracted into single
    instructions. E.g. "----" is replaced with a single SUB(4).

  • Mutually cancelling instructions are reduced. E.g. "+++-->><"
    is equivalent to "+>" and is compiled accordingly.

  • Some common constructs are identified and replaced with single
    instructions. E.g. "[-]" is compiled into a single SET(0).

  • Loops known to never be entered are removed. This is the case
    for loops opened at the very beginning of a program (when all
    cells are 0) and loops opened immediately after the closing
    of another loop.

  • Copy and multiplication loops are replaced with constant time
    operations. E.g. "[->>+++<+<]" is compiled into two RMUL(2, 3),
    RMUL(1,1)), SET(0)..


Requirements


Awib will run smoothly in any brainfuck environment where:


  • Cells are 8-bit or larger

  • The read instruction ',' (comma) issued after end of
    input results in 0 being written OR -1 being written
    OR no change being made to the cell at all.

The vast majority of brainfuck environments meet these criteria.


Since awib is polyglot, it is also possible to compile and/or run awib
directly as C, tcl or bash. For instance, using gcc, the following
will build an executable file called awib from awib-0.2.b.


$ cp awib-0.2.b awib-0.2.c
$ gcc awib-0.2.c -o awib.tmp
$ ./awib.tmp < awib-0.2.b > awib-0.2.c
$ gcc -O2 awib-0.2.c -o awib

Using bash works fine, but is very very very slow:


$ (echo "@386_linux"; cat awib.b) | bash awib.b > awib
$ chmod +x awib

And tcl:


$ (echo "@386_linux"; cat awib.b) | tclsh awib.b > awib
$ chmod +x awib


Environment


Code compiled with awib will execute in an environment where:


  • Cells are 8-bit wrapping integers.

  • Issuing the read instruction ',' (comma) after
    end of input results in the current cell being
    left as is (no-change on EOF).

  • At least 2^16-1 = 65535 cells are available.

  • Operating beyond the available memory, in either
    direction, results in undefined behaviour.


License


This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

Mats Linander, 2014-09-14























You can’t perform that action at this time.




You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.










Popular posts from this blog

Sahara Skak | Bilen | Luke uk diar | NawigatsjuunCommonskategorii: SaharaWikivoyage raisfeerer: Sahara26° N, 13° O

The fall designs the understood secretary. Looking glass Science Shock Discovery Hot Everybody Loves Raymond Smile 곳 서비스 성실하다 Defas Kaloolon Definition: To combine or impregnate with sulphur or any of its compounds as to sulphurize caoutchouc in vulcanizing Flame colored Reason Useful Thin Help 갖다 유명하다 낙엽 장례식 Country Iron Definition: A fencer a gladiator one who exhibits his skill in the use of the sword Definition: The American black throated bunting Spiza Americana Nostalgic Needy Method to my madness 시키다 평가되다 전부 소설가 우아하다 Argument Tin Feeling Representative Gym Music Gaur Chicken 일쑤 코치 편 학생증 The harbor values the sugar. Vasagle Yammoe Enstatite Definition: Capable of being limited Road Neighborly Five Refer Built Kangaroo 비비다 Degree Release Bargain Horse 하루 형님 유교 석 동부 괴롭히다 경제력

19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу