How To Use Parts Based Programming - PBP
2024-09-24
Objective
To make drawings yourself and to compile and run them - yes
To clone the source for draw.io and customize the editor source code - no
Tinkering With The Drawing Editor Source Code
I veer away from tinkering with a drawing editor, on the assumption that this is hard work and is already done better by someone else.
My goal is to choose drawing editors like draw.io that produce parseable output.
I draw the drawing with the editor, save it out to a .drawio file, then parse the .drawio file and combine it with the PBP kernel and run the drawn program.
I think that other editors, like Excalidraw can be used, but I haven’t had the time to try them out.
In the past, I used yEd and I used raw SVG - both of these formats can be parsed and turned into running code, but draw.io is a lot easier.
Zac knows how to use draw.io and built a parser for .drawio in Odin and a kernel in Odin and uses these techniques at Kagi.com, targeting other languages.
I converted the parser to das2json.mjs (Javascript) and I ported the kernel to Python, Javascript and Common Lisp. Currently, I use the Python version heavily. I, also, have written one larger example in Javascript that runs PBP code in a browser (“html-larson”).
All of PBP/0D/drawware is available in github and can be cloned and played with. I would be glad to help and kibitz.
Easy Start
I think that the easiest place to start is:
cd to pbp/examples/ordered or pbp/examples/helloworld/seq or pbp/examples/helloworld/par
$ make
open ‘ordered.drawio’ and fool around, then recompile. I (we) can advise on tips and tricks for using drawio (or you can read drawio’s documentation or watch their explainer videos). I (we) can advise on PBP programming. Looking at examples pbp/examples/helloworld/seq/seq.drawio or pbp/examples/helloworld/par/par.drawio might help.
Caveat: I’ve tried to make the repo clean and usable, with help from the programming simplicity discord. It all runs on my machine, but github-ery is out of my comfort zone, so there might be glitches (if so, ask and I will try to correct and advise).
Big Example of PBP
The biggest(?) example of PBP programming is the PBP kernel (or Kagi’s stuff, but, I don’t know if that’s public). If you want to port the kernel to any other language, I (we) can help and advise.
The place to get the kernel is https://github.com/guitarvydas/pbp-dev, as above.
Clone it, then cd to pbp/kernel and ask ChatGPT / Claude to explain the code in ‘kernel.rt’ and ‘stock.rt’ and ‘external.rt’ and ‘kernel_external.rt’ or just read the code and try to understand it yourself (questions welcome (please, get me talking about this stuff)).
The source code for the kernel compiler is in ‘kernel.drawio’. The kernel compiler is written in PBP and uses a custom VHLL that I call ‘RT’ that looks a lot like Python.
RT is used to make Leaf Parts. The Container parts are written in kernel.drawio.
Make a copy of ‘emitPython.rewrite’ for whatever other language you want to target, then tweak the code. The ‘.rewrite’ file mates with the generic ‘emit.ohm’. Then run ‘make’. The make process needs to use ‘kernel0d.py’. If you change kernel0d.py, you might get into a chicken-and-egg problem, but, this shouldn’t be a problem when porting to some other language. Maybe, delete the wires (in ‘kernel.drawio’) that cause recompilation of the Python version.
If you do try to port the kernel or otherwise use the T2T stuff, you will need to know how to write .ohm grammars (ohmjs.org) and how to write .rwr rewrite specs (sometimes named ‘*.rewrite’). The documentation for RWR is in github at https://github.com/guitarvydas/pbp-dev/blob/main/t2t/doc/rwr/RWR%20Spec.pdf.
The T2T tool (text-to-text-transpilation) is included in the pbp-dev repo - you already get a copy when you clone the repo.
I’m hoping to make a bare-minimum pbp-substrate repo that includes only the PBP tools but not the full tool development source. I’m writing a handbook on “das2json” and hope to follow that with a handbook for using PBP. The arith and zddemos repos contain earlier attempts at making example PBP code (including an LLM doo-hickey written in PBP). [aside: “DaS” means Diagrams as Syntax. Das2json is a parser that converts .drawio format to .json format and culls out the unneeded graphical information]. I need to be asked questions, to help guide me in what to write. Please ask questions. Please join the discord “programming simplicity” server and ask questions.
See Also
Email: ptcomputingsimplicity@gmail.com
Substack: paultarvydas.substack.com
Videos: https://www.youtube.com/@programmingsimplicity2980
Discord: https://discord.gg/65YZUh6Jpq
Leanpub: [WIP] https://leanpub.com/u/paul-tarvydas
Twitter: @paul_tarvydas
Bluesky: @paultarvydas.bsky.social
Mastodon: @paultarvydas
(earlier) Blog: guitarvydas.github.io
References: https://guitarvydas.github.io/2024/01/06/References.html

