Skip to main content

Downloads Downloads Downloads

BFFuck

Makes brainfucking easier

The tools is an esoteric language that compiles to brainfuck, using algorithms in brainfuck algorithms.

Usage:

Run this in Python:

from bffuck import BFFuck
bff=BFFuck()
bf=bff.compile('Your code')

Alternatively, you can use the bcompile shortcut introduced in BFFuck 3.3.0:

from bffuck import bcompile
bf=bcompile('Your code')
# Keyword arguments will be passed to BFFuck()
# while positional ones will be passed to .compile()

Note that if a BFFuck object is created and used, its state will change and therefore cannot compile another program.

Syntax

BFFuck currently supports the following syntax:

Comment:

# Comment

Raw brainfuck code injection:

bf "BF code" # Raw BF code injection

Variable definition:

<variable 1>=<variable 2>
or
<variable>=<number>

Move instruction:

a->b
b<-a
# These two do the same thing:
# They move the value of a to b (overwriting b's value, and make a 0)
# The same as a=b<LF>b=0, but does point-to-point movement between *existing variables*
# so it's both shorter and faster

Pointer-moving command:

moveto(a) # Move pointer to the address of variable a
# Useful with raw brainfuck code generation when interpreting in extensions of brainfuck 

Addition:

add(x,<number>)
or
add(x,<variable>)

Subtraction:

sub(x,<number>)
or
sub(x,<variable>)

Multiplication:

mul(x,<number>)
or
mul(x,<variable>)

Floor division:

div(x,<number>)
or
div(x,<variable>)

Modulo:

mod(x,<number>)
or
mod(x,<variable>)

While loop:

while(<variable or number>)
CODE
endwhile

I/O:

<variable>=in # Reads <variable> as decimal integer
<variable>=inc # Reads <variable> as ASCII character
out(<variable or number>) # Outputs <variable> as decimal integer
outc(<variable or number>) # Outputs <variable> as ASCII character

String output shortcut:

print(STRING) # Without quotes
# For instance
print(Hello World!)

If statement:

if(<variable or number>)
CODE
endif

if(<variable or number>)
CODE1
else
CODE2
endif

Comparison:

lt(x,<number>) # Compares x and the variable or number, if x is less than the variable or number, set x to 1, otherwise 0
or
lt(x,<variable>)

le(x,<number>) # Compares x and the variable or number, if x is less than or equal to the variable or number, set x to 1, otherwise 0
or
le(x,<variable>)

gt(x,<number>) # Compares x and the variable or number, if x is greater than the variable or number, set x to 1, otherwise 0
or
gt(x,<variable>)

ge(x,<number>) # Compares x and the variable or number, if x is greater than or equal to the variable or number, set x to 1, otherwise 0
or
ge(x,<variable>)

eq(x,<number>) # Compares x and the variable or number, if x is equal to the variable or number, set x to 1, otherwise 0
or
eq(x,<variable>)

ne(x,<number>) # Compares x and the variable or number, if x is not equal to the variable or number, set x to 1, otherwise 0
or
ne(x,<variable>)

Macros:

macro $<name> # Macro with no arguments
CODE
endmacro

macro $<name>(<arg1>,<arg2>,...) # Macro with arguments
CODE
endmacro

$<name> # Using a macro with no arguments
$<name>(<arg1>,<arg2>,...) # Using a macro with arguments

Memory:

ptr(a,b) # Store address of a to variable b
ref(a,b) # Store value of address b to variable a
set(a,b) # Set value of address b to a (variable or integer literal)

Structures:

struct struct_name(struct_attr1[:struct_attr1_type],struct_attr2[:struct_attr2_type],...) # define a struct type. Struct attributes can be numbers or other structs
declare struct_name v # define a struct variable of type struct_name named v 

Structures are merely syntactic sugar in BFFuck. For example:

struct pr(fi,se)
pr x

creates variables x.fi and x.se. x doesn't actually exist.

Libraries:

?libraryname

Includes the library library name (with file extension).

It first searches the library in current directory, and then in the stdlib directory in the package.

There are standard libraries for BFFuck, they are:

  • algo.bff implements some algorithms. Currently, there are swap and printarray.
  • alloc.bff allocates memory.
  • array.bff manages memory using arrays.
    • arraystruct.bff manages arrays packed as structs.
  • env.bff gets size of a "byte" specified by the compiler.
  • math.bff implements some math functions.
  • rng.bff a not very decent random number generator.

stdlib.bff is a shortcut to include all standard libraries.

An example of the rng.bff library is here:

?rng.bff
x=0
while(1)
$rnd(x)
outc(x)
endwhile

Prints random bytes.

An example of the algo.bff library is here:

?algo.bff
?arraystruct.bff
a=11
b=25
$swap(a,b)
out(a)
outc(10)
out(b)
outc(10)
declare array arr
$newarray(arr,3)
$ssseta(arr,1,3)
$printarray(arr,44)

Which prints:

25
11
0,3,0

Flags and shortcuts

You can pass these flags to configure the compilation:

  • byte: Passed to BFFuck.compile(), controls the number of bytes for each number (must be 1, 2 or 4).
  • playfield: Passed to BFFuck(), controls the length of playfield.
  • force_trivial_literals: Passed to BFFuck(). If this is True, literals will always be represented by a bunch of pluses

Platform

BFFuck is in pure Python and therefore it supports any platform.

Constraints

Programs compiled from BFFuck needs you to have 8 bit cells that wrap.

Disadvantages

BFFuck currently has these disadvantages:

  1. It's numbers are 8 bit numbers. You can choose 8-bit, 16-bit or 32-bit numbers using the byte keyword argument. But you need to run it on a 8-bit interpreter. REMEMBER: Using numbers with more bits is slower and increases the size of program largely! If you're using 32 bit, remember to use an extremely optimizing interpreter like bffsree!
  2. It has some bugs.

The repository contains some examples, including a Hello World program, a cat program and an A+B program.

Metadata

Release files for bffuck 3.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bffuck 3.4.0
File Size Uploaded Provenance Actions
bffuck-3.4.0.tar.gz 12.7 kB Without provenance Details for bffuck-3.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bffuck 3.4.0
File Interpreter ABI Platform Actions
bffuck-3.4.0-py3-none-any.whl Python 3 none any Details for bffuck-3.4.0-py3-none-any.whl

Total release size: 27.7 kB

Release files / bffuck-3.4.0.tar.gz

Download URL bffuck-3.4.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c1258ddfd629f4f365299f0a434c5cf14c1c3ecf03e3b656c1858817caab100b
BLAKE2b-256 checksum
How to use checksums
d4a182fbaa751d312f51fa344cffde73192850f29a49aeee69ad108e1913a4f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Release files / bffuck-3.4.0-py3-none-any.whl

Download URL bffuck-3.4.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
969f28ae674b23a640deff314c38b120a6ac17e2a6d8fc89b4137f7a38e47fd1
BLAKE2b-256 checksum
How to use checksums
d211254eee8e9abfb151615f568abc83b464e255d34b5346888c64fb0698ab60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Security for bffuck 3.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page