Does kotlin native dll/win have VM which contains ...
# getting-started
t
Does kotlin native dll/win have VM which contains kotlin GC inside? Or it's just pure C without any GC or VM inside?
p
I read somewhere that the new memory model ships with a small runtime that does garbage collection.
t
I'm confused. C language doesn't have any run time and GC. if the native DLL is pure C. How can it have runtime inside it?
p
KN is not c, is binary/machine code generated by the kotlin compiler. The fact that it is compliant with header files doesn't mean it is quite the same as c generated binaries, probably similar tho. The runtime, is basically a library similar to the c standard lib, glibc. Where you got memory allocation utility functions and other utility functions. Perhaps the term runtime is misleading in this case.
t
The binary/machine code generated by kotlin is same to generated by mingw/gcc? Or it's still different?
for example: one kotlin hello world program and generated by kotlin. same hello world program by C and compiled by gcc or mingw. Are the result same?
p
Humm, that is a good question that I don't know how to answer. But, my intuition says that it won't be quite the same. Is it possible that KN compiler reuses some gcc outputs in some operations. After all gcc has been out for a while and is compatible with all hardware/architecture abis. But to see if it looks the same you will have to check it on your own.
Perhaps for a hello world the output looks similar because is a really small program with one standard library function call. But as a program grows it will start deviating more and more. The 2 languages these compilers parse are very different.
e
No VM, yes GC
C doesn't mean no GC, as past projects like Boehm-GC demonstrate
👍 1
But in any case, Kotlin/Native doesn't emit C, it produces LLVM IR which is converted directly to machine code
which makes use of the runtime that K/N links into the binary output, for things like GC and RTTI

https://youtu.be/D4ViSA9KVEw

t
Kotlin native, swift/objective-c are using LLVM as the backend compiler. Is this the main reason that the mac/ios build package of kotlin can be used directly by swift. the class/instance in kotlin can be used in swift without additional transformation.
🚫 1
p
The reason why it can be used directly is because it implements the Apple native protocols. Is kinda similar to the jni in the java world. These Applications are packaged in a way where they allow a "host" code to execute under the App process. It doesn't care what compiled it, it is basically a jump to the region in memory where the "foreign" code resides and then let it execute. For your binary file to run, it needs to conform to Apples protocol, just that.