SlideShare a Scribd company logo
/29
Kotlin
Kotlin
Compiler Construction
Nurgaliev Ildar
/29
Kotlin
Why?
One reason is enough:
Java platform and Java language there is huge gap
/29
Kotlin
Chalenges in JVM language design.
/29
Kotlin
Introduction
● Statically typed
● Compiles to JVM byte codes or JavaScript
● JVM version is Java compatible both ways
● Intended for industrial use
o Designed for READABILITY
o Relies simple (but powerful) abstractions
o Performance is a priority
o Tooling matters
● Open Source (Apache 2)
o http://github.com/JetBrains/Kotlin
/29
Kotlin
Keywords
for
while
match
case
if
then
else
do
return
fun
initial
in
val
var
null
continue
String
package
class
private
void
internal
protected
/29
Kotlin
Java
type
Kotlin type
byte kotlin.Byte
short kotlin.Short
int kotlin.Int
double kotlin.Double
boolean kotlin.Boolean
Mapped types
Kotlin treats some Java types specially. Such types are
not loaded from Java “as is”, but are mapped to
corresponding Kotlin types. The mapping only matters
at compile time, the runtime representation remains
unchanged. Java’s primitive types are mapped to
corresponding Kotlin types (keeping platform types in
mind):
java.lang.Object kotlin.Any!
int[] kotlin.IntArray!
/29
Kotlin
Basic syntax
● You do not need ; to break statements.
● Comments are similar to Java or C#, /* This is comment */ for multi line comments and // for single line
comment.
● Unlike Java, you do not need to match your file name to your class name.
● Like JavaScript, you can create functions outside classes. So there is no need to stuff your functions as static
members of classes like what you do in C# or Java.
● Kotlin has string templates, which is awesome. e.g. "$firstName $lastName" for simple variable name or
"${person.name} is ${1 * 2}" for any expressions. You can still do the string concatenation if you like e.g.
"hello " + "world", but that means being stupid.
● It has no tuple although Kotlin's data classes is an option to use in place of tuple.
● Use function literals to filter and map collections: basic functional programming inside
/29
Kotlin
Variable semantic
● There are two keywords for variable declaration, var and val.
● Use var when the variable value is to be modified and val where the variable value will not change after first
assigned.
● This val is similar to readonly keyword in C# or final keyword in Java.
● val variable must be initialized at declaration.
● Unlike Java or C#, you declare the type of a variable after the name, e.g. var firstName : String
● Number primitive types are as follows: Double, Float, Long, Int, Short, Byte. There is no automatic conversion
between types. You have to explicitly convert them.
● More primitive types: Char, String, Boolean.
● All variable declarations in Kotlin must be initialized.
/29
Kotlin
Identifiers
4 types of identifiers supported by Scala:
● ALPHANUMERIC IDENTIFIERS
● OPERATOR IDENTIFIERS
● LITERAL IDENTIFIERS
/29
Kotlin
ALPHANUMERIC IDENTIFIERS
● An ALPHANUMERIC IDENTIFIERS starts with a letter or underscore,
which can be followed by further letters, digits, or underscores.
● '$' character is a reserved keyword
Legal alphanumeric identifiers:
age, salary, _value, __1_value
Illegal identifiers:
$salary, 123abc, -salary
/29
Kotlin
grammar
На сайте выложено, EBNF
/29
Kotlin
Semantic
- arrays the index used in an array selection expression must be of
integer type
- expressions the two operands to logical && must both be bool type, the result
is bool type
- functions the type of each actual argument in a function call must be
compatible with the formal parameter
- classes if specified, the parent of a class must be a properly declared class
type
- interfaces all methods of the interface must be implemented if a class states
that it implements the interface
/29
Kotlin
Semantic (easy stuff)
Class names can be used before being defined
• We can’t check class names
– using a symbol table
– or even in one pass
• Solution
– Pass 1: Gather all class names
– Pass 2: Do the checking
/29
Kotlin
AST
– Before: Process an AST node n
– Recurse: Process the children of n
– After: Finish processing the AST node n
/29
Kotlin
Example AST rules
● Before processing e, add definition of x to current
definitions, overriding any other definition of x
● – Recurse
● – After processing e, remove definition of x and restore
old definition of x
for (x : Char in “abc”){ ( x )
Expressions…. ( e )
}
/29
Kotlin
Symbol table operations
● addSymbol(x) push x and associated info, such as
x’s type, on the stack
● findSymbol(x) search stack, starting from top, for
x. Return first x found or NULL if none found
● removeSymbol() pop the stack
● enterScope() start a new nested scope
● findSymbol(x) finds current x (or null)
● addSymbol(x) add a symbol x to the table
● checkScope(x) true if x defined in current scope
● exitScope() exit current scope
/29
Kotlin
Recall to symbol tables for resolving
fun main(args: Array<String>) {
if (args.size == 0) {
println("Provide a name")
return
}
println("Hello, ${args[0]}!")
//String Interpolation to cut down ceremony.
}
/29
Kotlin
Method declaration
● Method names have complex rules
● A method need not to be defined in the class in which it
is used, but in some parent class
● Methods may also be redefined (overridden) (Hard point)
/29
Kotlin
Type checking
Type checking computes via reasoning:
If E1 and E2 have certain types, then E3 has a certain type
(e1 : Int AND e2: Int) IMPLIES e1 + e2: Int
We work with hypotheses and conclusions.
So we create type rules.
Ex: is add minus
/29
Kotlin
Type checking
Type checking proves facts e: T
– Proof is on the structure of the AST
– Proof has the shape of the AST
– One type rule is used for each AST node
• In the type rule used for a node e:
– Hypotheses are the proofs of types of e’s subexpressions
– Conclusion is the type of e
• Types are computed in a bottom-up pass over the AST
/29
Kotlin
Type environment before type check
The type environment gives types to the free
identifiers in the current scope
• The type environment is passed down the AST from
the root towards the leaves
• Types are computed up the AST from the leaves
towards the root
/29
Kotlin
Subtyping
Consider:
if e0 then e1 else e2
• The result can be either e1 or e2
• The type is either e1’s type or of e2’s type
• The best we can do is the smallest supertype larger than the type of e1 or e2
/29
Kotlin
Subtyping
lub(X,Y), the Least Upper Bound of X and Y, is Z if
– X ⩽ Z AND Y ⩽ Z
Z is an upper bound
– X ⩽ Z’ AND Y ⩽ Z’ IMPLIES Z ⩽ Z’
Z is least among upper bounds
so the least upper bound of two types is their
least common ancestor in the inheritance tree
/29
Kotlin
Subtyping
Ex 2: The rule for case expressions takes a lub over all branches
Ex 1: if-Then-Else
/29
Kotlin
Typing methods
prelude: A method foo and an object foo can coexist in the
same scope
• In the type rules, this is reflected by a separate mapping
M for method signatures
M(C,f) = (T1,. . .Tn,Tn+1)
means in class C there is a method f
f(x1:T1,. . .,xn:Tn): Tn+1 the last one is type of return st
/29
Kotlin
Polymorphism (Self type)
class Count {
val i = 0;
fun inc() : Count {
i++
return this
}
};
inc() should return “dynamic type”
class Stock extends Count(var name:String)
{
};
fun main(args: Array<>String){
val a = Stock(“test”)
a = (new Stock).inc (); // fail
… a.name …
};
/29
Kotlin
Polymorphism (Self type)
– So, we must redefine inc for each of the subclasses, with a specialized return
type
● Introduce the keyword SELF_TYPE to use for the return value of such
functions
SELF_TYPE is not a dynamic type
– It is a static type
– It helps the type checker to keep better track of types
– It enables the type checker to accept more correct
programs
/29
Kotlin
Semantic
Else one Hard aspect:
1) Lamda expressions as new feature of the language:
val positiveNumbers = list.filter {it > 0}
Правила редукции типовых и без типовых лямбда исчислений
Область видимо-сти. Операционная семантика, виды редукций.
Представление термов без использования имён (индексы де Брауна)
Безопасность, продвижение, сохранение.
Простое типизированное лямбда-исчисление: Типы функций.
Отношение типизации. Свойства типизации. Соответствие Карри–Говарда(введения
устранения, при совпадении вычисление).
Стирание типов и типизируемость
/29
Kotlin
Code generation
Вряд ли я с этим справлюсь

