{"id":19347871,"url":"https://github.com/korlibs/ktcc","last_synced_at":"2025-04-30T11:22:00.681Z","repository":{"id":84110132,"uuid":"165555533","full_name":"korlibs/ktcc","owner":"korlibs","description":"C Compiler that generates readable Kotlin and C# - Written in Kotlin + Small web-based Editor with autocompletion","archived":false,"fork":false,"pushed_at":"2024-08-22T08:56:06.000Z","size":4206,"stargazers_count":71,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T15:46:52.405Z","etag":null,"topics":["ace-editor","c","c-compiler","compiler","docker-image","kotlin","kotlin-js","kotlin-native"],"latest_commit_sha":null,"homepage":"https://korlibs.github.io/ktcc/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/korlibs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"soywiz","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-01-13T21:17:11.000Z","updated_at":"2024-12-17T19:23:42.000Z","dependencies_parsed_at":"2025-01-01T21:12:05.927Z","dependency_job_id":"430de2cb-d784-491a-bbd8-3df27e17becc","html_url":"https://github.com/korlibs/ktcc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fktcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fktcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fktcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fktcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/korlibs","download_url":"https://codeload.github.com/korlibs/ktcc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251689009,"owners_count":21627815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ace-editor","c","c-compiler","compiler","docker-image","kotlin","kotlin-js","kotlin-native"],"created_at":"2024-11-10T04:18:21.374Z","updated_at":"2025-04-30T11:22:00.659Z","avatar_url":"https://github.com/korlibs.png","language":"Kotlin","funding_links":["https://github.com/sponsors/soywiz"],"categories":[],"sub_categories":[],"readme":"# ktcc\n\nA C Compiler written in Multiplatform Kotlin (JVM, JS and Native).\n\n[![Actions Status](https://github.com/soywiz/ktcc/workflows/Java%20CI/badge.svg)](https://github.com/soywiz/ktcc/actions)\n\n\n## [Online live editor](https://korlibs.github.io/ktcc/) ([Video](https://youtu.be/r-yeEjJ0Ld0))\n\n## [MASTER ONLINE LIVE DEMO](https://korlibs.github.io/ktcc/)\n\nIt aims to generate Kotlin and potentially other targets from ANSI C code.\n\nUse cases:\n\n* Compile C libraries into multiplatform Kotlin projects (that works on the JVM, JS and Native)\n* Convert C libraries into logical Kotlin code that can be modified\n\nUsing:\n\n* Provided as JVM library and CLI tool.\n* Provided as native executable (linux, mac and windows).\n* Provided as [docker image](https://cloud.docker.com/repository/docker/soywiz/ktcc/) with the compiler native executable. Just run latest uploaded version with: `docker run --rm \"-v$PWD:/data\" soywiz/ktcc $*`\n* Provided as JavaScript library and [pure client-side online service](https://korlibs.github.io/ktcc/). It autocompletes and generates Kotlin code on the fly on your browser.\n\nCLI usage:\n\n```kotlin\n./gradlew fatJar\njava -jar build/libs/ktcc-all.jar samples/simple.c      # outputs the kotlin code\n```\n\nCompile the c compiler with kotlin-native as a executable without dependencies:\n\n```kotlin\n./gradlew linkReleaseExecutableMacosArm64\n./build/bin/macosArm64/releaseExecutable/ktcc.kexe samples/simple.c\n```\n\nCross-compile the compiler native executable for windows or linux in a mac machine (requires docker):\n\n```kotlin\n./gradlew_linux linkReleaseExecutableLinuxX64 # linux\n./gradlew_win linkReleaseExecutableMingwX64   # windows\n```\n\nCompile the docker image:\n\n```kotlin\n./build_docker_image.sh\n```\n\nExample:\n\n```bash\n./ktcc_jvm samples/mp3dec.c --subtarget=jvm --runtime -o samples/mp3dec.kt\nkotlinc samples/mp3dec.kt -include-runtime -d samples/mp3dec.jar\njava -jar samples/mp3dec.jar samples/mp31.mp3 samples/mp32.mp3.out.pcm\n```\n\n## Ideas\n\n### Handling structs with inline classes\n\nWhile keeping the code using structures sane.\n\n```kotlin\nfun alloca(size: Int): CPointer\u003cUnit\u003e = CPointer\u003cUnit\u003e((STACK_PTR - size).also { STACK_PTR -= size })\n\ninline fun \u003cT\u003e stackFrame(callback: () -\u003e T): T {\n    val oldPos = STACK_PTR\n    return try { callback() } finally { STACK_PTR = oldPos }\n}\n\ninline class MyStruct2(val ptr: Int) {\n    companion object {\n        val SIZEOF = 4\n        val OFFSET_a = 0\n    }\n    var a: Int get() = lw(ptr + OFFSET_a); set(value) = run { sw(ptr + OFFSET_a, value) }\n}\n\ninline class MyStruct(val ptr: Int) {\n    companion object {\n        val SIZEOF = 12\n        val OFFSET_a = 0\n        val OFFSET_b = 4\n        val OFFSET_c = 8\n    }\n    var a: Int get() = lw(ptr + OFFSET_a); set(value) = run { sw(ptr + OFFSET_a, value) }\n    var b: MyStruct2 get() = MyStruct2(lw(ptr + OFFSET_b)); set(value) = run { sw(ptr + OFFSET_b, value.ptr) } // Pointer to MyStruct2\n    val c: MyStruct2 get() = MyStruct2(ptr + OFFSET_c); set(value) = run { /* memcpy */ }\n}\n\n/////////////\n\nfun test() = stackFrame {\n    val ms = MyStruct(alloca(MyStruct.SIZEOF)) \n    ms.b = MyStruct2(10)\n    ms.b.a = 10\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorlibs%2Fktcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkorlibs%2Fktcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorlibs%2Fktcc/lists"}