PROPBrainFsck; an Interpreter for Obfuscated Programming. Code included.
UltraLazer
Posts: 30
The BrainFsck "programming language is an esoteric programming language noted for its extreme minimalism. It is a Turing tarpit, designed to challenge and amuse programmers, and is not suitable for practical use" - Wikipedia.
there are 8 instructions and they go like:
> increment the data pointer (to point to the next cell to the right).
< decrement the data pointer (to point to the next cell to the left).
+ increment (increase by one) the byte at the data pointer.
- decrement (decrease by one) the byte at the data pointer.
. output a character, the ASCII value of which being the byte at the data pointer.
, accept one byte of input, storing its value in the byte at the data pointer.
[ if the byte 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*.
] if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command*.
PROPBrainFsck.spin is a quick BrainFsck interpreter that should be able to run most BF code.
I thought BF might be an interesting way to experiment with genetic computation in spin. BF programs generated by the propeller from blocks of BF code could be evaluated (output/memory), recombined, and evolved over time. I wonder how long it would take to evolve 1+1=2? Sounds like a big can of worms...
Anyway, please let me know about any bugs etc.
Lots of great code, and blocks for standard math and logic operations are found on the internet.
PropBrainFsck.spin requires the Parallax Serial Terminal.
Includes 2 BF demo programs.
program1 - Outputs some text
program2 - Outputs arbitrarily many Fibonacci numbers.
(program2 work of Daniel B Cristofani http://www.hevanet.com/cristofd/)
A.
there are 8 instructions and they go like:
> increment the data pointer (to point to the next cell to the right).
< decrement the data pointer (to point to the next cell to the left).
+ increment (increase by one) the byte at the data pointer.
- decrement (decrease by one) the byte at the data pointer.
. output a character, the ASCII value of which being the byte at the data pointer.
, accept one byte of input, storing its value in the byte at the data pointer.
[ if the byte 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*.
] if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command*.
PROPBrainFsck.spin is a quick BrainFsck interpreter that should be able to run most BF code.
I thought BF might be an interesting way to experiment with genetic computation in spin. BF programs generated by the propeller from blocks of BF code could be evaluated (output/memory), recombined, and evolved over time. I wonder how long it would take to evolve 1+1=2? Sounds like a big can of worms...
Anyway, please let me know about any bugs etc.
Lots of great code, and blocks for standard math and logic operations are found on the internet.
PropBrainFsck.spin requires the Parallax Serial Terminal.
Includes 2 BF demo programs.
program1 - Outputs some text
program2 - Outputs arbitrarily many Fibonacci numbers.
(program2 work of Daniel B Cristofani http://www.hevanet.com/cristofd/)
A.
Comments
-Phil
@phil, Exactly, because the genotype and phenotype are so far removed from one another there is good chance that many genes will have no impact on the final computation result. There is allot to be said for the potential to do nothing, that way when the genes need to do something different there is more genetic potential stock piled in tag-along genes that had been useless. It would be cool to run a few populations in parallel on islands in different cogs. As these populations diverge from one another a few genes are allowed to emigrate to another island
As for the recombination, I was thinking of treating the BF programs like trees. [ ] loops correspond to sexed branch structures (preserve loop "balance"?) and the code/blocks are leaves.
@humanoid
I had the interpreter starting and stopping the terminal if you remover "'PST.Stop " on line # 68 it should be good to go. sorry.
Cheers.
--Steve
I did a simple GA optimization in spin, but optimizing the GA it self is very difficult outside of tweaking a few parameters (mutation rate, initial population etc). I thought it might be possible to code the fitness function for the spin GA in BF. This way the function that decides which genes survive has the chance to evolve it self. The prop could generate, run and evaluate BF fitness functions. Then the issue it the meta fitness function...