Thanks to visit codestin.com
Credit goes to github.com

Skip to content

"Function" metatype in ASR.asdl should have parameters, not arguments #1418

Open
@rebcabin

Description

@rebcabin

"parameters" are pairs of names and types in a function declaration or definition. For example, in C,

int f (int x, double d);

Function f has two parameters, x and d, of types int and double, respectively. In fact, in C, only the parameter types are necessary for a unique declaration; the above is the same as

int f (int, double);

In an ASR Function, there are no values associated with the parameters.

"Arguments" pertain to ASR FunctionCall, not to ASR Function. in the following C snippet,

int r = f (42, 3.141);

42 and 3.141 are arguments. The arguments are values that are bound to the parameters x and d in a new environment st_new (i.e., environment is symbol_table in ASR jargon). The new environment is rooted in the old environment st_old. st_old was attached to the Function.

Let the Function for f have symbol_table (environment) st_old. st_old does not contain slots for x and d, the parameters of f. The FunctionCall for int r = f (42, 3.141); binds x=42 and d=3.141 in st_new. In case of arguments that are complex expressions, as in

int r = f (z * x, arccos(d));

z, x, and d are looked up in st_old. The results of the arithmetic expressions are bound to fresh symbols x and d in st_new, which now shadow the bindings in st_old.

st_new must be created at the call site because recursive calls obey a stack discipline and there must be new space created for new bindings (recursively).

In the example above, code must be generated to look up x and d in st_old, bind arithmetic results to fresh instances of x and d in st_new, and shadow x and d in st_old, save and restore on a stack, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    asrASR related changesbugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions