I need function pointers!!!
SPIN, you're letting me down. I like need some function pointers for indirecting RTC access for my file system driver.
I look forward to C on the Prop 2 - Or atleast some type of C -> SPIN bytecode translator.
I look forward to C on the Prop 2 - Or atleast some type of C -> SPIN bytecode translator.
Comments
Bill
http://forums.parallax.com/showthread.php?127057-DEMO-Self-Modify-Spin-Code-Example&highlight=pointers
I posted a MethodPointer object to the OBEX earlier this month. It is located at http://obex.parallax.com/objects/697/ .
It was discussed in the thread at http://forums.parallax.com/showthread.php?128397-Callbacks-and-Method-Pointers-in-Spin&highlight=pointer . The technique I use doesn't modify the method tables or the Spn bytecodes (except for a small amount done at initialization). It just requires a 4-word buffer for each method pointer that is used.
Dave
obj ' normal code serial : "FullDuplexSerial" ' insert other normal object here ' unbound method code is last objarray[1] : "method0" ' contains PUB method to call per array index opt1method : "method1" ' contains PUB method to call per array index opt2method : "method2" ' contains PUB method to call per array index optNmethod : "methodN" ' contains PUB method to call per array index ' no more objects
Call method by object index. This has risks of course like if Parallax updates the compiler to do object array bounds checks - one would hope that our list of desirable enhancements might get addressed first. YMMV.
Very cute! I had forgotten all about object arrays - thank goodness for languages that do not do any bounds checking!
Ross.