I’m writing an implementation of the Aa-machine in Guile Scheme. It’s still very much a WIP, but I plan on giving it good runtime inspection facilities so that I can examine a game’s internal state (and possibly help me to find the secret ending to Tethered). It also comes with a graph generator for a dissassembled Aa-machine story’s control-flow DAG.
At this stage, there’s no actual opcode interpreter yet, and I’m still completing the string decoder. Feel free to inspect, use and modify it for your own purposes if you want to.
As a small update, it can properly run simple programs now. The player input parsing still has bugs unfortunately, so here’s an automated guessing game instead:
(global variable (lower 1))
(global variable (upper 50))
(program entry point)
(lower $lower)
(upper $upper)
(random from $lower to $upper into $Secret)
*(repeat forever)
(random from $lower to $upper into $Guess)
(if) ($Guess > $Secret) (then)
$Guess is too high! (line)
(fail)
(elseif) ($Guess < $Secret) (then)
$Guess is too low! (line)
(fail)
(else)
Yay! We correctly guessed the secret number, $Secret.
(endif)
Equivalent in Lispy-style Aa-machine assembly:
(execute test-vm
'((assign (num 1) (reg 0)) ; (global variable (lower 1))
(assign (num 50) (reg 1)) ; (global variable (upper 50))
(num-rand (reg 0) (reg 1) (reg 2)) ; (random from $lower to $upper into $Secret)
(idx-set (reg 2)) ; Compare against $Secret
(choice-push (byte 0) (jump 6)) ; start *(repeat forever) loop from next line
(num-rand (reg 0) (reg 1) (reg 3)) ; (random from $lower to $upper into $Guess)
(check-gt-eq? (reg 3) (jump 13) (jump 17))
(jmp (jump 9))
;; (if) ($Guess > $Secret) (then)
(print-val (reg 3)) ; $Guess
(print-a-str-a "is too high!")
(line)
(backtrack)
;; (elseif) ($Guess < $Secret) (then)
(print-val (reg 3)) ; $Guess
(print-a-str-a "is too low!")
(line)
(backtrack)
;; (else)
(print-a-str-a "Yay! We correctly guessed the secret number,")
(print-val (reg 2)) ; $Secret
(print-n-str-a ".")
(quit)))
(Not to hijack this thread, but long ago, I wrote a Å-machine interpreter. I believe it’s feature-complete, but a bit rough since I was still learning Rust at that moment. Also I might move the repo to Codeberg at some point.)