Shop OBEX P1 Docs P2 Docs Learn Events
More compiler oddities — Parallax Forums

More compiler oddities

BradCBradC Posts: 2,601
edited 2008-08-08 16:58 in Propeller 1
Just for the record.
You don't need to declare a CON block.
Starting the file with..
FRED = 24, A = 1, B = 2
.. works perfectly..

You don't need to declare your enumerators from zero.. it happens by default in the con block..
so
CON A, B, C
za = 24, zb = 25
D, E, F

will give you A = 0, B = 1, C = 2, D = 3... and so on..

You can space your enumerators..
#0, A[noparse][[/noparse]10], B[noparse][[/noparse]10], C[noparse][[/noparse]10]
will give you A = 0, B = 10, C = 20..
And you can use pre-defined constants and mathematics in the [noparse]/noparse fields..
so
zz = 20
A[noparse][[/noparse]zz], B[noparse][[/noparse]zz+10], C[noparse][[/noparse]zz]
will give you A = 0, B = 20, C = 50..

You never know when it might come in handy [noparse]:)[/noparse]

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pull my finger!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-07 20:05
    Interesting discovery! Odd that it's not in the manual, since it could be rather useful.

    Using that technique, here's an easy way to express a Fibonacci sequence using CON:

    [b]CON[/b]
    
      [b]_clkmode[/b]      = [b]xtal[/b]1 + [b]pll[/b]16x
      [b]_xinfreq[/b]      = 5_000_000
    
      #1, a[noparse][[/noparse]0], b[noparse][[/noparse]a], c[noparse][[/noparse]b], d[noparse][[/noparse]c], e[noparse][[/noparse]d], f[noparse][[/noparse]e], g[noparse][[/noparse]f]
    
    [b]OBJ[/b]
    
      pr : "tv_wtext"
    
    [b]PUB[/b] Start | i
    
      pr.start(12)
      pr.dec(a)
      pr.out(" ")
      pr.dec(b)
      pr.out(" ")
      pr.dec(c)
      pr.out(" ")
      pr.dec(d)
      pr.out(" ")
      pr.dec(e)
      pr.out(" ")
      pr.dec(f)
      pr.out(" ")
      pr.dec(g)
    
    
    


    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • RaymanRayman Posts: 14,162
    edited 2008-08-07 23:30
    Interesting! Maybe this should go in Tricks&Traps (if not already there...).
  • BradCBradC Posts: 2,601
    edited 2008-08-08 06:44
    I suspect its an oddity related to consolidating the way VAR and CON blocks are parsed, so its not in the manual as it was probably not an intended language feature, but maybe shared code in the tokenizer/lexer/parser..

    It certainly has the potential to be useful anyway..
    Another "interesting" point is the [noparse]/noparse block does not need to be attached to its parent. Whitespace is gracefully ignored.

    ie
    CON
    A [noparse][[/noparse]10] , B [noparse][[/noparse]10]
    VAR
    long Fred [noparse][[/noparse]15]

    are all perfectly valid.. it makes it easier when looking at it from the perspective of a tokenizer..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pull my finger!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-08 06:57
    'Makes sense. CONstants are treated like the addresses of phantom byte arrays, which can be assigned either explicitly (x = n) or implicitly (#n being like an ORG).

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • heaterheater Posts: 3,370
    edited 2008-08-08 14:03
    Hmm, I stumbled across these oddities a few weeks ago. Thought everyone knew so I kept quite.

    Phil: I love that fibo sequence idea.

    "Makes sense" In a kind of Alice in Wonderland way. Strangest syntax for enums I ever saw.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • AribaAriba Posts: 2,685
    edited 2008-08-08 16:58
    From the sourcecode of the VGA HiRes Text Driver:
    ...
    CON
      #1, scanbuff[noparse][[/noparse]128], scancode[noparse][[/noparse]128*2-1+3], maincode      'enumerate COG RAM usage
    ...
    
    


    So this enumeration syntax seems to be expected, but not documented in the Manual.

    Andy
Sign In or Register to comment.