lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.51k stars 164 forks source link

Mismatch in `SubroutineCall` #1465

Open rebcabin opened 1 year ago

rebcabin commented 1 year ago

lpython expr2.py --show-asr --no-color prints the following (edited)

[(SubroutineCall                 ; head, term: stmt
         1                       ; ???
         main0                   ; symbol        nym
         ()                      ; symbol ?      original-nym
         []                      ; call_arg *    args
         ())                     ; expr ?        dt
        ]              

But the ASR has no term for the first element, 1:

| SubroutineCall(symbol name, 
                     symbol? original_name, 
                     call_arg* args, 
                     expr? dt)

I assume 1 is a symbol-table ID, but the shape mis-match leads me to believe there is a bug.

certik commented 1 year ago

This is how we print symbols: we print the number and then the symbol name.

We could print it using some other notation, say:

[(SubroutineCall                 ; head, term: stmt
         (1                      
         main0)                   ; symbol        nym
         ()                      ; symbol ?      original-nym
         []                      ; call_arg *    args
         ())                     ; expr ?        dt
        ]              
certik commented 1 year ago

If you can come up with a more natural printing, that would be great. Thanks for reviewing this!

rebcabin commented 1 year ago

definitely need to pair the symbol-table-id with the name in brackets, not have implicit grouping. {main0 1} would be best for Clojure because symbols in clojure act like dictionary lookup keys. {main0 1} is a singleton dictionary in Clojure.* Either the dictionary or a symbol (appropriately quoted) act like functions; the following illustrates many ways to look up the 1 from the main0:

user=> {'main0 1}
{main0 1}
user=> ({'main0 1} 'main0)
1
user=> '{main0 1}
{main0 1}
user=> ('{main0 1} 'main0)
1
user=> ('main0 '{main0 1})
1
user=> ('main0 {'main0 1})
1

The meaning here is "what symbol-table am I in (by id number)."

certik commented 1 year ago

{main0 1} is fine. How does Clojure know where to lookup main0 using the integer 1?