lcompilers / libasr

The ASR (Abstract Semantic Representation), backends, optimizations and other tooling
MIT License
12 stars 2 forks source link

Dimensions? #6

Open rebcabin opened 2 years ago

rebcabin commented 2 years ago

I noticed that while dimension is spec'ced as follows

dimension = (expr? start, expr? length)

concrete examples of dimension print out as in the following

(Integer 4 [2 3] [4]) # a ttype for an array of 4-byte ints; 
# [2 3] and [4] are of ASDL type "dimension"

instead of as

(Integer 4 [(IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4[]))] 
           [(IntegerConstant 4 (Integer 4 []))])

This is surprising because 2, 3, and 4 in [2 3] [4] are not exprs.

Is this just shorthand in the printout? Is the long-form acceptable input to ASR processors?

certik commented 2 years ago

Can you give an example? I can't reproduce it. The following Fortran code:

integer :: x(2:4, 3)

Prints as:

                            x:
                                (Variable 
                                    2 
                                    x 
                                    Local 
                                    () 
                                    () 
                                    Default 
                                    (Integer 4 [((IntegerConstant 2 (Integer 4 [])) 
                                    (IntegerConstant 3 (Integer 4 [])))
                                    ((IntegerConstant 1 (Integer 4 [])) 
                                    (IntegerConstant 3 (Integer 4 [])))]) 
                                    Source 
                                    Public 
                                    Required 
                                    .false.
                                )

Which already seems exactly in the form that you want.

Is the long-form acceptable input to ASR processors?

Yes, I would recommend to only use long form. We use short form in AST, but it doesn't seem worth it, because one looks at it infrequently, and when one does look at it, it's better to use longform so that one knows exactly what nodes are in there.

rebcabin commented 2 years ago

Investigating ... I thought I saw this in one of the LPython xxx.stdout examples.