juvix icon indicating copy to clipboard operation
juvix copied to clipboard

Reg->C: ALLOC_CONSTR_TUPLE calls are generated with the incorrect number of arguments

Open paulcadman opened this issue 6 months ago • 1 comments

We wish to use the MemRepTuple constructor representation in the Nockma backend.

However the code emitted by the Reg->C translation is incorrect:

https://github.com/anoma/juvix/blob/1147e1fce131f5b423fd558e5636e6aaf23120ac/src/Juvix/Compiler/Backend/C/Translation/FromReg.hs#L341-L342

Specifically an ALLOC_CONSTR_TUPLE call is generated with too many arguments.

/private/var/folders/z5/h_kmf4q1139f0gqhj1_hqd4w0000gn/T/tmp-b0a3b6f6c4b6a816/test055.c:56:48: error: too many arguments provided to function-like macro invocation
   56 |         ALLOC_CONSTR_TUPLE(juvix_temp_var, 11, 2);

paulcadman avatar Jan 23 '24 09:01 paulcadman

In general, only MemRepConstr is supported in C code generation. There are macros/functions in the C runtime that enable support for other representations, but they have not been tested and code generation with them has not been fully implemented.

To support MemRepTuple one needs to look at and modify C code generation for:

  • constructor allocation,
  • Case instruction (accesses the tag),
  • MemRef and Field -- reading constructor arguments (we might need to shift the index by 1 for tuples without tag, or preferably use a different runtime macro).

lukaszcz avatar Jan 23 '24 09:01 lukaszcz