Created
September 7, 2018 16:05
-
-
Save belisarius222/a0b7d590c3553670687d02904dbf4759 to your computer and use it in GitHub Desktop.
Sketch of an interpreter for new Ford runes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|% | |
+$ op | |
$@ $? %bail :: error out | |
%call :: =+ gate=pop =+sample=pop (gate sample) | |
%cons :: =+ head=pop =+ tail=pop [head tail] | |
%copy :: duplicate top of stack | |
%done :: halt (successfully) | |
%eval :: eval top of stack as schematic against next top as subject | |
%numb :: catch error | |
%swap :: swaps top two elements of stack | |
== | |
$% [%face face=@tas] | |
[%here =vase] | |
[%load =term] | |
[%lock date=@da] | |
[%ride =hoon] | |
== | |
+$ rez | |
$% [%0 =vase] | |
[%1 block=[=term =beam] rest=[stack=(list vase) ops=(list op)]] | |
[%2 =tang] | |
== | |
-- | |
|% | |
++ run | |
=| stack=(list vase) | |
=/ live=? %.y | |
|= [date=@da bus=vase ops=(list op)] | |
^- rez | |
:: | |
=. stack ~[bus] | |
:: | |
|^ ?~ ops | |
?> ?=([* ~] stack) | |
[%0 i.stack] | |
:: | |
?- i.ops | |
%bail !! :: TODO | |
%call | |
=^ gate stack pop | |
=^ sample stack pop | |
$(ops t.ops, stack (push (slam gate sample))) | |
:: | |
%cons | |
=^ head stack pop | |
=^ tail stack pop | |
$(ops t.ops, stack (push (slop head tail))) | |
:: | |
%copy | |
$(ops t.ops, stack (push i.stack)) | |
:: | |
%eval | |
=^ schematic stack pop | |
=^ subject stack pop | |
:: | |
?> (~(nest ut -:!>(*^schematic)) | p.schematic) | |
:: TODO probably wrong because we don't know the type of q.schematic | |
:: We could either make the compilation function a wet gate, | |
:: or we could try to embed the compilation into a %ride ... | |
:: | |
=/ new-ops (compile-schematic-to-ops q.schematic) | |
:: | |
$(ops (weld new-ops ops), stack [subject stack]) :: TODO wrong | |
:: | |
%numb !! :: TODO | |
%swap | |
=^ one stack pop | |
=^ two stack pop | |
$(ops t.ops, stack [two one stack]) | |
:: | |
[%face *] | |
$(ops t.ops, p.i.stack [%face face p.i.stack]) | |
:: | |
[%here *] | |
$(ops t.ops, stack [vase.i.ops stack]) | |
:: | |
[%load *] !! :: TODO | |
:: | |
[%lock *] | |
=. live %.n | |
=. date date.i.ops | |
$(ops t.ops) | |
:: | |
[%ride *] | |
=^ subject stack pop | |
$(ops t.ops, stack (slap subject hoon.i.ops)) | |
== | |
++ push | |
|= =vase | |
^+ stack | |
:: | |
[vase stack] | |
++ pop | |
^- [vase _stack] | |
?~ stack | |
!! | |
[i.stack t.stack] | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment