4 ms·
Nim compiles to js (as well as c and c++)
by shirleyquirk 6y ago
Nim compiles to js (as well as c and c++)
- magicalhippo 6y agoHow much of C and the standard library does it use? Like, if I wanted to make my own C compiler, how much would I have to implement for it to be usable with Nim-generated code? Does it use a fairly constrained subset or does it use a lot of C and the standard library? I imagine the latter but just curious.
- cb321 6y agoWell, it works with TinyCC/tcc where you can get order 200 millisecond compiles. While tcc does do most of c99, I do not think Nim requires anything past c89. libc-wise, it doesn't use even all of standard C. Minimal stdio/string stuff. You can easily access any C libs, though. So, a given program may have more dependency, but that is up to you (or to your Nim package deps). Full disclosure, not everything works - different backends tend to have slightly different bugs/coverage, but this also applies to c++ and js backends. But I use tcc as my default backend (in my nim.cfg file) every day and only run into problems like a time or two per year.
- beagle3 6y agoDoesn't depend much on the standard library -- almost not at all, and usually behind flag (e.g., if you don't -d:useMalloc , nim will not us malloc). I think it's no longer maintained, but there's a kernel that boots on metal written in Nim. Furthermore, people are running Nim on ESP32, Nintendo Switch, JS (Browser, Node), iOS, Android and more; From that alone its clear that the C library can't be a significant dependency. (And ... just about any C compiler around, including GCC, LLVM, TCC, MS C, Intel C, Zig C are supported when using C as a backend).
- pjmlp 6y agoIt is just a convenience, Objective-C and C++ also generated code like that on the early days.