Giter Site home page Giter Site logo

the-self-taught-software-engineer / kotlin-decompiled Goto Github PK

View Code? Open in Web Editor NEW
28.0 0.0 4.0 51 KB

(Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java again for better readability

Home Page: https://youtu.be/6pWXre4gDyM

License: MIT License

Kotlin 24.17% Java 75.83%
kotlin jvm compiler java

kotlin-decompiled's Introduction

Kotlin: Decompiled

(Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java again for better readability

Find my explanation of this below in video form!

Idea

The point of this repository is to see quickly how Kotlin language features that seem to have no clear equivalent in Java are compiled to run on the JVM in the end. The Kotlin core developers came up with some interesting ways to overcome this. Some are more straight forward, some less so. In any case, they used to major methodologies: Resolve and enforce the language feature at hand in the front-end of the Kotlin compiler or do the conversion to bytecode solely in the back-end to "emulate" the feature. Of course, for most features, a combination of both is used although at the same time, most features either rely more on front-end or back-end functionality respectively.

Structure

I created one example for each of the below language features, compiled that to JVM bytecode and then decompiled that again with CFR to Java code (and cleaned it up a bit). You will find a directory in both, the kotlin and the java directories for each feature that corresponds to each other. For instance: src/main/kotlin/toplevelfunction compiles to src/main/java/toplevelfunction. Sometimes, there are multiple files necessary to bring across the example, in which case you will find all of them in both again. Note that the output is sometimes not 100% representative of how the bytecode looked but in most examples (mainly apart from suspendkeyword), the output is pretty clear.

Language Features

In the following table, you'll find all the analyzed lanuage features:

Feature
Companion object
const keyword
Data class
Default argument
Delegation
Destructuring declaration
Elvis operator (?:)
Extension function
Extension property
if expression
infix keyword
init block
in keyword
inline keyword
Iterate over range
Lambda labeling
this labeling
lateinit keyword
Local function
Named argument
Nullability ignore operator (!!)
Nullability operator (?.)
Singleton object
Value object
Operator overloading
Read-only collection
reified keyword
Sealed interface
Secondary constructor
String interpolation
suspend keyword
synchronized keyword
Top-level function
tailrec keyword
Try-Catch expression
typealias keyword
Safe typecasting
Unsafe typecasting
Value class

Most interesting examples

In a video on my channel, I looked at the most interesting of the above features to discuss how they were achieved in compiled code:

  • Top-level function
  • inline keyword
  • Local function
  • Operator overloading
  • Named argument
  • Iterate over range
  • Sealed interface
  • reified keyword

Over here, you'll find the video.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.