

Let's build an entire programming environment around Brainfuck - malonedotcc
http://malone.cc/posts/lhbs_1.html

======
melling
He's 27... As someone who's 47, I'd like to say: take that energy and try to
build a company, join a few start-ups, try to change the world, travel a lot,
drink in some far away land, etc. This place is a lot of fun :-):
<http://www.cafenose.com/>

~~~
spacemanaki
Your comment really hit a nerve with me, probably because I'm the same age as
the OP and playing around with programming language implementations is a bit
of a hobby for me, so I'll apologize for my reaction ahead of time, I tried to
tone down what follows from the screed I initially wrote.

Your comment comes off as a little bit condescending and presumptuous. There's
this underlying judgement about the relative worth of writing a Brainfuck
interpreter and environment versus drinking in some bar in Guatemala or
starting a company, like the latter is obviously a better use of time and
energy. Aside from the fact that doing the things you mention aren't mutually
exclusive with this little project, it's really tiring to hear (older) people
constantly beat the drum of "you're young! go travel! drink!" on top of the
"start your own company!" startup mantra. Maybe you wish you did more of those
things when you were younger, or maybe you wish you were doing more of them
now, and maybe I will wish the same thing when I'm older...

But they are absolutely not for everyone. I think it's disingenuous to just
throw out "take that energy and try to build a company" as an alternative. Not
everyone has it in them to do all the schlep work required to succeed at their
own startup, so why assume this person hasn't considered it and chosen not to
follow that path? Furthermore, I would personally prefer to tinker with a
Brainfuck implementation than spend any amount of time in any bar, even it's
in Guatemala or Colombia. I usually find them noisy and unpleasant, and I
would find "partying the night away" to be a boring waste of time. But I would
never suggest someone _else_ shouldn't spend their time that way because that
would be assuming a great deal about what's important to them.

Maybe this was just a little flip remark on your behalf, not meant to be taken
seriously. I'm probably projecting a little bit, and reacting to something you
may not have intended to imply. For that, I apologize again.

~~~
matchu
That's not at all what I heard in the parent comment. It's not that tinkering
with programming languages is bad at all. Rather, what OP proposes is a
veritable shitton of work, and really won't be as much fun as he imagines
right now; it'll be work. Hard, hard work, with tons of organizational
overhead. If OP wants to do work of this caliber, the parent comment suggests
that OP first seek out more productive, equally exciting and technically
challenging ways to channel that energy.

That's my interpretation, anyway. Not that hobbies are bad, but that this is
gonna be a life-consuming hobby, will likely detract from other pursuits, and
may not pay off as well as OP thinks it will.

~~~
malonedotcc
You assume that:

a) I'm going to be doing this "work" (which, okay yeah it is) full-time or
even constantly, when I'm probably just going to hack on it for the next few
months or years; whenever I've got a coding itch. I doubt I'll ever go into
crunch mode on this or get "burned out". I'll just put it aside for a while
and do something else.

b) That I can't just say "Whelp, it was fun but I'm done" at some point during
the project and find something else to do. There's no hardcore commitment
here; like all projects, everything beyond the first step is a pipe dream.

I get what you're saying though and it could definitely be a shitton of work
that's probably not usable IRL. But it's still a fun plaything.

------
haberman
Blog entry describing my 100-line x86-64 Brainfuck JIT (built on DynASM):
[http://blog.reverberate.org/2012/12/hello-jit-world-joy-
of-s...](http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-simple-
jits.html)

(Direct link to the code:
<https://github.com/haberman/jitdemo/blob/master/jit3.dasc>)

~~~
Scaevolus
I've been looking for a DynASM tutorial for ages, and wanted to use it to make
a fast BF interpreter-- this is great!

I added some optimizations using Flex to identify patterns, and got a 3.8x
speedup on the Mandelbrot benchmark -- <https://github.com/rmmh/beefit>

~~~
haberman
Very nice! I wouldn't have thought to use flex to recognize optimizable
patterns. :) It crashes for me on OS X but I'll have to try it on Linux.

