Null Program

Christopher Wellons
mosquitopsu@gmail.com
Public GPG Key

Chris Wellons


Post Index - see a list of all of the entries.


RSS Logo RSS Feed




Hacker Logo

I am a computer engineer working at the Johns Hopkins University Applied Physics Laboratory. I love computers and free software.

Most of the topics you will find here are about hobby computing and programming with free software (and a few exceptions).

E-mail me: mosquitopsu@gmail.com


My Git Repositories


Projects:
- Brainfuck Compiler
- PNG Archiver
- BINI Tools
- Parallel Mandelbrot Generator


Archives:
September 2007
October 2007
November 2007
December 2007
January 2008
February 2008
March 2008
April 2008
June 2008
July 2008
August 2008
September 2008
December 2008
January 2009


This site is powered by blosxom and DreamHost.

20 Jan 2008

Optimizing, Multi-threading Brainfuck to C Converter

wbf2c converts an esoteric programming language called brainfuck into C code which can be machine compiled. Several optimizations are done to make the resulting program extremely fast an efficient. The converter supports both a static (standard 30,000 cells) array or a dynamically-sized array. It also supports many different cell types, from the standard char to multi-precision cells using GMP.

The converter can also run several brainfuck programs on the same memory array at once by running each one in a thread. To make sure each brainfuck operation is atomic, each cell gets a mutex lock. The only other multi-threading brainfuck implementation I know of is Brainfork.

For an example of some brainfuck code I wrote,

+>+<
[
[->>+>+<<<]>>>
[-<<<+>>>]<<

[->+>+<<]>>
[-<<+>>]<<
]

This program fills the memory with the Fibonacci series. Make sure you use the dynamically sized array, along with the bignum cell type. After two or three seconds of running, my laptop (unmodified Dell Inspiron 1000) can calculate and spit out a 140MB text file containing the first 50,000 numbers in the series. I used the -d dump option to see this output.

Download information, as well as some more examples, including a multi-threaded one, are on the project website.

[] permanent link


Don't stop here! This isn't everything. Check out the archives (on the left) for more posts. Or just have a look at the index.