All Projects → korlibs → ktcc

korlibs / ktcc

Licence: MIT license
C Compiler that generates readable Kotlin and C# - Written in Kotlin + Small web-based Editor with autocompletion

Programming Languages

kotlin
9241 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to ktcc

mqtt
Kotlin cross-platform, coroutine based, reflectionless MQTT 3.1.1 & 5.0 client & server
Stars: ✭ 31 (-42.59%)
Mutual labels:  kotlin-js, kotlin-native
kfsm
Finite State Machine in Kotlin
Stars: ✭ 76 (+40.74%)
Mutual labels:  kotlin-js, kotlin-native
thelema-engine
Thelema - 3D graphics engine, written in Kotlin. Based on sources of libGDX.
Stars: ✭ 51 (-5.56%)
Mutual labels:  kotlin-js, kotlin-native
vjson
A simple JSON parser and (de)serializer library for java/kotlin and kotlin-native/js. Also provides a strongly-typed language: vjson-lang.
Stars: ✭ 31 (-42.59%)
Mutual labels:  kotlin-js, kotlin-native
kotlin-multiplatform-example
A Kotlin multiplatform example app that targets Android, ReactJS, iOS, JavaFx, and Spring Boot
Stars: ✭ 115 (+112.96%)
Mutual labels:  kotlin-js, kotlin-native
tmdb-api
This Kotlin Multiplatform library is for accessing the TMDB API to get movie and TV show content. Using for Android, iOS, and JS projects.
Stars: ✭ 31 (-42.59%)
Mutual labels:  kotlin-js, kotlin-native
KotlinMultiplatformAndoridParcelize
Use the Parcelize Annotation of the Kotlin Android Extensions in Kotin Multiplatform projects
Stars: ✭ 16 (-70.37%)
Mutual labels:  kotlin-js, kotlin-native
kmm-production-sample
This is an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile. It's a simple RSS reader, and you can download it from the App Store and Google Play. It's been designed to demonstrate how KMM can be used in real production projects.
Stars: ✭ 1,476 (+2633.33%)
Mutual labels:  kotlin-native
KMQTT
Embeddable and standalone Kotlin Multiplatform MQTT broker
Stars: ✭ 56 (+3.7%)
Mutual labels:  kotlin-native
kotlin-telegram
Repository with information about Kotlin chats on Telegram.
Stars: ✭ 21 (-61.11%)
Mutual labels:  kotlin-js
Small-C
Small-C Compiler, Assembler, Linker, and Library for 16-bit MS-DOS. Includes "YLink", an object file linker for MS-DOS executables.
Stars: ✭ 35 (-35.19%)
Mutual labels:  c-compiler
kotlin-js-D3js-example
A simple example of a D3 JavaScript program in Kotlin
Stars: ✭ 13 (-75.93%)
Mutual labels:  kotlin-js
MultiplatformPlayground
Kotlin Multiplatform project in Jetpack Compose & SwiftUI with shared ViewModel layer and File upload
Stars: ✭ 72 (+33.33%)
Mutual labels:  kotlin-native
rdocsyntax
Syntax highlighting for R HTML documentation
Stars: ✭ 20 (-62.96%)
Mutual labels:  ace-editor
fiddlestick
Local JSFiddle easy to use and modulate
Stars: ✭ 14 (-74.07%)
Mutual labels:  ace-editor
StarWars
Minimal GraphQL based Jetpack Compose, Wear Compose and SwiftUI Kotlin Multiplatform sample (using StarWars endpoint - https://graphql.org/swapi-graphql)
Stars: ✭ 165 (+205.56%)
Mutual labels:  kotlin-native
fongshen-editor
A highly customizable code-inserting editor for markdown or other languages
Stars: ✭ 35 (-35.19%)
Mutual labels:  ace-editor
KParser
Kotlin Multiplatform Arithmatic Parser
Stars: ✭ 32 (-40.74%)
Mutual labels:  kotlin-native
CompleteKotlin
Gradle Plugin to enable auto-completion and symbol resolution for all Kotlin/Native platforms.
Stars: ✭ 236 (+337.04%)
Mutual labels:  kotlin-native
kcc
A Small C Compiler
Stars: ✭ 18 (-66.67%)
Mutual labels:  c-compiler

ktcc

A C Compiler written in Multiplatform Kotlin (JVM, JS and Native).

Actions Status

Online live editor (Video)

MASTER ONLINE LIVE DEMO

It aims to generate Kotlin and potentially other targets from ANSI C code.

Use cases:

  • Compile C libraries into multiplatform Kotlin projects (that works on the JVM, JS and Native)
  • Convert C libraries into logical Kotlin code that can be modified

Using:

  • Provided as JVM library and CLI tool.
  • Provided as native executable (linux, mac and windows).
  • Provided as docker image with the compiler native executable. Just run latest uploaded version with: docker run --rm "-v$PWD:/data" soywiz/ktcc $*
  • Provided as JavaScript library and pure client-side online service. It autocompletes and generates Kotlin code on the fly on your browser.

CLI usage:

./gradlew fatJar
java -jar build/libs/ktcc-all.jar samples/simple.c      # outputs the kotlin code

Compile the c compiler with kotlin-native as a executable without dependencies:

./gradlew linkReleaseExecutableMacosArm64
./build/bin/macosArm64/releaseExecutable/ktcc.kexe samples/simple.c

Cross-compile the compiler native executable for windows or linux in a mac machine (requires docker):

./gradlew_linux linkReleaseExecutableLinuxX64 # linux
./gradlew_win linkReleaseExecutableMingwX64   # windows

Compile the docker image:

./build_docker_image.sh

Example:

./ktcc_jvm samples/mp3dec.c --subtarget=jvm --runtime -o samples/mp3dec.kt
kotlinc samples/mp3dec.kt -include-runtime -d samples/mp3dec.jar
java -jar samples/mp3dec.jar samples/mp31.mp3 samples/mp32.mp3.out.pcm

Ideas

Handling structs with inline classes

While keeping the code using structures sane.

fun alloca(size: Int): CPointer<Unit> = CPointer<Unit>((STACK_PTR - size).also { STACK_PTR -= size })

inline fun <T> stackFrame(callback: () -> T): T {
    val oldPos = STACK_PTR
    return try { callback() } finally { STACK_PTR = oldPos }
}

inline class MyStruct2(val ptr: Int) {
    companion object {
        val SIZEOF = 4
        val OFFSET_a = 0
    }
    var a: Int get() = lw(ptr + OFFSET_a); set(value) = run { sw(ptr + OFFSET_a, value) }
}

inline class MyStruct(val ptr: Int) {
    companion object {
        val SIZEOF = 12
        val OFFSET_a = 0
        val OFFSET_b = 4
        val OFFSET_c = 8
    }
    var a: Int get() = lw(ptr + OFFSET_a); set(value) = run { sw(ptr + OFFSET_a, value) }
    var b: MyStruct2 get() = MyStruct2(lw(ptr + OFFSET_b)); set(value) = run { sw(ptr + OFFSET_b, value.ptr) } // Pointer to MyStruct2
    val c: MyStruct2 get() = MyStruct2(ptr + OFFSET_c); set(value) = run { /* memcpy */ }
}

/////////////

fun test() = stackFrame {
    val ms = MyStruct(alloca(MyStruct.SIZEOF)) 
    ms.b = MyStruct2(10)
    ms.b.a = 10
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].