-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to using function-pointers. #2
Comments
I have a workable proof of concept at the moment, but there are implications I'd not forseen.
For the moment I've updated my operations signature to this: Bool op_foo( void * input ); If that function returns TRUE then it is assumed IP has been updated and it is left alone, otherwise it increments appropriately. This works but it feels a little unclean. Will commit shortly. Just tweaking the emacs macro to mass-edit ;) |
This is a hugely-churnful update which moves all the opcode-processing out of the large switch/case statement and into a distinct routine for each opcode. This will cause a slowdown, but not significantly enough to care about. Updates #2 - which I will leave open until I've moved the code into external files.
We needed to update the storing of integers, because the following program failed: # # Set the byte at 0x5000 to read "NOP" # store #1, 0x50 store #2, 0x5000 poke #1, #2 # # Set the byte at 0x5001 to read "EXIT" # store #1, 0 store #2, 0x5001 poke #1, #2 # # Jump to that new code. # goto 0x5000 Now it works as expected.
So now we can do "set reg1 = reg2", via "store #1, #2" and it works as the following program demonstrates: # reg1 = steve... store #1, "steve\n" print_str #1 # now reg2 == reg1 store #2, #1 print_str #2 # and so a comparison is OK cmp #1, #2 jmpz OK store #1, "ERROR reg1 != reg2" print_str #1 exit :OK store #1, "'store #1, #2' worked!\n" print_str #1 exit This means we now have: store #1, "String" # string store #1, 0x3342 # number store #1, label # label store #1, #2 # register
Rather than having a giant
switch
statement, with acase
for each opcode, we should break out the implementations of the opcodes into their own functions.If we define an array of 255-opcodes in the
svm_t
function then we can use function pointers to invoke the correct function.svm_t
instance.The text was updated successfully, but these errors were encountered: