2 ms·
It is possible but the Swift stdlib does rely on a minimal set of libc functions including malloc()/free() and the usual str* and mem* functions. Some of the ot
by whistler 10y ago
It is possible but the Swift stdlib does rely on a minimal set of libc functions including malloc()/free() and the usual str* and mem* functions. Some of the other functionality can be removed eg the math and floating point but even implementing malloc() in Swift would be hard because any data structures that get used eg Arrays will themselves rely on malloc(), and even if you wrote it using UnsafeMutablePointer it would not be much different to a C implentation. Also the globalinit functions that get called at startup themselves rely on malloc() so it ends up being circular.
However if you are willing to accept some functionality will be written in C it is possible to run Swift directly on bare metal.
- pjmlp 10y ago> However if you are willing to accept some functionality will be written in C it is possible to run Swift directly on bare metal. I would rather use Assembly or compiler intrinsics instead, just like many C alternatives, some much older like NEWP, do. Also many of the C library calls are impossible to implement in pure ANSI C without language extensions or Assembly, malloc() and free() being two of them.