While Golfrun specifications are becoming foggy day by day (month by month, year by year…) and C++11 implementation of a Golfrun interpreter is still far to come, I am experimenting with the Go language, as done in the previous post. Thus I have decided to implement an interpreter of an esoteric programming language I liked very much: SNUSP. In the past I have already written a C interpreter for Modular SNUSP: it was my first contribution (as far as I can remember) to RosettaCode; then, I uploaded it to SourceForge too.
Now I have implemented an interpreter for SNUSP using the Go language. You can find GoSNUSP code on github.
GoSNUSP can interpret (bugs apart…) Core, Modular and Bloated SNUSP.
If you search for Bloated SNUSP, you won't find too much. If John Bauman's Bloated SNUSP interpreter is the first full implementation of Bloated SNUSP, then the
second third … nth1 I am aware of, is my own implementation — the first one written in Go, anyway (as far as I know).
There is not too much more to say now… For your ease here few links you may find useful.
- About SNUSP on c2 wiki
- About SNUSP on esolangs wiki
- SNUSP examples on RosettaCode
Details about “twisted” and “untwisted” Modular SNUSP
Let's consider this small Modular SNUSP code:
$=====++++====@\====++++.# 4 . 8 #
“Twisted” Modular SNUSP (default for GoSNUSP) will output two bytes, 0x04 and 0x08: because when the
@ is interpreted, first the execution goes on (so we “turn” down,
. is executed — the 0x04 is output), and when the Leave code
# is found, we go back at where the
@ was, skipping the
\ which was on the path (according to the stored direction in that point). So the cell will be incremented by 4 and 4+4=8, so 0x08 is output.
“Untwisted” Modular SNUSP write 0x08 0x08. Why? Since the order is swapped: first we go beyond the next instruction after the
@; so the cell is incremented by 8 when the first
. is executed; and the first
# to be executed is the leftmost one, which makes the IP (Instruction Pointer) to be back on the
\, that makes the direction “turn” down, write the cell again (another 0x08) and then leave (
#) again — and since there are no other stored positions on the stack, the program exits.
Snuspi (my Modular SNUSP C interpreter) is an “untwisted” flavour of Modular SNUSP — I became aware of this trying to run the Hello World example on esolangs wiki — astonishingly I haven't tried it before…
GoSNUSP is “twisted” by default now; therefore you can execute examples on esolangs wiki page dedicated to SNUSP.
Final note: a notable example that works with the “untwisted” flavour of Modular SNUSP is the ambassador example — not by chance it was an example I kept for snuspi. To see the correct output with GoSNUSP, you must add
-twist=false to the command line.
Post a Comment