How to eliminate the need for @@@ in PropBASIC ?

BeanBean Posts: 8,011
edited 2019-08-28 - 13:00:26 in Propeller 1
Here is some code showing how PropBASIC uses the @ @ @ operator.
'  hubVar1    HUB   LONG
'
  mov __temp,#0    ' WRLONG hubVar1,0
  wrlong __temp,__hubVar_adr
'
__hubVar_adr   LONG @ @ @ hubVar1

DAT
hubVar1   LONG  0
'

How can the use of @ @ @ be avoided ?
I am open to any ideas.

Bean

Comments

  • In the top object "@ @ @ hubvar" is equivalent to "@ hubvar + 16". However, this only works in the top object. In the past, if I needed absolute address in lower objects and I wanted to avoid the @ @ @ operator I would adjust the addresses in memory at startup.
  • Dave HeinDave Hein Posts: 5,942
    edited 2019-08-28 - 14:37:13
    Here's how CSPIN handles a list of strings in C, such as
    static char *ops[] = {
        "++", "+=", "+", "--", "-=", "-", ">>=", ">>",
        ">-=", ">-", "><=", "><", ">|", ">=", ">", "<<=",
        "<<", "<-=", "<-", "<#=", "<#", "<>=", "<>", "<=",
        "<", "**=", "**", "*=", "*", "//=", "//", "/=",
        "/", "||", "|<", "|=", "|", " @ @ ", " @ ", "#>=",
        "#>", "^^", "^=", "^", "=>=", "=>", "=<=", "=<",
        "!", "~~", "~>=", "~>", "~", "?", "===", "==", 0};
    
    /* INLINE SPIN
    PUB start | ptr
      ptr := @ops
      repeat while long[ptr]
        long[ptr] += @ @0 - 16
        ptr += 4
    */
    
    It produces the following Spin code
    DAT
      ops long
      long @datstr + 16, @datstr + 19, @datstr + 22, @datstr + 24, @datstr + 27, @datstr + 30, @datstr + 32, @datstr + 36
      long @datstr + 39, @datstr + 43, @datstr + 46, @datstr + 50, @datstr + 53, @datstr + 56, @datstr + 59, @datstr + 61
      long @datstr + 65, @datstr + 68, @datstr + 72, @datstr + 75, @datstr + 79, @datstr + 82, @datstr + 86, @datstr + 89
      long @datstr + 92, @datstr + 94, @datstr + 98, @datstr + 101, @datstr + 104, @datstr + 106, @datstr + 110, @datstr + 113
      long @datstr + 116, @datstr + 118, @datstr + 121, @datstr + 124, @datstr + 127, @datstr + 129, @datstr + 132, @datstr + 134
      long @datstr + 138, @datstr + 141, @datstr + 144, @datstr + 147, @datstr + 149, @datstr + 153, @datstr + 156, @datstr + 160
      long @datstr + 163, @datstr + 165, @datstr + 168, @datstr + 172, @datstr + 175, @datstr + 177, @datstr + 179, @datstr + 183, 0
    
      datstr byte "++", 0, "+=", 0, "+", 0, "--", 0, "-=", 0, "-", 0, ">>=", 0, ">>", 0
      byte ">-=", 0, ">-", 0, "><=", 0, "><", 0, ">|", 0, ">=", 0, ">", 0, "<<=", 0
      byte "<<", 0, "<-=", 0, "<-", 0, "<#=", 0, "<#", 0, "<>=", 0, "<>", 0, "<=", 0
      byte "<", 0, "**=", 0, "**", 0, "*=", 0, "*", 0, "//=", 0, "//", 0, "/=", 0
      byte "/", 0, "||", 0, "|<", 0, "|=", 0, "|", 0, " @ @ ", 0, " @ ", 0, "#>=", 0
      byte "#>", 0, "^^", 0, "^=", 0, "^", 0, "=>=", 0, "=>", 0, "=<=", 0, "=<", 0
      byte "!", 0, "~~", 0, "~>=", 0, "~>", 0, "~", 0, "?", 0, "===", 0, "==", 0
    
    ' INLINE SPIN
    PUB start | ptr
      ptr := @ops
      repeat while long[ptr]
        long[ptr] += @ @0 - 16
        ptr += 4
    
    The start method is not needed for the top object. It is only needed for the lower objects. The start method is generated using CSPIN's inline directive. I never implemented an automatic way of generating the start method.

  • It was a long time ago, but I think the issue was I wasn't sure the +16 would ALWAYS be valid.
    I think you are saying that it is, but only for the top object.
    If that is true, I can try using the +16 and see if it works.

    Thanks for the tip, I will try it.

    Bean
  • Dave,
    Can you explain this line ?
     long[ptr] += @ @0 - 16
    

    Bean
  • There are a number of compilers that support @ @ @: bstc (you already know about that one), homespun, and fastspin, at least. homespun and fastspin are open source, so neither of those is going away anytime soon. I have used fastspin to successfully compile PropBASIC output.
  • Dave HeinDave Hein Posts: 5,942
    edited 2019-08-28 - 16:13:21
    Bean wrote: »
    Dave,
    Can you explain this line ?
     long[ptr] += @ @0 - 16
    

    Bean
    Cspin adds 16 for the top object, so when adjusting for a lower object I have to subtract 16 and add the lower object's offset. The "@ @ " operator is used to add the object offset to a value, so "@ @ 0" is the object offset plus zero. I could have written this expression as "@ @ (-16)" to make it more efficient.
Sign In or Register to comment.