hp
jblog
toc

Compiling to native brainfuck

2021-09-04, post № 248

programming, #brainfuck, #compiler, #antibloat

Esoteric languages explore novel approaches to computing. Whilst the vast majority of traditional languages decend from C-style von Neumann architecture commandments, these language’s notation and approach to data processing is by design and identity different. Yet in contrast to golfing languages, graphical languages or the even more esoterically inclined, brainfuck can be thought of as a supremely distilled imperative instruction set rather than an unknown beast entirely. Furthermore, its Unix-like approach to I/O makes it suitable to truly use as a target instruction set as the isomorphism behind its Turing completeness is not as opaque as in other esolangs. However, with its minimalistic nature comes questionable performance and tedious development overhead. Thus, a lot of brainfuck programs found in the wild are mere Kolmogorov complexity solutions, taking no input and being optimized to tersely output a constant string of bytes. Nevertheless, writing non-Kolmogorov programs by hand is possible as I have shown in e. g. Interpreting brainfuck in C.
To be able to write more complex programs and compile them to native brainfuck, I have been working since late 2018 on an abstraction concept and implementation thereof. Interest faded inexplicably around Christmas of 2019 such that I only now — one an a half years later — polished my Brainfuck Compiler Project to the point of readiness for unveiling. Notably, it has already been used without mention in Generating the Prouhet-Thue-Morse sequence in brainfuck.

At its core lie two means of abstraction: firstly, the raw tape is symbolically named and scoped via the Tape Abstraction Language which secondly gets extended to a Macro Assembler complete with a basic usage-oriented cell type system and natural derivation capabilities. After all macros are expanded, the residue is compiled to brainfuck. For execution purposes, said brainfuck code is transpiled to C and compiled to a binary using an off-the-shelve C compiler. The result is a fairly readable LISP-inspired macro language which compiles down to machine-executable brainfuck.

Brainfuck Compiler Project is truly free software in the moral interpretation. All project files are bundled in a single tarball: 2021-09-04_jonathan-frech_brainfuck-compiler-project.tar [1]. For ease of use I wrote a shell script which downloads said tarball, installs it temporarily and runs it on a given source file: run.sh

2018-10-11_bcp-draft-1_rotated.jpg
Early Tape Abstraction Language drafting.

Plant fibre puppet

2021-08-07, post № 247

poetry, art, #dialogue, #drawing

2021-07-20_jonathan-frech_plant-fibre-puppet.jpg
              |         such
zuch          |             
              |    thus such
thuz zuch     |             
              |  seldom such
zeldom zuch   |             
              |         such
zuch          |             
              |         such
zuch          |             
              |           so
zo            |             
              |            .
nah           |             
zuch-zeldom-  |             
  zuch-zuch   |             
nah           |             
              |      similar
zimilar       |             
              |            .
nah           |             
zeldom-zuch-  |             
  zimilar-    |             
  zuch-zuch   |             
nah           |             
              |          ...
...           |             
              |         nah.
! zrk-rr r    |             

Factoids #3

2021-07-10, post № 246

mathematics, #topology, #reals, #lipschitzian

X) An intriguingly delicate arbitrarily small countable open cover of uncountably many unbounded points inferred from locally lipschitzian maps’ inability to increase a set’s Hausdorff dimension

