Skip to main content


finished my #uxn implementation the other day.
https://github.com/omentic/nim-uxn/blob/main/src/uxn/uxn.nim

as a spec it's interesting because it's so simple and so aesthetic. very Quite-OK style. and the official implementations (in C and JavaScript) are neat and tidy and tiny too (https://sr.ht/~rabbits/uxn/)

but when you go to implement it in a typed language... almost all of the tricks used by the C and JS implementations fall through. you just, can't write it in the same style. and so all of the typed implementations i've seen just put everything in one big switch statement, repeat some logic, call it a day.

i ended up doing some funky metaprogramming to get it working without repetition of logic. which did force me to learn how to properly write Nim macros, huzzah! but man... the spec screams "there is a short & simple way to implement this", and there is, but i think you need either a poorly typed language or good metaprogramming support. kind of interesting.

anyway, on to varvara! (and tests!)

#uxn
in reply to JJ :blobblackcat:

wow, this is such a different way of doing the operation primitives! Did you also port the assembler to Nim?

Let me know once uxn.nim passes the opcode tests 😀

It'd be lovely to have a typed implementation reference as to help it cross over to typed languages.

This entry was edited (1 year ago)
in reply to Devine Lu Linvega

@neauoire no, not yet! i have some wip work in there but want to try my hand at varvara before getting back to it, i think.

the operation primitives were quite fun, i had to approach each in a different way... return mode is implemented by a sneaky function that looks like field access because of Nim's UFCS. keep mode is implemented by the pop8 and pop16 values pushing to another stack when in keep mode, which is then restored before the opcode's operation is computed. and short mode is, yeah

and heh will do! i'm very sure i have at least a bug or two. there's a good chance my LIT and JSR opcodes are wrong and i may be restoring values from the stack backwards. excited to keep going and get roms running, then i might do some benchmark chasing... very curious how nim will compare to c

in reply to JJ :blobblackcat:

the keep mode is a bit tricky, my strategy for it is usually to read from the stack without popping, moving the pointer, then writing with the result with the new pointer offset.

For the short mode, there's an implementation strategy where you don't create new cases, I've got a reference for this strategy here: https://git.sr.ht/~rabbits/uxn/tree/main/item/etc/cores/uxn-abc.c

It might give you a few ideas for the primitives, it's trying to follow the table here: https://wiki.xxiivv.com/site/uxntal.html

Lo, thar be cookies on this site to keep track of your login. By clicking 'okay', you are CONSENTING to this.