Open certik opened 1 year ago
How do we support this? I guess we need a new data structure/node at the ASR Level.
Yes, I need to think about it. This is very low priority, I think we'll just remove it from fastGPT. I initially thought I would set more variables this way, but it looks like we'll just set them at the command line if needed.
Let's figure out how to represent namelists at the ASR level. It would be good to design them in such a way as to allow (later) to represent any user-defined custom readers/writers for other formats like JSON, TOML, NPY, HDF5, GGUF, etc.
It looks like the read(u, input_fastGPT)
line will read a structure format from the textual input file. One way is to transform it to something like _lfortran_namelist_read(u, "A", A, "B", B, etc.)
, and it would populate those variables if present in the input file. Similar to how we handle printing.
See also: https://github.com/j3-fortran/fortran_proposals/issues/331.
One way that might work: read(u, input_fastGPT)
where input_fastGPT
is a namelist that contains arrays A
, B
and an integer i
gets transformed into
_lfortran_namelist_context ctx;
_lfortran_namelist_read(u, &ctx);
_lfortran_namelist_read_array_f32(ctx, "A", size(A), A);
_lfortran_namelist_read_array_f64(ctx, "B", size(B), B);
_lfortran_namelist_read_i64(ctx, "i", i);
Let's check how other compilers do this.
In the first implementation, let's do the following:
FileReadNamelist
node that accepts the file (handle) and list of variables to fill in (expr *vars
)._lfortran_namelist_read
. Possibly it might translate it to a sequence of calls per https://github.com/lfortran/lfortran/issues/1999#issuecomment-2007586757.read(u, some_namelist)
is encountered by the frontend, it would translate it to FileReadNamelist
with explicit vars, so it would reuse the previous two points.
https://github.com/certik/fastGPT/commit/11ead54d4943be4a1e189ce97b5f31c6a182dcb5