Skip to content

Repository files navigation

Brainfuck Virtual Machine

The virtual machine for trivial Brainfuck semantic programming language. This project contains virtual machine, compilers, basic libraries for brainfuck-like programming language construction.

Overview

Brainfuck virtual machine is a memory-base virtual machine. Compile (brainfuck,aSSfuck,reversefuck,Alphuck) to bytecode. Use brainfuck virtual machine to execute bytecodes. Or Decode bytecodes to (brainfuck,aSSfuck,reversefuck,Alphuck).

 brainfuck\ /enecoded to Triplet aSSfuck ------------------------> (packed bytecode) ------------------------> (run on bfvm) Alphuck/ \encoded to Ook!

Bytecode

InstructionDescription
0000Increment the memory cell under the pointer
0001Decrement the memory cell under the pointer
0010Move the pointer to the right
0011Move the pointer to the left
0100Output the character signified by the cell at the pointer
0101Input a character and store it in the cell at the pointer
0110Begin of loop structure, Jump out loop structured if the cell under the pointer is 0
0111End of loop structure, Jump to Begin of loop structure
1000No Processing

Packed bytecode

Bytecode contains 4 bits of binary. Then make two bytecodes to a byte (8 bits). 50% Packed.

packed bytecodeDescription
0000 0000++*ptr , ++*ptr
0110 0010while(*ptr){ , ++ptr
0011 0111--pre , }

aSSfuck language

aSSfuck is a joke programming language that uses brainfuck's semantic.

AsS	hello.ass	Hello World! for aSSfuckASSassassassassassassassassassassAsSaSsassassassassassassassaSsassassassassassassassassassassaSsassassassaSsassasSasSasSasSAssASSaSsassassASsaSsassASsassassassassassassassASsASsassassassASsaSsassassASsasSasSassassassassassassassassassassassassassassassASsaSsASsassassassASsAssAssAssAssAssAssASsAssAssAssAssAssAssAssAssASsaSsassASsaSsASs

Compiled to packed bytecodes

Dumpbin by hexdmp

$ ass hello.ass$ hexdmp -h hello.ass.pbc== hello.ass.pbc ==0000000000000000: 067500000000002600000020000000000000000000000010: 000200023333710240020400000044000000000000000020: 400240330000000000000040420040110000000000000030: 11111411111141022484

Run on Brainfuck Virtual Machine

$ bfvm hello.ass.pbcHello World!

Encode packed bytecode to brainfuck!!

$ bc2brainfuck hello.ass.pbc[+,]++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

bfvm specification

  • Manual cell type such as char, short, int, long long int via CELL_T in Makefile.in
  • Fixed tape size, manual tape size via TAPESIZE in Makefile.in
  • At the begin of TAPE, can not move cell ptr to left
  • At the end of TAPE, can not move cell ptr to right
  • Output INST::PUT_VALUE as binary
  • Default EOF is lib's EOF, manual EOF behavior by EOF_UNCHANGED, EOF_MINUS1, EOF_0 in Makefile.in
  • Fixed program size but reuseable
  • Program as iterator not stream
  • Error management, Segmentation fault is imposible!!!!!!

Contact me

About

Brainfuck virtual machine that can run intermediate packed bytecode and any trivial brainfuck semantics language

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages