spin dynamic calls possible, in theory?
Peter Verkaik
Posts: 3,956
I was wondering if there is·a way to make the following happening:
·The above compiles, but I would like jb1[noparse][[/noparse]0] to be "jb1", and jb1[noparse][[/noparse]1] to be "jb2"
If it were possible to do
OBJ
· jb1[noparse][[/noparse]2]: "jb1","jb2"· 'object array filled from list
then jb1[noparse][[/noparse]c].main calls different type of objects without the need for a (large) CASE statement.
If jb1 specifies more entries than the list supplies, the remaining entries are set to the
last object in the list. This ensures compatibility with current behaviour.
Any chance of updating the compiler to allow this? Is there currently a way to make it·happen
manually (people have been poking around in the object tables)?
Edit: it should be allowed to continue the list on the next line by using a comma at the end of a line
eg.
· jb1[noparse][[/noparse]4]: "jb1","jb2",
············ "jb3","jb4"·· 'no comma so list ends here
regards peter
Post Edited (Peter Verkaik) : 11/11/2008 2:59:35 PM GMT
OBJ jb1[noparse][[/noparse]2]: "jb1" 'object with PUB main jb2: "jb2" 'another object with PUB main PUB main | c {{ application starts here }} c := 0 repeat 2 jb1[noparse][[/noparse]c].main 'call main for selected object jb2.main c++ repeat
·The above compiles, but I would like jb1[noparse][[/noparse]0] to be "jb1", and jb1[noparse][[/noparse]1] to be "jb2"
If it were possible to do
OBJ
· jb1[noparse][[/noparse]2]: "jb1","jb2"· 'object array filled from list
then jb1[noparse][[/noparse]c].main calls different type of objects without the need for a (large) CASE statement.
If jb1 specifies more entries than the list supplies, the remaining entries are set to the
last object in the list. This ensures compatibility with current behaviour.
Any chance of updating the compiler to allow this? Is there currently a way to make it·happen
manually (people have been poking around in the object tables)?
Edit: it should be allowed to continue the list on the next line by using a comma at the end of a line
eg.
· jb1[noparse][[/noparse]4]: "jb1","jb2",
············ "jb3","jb4"·· 'no comma so list ends here
regards peter
Post Edited (Peter Verkaik) : 11/11/2008 2:59:35 PM GMT
Comments
OBJ
jb1: "jb1"
jb2: "jb2"
jb3: "jb3"
jb4: "jb4"
and then
jb1[noparse][[/noparse] 3 ].main '<== same as jb4.main
as long as the various jb* objects are compatible.
You don't get the "filling out the rest of the array" behavior you want, though.
Does that mean the objects PUB main must be at identical offsets
(I can make PUB·main the first method in the objects).
Other than a shared name (eg. main) the objects are independant
with different content.
I like the implied array access via the first object, that will do for me.
regards peter
mpark, that's a pretty neat trick, BTW!
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
irrelevant, as are included OBJ in the objects that I want in the list?
Also, the presence of local variables in some of the PUB 'main' methods
is irrelevant?
If that is all true, I can just make my PUB 'main' the first method in
the objects and use the implied array for calling different object types.
Thanks.
regards peter
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
No, it wasn't me. (Or if it was, I can testify that one advantage of early-onset senility is the perpetual joy of rediscovery!) Since Hippy doesn't seem to be lurking about, maybe we can credit (blame) him!
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
Post Edited (Phil Pilgrim (PhiPi)) : 11/12/2008 1:01:58 AM GMT
Re: "...the perpetual joy of rediscovery!", how then does one even know it is a rediscovery? Recent 'turning 80' makes me wonder at times about such situations. "Seems like I've been here before" but can't recall when.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
void (*f[noparse]/noparse)(void);
However, if all PUB main are defined identical in terms of arguments and return type,
for example PUB main(a1,a2): retval
then also the following should be possible I assume
long (*f[noparse]/noparse)(long,long);
by using
val := jb[noparse][[/noparse]index].main(arg1,arg2)
regards peter
Don't worry about return type, it's always a long whether or not a return type is defined, but the parameter counts must match or you'll tie the stack in a knot.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pull my finger!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
OBJ
Servo[noparse][[/noparse]12]: "Generic Servo"
CON
Throttle 1
Rudder 2
Then setting the properties for each one as needed.
Result := Servo[noparse][[/noparse]Throttle].SetDirection(counterclock)
Result := Servo[noparse][[/noparse]Throttle].SetZero(0)
Result := Servo[noparse][[/noparse]Rudder].SetDirection(clock)
Result := Servo[noparse][[/noparse]Rudder].SetZero(128)
I lifted this from the Blinker code in the education kit. But it allows me to encapsulate a lot of ugly calculations. So will this work conceptually ?
@peter v. Like brad said the only thing that matters is that the method is in the same spot in the method table (first method in the file works well) and that it has the same number of arguments.
As to who discovered it I can't remember but it came from someone wanting to initialise and start a whole heap of different objects with a loop. It's really just a side effect of spin not doing any bounds checking on the array. For interests sake a method call gets compiled to a spin byte code that has the index of the object in the method table and then the index of the method in the new table. The table is just a list of pointers to where the other objects are. The only slight complication is that all the pointers are offsets and not the actual location (which is actually very helpful for some things). There is a page on the propeller wiki that hippy wrote if you want to know more about it.
Hawaii ? I wish ! If I ever get that close to America you can guarantee I'll drop in to say hello to the Parallax staff - keep a cup of rosey lee ready just in case
Started a new job; in at the deep end so have been quite pre-occupied in that respect and battling some consequences of the Great Global Economic Downturn (TM).
When everything settles down I hope to be back and contributing more and getting my half-finished projects completed. Just been a bit hectic ( and will be for a time ) but I've not deserted, just been tied up elsewhere. I'll try to drop in more frequently.
Isn't it always the way - (1) Real life gets in the way of fun, (2) You can have money but not the time or time but no money (3) When you have no money the exchange rate is in your favour, when you get some money ...
Post Edited (hippy) : 11/15/2008 8:05:49 PM GMT