McCode
McCode copied to clipboard
FOR ... ASSEMBLY (auto-generating lists of components)
@g5t and I have had a nice LeX 'n' Yacc discussion and look at instrument.l/.y/cogen.c and friends, thinking to implement something like
COMPONENT A = Something
AT (...)
FOR (${j}=N) ASSEMBLY my_assembly_${j} = Something_else(par1 = pararray[${j}],...)
AT (0,0,POS_Z[${j}])
[GROUP some_group]
EXTEND %{
my_flag=${j};
%}
The thought is that
-
ASSEMBLY
would be implemented "in parallel" with component: in instrument.y -
ASSEMBLY
would trigger auto-generation of a list (length N) of normal components, with a loop identifier, e.g.${j}
- Auto-generate the instance names
- Fill in
${j}
within "the remaining" component definition, i.e. everywhere right of=
up to the nextCOMPONENT
orASSEMBLY
- Would work together with arrays defined in instrument
DECLARE
for pars, position etc. - Would "simply" regex on the literal code from the instrument-file, increment
${j}
and so forth - (We may even be able to do something based on
COPY(my_assembly_0)(par1=pararray${j}
, but let's see...) - Or ... generate a file to reinject to the code-generator... I.e. write a file that we read again? ... (maybe not)
@farhi I think we need
- a telco in the near future
- maybe a hackathon in the foreseeable future: DTU, ESS, SOLEIL maybe others in one place...
Nice thoughts indeed. I even think the syntax can be as simple as e.g.:
FOR (C-style,e.g. i=0; i<N; i++)
COMPONENT
...
ENDFOR
Indeed we already have parameter expansion (component par) and C expression handling. So, in short it boils down to defining a look variable to be used elsewhere, in AT, ROTATED, etc. and iterate the code generation. In practice, a list of component pointers can be set-up when analysing the DSL symbolic tree, and it can then be iterated at the C generation level, with a 'loop' new.
If I understand you correctly @farhi, you would then add and initialise something like
comp->assembly; // Set to indicate which assembly we are part of
comp->assembly_index; // Set to indicate which element in the assembly we are
then more or less "do the rest" in the code-generation? (I am thinking if we used another type of symbol than ´${j}´, e.g. @j@ one could even do a bit of #define / #undefine magic in setpos / INITIALIZE ?)
i.e.
#define @j@ comp->assembly_index
// do stuff
#undef @j@