digibury: edd barrett - a case study in cross-language tracing
DESCRIPTION
A talk exploring the challenges of programming language composition and how the team at King's College London propose to overcome them.TRANSCRIPT
Language CompositionA Case Study in Cross-Language Tracing
Edd Barrett CarlFriedrich
Bolz
LaurenceTratt
NaveneethaKrishnan
Vasudevan
LukasDiekmann
Software Development Team2013-11-13
1 / 25 http://soft-dev.org/
That is, until...
// A load of Android Java code...
// find pairs where i + j < 10Arraylist<int> result = new ArrayList();
for (int i : ints1) {for (int j : ints2) {
if (i + j < 10) {ArrayList<int> n = new ArrayList();n.add(i);n.add(j);result.add(n);
}}
}// More Android Java code...
3 / 25 http://soft-dev.org/
That is, until...
// A load of Android Java code...
# find pairs where i + j < 10 in *Python*result = [
(i, j) for i in ints1 for j in ints2if i + j < 10
]
// More Android Java code...
3 / 25 http://soft-dev.org/
Or until...
# Some Python code...if first == 1:
if second == 1:return 999
elif second == 2:return 666
else:raise TrollException("naughty")
elif first == 2:if second == 1:
return 1337elif second == 2:
return 42else:
raise TrollException("naughty")else:
raise TrollException("naughty")# More Python code...
4 / 25 http://soft-dev.org/
Or until...
# Some Python code...
(* Much easier to use pattern matching from functionalworld, e.g. Ocaml *)
match (first, second) with| (1, 1) -> 999| (1, 2) -> 666| (2, 1) -> 1337| (2, 2) -> 42| _ -> raise (TrollException "naughty");;
# More Python code...
4 / 25 http://soft-dev.org/
So what is my point?
THE POINT:
5 / 25 http://soft-dev.org/
So what is my point?
THE POINT:
PL Wars!
5 / 25 http://soft-dev.org/
So what is my point?
THE POINT:
PL Wars!
5 / 25 http://soft-dev.org/
So what is my point?
THE POINT:
It would be sweet to composeprogramming languages.
5 / 25 http://soft-dev.org/
Language Composition
PL X
PL Y
PL Z
6 / 25 http://soft-dev.org/
Not a New Idea
Existing composition methods:
Poor syntactic integration.Stringly-typed.
Languages not born equal.One language hosts the other.
Poor performanceNo cross-language optimisations.
Too much engineering effort.
7 / 25 http://soft-dev.org/
What do we want from a languagecomposition?
8 / 25 http://soft-dev.org/
What do we want from a language composition?
High performance
PL
>>>
9 / 25 http://soft-dev.org/
What do we want from a language composition?
Good syntactic integration
pl x
pl ypl z
9 / 25 http://soft-dev.org/
What do we want from a language composition?
Little effort
<
9 / 25 http://soft-dev.org/
Breaking Down the Problem
PL X
PL Y
PL Z
11 / 25 http://soft-dev.org/
Breaking Down the Problem
PL X
PL Y
PL Z
syntax
runtime
syntax
runtime
syntax
runtime
11 / 25 http://soft-dev.org/
Challenges: Syntactic Composition
12 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
13 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL X<program>
for (j : js) { doStuff();}...
13 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL X<program>
for (j : js) { doStuff();}...
Parsing
13 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL X<program>
for (j : js) { doStuff();}...
Parsing
Parse Tree
13 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
14 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL Y<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
14 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL Y<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL Z<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
14 / 25 http://soft-dev.org/
Parsing
PL X<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL Y<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
PL Z<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
AMBIGUOUS
14 / 25 http://soft-dev.org/
Parsing
PL Z<program>
for (j : js) { doStuff();}...
Parsing
PL Z<grammar>
expr::= ...term::= ... | ... | ...func ::= ...
AMBIGUOUS ?14 / 25 http://soft-dev.org/
Challenges: Runtime Composition
15 / 25 http://soft-dev.org/
Challenges: Runtime Composition
PL X PL Y
C/C++
Interpreter Interpreter
16 / 25 http://soft-dev.org/
Challenges: Runtime Composition
PL X PL Y
C/C++
Interpreter Interpreter
Too slow
16 / 25 http://soft-dev.org/
Challenges: Runtime Composition
PL X PL Y
C/C++
Interpreter Interpreter
JIT Compiler JIT Compiler
16 / 25 http://soft-dev.org/
Challenges: Runtime Composition
PL X PL Y
C/C++
Interpreter Interpreter
Too much
engineering
JIT Compiler JIT Compiler
16 / 25 http://soft-dev.org/
Challenges: Runtime Composition
PL X PL Y
JVM/CLR
Interpreter Interpreter
JIT Compiler
16 / 25 http://soft-dev.org/
Challenges: Runtime Composition
PL X PL Y
JVM/CLR
Interpreter
JIT Compiler
Interpreter
Poor performance
for dynamic languages
16 / 25 http://soft-dev.org/
Proposed solution
Meta-tracing + Language Boxes
18 / 25 http://soft-dev.org/
Meta-tracing
Meta
-tra
cing
PLInterpreter
Tracing JIT
PLInterpreter
20 / 25 http://soft-dev.org/
Meta-tracing
RPyth
on
Interpreter
Tracing JIT
PL YPL X
Interpreters
Glue
PL Z
Meta
-tra
cing
20 / 25 http://soft-dev.org/
Meta-tracing
Meta
-tra
cing
Interpreter
Tracing JIT
PL YPL X
Interpreters
Glue
PL ZGood performance
20 / 25 http://soft-dev.org/
Meta-tracing
Meta
-tra
cing
Interpreter
Tracing JIT
PL YPL X
Interpreters
Glue
PL ZGood performance
Little effort
20 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
22 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
for (string s :
Begin writing Java code
22 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
for (string s :
Open SQL language box
22 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
for (string s :
Write SQL code
SELECT * FROM tbl WHERE
22 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
for (string s :
Java code
SELECT * FROM tbl WHEREname = this.name;) {
22 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
for (string s :
Java code
SELECT * FROM tbl WHEREname = this.name;) {
Good Syntactic Integration
22 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
for (string s :
Java code
SELECT * FROM tbl WHEREname = this.name;) {
Good Syntactic Integration
Avoids Ambiguity
22 / 25 http://soft-dev.org/
Language Boxes Editor
Suppose we want to write a Java + SQL program.
for (string s :
Java code
SELECT * FROM tbl WHEREname = this.name;) {
Good Syntactic Integration
Avoids Ambiguity
Needs Custom Editor
22 / 25 http://soft-dev.org/
Unipycation
RPyth
on
Unip
yca
tion
Interpreter
Tracing JIT
PrologPython
Interpreters
Glue
+ our language box editor (eco)
24 / 25 http://soft-dev.org/
Thanks
for (string s :
Java code
SELECT * FROM tbl WHEREname = this.name;) {
RPyth
on
Unip
yca
tion
Interpreter
Tracing JIT
PrologPython
Interpreters
Glue
http://soft-dev.org
25 / 25 http://soft-dev.org/