View Full Version : Is there a way to overload a method in SPIN?
05-12-2008, 12:24 AM
Is there a way to overload a SPIN method or supply a variable length argument list?
05-12-2008, 12:49 AM
If you want to supply a variable length argument list, you could pass the address of an array of pointers, possibly with an argument count as the first element. You could have several short "stub" routines with declared argument lists of various lengths and pass an argument count and the address of the first argument to your main routine since the actual parameters are pushed in order into the stack with the first being lowest in memory like:
' here "count" is the number of arguments
' and "first" is the address of the first argument
I had exactly this problem: Somewhere in global memory I store variable and I wish to have access to these variables from other COG's without changing the argument list. I decided to pass an array of pointers to the start routine. The first referenced value allows to send a command to the process and with help of a little synchronising mechanism it is possible to activate different functions running parallel. The propeller is just great! http://forums.parallax.com/showthread.php?p=725595 It should be possible to understand the code without understanding german. But I'm ready to translate if there is some resonance
05-12-2008, 03:58 AM
Thanks for the suggestions.
05-12-2008, 07:39 PM
If you really, really need to be able to change the method called it is possible but a pain in the neck and all the different methods will need to have the same number of variables. The easiest thing to do is something like this
It is possible to play around with the pointers in the method table as well but it takes a fair bit of work. If you want I can try to explain it.
05-12-2008, 07:51 PM
I appreciate everyone's help. It's much less work if I change my coding strategy. I guess using a memory pointer and length, like passing a variable length string, should do the trick just fine.