More Related Content

What's hot

It's All About Morphisms
It's All About MorphismsIt's All About Morphisms
It's All About Morphisms
Uberto Barbini
 
FINITE STATE MACHINE AND CHOMSKY HIERARCHY
FINITE STATE MACHINE AND CHOMSKY HIERARCHYFINITE STATE MACHINE AND CHOMSKY HIERARCHY
FINITE STATE MACHINE AND CHOMSKY HIERARCHY
nishimanglani
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
Mukesh Tekwani
 
Lecture: Automata
Lecture: AutomataLecture: Automata
Lecture: Automata
Marina Santini
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
Dattatray Gandhmal
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
Ratnakar Mikkili
 
Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)
Alexander Podkhalyuzin
 
Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Alexander Podkhalyuzin
 
Lexical
LexicalLexical
Lexical
baran19901990
 
Java moderno java para Jedis episodio I
Java moderno  java para  Jedis  episodio IJava moderno  java para  Jedis  episodio I
Java moderno java para Jedis episodio I
Roan Brasil Monteiro
 
Ch2 finite automaton
Ch2 finite automatonCh2 finite automaton
Ch2 finite automaton
meresie tesfay
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysisraosir123
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
rfojdar
 
Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
Kiran Acharya
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 
Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01
Iffat Anjum
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
Daniyal Mughal
 

