Advanced Namespace Tools blog

17 August 2019

Digging to the Roots of data and algorithms

I decided I really needed to put some blog posts up again so I opened the blog folder in the ANTS repo and found I had gotten as far as creating the data and title of this post, so I'm just going to roll with it. Let's start with a fragment of Weird Code:

txtcmdone = dicref(pushItem((Inputtoken 30), (pushInputItem ((Inputtoken 31), (makedic (Just [Inputtoken 31], ""))))))
txtcmdtwo = stk2d(pushInputBind(Inputtoken 17, (oneplus(tostack(pushInputBind(Inputtoken 16, setfiletarg(dup(s2da(pushInputBind(Inputtoken 20, quote(Just [Inputtoken 30], "")))))))))))
txtcmdthree = stk2d(pushInputBind(Inputtoken 31, pushCounter(Counter 1, s2da(pushInputBind(Inputtoken 20, quote(Just [Inputtoken 39], ""))))))
txtcmdfour = stk2d(pushInputBind(Inputtoken 13, (oneplus(tostack(pushInputBind (Inputtoken 12, ((tick(Just [Inputtoken 30], "")))))))))

Give your eyes a moment to stop bleeding. And now for something completely different:

: DICREF ( <"name"> dicaddr -- ) \ create dicref jump word

CREATE , DOES> @ STARTDIC CURLIDIC ; : INCSTREND ( dicaddr — openaddr ) \ prep for storage of new word INCDIC INCSTARTDIC ENDSTRDIC ; : INCLIEND ( dicaddr n — openaddr ) INCDIC INCSTARTDIC ENDLIDIC ; : S2DA ( straddr dicaddr — newaddr ) \ store string in dic leave new addr INCSTREND dup -rot swap dup C@ 1+ rot swap move ; : STK2D ( ...items n dicaddr — ) \ append stack to dic INCLIEND LISTO ;

Let's change it up a little bit. How about a bit of shell?

hub -b $s.ctl
mount -c /srv/$s.ctl /n/$s.ctl
echo cd /n/$s.ram >>/n/$s/io0
echo pforth >> /n/$s/io0
echo include $thisdir/map9p.fth >> /n/$s/io0
echo include $thisdir/root.fth >> /n/$s/io0
echo dispatch.rc -t /n/$s/io0 >> $xx
echo mkdir dir1 >> $xx

And maybe a slightly different view of a layer to conclude this introduction:

makedic droot droot dicref root	\ list dic of pointers to files - the directory object itself
" root_" drootstrs s2da dup 1 drootn stk2d	\ create dirname str saving ptr in both rootn
1 drootfiles stk2d	\ and in drootfiles
' rootn ' rootfiles 2 droot stk2d		\ make dir object with no files, name + filenames ptrs
' root 1 ddirtypes stk2d	\ add new dir to list of dirtypes

So, these are a few fragments of code from a toy database/fs system for Plan 9 built from pforth forth, hugs haskell, rc shell, and the hubfs 9p fs. It was created to investigate the ways in which a single core datastructure - a filesystem-like data tree - could be created as a single unified abstraction from the composition of several different language environments.