5 ms·
Let's build an entire programming environment around Brainfuck
- faizanaziz 13y ago++++++++++[ > +++++ +++ > +++++ +++++ << - ] > -- . > +++++ . ----- - . ++ . > +++++ +++++ .
- michaelochurch 13y agoI think you want two more > characters in your loop. As written now, you're decrementing negative-indexed memory.
- faizanaziz 13y agoOops, brainfucked! Fixed BTW
- michaelochurch 13y agoNice\0
- deleted 13y ago[deleted]
- ctdonath 13y agohttp://fatiherikli.github.io/brainfuck-visualizer/ http://fatiherikli.github.io/brainfuck-visualizer/
- faizanaziz 13y agoWow thats a cool tool… Makes sense also, after all not many operators to worry about :)
- bjourne 13y agoSounds like fun, but maybe you should wait with submitting it until you have something going? In case you lose interest for some reason.
- michaelochurch 13y agoIt 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 13y agoGC doesn't have to be terribly complex: https://gist.github.com/JohnEarnest/4522067 https://gist.github.com/JohnEarnest/4522067
- jjs 13y agoYou can prototype with the null-GC until you run out of memory...
- robin_reala 13y agoThere’s a follow-up post detailing some first steps: http://malone.cc/posts/lobe_1.html http://malone.cc/posts/lobe_1.html
- film42 13y ago> In case you lose interest for some reason. I think it's that very reason he's submitting it so early.
- swah 13y agoThere are two camps (I think I'm in the latter): - telling everyone motivates you: you made a public commitment, you get early feedback, "if your idea is any good people will reject it at first" - don't tell anyone motivates you: the idea is yours, you want to build something beautiful and show to the world, you don't like to be criticized when starting up
- alganet 13y agohttp://reinventingthewheel.github.com http://reinventingthewheel.github.com (2011)
- arnehormann 13y agoWhat good does a body if a soul makes a soul?
- otibom 13y agoWhy not just write an LLVM to brainfuck compiler ?
- smoyer 13y agoInteresting 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).
- malonedotcc 13y agoI have distant dreams of building a shell out of this and putting it on a Raspberry Pi... Beyond that, it's far too young for me to decide.
- michaelochurch 13y agoOut of curiosity, am I correct (from your follow-up post) that your cell size is 16-bits (integer range of [0..65535]) and that your tape size is only 256? I suppose it works but convention seems to be 30,000+ bytes and 8-bit cells. Of course, getting pedantic about brainfuck conventions is a bit beside the point (like Orthodox Discordianism). I just want to know if I'm correct and, if so, I'm curious about what is gained through such nonconventional decisions.
- malonedotcc 13y agoI want the core Brainfuck to be as simple and clear-cut as possible. I can implement negative numbers when I get to the assembly stage, and I limited tape size because I'm implementing multiple tapes in the future. I'd rather have many smaller tapes instead of fewer large ones.
- michaelochurch 13y agoThat makes a lot of sense. However, I'd still consider your work a success if it broke the 30,000 barrier in cell count. The brainfuck spec says at least 30k cells. It's not an upper limit. I get why you excluded negative numbers. I was wondering if I was correct in understanding the cell size to be 2 bytes because it's typical for it to be 1 byte. Am I correct that - on a cell at 0 (or + on a cell at MaxVal) is a no-op, just like < and > at the end of the tape?
- klez 13y agoSome 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/ https://github.com/federicoculloca/m4bf/
- michaelfeathers 13y agoLisp on top? Why not Perl 6?
- patrickmay 13y agoRelevant xkcd: http://xkcd.com/224/ http://xkcd.com/224/
- flippyhead 13y agocraziness
- michaelochurch 13y agoOP, this seems cool and might be of use to you when you include functions: http://en.wikipedia.org/wiki/Binary_lambda_calculus http://en.wikipedia.org/wiki/Binary_lambda_calculus
- lucian1900 13y agoYou could write (or re-use) a RPython brainfuck interpreter, so you'd get a JIT for free :)
- d0mine 13y agoThere 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-jit.html http://morepypy.blogspot.ru/2011/04/tutorial-part-2-adding-j...
- qixxiq 13y agoI 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 https://github.com/qix/c2brainfuck [2] https://github.com/qix/c2brainfuck/blob/master/samples/beer.c https://github.com/qix/c2brainfuck/blob/master/samples/beer.... [3] https://github.com/qix/c2brainfuck/blob/master/samples/beer.bf https://github.com/qix/c2brainfuck/blob/master/samples/beer....
- melling 13y agoHe'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/ http://www.cafenose.com/
- rallison 13y agoSmall world. I was just thinking of Cafe No Se this morning because of a brochure of Antigua that I have from a trip there. Cafe No Se advertised on the back of it with a catchy phrase along the lines of "Every dive needs a good town." But yes, I would agree with the general sentiment of experiencing the world. For me, there is not much that is more satisfying than exploring - be it traveling to new places, climbing a mountain or just trying something new. That said, if this project removes the boredom and is interesting/fun to the OP, there is value in that as well.
- melling 13y agoAny project like that is going to be a lot of work. It would probably turn into many man years. Sure, do it if you want. Time is your most valuable asset. Choose wisely. Since Antigua isn't too far off the beaten path, let me throw out Colombia. Spend the night in a hammock near the ocean. http://wikitravel.org/en/Tayrona_National_Park http://wikitravel.org/en/Tayrona_National_Park Party into the night: http://www.lonelyplanet.com/colombia/northwest-colombia/medellin/entertainment-nightlife/bar/zona-rosa http://www.lonelyplanet.com/colombia/northwest-colombia/mede...
- spacemanaki 13y agoYour 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.
- hardwaresofton 13y agoI think there real questions here are: 1) How long have you been insane? 2) Static or Dynamic typing?
- andyjohnson0 13y ago3) Generics?
- hardwaresofton 13y ago4) Iterators? 5) ??? 6) Web framework?
- malonedotcc 13y ago4) 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.
- malonedotcc 13y ago1) I don't think I'm that crazy, I mean this isn't Temple OS or anything (http://www.templeos.org/ http://www.templeos.org/). 2) Integers! Strings are integers, arrays are tapes of integers, etc... I guess this means it's dynamic, but at the bottom levels I'm not (yet) concerned with typing.
- bachback 13y agoAnnouncing things that will never get finished. How exciting.
- fabriceleal 13y agoHere's an interpreter of mine made in Lisp: https://github.com/fabriceleal/Brainfuck https://github.com/fabriceleal/Brainfuck
- mgoeppner 13y agoIn the same vein, here's my JS interpreter: https://github.com/mgoeppner/brainfuck.js https://github.com/mgoeppner/brainfuck.js
- haberman 13y agoBlog entry describing my 100-line x86-64 Brainfuck JIT (built on DynASM): http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-simple-jits.html http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-s... (Direct link to the code: https://github.com/haberman/jitdemo/blob/master/jit3.dasc https://github.com/haberman/jitdemo/blob/master/jit3.dasc)
- Scaevolus 13y agoI'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 https://github.com/rmmh/beefit
- haberman 13y agoVery 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 13y agoHm, 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 13y agoYes, 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.
- acqq 13y agoLet's not. The offensive name, suitable only for inside jokes. Slow as hell. No chance to achieve any usable insights.
- abraham_s 13y agoBefore 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.
- shasta 13y agoNot brainscrew, please. I find that offensive.
- lucian1900 13y agoNothing wrong with Brainfuck, or fuck for that matter. If anything, it'll get the people that are bothered by it desensitised :)
- dysoco 13y agoI 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.
- deleted 13y ago[deleted]
- samatman 13y agoThis reminds me of Urbit: https://github.com/cgyarvin/urbit https://github.com/cgyarvin/urbit Which is at least as weird, more serious, further along, and orders of magnitude more ambitious.
- shoo 13y agobrainfuck 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/ http://compilers.iecc.com/crenshaw/ [2] https://github.com/fcostin/abfc https://github.com/fcostin/abfc [3] https://github.com/fcostin/abfc_hs https://github.com/fcostin/abfc_hs [4] http://www.haskell.org/haskellwiki/Parsec http://www.haskell.org/haskellwiki/Parsec