What's hot (20)

It's All About Morphisms
It's All About MorphismsIt's All About Morphisms
It's All About Morphisms
 
FINITE STATE MACHINE AND CHOMSKY HIERARCHY
FINITE STATE MACHINE AND CHOMSKY HIERARCHYFINITE STATE MACHINE AND CHOMSKY HIERARCHY
FINITE STATE MACHINE AND CHOMSKY HIERARCHY
 
Finite automata
Finite automataFinite automata
Finite automata
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Lecture: Automata
Lecture: AutomataLecture: Automata
Lecture: Automata
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)
 
Finite automata
Finite automataFinite automata
Finite automata
 
Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)
 
Template classes and ROS messages
Template classes and ROS messagesTemplate classes and ROS messages
Template classes and ROS messages
 
Lexical
LexicalLexical
Lexical
 
Java moderno java para Jedis episodio I
Java moderno  java para  Jedis  episodio IJava moderno  java para  Jedis  episodio I
Java moderno java para Jedis episodio I
 
Ch2 finite automaton
Ch2 finite automatonCh2 finite automaton
Ch2 finite automaton
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
 
Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
 

Similar to Kotlin compiler construction (very brief)

Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
Mohamed Wael
 
Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iii
Nico Ludwig
 
9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin
Zoran Stanimirovic
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
Coder Tech
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
Shimi Bandiel
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
Nico Ludwig
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
Mahdi Hasanzadeh
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
Nico Ludwig
 
Finals-review.pptx
Finals-review.pptxFinals-review.pptx
Finals-review.pptx
amara jyothi
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
Chaitanya Jambotkar
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
KauserJahan6
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
RKarthickCSEKIOT
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
ssusera0bb35
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and concepts
Nicola Bonelli
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
Nico Ludwig
 
C#unit4
C#unit4C#unit4
C#unit4
raksharao
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
AbdulRazaqAnjum
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
InfinityWorld3
 

Similar to Kotlin compiler construction (very brief) (20)

Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iii
 
9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
Finals-review.pptx
Finals-review.pptxFinals-review.pptx
Finals-review.pptx
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and concepts
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
C#unit4
C#unit4C#unit4
C#unit4
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 

More from Ildar Nurgaliev

Presentation
PresentationPresentation
Presentation
Ildar Nurgaliev
 
CloSapn
CloSapnCloSapn
Анализ маркетинговой деятельности ООО “БАРС ГРУП”
Анализ маркетинговой деятельности  ООО “БАРС ГРУП”Анализ маркетинговой деятельности  ООО “БАРС ГРУП”
Анализ маркетинговой деятельности ООО “БАРС ГРУП”
Ildar Nurgaliev
 
Fuzzy logic and application in AI
Fuzzy logic and application in AIFuzzy logic and application in AI
Fuzzy logic and application in AI
Ildar Nurgaliev
 
Scala syntax analysis
Scala syntax analysisScala syntax analysis
Scala syntax analysis
Ildar Nurgaliev
 
Artificial neural network
Artificial neural networkArtificial neural network
Artificial neural network
Ildar Nurgaliev
 
Social dynamic simulation
Social dynamic simulationSocial dynamic simulation
Social dynamic simulation
Ildar Nurgaliev
 

More from Ildar Nurgaliev (7)

Presentation
PresentationPresentation
Presentation
 
CloSapn
CloSapnCloSapn
CloSapn
 
Анализ маркетинговой деятельности ООО “БАРС ГРУП”
Анализ маркетинговой деятельности  ООО “БАРС ГРУП”Анализ маркетинговой деятельности  ООО “БАРС ГРУП”
Анализ маркетинговой деятельности ООО “БАРС ГРУП”
 
Fuzzy logic and application in AI
Fuzzy logic and application in AIFuzzy logic and application in AI
Fuzzy logic and application in AI
 
Scala syntax analysis
Scala syntax analysisScala syntax analysis
Scala syntax analysis
 
Artificial neural network
Artificial neural networkArtificial neural network
Artificial neural network
 
Social dynamic simulation
Social dynamic simulationSocial dynamic simulation
Social dynamic simulation
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 

Recently uploaded (20)

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 

