Let me just be more specific about why I think the Kotlin target would
be useful:
1) Kotlin is an amazing language: it makes more very productive and I
think that having a proper Kotlin parser, written in idiomatic Kotlin
would be nice
2) Kotlin has now support for multi-platform project therefore having
a Kotlin target would allow having a multi-platform compiler or other
language tools that run on multiple platforms
Let's dive in the multi-platform thing.
Kotlin is a language that can be compiled:
* to JVM bytecode
* to JavaScript to be run in the browser
* to native code through LLVM (so it can run on iOS, it could be
compiled to WebAssembly, etc.)
Now, the problem is that you typically write a project in Kotlin
looking at a specific platform (e.g., JVM) and therefore you use all
the specific platform capabilities. For example, if I write a project
in Kotlin to compile it to JVM bytecode I can access the whole Java
standard library. The problem is that I cannot compile the same code
to JavaScript.
With multi-platform support this changes because you can write Kotlin
and use the multi-platform Kotlin standard library and get the same
Kotlin code to compile to different platforms. So if I get a Kotlin
parser and lexer, using just the multi-platform Kotlin standard
library I can compile that code and run it as-is on the JVM and the
browser. I can then write a whole compiler or an interpreter that will
reuse that parser and could also run on the JVM or the browser. I
think this is cool.
Currently I can write one ANTLR grammar and use different target, like
the Java and the JS target but then I get two different parsers, one
in Java and one in JS so if I want to write a compiler that run both
on Java and JS I have to write it twice.
# How the multi-platform Kotlin projects work
Now I am working on having a complete Kotlin runtime and it is already
almost done. How I did that?
1) I took the Java runtime
2) I converted it to Kotlin: there is a utility for doing that sort of
automatically but it then requires some adjustments
3) I stripped out every element that was supported only on the JVM but
not on the multi-platform Kotlin standard library
4) For those things that I needed and that were not available in the
multi-platform Kotlin standard library I defined the "expectations"
and then the "actual implementations" for both the JVM and JS. Think
of a mechanism like interface/implementation: you define the interface
in general and the implementation for the two platforms. We are
talking about a few classes, compared to the hundreds of classes of
the runtime, so the platform specific effort is pretty low
I am currently at a good point on the JVM, I still need work on the JS side.
Let's see if I find the time to get this thing finished and then write
some documentation for it.
Cheers,
Federico