Nim is supported in RTOS systems with flat memory space.
If multiple tasks written in Nim are to be started individually, does NimMain() function need to be executed at the entry point of each task? Or is GC (ARC/ORC) process common to all tasks?
NimMain only handles setting up global variables and some consts with ARC/ORC. There is no global orc thread. I think orc cycle collection is run per-thread based on a trigger mechanism.
So calling NimMain once on startup is fine. At least it works well for me. ;) There was a PR to remove even needing to call NimMain by letting C initialize the variables. Not sure what happened to it.
Thank you for your answer! I tried to read NimMain(), but I couldn't understand it because tag jumps don't work in emacs...
I will try to test it in NuttX as well.
Thank you! I've never bothered with it for PC Linux use (because just strip it all out), but I see that there are various flags.
I tried it immediately.
In NimMain(), PreMain() and NimMainInner() were called, and function called from NimMainInner() looked like a Jester module initialization process. Is the entity of NimMain() called from PreMain()?
N_CDECL(void, NimMain)(void) {
#if 0
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
(*inner)();
#else
PreMain(); <-----
NimMainInner();
#endif
}
PreMain() The last place to go was to initialize some constants in nativesockets.
nativeAfInet__pureZnativesockets_48 = AF_INET;
nativeAfInet6__pureZnativesockets_49 = AF_INET6;
nativeAfUnix__pureZnativesockets_50 = AF_UNIX;
Nice! Yah I’m not too familiar with the inner parts of NimMain.
But it sounds about right. Any code in modules that live outside proc’s will get called from NimMain.
I’m not sure what you meant by PreMain calling NimMain, but NimMain is called from a C main function. That’s what you disable for embedded platforms. But NimMain still needs to be called once at startup. Otherwise you get really weird faults.
The N_CDECL piece is just a C macro that declares the C function NimMain. It’s done that way to control the function declaration for various compilers and settings.