louiscad
04/12/2021, 9:37 PMYoussef Shoaib [MOD]
04/12/2021, 9:40 PMIrGenerationExtension
and just literally transform the code into a string of C++ code and print that out to the console so that you can easily play with itYoussef Shoaib [MOD]
04/12/2021, 9:41 PMYoussef Shoaib [MOD]
04/12/2021, 9:41 PMshikasd
04/12/2021, 10:00 PMshikasd
04/12/2021, 10:02 PMlouiscad
04/12/2021, 10:05 PMlouiscad
04/12/2021, 10:07 PMlouiscad
04/12/2021, 10:09 PMIrGenerationExtension
is the class to look for? I guess I can find it in the API for compiler plugins?
I'm wondering how I should get started, if there's any example project, or some info to get setup and figure it out with the right APIs.rocketraman
04/12/2021, 10:13 PMshikasd
04/12/2021, 10:19 PMIrGenerationExtension
is more about adding stuff to IR. You probably want to compile the library, take IR and use it for assembly/source generation.
For this, I would recommend looking into how Kotlin creates KLIBs: https://github.com/JetBrains/kotlin/blob/master/kotlin-native/backend.native/compi[…]ackend.native/src/org/jetbrains/kotlin/backend/konan/PsiToIr.kt (this one from native)
After that you can check the phases the compiler goes through to create LLVM representation, probably you need like one of those: https://github.com/JetBrains/kotlin/blob/master/kotlin-native/backend.native/compi[…]native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.ktlouiscad
04/12/2021, 10:38 PMHyugga
04/12/2021, 11:42 PMlouiscad
04/13/2021, 8:10 AMmsink
04/13/2021, 8:42 AMAVR is not among Kotlin/Native current targetsAnd never will - minimal requirements are 32-bit CPU and at least 300KB memory.
louiscad
04/13/2021, 9:20 AMLong
and Double
on 32-bit CPUs.
I'm not saying everything made in Kotlin should run on AVR. Just that it should be possible to use Kotlin syntax to generate AVR compatible code.msink
04/13/2021, 9:44 AMlouiscad
04/13/2021, 9:52 AMrepeat(x) { … }
could be unwrapped to a simple while
or for
loop in C++.
Function calls can be mapped directly.
Arithmetic, it's no different.
Of course, the kind of errors, if any would be different that typical Kotlin code, but you can design your Kotlin program so that it can translate properly to C++.
You probably have a different point of view with 30 years of C++, it's likely easier for you to use it directly, I understand that, but that won't stop me from trying to make a Kotlin to C++ translator/compiler, even if it doesn't support all of what Kotlin can offer.louiscad
04/13/2021, 9:56 AMmsink
04/13/2021, 10:48 AMlouiscad
04/13/2021, 11:43 AMlouiscad
04/13/2021, 12:07 PMmsink
04/13/2021, 2:08 PMlouiscad
04/14/2021, 9:02 PM