BFMacros

From Esolang
Jump to navigation Jump to search

BFMacros is a brainfuck clone except with random commands that may or may not be useful.

Overview

BFMacros (Brainfuck Macros) runs with a rightward infinite tape where each cell is an 8-bit wrapping cell, initialized to 0. The pointer starts at the first cell.

Instruction set

All "macros" are run with the current state of the tape.

+ - < > [ ] . , Same as brainfuck
a Runs [>+<-]>
s Runs [>-<-]>
S Runs [->-[>]<<]>
d Runs [>++<-]>
h Runs [>+<--]>
A Runs [-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a Runs [-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
: Runs >>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<
c Runs ,.[,.]
! Runs [-]+++++++++++++++++++++++++++++++++.

Custom macros

D Define a custom macro with a name of the value of the current cell. The code inside of the macro definition will not be run.
d End definition of macro. When used while not defining a macro, do nothing.
m Pause current execution, read the current cell's value, run the macro with the name of that value, continue with normal execution.

Examples

Output a number

++++++
:

Cat program

Trivial,

c

Quine

Also trivial,

!

Macro demonstration

The macro will add 5 to the current cell and the macro has the name of 3.

+++D<+++++>d 3
[-]          0
+++++++      7
>+++         7 3
m            call macro,
[-]<:        clear cell with 3 and output 12


Turing-completeness

Since any brainfuck program will work in BFMacros, BFMacros is Turing-complete.