You may have tried this already, but where you have:

    
    
        mov al, byte [PTR]
    

Usually you want to write this instead to avoid a partial register stall (also
in case there's junk sitting in the register).

    
    
        movzx  eax, byte [PTR]

~~~
Scaevolus
Hm, the OSX crash is probably because they have a different ABI from Linux --
Google "osx ia32 abi" for details-- I'm probably violating stack alignment.

Partial register stalls are where you write part of the register, then read
the full register:

    
    
        mov al, byte [PTR]
        add ebx, eax
    

But I am emitting this:

    
    
        mov al, byte [PTR]
        add byte [PTR+3], al
    

So there's no stall.

I got jit4 about as far as is reasonable for a single-pass compiler, but I
intend to implement a proper BF->IR->ASM compiler to implement some more
complex multi-pass optimizations I have in mind.

~~~
haberman
Yes, I have encountered the problem before that OS X crashes on incorrect
stack alignment even where other platforms tolerate it.

Good point about the stall -- I always thought that partial register stall
happened at the point that you do the partial write, since the logical
contents of the register now depend on its previous contents. I didn't realize
that the dependency logic was sophisticated enough to allow the partial read
without depending on the entire register's value.

------
bjourne
Sounds like fun, but maybe you should wait with submitting it until you have
something going? In case you lose interest for some reason.

~~~
michaelochurch
It does sound cool, and it's no small undertaking. A high-level language like
a Lisp requires GC, for one example.

It'll be neat to see what he comes up with.

~~~
RodgerTheGreat
GC doesn't have to be terribly complex:
<https://gist.github.com/JohnEarnest/4522067>

------
faizanaziz
++++++++++[ > +++++ +++ > +++++ +++++ << \- ] > \-- . > +++++ . \----- - . ++
. > +++++ +++++ .

~~~
ctdonath
<http://fatiherikli.github.io/brainfuck-visualizer/>

~~~
faizanaziz
Wow thats a cool tool… Makes sense also, after all not many operators to worry
about :)

------
hardwaresofton
I think there real questions here are:

1) How long have you been insane?

2) Static or Dynamic typing?

~~~
andyjohnson0
3) Generics?

~~~
hardwaresofton
4) Iterators?

5) ???

6) Web framework?

~~~
malonedotcc
4) Already got 'em. A Brainfuck iterator is just a bracket loop with an ascend
command before the closer.

5) !!!

6) I am but a mere mortal, sir.

------
alganet
<http://reinventingthewheel.github.com> (2011)

~~~
azmenthe
The name of that project is horribly relevant.

~~~
siddboots
I feel pretty safe in assuming that it is intentionally ironic.

------
dysoco
I wrote some kind of assembler on top of Brainfuck: Basically tweaked a
Brainfuck interpreter that I wrote in C.

So instead of: +++++++. You would write 7+. or something similar... can't
remember now.

------
qixxiq
I started writing a simple parser/interpreter to convert a C-like language to
brainfuck[1]. Simple sample code with a loop at [2] and result code [3]

I never quite got around to functions, but there is basic support for
arithmetic, for loops and rand()