Claim. For any uncountable Lebesgue measure zero set Z\subset\mathbb{R}, there exists a point z_0\in Z such that \forall\,\varepsilon>0:{]}z_0,z_0+\varepsilon{[} is still uncountably infinite. Define Z_>:=Z\cap{]}z_0,\infty{[} and on this right portion u:Z_>\to\mathbb{R} as u(z):=\sfrac1{(z-z_0)}. Looking at the graph \mathrm{graph}\,u\subset\mathbb{R}^2, it is a Hausdorff measure zero set — meaning the entirety of all uncountably many points clustered at z_0 span an infinite vertical distance and yet are coverable by countably many sets of arbitrarily small diameter in sum.
Proof. Since \sfrac1x is locally lipschitzian and the reals are Lebesgue \sigma-compact, its image cannot increase the one-dimensional Hausdorff measure which is presumed to vanish.

Solving peg solitaire by pure chance

2021-06-12, post № 245

C, #board-game

In all the years I regularly glanced at our peg solitaire on the board game shelf, seldomly even playing it and attempting a solve — moving 31 out of the total 32 pegs such that the final peg ends up at the board’s center —, yet never succeeded. The closest I got always left two or three pegs standing far between each other, calling doom for my solve.

solving-peg-solitaire-by-pure-chance_one-lobe-cleared.jpg
One lobe cleared.

Not being able to solve this game, the other day I had the idea of pseudo-random game space exploration, my optimism driven by both the moderate number of pegs as well as the strict monotonicity of the game leading to all solutions being of the same length and thus in a sense equal — bearing in mind consecutive hops in the same direction are not considered as a singular move.

Wholly brainfuck

2021-05-15, post № 244

C, brainfuck, #querying

Sparked by a vague idea to query the space of all brainfuck programs — which indeed came to fruition and is detailed in my recent paper Going for a miniKanren implementation. — I thought to capture a miniscule glimpse of said space in a two-dimensional visualization:

wholly-brainfuck_last-stdout_l6.png
All 2^{12+12} generalized 𝟨-long brainfuck programs’ initial three bytes of output.

Cogent chimeras compelling chastised computing

2021-04-17, post № 243

poem, #doubt

Insightful sparks, a forceful nudge —
distant glory or arcane mist:
now wobbly treading trodden paths,
sensing tender sprawling fates …
A step is taken.
A step is taken to one’s side.
Lured in by wonderous ideals,
a gate is shut, the key expunged.
But is what one seeks on this flank to be found?
Or has one only shown themselves:
what one wants most do not;
since never urged to do inquire
about attaining what they never
have proven to be all they could accept?
Away with all the doubt!
One tightly clings to specks deemed fit.
It cannot, must not, dare not crumble!
The flimsy veil begins to lift.
What now? Where to? Once one has sipped?
Stuck in between, not free, not flocking.
Gazing through bars into the veldt
whose sparse and slanted Terminaliae
crash down, they too reveil a fence.

— Jonathan Frech, April of 2021

A source location identification regression in GHC triggered by seven bytes

2021-03-22, post № 242

haskell, compiler-bug, #ghc, #parsing

Working on a minimal XML parser which does both build a data structure and remember its nodes’ source origin, I discarded the second part of a two-tuple by not requiring anything to be present. Yet instead of informing me that a mapping cannot be deconstructed, GHC 8.10.4 gave me an obscure error message:

% runhaskell Xml.hs

<no location info>: error: Tuple section in pattern context

Thankfully I sometimes adhere to a mindfully incremental approach and was not as bewilderingly disoriented as I could have been — after all, a there is an error message possesses little more value than solely stating an executable cannot be built.

Inspecting the probable location I had intelligence on, I managed to extract a seven long byte sequence which triggers a <no location info> compilation error:

j(0,)=0

Yet compilers are squeamish and shapeshifting entities — especially with regards to diagnostic capabilities. Whilst j(0,)=0 cannot be traced, j(,0)=0 induces the expected and appropriate error. As such, I tested the phenomenon using varying GHC versions:

% ghc --version && printf '%s' 'j(0,)=0' > /tmp/nli.hs && ghc /tmp/nli.hs 2>&1 \
cmdand cmdand>     | grep -q '<no location info>' ; echo $?
The Glorious Glasgow Haskell Compilation System, version 8.10.4
0
% ghc --version && printf '%s' 'j(0,)=0' > /tmp/nli.hs && ghc /tmp/nli.hs 2>&1 \
cmdand cmdand>     | grep -q '<no location info>' ; echo $?
The Glorious Glasgow Haskell Compilation System, version 8.8.4
1

To my surprise, I seemed to have found a GHC regression — triggered by only seven bytes.

Alas, this regression is a known one: Another <no location info> error (Tuple section in pattern context) has been opened on the 8th of March 2021, with its comments identifying it as a regression. Yet the fix outlined and performed is as much resolving an aspect of the issue as is it making a stylistic decision — myself facing the same problem of source location corseness, I am leaning further and further towards the approach of less pedantically accurate reporting allowing for a more minimal implementation.

Intriguingly Matured Graphics

2021-03-20, post № 241

imagery, Pygame, #throwback, #png, #colorful

Following digital excavation efforts at my disk’s deep directories, I stumbled upon a collection of colorful pseudo-random walk graphics. Since they are dated September of 2015 and were generated using unidiomatic slow snake script, their only property of note is a visually jolly aura; the following three possess a particularly vibrant one:

intriguingly-matured-graphics_2015-09-24_fancy-12.png
Autumn Colors
intriguingly-matured-graphics_2015-09-25_fancy-24.png
Deep Blue
intriguingly-matured-graphics_2015-09-27_fancy-29.png
Woven Violet
Jonathan Frech's blog; built 2024/07/06 12:42:51 CEST