Would it possible to run the compiler in JavaScript or does it need some JVM/C (?) api to compile Kotlin to JavaScript (IR) in your browser? Use case is a local Kotlin web playground
s
shikasd
04/04/2022, 3:11 PM
You'll need JVM to run the compiler for sure :)
Btw, I am pretty sure JB has a playground on Kotlin website, it should be embeddable (or maybe sources are available somewhere)
h
hfhbd
04/04/2022, 3:13 PM
Hm.
Yeah, I do know the Kotlin playground by JB, but AFAIK its not possible to execute the resulting JS in your JS app. And it still requires a JVM backend.
m
mcpiroman
04/04/2022, 4:20 PM
If you ask about compiling kotlin compiler for target other than JVM, then it is absolutelly impossible - it has many dependencies on JVM and JVM libraries. It even has a good about of remaining java source files, although they could be threoretically translated to kotlin quite eaisly.
e
ephemient
04/04/2022, 4:37 PM
if you were very motivated, you could try running the Kotlin compiler with TeaVM (which converts JVM bytecode to JS). I wouldn't find it much fun, though.
^^^ yep, that's what I was thinking of earlier
You could also just have server call Kotlinc and return/execute resulting JS, if it is feasible for your project
h
hfhbd
04/05/2022, 8:33 AM
Thanks for the information!
The project does not exists yet, so I will try to prototype it with kotlin-playground first.