Adding more generic examples (7th week)

luthfan
Published: 07/31/2022

What I did this week

- Generic array types

I added support for generic array types. In the following simple example, T[:] signifies the type of one-dimensional array T.

T = TypeVar('T')

def f(lst: T[:], i: T) -> T:
    lst[0] = i
    return lst[0]

It is then possible to have different function calls involving different types of arrays:

f([1],2)
f([1.0],2.0)

To implement this, the type substitution checks between the formal parameter lst: T[:] and the argument [1] (i32[:]) match the type parameter T with i32 and to also check that the dimensions are equal.

- Merging TemplateFunction with Function

To distinguish generic functions from functions, I added a new syntactic construct TemplateFunction into LPython's intermediate representation ASR. However, this construct appears to be unnecessary and can be handled by the original Function construct by adding another field where type parameters are stored.

On a separate PR, I removed TemplateFunction from the grammar and modified the definition for Function.

What is coming up next week

There are tests that the compiler does not yet pass. So I will have to solve those first.

Did I get stuck anywhere

There was no issue specifically this week.

DJDT

Versions

Time

Settings from gsoc.settings

Headers

Request

SQL queries from 1 connection

Static files (2312 found, 3 used)

Templates (11 rendered)

Cache calls from 1 backend

Signals

Log messages