CSE 6305 Programming Languages and Systems Programming languages




![a little js… $ jsc > [] + [] > [] + {} [object a little js… $ jsc > [] + [] > [] + {} [object](https://slidetodoc.com/presentation_image_h2/44228e27c9959e92e0af2389df69431d/image-5.jpg)

![some php… <? php $A = array(); $A[0] = 5; echo "A[0]: $A[0]"; ? some php… <? php $A = array(); $A[0] = 5; echo "A[0]: $A[0]"; ?](https://slidetodoc.com/presentation_image_h2/44228e27c9959e92e0af2389df69431d/image-7.jpg)
![some php… <? php $A = array(); $A[0] = 5; $C = $A; $C[0] some php… <? php $A = array(); $A[0] = 5; $C = $A; $C[0]](https://slidetodoc.com/presentation_image_h2/44228e27c9959e92e0af2389df69431d/image-8.jpg)

![some php… <? php $A = array(); $A[0] = 5; $b = &$A[0]; $C some php… <? php $A = array(); $A[0] = 5; $b = &$A[0]; $C](https://slidetodoc.com/presentation_image_h2/44228e27c9959e92e0af2389df69431d/image-10.jpg)
![some php… <? php $A = array(); $A[0] = 5; $b = &$A[0]; $C some php… <? php $A = array(); $A[0] = 5; $b = &$A[0]; $C](https://slidetodoc.com/presentation_image_h2/44228e27c9959e92e0af2389df69431d/image-11.jpg)












































- Slides: 55
CSE 6305 Programming Languages and Systems
Programming languages suck. 2
wtf? 3
*all of these numbers are pretty meaningless Ja Cl rl oj ur e Pe C Ru by va Vi m L Em PH a P Ob cs. Li je sp ct ive -C va C# Sc rip t Sh el l CS Py S Co th ffe on e. S cr ip Ha t sk el l Go Ja C+ + Lu a Sc al a Comments with "WTF"/repo* 0, 006 0, 005 0, 004 0, 003 0, 002 0, 001 0 Source: Phil Johnson, IT World, 25/9/13 4
a little js… $ jsc > [] + [] > [] + {} [object Object] > {} + [] 0 > {} + {} Na. N Source: Gary Bernhardt Code. Mash 2012 5
a little more js… $ jsc > Array(14) , , , , > Array(14). join("foo") foofoofoofoofoofoofoo > Array(14). join("foo" + 1) foo 1 foo 1 foo 1 foo 1 > Array(14). join("foo" - 1) + "Batman!" Na. NNa. N Batman! Source: Gary Bernhardt Code. Mash 2012 6
some php… <? php $A = array(); $A[0] = 5; echo "A[0]: $A[0]"; ? > A[0]: 5 7
some php… <? php $A = array(); $A[0] = 5; $C = $A; $C[0] = 10; echo "A[0]: $A[0]"; ? > A[0]: 5 8
• In PHP, variables are always assigned by value. • That is to say, when you assign an expression to a variable, the entire value of the original expression is copied into the destination variable. • This means, for instance, that after assigning one variable's value to another, changing one of those variables will have no effect on the other. 9
some php… <? php $A = array(); $A[0] = 5; $b = &$A[0]; $C = $A; $C[0] = 10; echo "A[0]: $A[0]"; ? > A[0]: 10 10
some php… <? php $A = array(); $A[0] = 5; $b = &$A[0]; $C = $A; unset($b); $C[0] = 10; echo "A[0]: $A[0]"; ? > A[0]: 5 11
12
13
POPL’ 09 14
PHP “I don’t know how to stop it, there was never any intent to write a programming language […] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way. ” • Rasmus Lerdorf, creator of PHP 15
some Python… C Python int NUM = 111181111; NUM = 111181111 int is_prime(int n) { def is_prime(n): int i; i = 2 C (GCC, O 0): 0. 624 s for(i = 2; i < n; i++) { while i < n: Python: 15. 609 s if (n % i == 0) { if n % i == 0: return 0; 25 x difference! return False } i += 1 } return 1; return True } 16
some java… List<int> il = new Array. List<int>(); 17
PLDI’ 01 18
Security & Correctness 19
20
21
22
23
24
a double edged sword • rich libraries • built in safety • strong abstractions • less opportunity for programmer errors • but… language itself presents a bigger target 25
Performance 26
spectral-norm* elapsed time/best (log) 1000 10 1 C++ g++ Fortran C gcc *all of these numbers are pretty meaningless Ada Lisp Haskell GHC Java 7 Go C# mono Erlang PHP Ruby jruby Perl Python 27 Source: http: //benchmarksgame. alioth. debian. org
mandelbrot* elapsed time/best (log) 1000 10 1 Fortran C++ g++ C gcc *all of these numbers are pretty meaningless Ada Haskell Java 7 GHC C# mono Go Lisp Erlang PHP Python Ruby Perl 28 Source: http: //benchmarksgame. alioth. debian. org
chameneos-redux* elapsed time/best (log) 1000 10 1 C gcc C++ g++ Lisp *all of these numbers are pretty meaningless Ada Go Java 7 C# mono Haskell GHC Erlang Ruby jruby Python Perl 29 Source: http: //benchmarksgame. alioth. debian. org
Existing Approaches 30
Approach 1: Build VM From Scratch 31
Approach 2: Existing VM Semantic gap Jython JVM Huge dependencies 32
Approach 3: Existing Frameworks LLVM • Excellent for C/C++/Objective. C • Not for managed languages Author 33
What is so difficult? 34
Three Foundamental Concerns Just-in-time Compiling Concurrency Garbage Collection 35
JIT + concurrency + GC 36
Concurrency Atomic ops. Memory model Concurrent GC Parallel GC Yieldpoints GC Barriers Transactional Memory Object map Stack map JIT GC 37
Language Implementations Lang. Impl. Concurrency Execution GC Hot. Spot ✔ Threads ✔ JIT ✔ Generational CPython ✖ GIL ✖ Interpreter ✖ Naïve RC Py. Py ✖ STM (exp. ) ✔ JIT ✔ MMTK-like Jython ✔ JVM Threads ✖ JVM JIT ✔ JVM GC Unladen Swallow ✖ GIL ✖ Template JIT ✖ Naïve RC Ruby ✖ GIL ✖ Interpreter ✖ MS PHP - ✖ Interpreter ✖ Naïve RC HHVM - ✔ JIT ✖ Naïve RC Lua ✖ No Threads ✖ Interpreter ✖ MS Lua. Jit ✖ No Threads ✔ JIT ✖ MS 38
Alan J Perlis 1/4/1922 – 2/7/1990 Turing Award 1966 Compiler construction, ALGOL 39
John Mc. Carthy 4/9/1927 – 24/10/2011 Turing Award 1971 Lisp, garbage collection 40
Edsger Dijkstra 11/5/1930 – 6/8/2002 Turing Award 1972 compilers, garbage collection 41
John Backus 3/12/1924 – 17/3/2007 Turing Award 1977 compilers, FORTRAN, ALGOL, BNF, functional languages 42
Robert Floyd 8/6/1936 – 25/9/2001 Turing Award 1978 parsing, pl semantics, program verification, synthesis 43
Tony Hoare 11/1/1934 – Turing Award 1980 ALOGOL 60, CSP, PL specification, monitors 44
Dennis Ritchie 9/9/41 – 12/10/2011 Turing Award 1983 ALTRAN, B, BCPL, C 45
Niklaus Wirth 15/2/34 – Turing Award 1984 Euler, Algol W, Pascal, Modula-2, Oberon-2 46
John Cocke 30/5/1925 – 16/7/2002 Turing Award 1987 compiler design, optimizing compiler design 47
Robin Milner 13/1/1934 – 20/3/2010 Turing Award 1991 ML, automated theorem proving, pi-calculus 48
Amir Pnueli 22/4/1941 – 2/11/2009 Turing Award 1996 temporal logic, concurrent systems, program verification 49
Ole-Johan Dhal 12/10/1931 – 29/6/2002 Turing Award 2001 Object-oriented programming, Simula 50
Kristen Nygaard 27/8/1926 – 10/8/2002 Turing Award 2001 Object-oriented programming, Simula 51
Alan Kay 17/5/1940 – Turing Award 2003 object-oriented programming, smalltalk 52
Peter Naur 8/6/1936 – 25/9/2001 Turing Award 2005 ALGOL, BNF 53
Fran Allen 4/8/1932 – Turing Award 2006 compilers, optimizing compilers, parallel compilers 54
Barbara Liskov 8/6/1936 – 25/9/2001 Turing Award 2008 CLU, ARGUS, data abstraction, distributed computing 55