Shop OBEX P1 Docs P2 Docs Learn Events
PNut/Spin2 Latest Version (v51 - New POW, LOG2, EXP2, LOG10, EXP10, LOG, EXP floating-point ops) - Page 75 — Parallax Forums

PNut/Spin2 Latest Version (v51 - New POW, LOG2, EXP2, LOG10, EXP10, LOG, EXP floating-point ops)

1697071727375»

Comments

  • @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
    
  • wummiwummi Posts: 100

    OK, i do not now that n must be greater than 0

  • evanhevanh Posts: 16,488

    Undefined is not the same as expected.

  • cgraceycgracey Posts: 14,280
    edited 2025-04-02 21:30

    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?

  • ersmithersmith Posts: 6,166

    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:

    STRUCT mavlink_message_header(BYTE mark = PROTOCOL_MARKER_V1, BYTE mlen, BYTE seq, BYTE srcSystem, BYTE srcComponent, BYTE msgId)
    

    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.

Sign In or Register to comment.