eviltrout/rubycpu — pull request #1 by matthiasbeyer (2012-04-21 19:44:14+00:00)
Title: Outsourced definitions of what a command does

Hi.
I outsourced the definitions of what a command exactly does.
The virtual machine does nothing except the executing of already defined stuff. The stuff is defined elsewhere.

First I added classes to store the opcode and the Proc what it does and created a class where all the "Actions" are stored in. I added some instance variable readers to the virtual machine for getting info about it which is required in the Procs of the commands.
Then I created a big setup for the vm, to define the whole stuff (commands and Procs for them). After some fixes, the whole thing was tested successfully, but still looked as too much code in one file.
So I outsourced the whole stuff again in lib/actions.rb and outsourced again.

Finally you have a file called actionmap.rb, which defines what a command does. You have a File action.rb where you can find some helpers.
Now, in your VirtualMachine class is no more code which defines the behaviour of the asm-code!

I hope you find this useful!
Let me know what you think about it!

I hope you will merge my stuff,
best regards,
Matthias Beyer