Dummy question about Kotlin to JVM compiler: 1. Wa...
# compiler
v
Dummy question about Kotlin to JVM compiler: 1. Was it implemented from scratch in Java? 2. Was it implemented using some standard Java lexer/parser framework? 3. Was it implemented using LLVM, compiled to LLVM IR and later compiled to JVM bytecode?
JIT and other compiler optimizations are quite boring/laborious to implement, so I was wondering the JetBrains was able to build it on top of LLVM in order to take benefit of the out-out-box optimizations
d
3 is a definite no.
t
I think the lexer/parser is written from scratch
v
@Dominaezzz why not 3️⃣? I thought it would be the easiest/better solution
d
That's how the Native compiler is implemented. If the JVM compiler was implemented the same way then Java interop would be a lot more difficult.
Also, LLVM supports JVM bytecode?
LLJVM seems to be dead now.
😢 2
s
That's how I see it, correct me if I am wrong 🙂 1. Almost from scratch, seems like first it was Java, now majority of the codebase in Kotlin 2. Parser is written by hand, Lexer is generated by JFlex (JetBrains use it almost everywhere in their products) 3. Nope, just three different backends compiling AST directly. Kotlin IR is totally different from LLVM IR. Also every platform has different external contributors (Java classes in JVM, C headers in native), so frontend implementation differs in some places as well.
💯 1