Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active December 27, 2023 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lupyuen/4d3f44b58fa88b17ca851decb0419b86 to your computer and use it in GitHub Desktop.
Save lupyuen/4d3f44b58fa88b17ca851decb0419b86 to your computer and use it in GitHub Desktop.
Nim on Apache NuttX RTOS: Compiled to C. See https://github.com/lupyuen/nuttx-nim
/* Generated by Nim Compiler v2.1.1 */
#define NIM_INTBITS 64
#include "nimbase.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <nuttx/leds/userled.h>
#include <unistd.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
#define nimfr_(proc, file) \
TFrame FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
#define nimfrs_(proc, file, slots, length) \
struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename;NI len;VarSlot s[slots];} FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
#define nimln_(n) \
FR_.line = n;
#define nimlf_(n, file) \
FR_.line = n; FR_.filename = file;
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
struct NimStrPayload { NI cap;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 { NI len;
NimStrPayload* p;
};
typedef NimStringV2 tyArray__nHXaesL0DJZHyVS07ARPRA[1];
N_LIB_PRIVATE N_CDECL(void, hello_nim)(void);
N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0);
N_LIB_PRIVATE N_NIMCALL(void, blink_led__hello95nim95async_u13)(void);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static N_INLINE(void, nimFrame)(TFrame* s_p0);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4541)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, GC_runOrc__system_u3404)(void);
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatshomeatsvscodeatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatshomeatsvscodeatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatspureatsnativesocketsdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatshomeatsvscodeatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatsstdatsexitprocsdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static const struct {
NI cap; NIM_CHAR data[10+1];
} TM__1vqzGCGyH8jPEpAwiaNwvg_3 = { 10 | NIM_STRLIT_FLAG, "Hello Nim!" };
static const struct {
NI cap; NIM_CHAR data[21+1];
} TM__1vqzGCGyH8jPEpAwiaNwvg_5 = { 21 | NIM_STRLIT_FLAG, "Opening /dev/userleds" };
static const struct {
NI cap; NIM_CHAR data[28+1];
} TM__1vqzGCGyH8jPEpAwiaNwvg_7 = { 28 | NIM_STRLIT_FLAG, "Failed to open /dev/userleds" };
static const struct {
NI cap; NIM_CHAR data[14+1];
} TM__1vqzGCGyH8jPEpAwiaNwvg_9 = { 14 | NIM_STRLIT_FLAG, "Set LED 0 to 1" };
static const struct {
NI cap; NIM_CHAR data[28+1];
} TM__1vqzGCGyH8jPEpAwiaNwvg_11 = { 28 | NIM_STRLIT_FLAG, "ioctl(ULEDIOC_SETALL) failed" };
static const struct {
NI cap; NIM_CHAR data[10+1];
} TM__1vqzGCGyH8jPEpAwiaNwvg_13 = { 10 | NIM_STRLIT_FLAG, "Waiting..." };
static const struct {
NI cap; NIM_CHAR data[14+1];
} TM__1vqzGCGyH8jPEpAwiaNwvg_15 = { 14 | NIM_STRLIT_FLAG, "Set LED 0 to 0" };
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__1vqzGCGyH8jPEpAwiaNwvg_2 = {{10, (NimStrPayload*)&TM__1vqzGCGyH8jPEpAwiaNwvg_3}}
;
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__1vqzGCGyH8jPEpAwiaNwvg_4 = {{21, (NimStrPayload*)&TM__1vqzGCGyH8jPEpAwiaNwvg_5}}
;
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__1vqzGCGyH8jPEpAwiaNwvg_6 = {{28, (NimStrPayload*)&TM__1vqzGCGyH8jPEpAwiaNwvg_7}}
;
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__1vqzGCGyH8jPEpAwiaNwvg_8 = {{14, (NimStrPayload*)&TM__1vqzGCGyH8jPEpAwiaNwvg_9}}
;
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__1vqzGCGyH8jPEpAwiaNwvg_10 = {{28, (NimStrPayload*)&TM__1vqzGCGyH8jPEpAwiaNwvg_11}}
;
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__1vqzGCGyH8jPEpAwiaNwvg_12 = {{10, (NimStrPayload*)&TM__1vqzGCGyH8jPEpAwiaNwvg_13}}
;
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__1vqzGCGyH8jPEpAwiaNwvg_14 = {{14, (NimStrPayload*)&TM__1vqzGCGyH8jPEpAwiaNwvg_15}}
;
extern NIM_BOOL nimInErrorMode__system_u4325;
extern TFrame* framePtr__system_u3923;
#line 423 "/home/vscode/.choosenim/toolchains/nim-#devel/lib/system/excpt.nim"
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) { NIM_BOOL* result;
#line 424
result = (&nimInErrorMode__system_u4325); return result;}
#line 549 "/home/vscode/.choosenim/toolchains/nim-#devel/lib/system/excpt.nim"
static N_INLINE(void, nimFrame)(TFrame* s_p0) {
#line 550
{ if (!(framePtr__system_u3923 == ((TFrame*) NIM_NIL))) goto LA3_;
#line 551
(*s_p0).calldepth = ((NI16)0); }
goto LA1_;
LA3_: ;
{
#line 554
(*s_p0).calldepth = (NI16)((*framePtr__system_u3923).calldepth + ((NI16)1)); }
LA1_: ;
#line 556
(*s_p0).prev = framePtr__system_u3923;
#line 557
framePtr__system_u3923 = s_p0;
#line 558
{ if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_;
callDepthLimitReached__system_u4541();
}
LA8_: ;
}
#line 99 "/home/vscode/.choosenim/toolchains/nim-#devel/lib/system/excpt.nim"
static N_INLINE(void, popFrame)(void) {
#line 100
framePtr__system_u3923 = (*framePtr__system_u3923).prev;}
#line 21 "/workspaces/bookworm/apps/examples/hello_nim/hello_nim_async.nim"
N_LIB_PRIVATE N_NIMCALL(void, blink_led__hello95nim95async_u13)(void) {
#line 31
int colontmpD_;
#line 25
int fd_1; int T6_;
#line 35
int ret; int T13_;NIM_BOOL* nimErr_; nimfr_("blink_led", "hello_nim_async.nim");{nimErr_ = nimErrorFlag(); colontmpD_ = (int)0;
#line 24
nimln_(24); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_4, 1); fd_1 = open("/dev/userleds", O_WRONLY);
#line 26
nimln_(26); { if (!(fd_1 < ((NI32)0))) goto LA3_;
#line 27
nimln_(27); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_6, 1);
#line 28
nimln_(28); goto BeforeRet_;
}
LA3_: ;
T6_ = (int)0;
#line 31
nimln_(31);
#line 34
nimln_(34); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_8, 1); ret = ioctl(fd_1, ULEDIOC_SETALL, ((NI)1));
#line 36
nimln_(36); { int T12_; if (!(ret < ((NI32)0))) goto LA10_;
#line 37
nimln_(37); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_10, 1);
#line 38
nimln_(38);
#line 31
nimln_(31); T12_ = (int)0; T12_ = close(fd_1); goto BeforeRet_;
}
LA10_: ;
#line 41
nimln_(41); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_12, 1);
#line 42
nimln_(42); T13_ = (int)0; T13_ = usleep(((unsigned int)1000000));
#line 45
nimln_(45); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_14, 1);
#line 46
nimln_(46); ret = ioctl(fd_1, ULEDIOC_SETALL, ((NI)0));
#line 47
nimln_(47); { int T18_; if (!(ret < ((NI32)0))) goto LA16_;
#line 48
nimln_(48); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_10, 1);
#line 49
nimln_(49);
#line 31
nimln_(31); T18_ = (int)0; T18_ = close(fd_1); goto BeforeRet_;
}
LA16_: ;
#line 52
nimln_(52); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_12, 1);
#line 53
nimln_(53); colontmpD_ = usleep(((unsigned int)1000000)); T6_ = colontmpD_; { LA7_:; }
{ }
if (NIM_UNLIKELY(*nimErr_)) goto LA5_; { LA5_:; }
{ int T23_;
#line 31
nimln_(31); T23_ = (int)0; T23_ = close(fd_1); }
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_; }BeforeRet_: ;
popFrame();}
#line 56 "/workspaces/bookworm/apps/examples/hello_nim/hello_nim_async.nim"
N_LIB_PRIVATE N_CDECL(void, hello_nim)(void) {NIM_BOOL oldNimErrFin1_;NIM_BOOL* nimErr_; nimfr_("hello_nim", "hello_nim_async.nim");{nimErr_ = nimErrorFlag();
#line 62
nimln_(62); echoBinSafe(TM__1vqzGCGyH8jPEpAwiaNwvg_2, 1); {
#line 65
NI loop;
#line 96 "/home/vscode/.choosenim/toolchains/nim-#devel/lib/system/iterators_1.nim"
NI res; loop = (NI)0; res = ((NI)0); {
#line 97
nimln_(97); while (1) { if (!(res <= ((NI)19))) goto LA4;
#line 65 "/workspaces/bookworm/apps/examples/hello_nim/hello_nim_async.nim"
nimlf_(65, "hello_nim_async.nim"); loop = ((NI) (res)); blink_led__hello95nim95async_u13();
if (NIM_UNLIKELY(*nimErr_)) goto LA1_;
#line 102 "/home/vscode/.choosenim/toolchains/nim-#devel/lib/system/iterators_1.nim"
nimlf_(102, "iterators_1.nim"); res += ((NI)1); } LA4: ;
}
}
{ LA1_:; }
{ oldNimErrFin1_ = *nimErr_; *nimErr_ = NIM_FALSE;
#line 59 "/workspaces/bookworm/apps/examples/hello_nim/hello_nim_async.nim"
nimlf_(59, "hello_nim_async.nim"); GC_runOrc__system_u3404();
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_; *nimErr_ = oldNimErrFin1_; }
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_; }BeforeRet_: ;
popFrame();}
N_LIB_PRIVATE void PreMainInner(void) {
atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatshomeatsvscodeatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatspureatsnativesocketsdotnim_Init000();
atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatshomeatsvscodeatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatsstdatsexitprocsdotnim_Init000();
}
N_LIB_PRIVATE void PreMain(void) {
#if 0
void (*volatile inner)(void);
inner = PreMainInner;
atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatshomeatsvscodeatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000();
(*inner)();
#else
atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatshomeatsvscodeatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000();
PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
(*inner)();
#else
PreMain();
NimMainInner();
#endif
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
#line 999999 "generated_not_to_break_here"
{
nimTestErrorFlag();}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment