HN2new | past | comments | ask | show | jobs | submitlogin

As soon as the spec popped up, I've been into implementing DCPU-16 in Python on my own too, and I quickly encountered the same issue. Currently, my Cell-equivalent class (which I called Pointer) defines __call__, so I can do a() to read and a(data) to set.

It arguably sucks less, but I'm looking for something better and currently trying various solutions involving __getitem__, closures, function attributes, decorators and a sprinkle of metaprogramming to keep things nicely separated and much less C-ish.

I've already defined opcodes this way (decorator+func) which makes it very descriptive and almost reduces the opcode dispatcher to a one-liner.



Here's my latest tentative approach to the values problem, where you use cpu[value_code] to get and set, dispatching being done behind the scenes.

https://github.com/lloeki/python-dcpu_16/blob/e78f4b8af895db...

Note that this may cause some problems with evaluation order (notably in SET), as spec says a should always be evaluated before b.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: