An exercise in exploring the Kotlin codebase.
Kotlin history
Search commits for “initial” and sort by oldest, or just go to last page of the repo. Possibly also useful is JetBrains’ issue tracker starting from earliest Kotlin issues. Apparently Kotlin was initially named JetL (presumably JetBrains Language?). Though it’s been renamed fairly quickly.
According to Wikipedia, Kotlin was publicly announced in July 2011. Let’s find commits around that time.
- Interesting commit: “Finally, green tests”. :)
- Tiny version of Kotlin’s library (
Numeric
,String
, etc) seems to contain interface for some of its primitives.- Search commits for Library.jet
to find that it’s been split to separate files,
in early 2012 - e.g.
Arrays
,Iterables
,Numbers
, etc.
- Search commits for Library.jet
to find that it’s been split to separate files,
in early 2012 - e.g.
- Early project structure
examples
for showing concrete examplesgrammar
for defining the language in ANTLRidea
for integrating language into IntelliJ, cf.JetHighlighter
Compiler, lexer, grammar and JetFile
1st commit shows early language prototypes. The project started with an initial grammar definition (formatted as ANTLR4) which auto-generates a lexer. Cf. Flex and Bison basics and simple Flex and Bison examples to find out more about syntax. The spec has since been extracted to a separate repo (2019 removal commit and link to other grammar updates).
Elsewhere, they define
Program Structure Interface
(PSI; GitHub API,
GitHub Impl).
JetFile
is a collection of imports and declarations.
Standard visitor pattern based on PSI.
JetElement
similarly extends ASTWrapperPsiElement
.
The entire tree structure is defined in jet/lang/psi
.
SemanticWhitespaceAwarePsiBuilder
extends PsiBuilderAdapter
implements the PsiBuilder
interface,
used by the state-machine implementation in
JetParsing
.
The whitespace-awareness comes into play because Kotlin has an optional ;
termination.
Structure remained mostly similar to this day, apart from renaming to
KtElementImpl
with the interface definition in Kotlin.
Introduction of project compilation from IDEA.
Some interesting commits
- Numbers are hashable.
- Not yet working
for...in
. - Boxing/unboxing
- Pattern matching
- Generate size for arrays. Simple test case.
- The testing framework
maps
.jet
code examples to.txt
parse trees.