I think I was approaching something like that. I was thinking of instruction subclasses rather than functions in a dict, though, and stopped going in that direction because subclassing for every instruction seemed overkill an maybe a bit unpythonic. A mapping in a dict actually sounds quite nice.
However, off the top of my head, I suppose every instruction implementation would still need to get a reference to the memory, the instruction pointer, the parameter modes... and either parse those or get them pre-parsed by the main loop.
I'm not entirely unhappy with the way my code looks, but it kind of does feel to me like it could perhaps be a bit more compact and elegant, so maybe I'll try and see if I can improve it with something like your dict idea.
The modifications for day 5 seem to be backwards compatible with day 2 so I just kept adding to the existing code apart from a task-specific main program.
View all comments
Show parent comment
1
u/Objective_Mine Dec 06 '19
I think I was approaching something like that. I was thinking of instruction subclasses rather than functions in a dict, though, and stopped going in that direction because subclassing for every instruction seemed overkill an maybe a bit unpythonic. A mapping in a dict actually sounds quite nice.
However, off the top of my head, I suppose every instruction implementation would still need to get a reference to the memory, the instruction pointer, the parameter modes... and either parse those or get them pre-parsed by the main loop.
I'm not entirely unhappy with the way my code looks, but it kind of does feel to me like it could perhaps be a bit more compact and elegant, so maybe I'll try and see if I can improve it with something like your dict idea.
The modifications for day 5 seem to be backwards compatible with day 2 so I just kept adding to the existing code apart from a task-specific main program.