[1] <https://github.com/qix/c2brainfuck> [2]
[https://github.com/qix/c2brainfuck/blob/master/samples/beer....](https://github.com/qix/c2brainfuck/blob/master/samples/beer.c)
[3]
[https://github.com/qix/c2brainfuck/blob/master/samples/beer....](https://github.com/qix/c2brainfuck/blob/master/samples/beer.bf)

------
smoyer
Interesting project ... but what about hardware?

It would be pretty trivial to create a uP out of high-speed logic that would
execute each instruction in a single clock cycle. Add a PIC uC to actually
load the program memory and you could have a nice little console machine.

As a side note, I've spent most of my career building uC systems that
communicate via RS-232 or RS-485 (if they communicated with the outside world
at all), so imagine my surprise to find I couldn't buy a laptop with a serial
port. It's like the end of an era (yes ... I know about USB-to-serial
adapters).

~~~
nitrogen
Is there a place where embedded systems job listings tend to be posted?

~~~
smoyer
The industry rag is "Embedded" ( <http://www.embedded.com/> ) which replaced
the print version published as "Embedded Systems Programming". There used to
be three to four pages of "Help Wanted" ads near the back of each issue and
that was the best place to find embedded systems jobs. The reality is that
most job boards have these listings now (and they're usually cross-listed) but
you often have to search for embedded related topics to find them. Try PIC,
Microchip, ARM, uC, uP, etc.

------
shoo
brainfuck is a wonderful toy language. it is so simple - the entire language
fits easily in your head, even though it is difficult to do anything useful
with it.

more generally, compilers are fun to learn about. i found Jack Crenshaw's
"Let's build a compiler" series a good starting reference and source of
inspiration [1].

i built a brainfuck to GNU assembly compiler in brainfuck. to be able to write
that compiler, i first built a higher-level macro language that could target
brainfuck, and wrote a compiler for that. the macro language was implemented
as a horrible DSL in python [2].

later i built an implementation in haskell that could parse and compile the
macro DSL to brainfuck, so things ended up entirely python-free [3]. Haskell's
Parsec parser combinator library was fun to learn about too [4].

[1] <http://compilers.iecc.com/crenshaw/>

[2] <https://github.com/fcostin/abfc>

[3] <https://github.com/fcostin/abfc_hs>

[4] <http://www.haskell.org/haskellwiki/Parsec>

------
klez
Some time ago I tried writing an extended Brainfuck interpreter (m4bf - macro
brainfuck)[1] .

In addition to the basic language it had a stack and, with a bit of c
preprocessor trickery, i devised a hackish way to have macros (despite the cpp
man page saying not to use this for anything but as a c preprocessor).

[1] <https://github.com/federicoculloca/m4bf/>

------
otibom
Why not just write an LLVM to brainfuck compiler ?

~~~
mhd
Like this: <https://github.com/jeremyroman/llvm-brainfuck> ?

~~~
zapu
This looks like brainfuck compiler (frontend, as in, it takes brainfuck and
makes executable), not brainfuck to llvm (backend) compiler.

------
lucian1900
You could write (or re-use) a RPython brainfuck interpreter, so you'd get a
JIT for free :)

------
d0mine
There is a tutorial on how to add JIT to the interpreter written in RPython
(if CPython 3 happens to be slow)
[http://morepypy.blogspot.ru/2011/04/tutorial-
part-2-adding-j...](http://morepypy.blogspot.ru/2011/04/tutorial-
part-2-adding-jit.html)

------
abraham_s
Before this goes any further, can we change the name of the language to
something inoffensive. The name makes it impossible to mention it in many
environments. Some alternatives I can think of is BrainF, Brainfreeze,
Brainscrew.

~~~
lucian1900
Nothing wrong with Brainfuck, or fuck for that matter. If anything, it'll get
the people that are bothered by it desensitised :)

------
samatman
This reminds me of Urbit: <https://github.com/cgyarvin/urbit>

Which is at least as weird, more serious, further along, and orders of
magnitude more ambitious.

------
fabriceleal
Here's an interpreter of mine made in Lisp:
<https://github.com/fabriceleal/Brainfuck>

~~~
mgoeppner
In the same vein, here's my JS interpreter:
<https://github.com/mgoeppner/brainfuck.js>

------
michaelfeathers
Lisp on top? Why not Perl 6?

~~~
patrickmay
Relevant xkcd: <http://xkcd.com/224/>

------
bachback
Announcing things that will never get finished. How exciting.

------
michaelochurch
OP, this seems cool and might be of use to you when you include functions:
<http://en.wikipedia.org/wiki/Binary_lambda_calculus>

------
flippyhead
craziness

------
arnehormann
What good does a body if a soul makes a soul?

------
acqq
Let's not. The offensive name, suitable only for inside jokes. Slow as hell.
No chance to achieve any usable insights.