Kotlin compiler construction (very brief)

  • 2. /29 Kotlin Why? One reason is enough: Java platform and Java language there is huge gap
  • 3. /29 Kotlin Chalenges in JVM language design.
  • 4. /29 Kotlin Introduction ● Statically typed ● Compiles to JVM byte codes or JavaScript ● JVM version is Java compatible both ways ● Intended for industrial use o Designed for READABILITY o Relies simple (but powerful) abstractions o Performance is a priority o Tooling matters ● Open Source (Apache 2) o http://github.com/JetBrains/Kotlin
  • 6. /29 Kotlin Java type Kotlin type byte kotlin.Byte short kotlin.Short int kotlin.Int double kotlin.Double boolean kotlin.Boolean Mapped types Kotlin treats some Java types specially. Such types are not loaded from Java “as is”, but are mapped to corresponding Kotlin types. The mapping only matters at compile time, the runtime representation remains unchanged. Java’s primitive types are mapped to corresponding Kotlin types (keeping platform types in mind): java.lang.Object kotlin.Any! int[] kotlin.IntArray!
  • 7. /29 Kotlin Basic syntax ● You do not need ; to break statements. ● Comments are similar to Java or C#, /* This is comment */ for multi line comments and // for single line comment. ● Unlike Java, you do not need to match your file name to your class name. ● Like JavaScript, you can create functions outside classes. So there is no need to stuff your functions as static members of classes like what you do in C# or Java. ● Kotlin has string templates, which is awesome. e.g. "$firstName $lastName" for simple variable name or "${person.name} is ${1 * 2}" for any expressions. You can still do the string concatenation if you like e.g. "hello " + "world", but that means being stupid. ● It has no tuple although Kotlin's data classes is an option to use in place of tuple. ● Use function literals to filter and map collections: basic functional programming inside
  • 8. /29 Kotlin Variable semantic ● There are two keywords for variable declaration, var and val. ● Use var when the variable value is to be modified and val where the variable value will not change after first assigned. ● This val is similar to readonly keyword in C# or final keyword in Java. ● val variable must be initialized at declaration. ● Unlike Java or C#, you declare the type of a variable after the name, e.g. var firstName : String ● Number primitive types are as follows: Double, Float, Long, Int, Short, Byte. There is no automatic conversion between types. You have to explicitly convert them. ● More primitive types: Char, String, Boolean. ● All variable declarations in Kotlin must be initialized.
  • 9. /29 Kotlin Identifiers 4 types of identifiers supported by Scala: ● ALPHANUMERIC IDENTIFIERS ● OPERATOR IDENTIFIERS ● LITERAL IDENTIFIERS
  • 10. /29 Kotlin ALPHANUMERIC IDENTIFIERS ● An ALPHANUMERIC IDENTIFIERS starts with a letter or underscore, which can be followed by further letters, digits, or underscores. ● '$' character is a reserved keyword Legal alphanumeric identifiers: age, salary, _value, __1_value Illegal identifiers: $salary, 123abc, -salary
  • 12. /29 Kotlin Semantic - arrays the index used in an array selection expression must be of integer type - expressions the two operands to logical && must both be bool type, the result is bool type - functions the type of each actual argument in a function call must be compatible with the formal parameter - classes if specified, the parent of a class must be a properly declared class type - interfaces all methods of the interface must be implemented if a class states that it implements the interface
  • 13. /29 Kotlin Semantic (easy stuff) Class names can be used before being defined • We can’t check class names – using a symbol table – or even in one pass • Solution – Pass 1: Gather all class names – Pass 2: Do the checking
  • 14. /29 Kotlin AST – Before: Process an AST node n – Recurse: Process the children of n – After: Finish processing the AST node n
  • 15. /29 Kotlin Example AST rules ● Before processing e, add definition of x to current definitions, overriding any other definition of x ● – Recurse ● – After processing e, remove definition of x and restore old definition of x for (x : Char in “abc”){ ( x ) Expressions…. ( e ) }
  • 16. /29 Kotlin Symbol table operations ● addSymbol(x) push x and associated info, such as x’s type, on the stack ● findSymbol(x) search stack, starting from top, for x. Return first x found or NULL if none found ● removeSymbol() pop the stack ● enterScope() start a new nested scope ● findSymbol(x) finds current x (or null) ● addSymbol(x) add a symbol x to the table ● checkScope(x) true if x defined in current scope ● exitScope() exit current scope
  • 17. /29 Kotlin Recall to symbol tables for resolving fun main(args: Array<String>) { if (args.size == 0) { println("Provide a name") return } println("Hello, ${args[0]}!") //String Interpolation to cut down ceremony. }
  • 18. /29 Kotlin Method declaration ● Method names have complex rules ● A method need not to be defined in the class in which it is used, but in some parent class ● Methods may also be redefined (overridden) (Hard point)
  • 19. /29 Kotlin Type checking Type checking computes via reasoning: If E1 and E2 have certain types, then E3 has a certain type (e1 : Int AND e2: Int) IMPLIES e1 + e2: Int We work with hypotheses and conclusions. So we create type rules. Ex: is add minus
  • 20. /29 Kotlin Type checking Type checking proves facts e: T – Proof is on the structure of the AST – Proof has the shape of the AST – One type rule is used for each AST node • In the type rule used for a node e: – Hypotheses are the proofs of types of e’s subexpressions – Conclusion is the type of e • Types are computed in a bottom-up pass over the AST
  • 21. /29 Kotlin Type environment before type check The type environment gives types to the free identifiers in the current scope • The type environment is passed down the AST from the root towards the leaves • Types are computed up the AST from the leaves towards the root
  • 22. /29 Kotlin Subtyping Consider: if e0 then e1 else e2 • The result can be either e1 or e2 • The type is either e1’s type or of e2’s type • The best we can do is the smallest supertype larger than the type of e1 or e2
  • 23. /29 Kotlin Subtyping lub(X,Y), the Least Upper Bound of X and Y, is Z if – X ⩽ Z AND Y ⩽ Z Z is an upper bound – X ⩽ Z’ AND Y ⩽ Z’ IMPLIES Z ⩽ Z’ Z is least among upper bounds so the least upper bound of two types is their least common ancestor in the inheritance tree
  • 24. /29 Kotlin Subtyping Ex 2: The rule for case expressions takes a lub over all branches Ex 1: if-Then-Else
  • 25. /29 Kotlin Typing methods prelude: A method foo and an object foo can coexist in the same scope • In the type rules, this is reflected by a separate mapping M for method signatures M(C,f) = (T1,. . .Tn,Tn+1) means in class C there is a method f f(x1:T1,. . .,xn:Tn): Tn+1 the last one is type of return st
  • 26. /29 Kotlin Polymorphism (Self type) class Count { val i = 0; fun inc() : Count { i++ return this } }; inc() should return “dynamic type” class Stock extends Count(var name:String) { }; fun main(args: Array<>String){ val a = Stock(“test”) a = (new Stock).inc (); // fail … a.name … };
  • 27. /29 Kotlin Polymorphism (Self type) – So, we must redefine inc for each of the subclasses, with a specialized return type ● Introduce the keyword SELF_TYPE to use for the return value of such functions SELF_TYPE is not a dynamic type – It is a static type – It helps the type checker to keep better track of types – It enables the type checker to accept more correct programs
  • 28. /29 Kotlin Semantic Else one Hard aspect: 1) Lamda expressions as new feature of the language: val positiveNumbers = list.filter {it > 0} Правила редукции типовых и без типовых лямбда исчислений Область видимо-сти. Операционная семантика, виды редукций. Представление термов без использования имён (индексы де Брауна) Безопасность, продвижение, сохранение. Простое типизированное лямбда-исчисление: Типы функций. Отношение типизации. Свойства типизации. Соответствие Карри–Говарда(введения устранения, при совпадении вычисление). Стирание типов и типизируемость
  • 29. /29 Kotlin Code generation Вряд ли я с этим справлюсь

Editor's Notes

  1. Big amount of java programmer. Because it’s well suitable and maintained so JAva platform is very nice ecosystem. Java platform and Java language there is huge gap. So for the java programers 10 лет, за монитором наблюдали за языком. Монитор развивался а язык нет.
  2. Kotlin — современный статически типизированный объектно-ориентированный язык программирования, компилируемый в байт-код Java и в JavaScript. Kotlin полностью совместим с Java и предоставляет дополнительные возможности, упрощающие повседневную работу программиста и повышающие продуктивность. Kotlin сочетает в себе лаконичность, выразительность, производительность и простоту в изучении.
  3. https://github.com/JetBrains/kotlin/tree/master/grammar/src https://confluence.jetbrains.com/display/Kotlin/Expressions
  4. Designing a Type Checker When designing a type checker for a compiler, here’s the process: 1. identify the types that are available in the language 2. identify the language constructs that have types associated with them 3. identify the semantic rules for the language String fake class String.last(): Char this[] Checks of many kinds . . . coolc checks: 1. All identifiers are declared 2. Types 3. Inheritance relationships 4. Classes defined only once 5. Methods in a class defined only once 6. Reserved identifiers are not misused And others . . . • The requirements depend on the language
  5. val people = hashMapOf<String, Int>() for ((person, age) in people) { println("${person} in ${age} years old") }
  6. Скормить байткоду java создание массива и присваиванию ему метода, к примеру, set то все пройдет нормально. Но после запуска там не будет никакой ошибки он просто там сдохнет незаметно и все