3 ms·
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-equival
by lloeki 15y ago
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.
- lloeki 15y agoHere'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/e78f4b8af895dba34627e4a3f57e6a8771460ee6/dcpu_16.py 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.