Hi everyone!
So, I'm working on porting the libnx Nintendo Switch library to Nim. I've made some good progress using c2nim and nimgen, but I'm having an issue with one type conversion.
Is there anyway to importc a 128bit integer type? GCC itself supports 128bit integers on some platforms, and so does the compiler for libnx. Right now, I'm trying it just in GCC on my local machine with the following code:
# t.nim
{.passC: "-I\".\"".}
type
MYTYPE {.importc: "MYTYPE", header: "t.h"} = int
// t.c
#define MYTYPE __int128_t
Obviously, I know that the Nim type decl won't work, but is there something I can do that would allow me to use the 128bit integer type?
Both require devel. Stint is a pure Nim solution, while TTMath is a wrapper for a C++ header library (and requires C++ compilation).
Due to some restrictions when wrapping C++, notably due to "non-trivial destructor" alerts when you want to cast it or put several in a seq and the lack of testing, I've redeveloped Stint from the ground up.
In the future Stint will use GCC/LLVM builtin 128-bit types but it's still very fast and portable to all C supported already.
@mratsim thanks for the pointer! Using your example code, I think I've got something working now :) Btw, for c compiling, I figured out I can use __int128_t and __uint128_t, which worked for my little example. I'll post the code for it when I'm at my laptop in case anyone is interested in the future.
@kaushalmodi, thanks for the info as well! I'll probably check out that module at some point now that I know it exists :)