import volatile
volatileStore(cast[ptr uint](0x20000000), 1)
... @mmain.nim.c:32:17: error: expected ')' before '(' token
32 | *((NU volatile*)(((NU*) 536870912))) = ((NI) 1);
| ^
| )
Error: execution of an external compiler program 'arm-none-eabi-gcc -c -w -fmax-errors=3 -mtune=cortex-m3 -mthumb -ffunction-sections -fdata-sections -O3 -fno-strict-aliasing -fno-ident ... @mmain.nim.c' failed with exit code: 1
After some digging, I'm not sure if this is a bug.
The reason is the emit pragma, which is used in the volatileStore template.
If you place emit pragma in the the main module scope, the code is placed not in the NimMainModule function, but in the NIM_merge_PROC_HEADERS section.
{. emit: "int localVariable;" .}
generates:
...
/* section: NIM_merge_FRAME_DEFINES */
#define nimfr_(x, y)
#define nimln_(x, y)
/* section: NIM_merge_PROC_HEADERS */
int localVariable;
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
/* section: NIM_merge_PROCS */
...
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
}
}
And I believe that this is the correct behavior.
Fix: I don't know. Perhaps, the definition of` volatileStore ' needs to change from template to proc.
Ah yep, I've run into this one before: https://github.com/nim-lang/Nim/issues/14623
I ended up solving it like this (so yeah, changing them from templates to inline procs is probably the way to go): https://github.com/exelotl/natu/blob/e65f107697420753fc8dc1d97383147e723398e3/natu/mgba.nim#L12
As an aside, I really like the names peek and poke and wonder if we might consider adding them as aliases x)