@wummi said:
Hi Chip,
I found a strange behavior with REPEAT <count> WITH <variable> when count is zero.
PUB go () | i
repeat 0 with i
debug(sdec(i))
{ debug output
Cog0 i = 0
Cog0 i = -1
}
I expected debug(sdec(i)) is never executed, but it executes twice.
I believe this behavior is expected. The Spin document indicates that the count value is normally expected to be a number greater than 0.
The WITH form of the REPEAT statement is a smaller/faster version than the REPEAT FROM statement.
v40 2023-09-21 ● New smaller/faster REPEAT form added for iterating a variable from 0 to n-1, where n > 0.
REPEAT n WITH i 'best way to iterate a variable from 0 to n - 1
REPEAT i from 0 to n - 1 'general equivalent, though WITH needs n > 0
Example:
_clkfreq = 200_000_000
PUB go () | i,n
repeat 0 with i
debug("with loop: ",sdec(i))
n := 0
repeat i from 0 to n-1
debug("from loop: ",sdec(i))
Output:
Cog0 with loop: i = 0
Cog0 with loop: i = -1
Cog0 from loop: i = 0
Cog0 from loop: i = -1
A new PNut_v51 has been posted at the top of this thread.
v51 - 2025.04.02 - New POW, LOG2, EXP2, LOG10, EXP10, LOG, and EXP floating-point operators. SIZEOF() can now be used by PASM code to get sizes of structures. Long variables within structures can now be used as method pointers. Ignore-multiple-return-values '_ (number_of_longs)' had a stack bug rendering it useless, so it has been fixed and the syntax has been changed to use brackets, instead: '_ [number_of_longs]'.
Thanks. I'd like to suggest this be made more prominent in the manual than just in a changelog note 10 versions back from current. This is extremely easy to miss if you don't know what you're looking for.
Also you are correct, you cannot have constant structure members or defaults in Spin2. Nice to have but really not required.
Matteo's been hoping for a Propeller Tool that supports v51 or a more portable solution, so that IDEs can be pointed to compiler executables and you can decouple IDE development from compiler development. Any possibility of these in the near future?
@RbtsEvrywhr_Riley said:
Matteo's been hoping for a Propeller Tool that supports v51 or a more portable solution, so that IDEs can be pointed to compiler executables and you can decouple IDE development from compiler development. Any possibility of these in the near future?
@RbtsEvrywhr_Riley said:
Also you are correct, you cannot have constant structure members or defaults in Spin2. Nice to have but really not required.
Matteo's been hoping for a Propeller Tool that supports v51 or a more portable solution, so that IDEs can be pointed to compiler executables and you can decouple IDE development from compiler development. Any possibility of these in the near future?
Have you looked at Spin Tools IDE? It has an internal compiler (which Marco keeps up to date with PNut) and facilities to use external compilers. There are features I still like about Propeller Tool (bookmarks and code folding in the main window), so I start there, then move to Spin Tools where I can call the latest version of PNut to do the compilation if desired.
Comments
I believe this behavior is expected. The Spin document indicates that the count value is normally expected to be a number greater than 0.
The WITH form of the REPEAT statement is a smaller/faster version than the REPEAT FROM statement.
OK, i do not now that n must be greater than 0
Undefined is not the same as expected.
A new PNut_v51 has been posted at the top of this thread.
v51 - 2025.04.02 - New POW, LOG2, EXP2, LOG10, EXP10, LOG, and EXP floating-point operators. SIZEOF() can now be used by PASM code to get sizes of structures. Long variables within structures can now be used as method pointers. Ignore-multiple-return-values '_ (number_of_longs)' had a stack bug rendering it useless, so it has been fixed and the syntax has been changed to use brackets, instead: '_ [number_of_longs]'.
Posted this to the github but I'm not sure if it goes there or here, having some syntax issues with structs vs the example.
https://github.com/parallaxinc/P2_PNut_Public/issues/6
Hope I didn't miss a post about it or something. lil help?
Make sure your code has a
{Spin2_v51}
comment at the very start to declare the Spin2 version number.In your posted example you've got syntax like:
I don't think initializing the structure members (
mark = xxx
) is legal in PNut; it certainly isn't in FlexSpin.Thanks. I'd like to suggest this be made more prominent in the manual than just in a changelog note 10 versions back from current. This is extremely easy to miss if you don't know what you're looking for.
Also you are correct, you cannot have constant structure members or defaults in Spin2. Nice to have but really not required.
Matteo's been hoping for a Propeller Tool that supports v51 or a more portable solution, so that IDEs can be pointed to compiler executables and you can decouple IDE development from compiler development. Any possibility of these in the near future?
Think that is the idea behind PNut_TS ...
Have you looked at Spin Tools IDE? It has an internal compiler (which Marco keeps up to date with PNut) and facilities to use external compilers. There are features I still like about Propeller Tool (bookmarks and code folding in the main window), so I start there, then move to Spin Tools where I can call the latest version of PNut to do the compilation if desired.
Spin Tools thread
-- https://forums.parallax.com/discussion/174436/spin-tools-ide#latest