KTCC Preview: C Compiler written in Kotlin

Published at Mon, 21 Jan 2019 05:07:37 UTC by soywiz

I have released a preview of my new pet project KTCC. It is not complete, but does a lot of things already.

It is a C Compiler written in Multiplatform Kotlin (with implementations for the browser, the JVM and Native). It generates Kotlin from C code and also provides the parsed tree of a C program to be used in Kotlin.

You can try it online: https://soywiz.github.io/ktcc/

I have created it to be able to use libraries in Multiplatform Kotlin without having to manually convert them.

I plan to use this to convert libraries like minimp3, stb_image, libwebp or ffmpeg to be usable inside Kotlin to use in my korlibs.

You can always use them on Kotlin/Native, and even convert them to JS/WebAssembly using emscripten, even create a native library for all the JVM targets you can use, and then call each function for each target.

This simplifies that a lot, and since it preserves a lot of useful information (like field names in structures), it is easier to port later to normal plain Kotlin.

It uses Kotlin inline classes to wrap integers that act as pointers, but also provide type information like normal access to fields, etc.

  • GitHub page: https://github.com/soywiz/ktcc
  • Online demo: https://soywiz.github.io/ktcc/
  • Small docker image (45MB including ubuntu) with the compiler compiled with K/N: https://hub.docker.com/r/soywiz/ktcc
  • Forum (ask questions here): https://forum.soywiz.com/category/20/ktcc