wyvern: a simple, typed, and pure object-oriented language
Post on 23-Dec-2016
229 Views
Preview:
TRANSCRIPT
Wyvern: A Simple, Typed, and Pure Object-Oriented Language
Ligia Nistor, Darya Kurilova, Stephanie Balzer, Benjamin Chung, Alex Potanin, and Jonathan Aldrich
Carnegie Mellon University
© Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
1
World Wide Web • Cross-‐Site Scrip-ng (XSS) • Cross-‐Site Request
Forgery (CSRF) • Injec-on A;acks • Insecure Direct Object
References • Broken Authen-ca-on
and Session Management • … (OWASP 2013)
• JavaScript • Ruby on Rails • Java • Flash • PHP • Python • CoffeeScript • …
2 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
World Wide Web
A web and mobile programming language that is
secure by default.
3 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Wyvern • Programming language:
– For mobile and web programming
– Secure by default
4 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Target Characteristics Web programming Security
• Pure object-oriented • Interactive, value-
based • Supporting functional
programming • High-level • Static typing • Simple
5 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Target Characteristics Web programming Security
• Pure object-oriented • Interactive, value-
based • Supporting functional
programming • High-level • Static typing • Simple
6 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Requirements for Pure OO • State encapsulation • Uniform access principle (Meyer) • Interoperability and uniform treatment
(Cook)
7 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Current State What Is There:
• Specialization and generalization of types
• A pure object-oriented model that supports reuse via composition mechanisms
What Is Missing:
• A reuse mechanism, such as inheritance or delegation
• A first-class, typed module system
• Support for abstract type members
8 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Next 1. Wyvern Object Model 2. Translating Classes to Objects 3. Discussion: Reuse Mechanism for Wyvern
9 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Next 1. Wyvern Object Model 2. Translating Classes to Objects 3. Discussion: Reuse Mechanism for Wyvern
10 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Object-Oriented Core of Wyvern 1 type Lot =
11 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Object-Oriented Core of Wyvern 1 type Lot = 2 meth value : Int
12 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Object-Oriented Core of Wyvern 1 type Lot = 2 meth value : Int 3 4 meth purchase(q : Int, p : Int) : Lot = 5 new
13 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Object-Oriented Core of Wyvern 1 type Lot = 2 meth value : Int 3 4 meth purchase(q : Int, p : Int) : Lot = 5 new 6 var quantity : Int = q 7 var price : Int = p
14 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Object-Oriented Core of Wyvern 1 type Lot = 2 meth value : Int 3 4 meth purchase(q : Int, p : Int) : Lot = 5 new 6 var quantity : Int = q 7 var price : Int = p 8 meth value : Int = 9 this.quantity * this.price
15 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Object-Oriented Core of Wyvern 1 type Lot = 2 meth value : Int 3 4 meth purchase(q : Int, p : Int) : Lot = 5 new 6 var quantity : Int = q 7 var price : Int = p 8 meth value : Int = 9 this.quantity * this.price 10 11 val aLot = purchase(100, 100) 12 val value = aLot.value
16 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Object-Oriented Core of Wyvern 1 type Lot = 2 meth value : Int 3 4 meth purchase(q : Int, p : Int) : Lot = 5 new 6 var quantity : Int = q 7 var price : Int = p 8 meth value : Int = 9 this.quantity * this.price 10 11 val aLot = purchase(100, 100) 12 val value = aLot.value
17 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern
• Simple • Support for functional
programming
18 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern
19 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern
20 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern
• State encapsulation • Uniform access principle • High-level • Pure OO
21 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Next 1. Wyvern Object Model 2. Translating Classes to Objects 3. Discussion: Reuse Mechanism for Wyvern
22 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Classes Are Not Essential
Cf. Self and JavaScript
…but they are convenient.
We believe classes should be syntactic sugar on top of a foundational object-oriented core.
23 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern with Classes
24 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern with Classes
25 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern with Classes
26 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Syntax of Object Oriented Core of Wyvern with Classes
27 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating from
28 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating to
29 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option
OO Wyvern with Classes
30 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0
OO Wyvern with Classes
31 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ...
OO Wyvern with Classes
32 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0
OO Wyvern with Classes
33 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new
OO Wyvern with Classes
34 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p
OO Wyvern with Classes
35 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
OO Wyvern with Classes
36 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
OO Wyvern with Classes
37 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
OO Wyvern with Classes
38 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
OO Wyvern OO Wyvern with Classes
39 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int
OO Wyvern OO Wyvern with Classes
40 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option
OO Wyvern OO Wyvern with Classes
41 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option 6 7 var Option : OptionClass = 8 new
OO Wyvern OO Wyvern with Classes
42 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option 6 7 var Option : OptionClass = 8 new 9 var totalQuantityIssued : Int = 0
OO Wyvern OO Wyvern with Classes
43 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option 6 7 var Option : OptionClass = 8 new 9 var totalQuantityIssued : Int = 0 10 meth issue(q : Int, 11 p : Int) : Option = 12 new
OO Wyvern OO Wyvern with Classes
44 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option 6 7 var Option : OptionClass = 8 new 9 var totalQuantityIssued : Int = 0 10 meth issue(q : Int, 11 p : Int) : Option = 12 new 13 var quantity : Int = q 14 var price : Int = p
OO Wyvern OO Wyvern with Classes
45 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option 6 7 var Option : OptionClass = 8 new 9 var totalQuantityIssued : Int = 0 10 meth issue(q : Int, 11 p : Int) : Option = 12 new 13 var quantity : Int = q 14 var price : Int = p 15 meth exercise : Int = ...
OO Wyvern OO Wyvern with Classes
46 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option 6 7 var Option : OptionClass = 8 new 9 var totalQuantityIssued : Int = 0 10 meth issue(q : Int, 11 p : Int) : Option = 12 new 13 var quantity : Int = q 14 var price : Int = p 15 meth exercise : Int = ... 16 17 var optn : Option = Option.issue(100, 50) 18 var ret : Int = optn.exercise
OO Wyvern OO Wyvern with Classes
47 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Translating Classes
1 class Option 2 var quantity : Int = 0 3 var price : Int = 0 4 meth exercise : Int = ... 5 6 class var totalQuantityIssued : Int = 0 7 class meth issue(q : Int, 8 p : Int) : Option = 9 new 10 var quantity : Int = q 11 var price : Int = p 12 13 var optn : Option = Option.issue(100, 50) 14 var ret : Int = optn.exercise
1 type Option = 2 meth exercise : Int 3 4 type OptionClass = 5 meth issue : Int -> Int -> Option 6 7 var Option : OptionClass = 8 new 9 var totalQuantityIssued : Int = 0 10 meth issue(q : Int, 11 p : Int) : Option = 12 new 13 var quantity : Int = q 14 var price : Int = p 15 meth exercise : Int = ... 16 17 var optn : Option = Option.issue(100, 50) 18 var ret : Int = optn.exercise
OO Wyvern OO Wyvern with Classes
48 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Next 1. Wyvern Object Model 2. Translating Classes to Objects 3. Discussion: Reuse Mechanism for Wyvern
49 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Discussion: Reuse Mechanism for Wyvern
Inheritance vs. Delegation
• Inheritance is more suitable for classes, but they are not essential.
• Is delegation more appropriate? • Inheritance implemented via delegation?
50 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
A Delegation Scenario Object A: • has method c() that has a reference to this
Object B: • delegates to object A • doesn’t have method c() • calls method c()
What object should this in method c() refer to? • e.g., in Self, this refers to object B • if refers to object B, open recursion
51 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Auxiliary Slides
52 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Interoperability and Uniform Treatment
1 type Lot = 2 meth value : Int 3 meth compare(other : Lot) : Int
53 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Interoperability and Uniform Treatment
4 meth purchase1(q : Int, 5 p : Int) : Lot = 6 new 7 var quantity : Int = q 8 var price : Int = p 9 meth value : Int = ... 10 meth compare(l : Lot) : Int = 11 this.value – l.value
4 meth purchase2(q : Int, 5 p : Int) : Lot = 6 new 7 var quantity : Int = q + 10 8 var price : Int = p 9 meth value : Int = ... 10 meth compare(l : Lot) : Int = 11 this.value – l.value
1 type Lot = 2 meth value : Int 3 meth compare(other : Lot) : Int
54 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Interoperability and Uniform Treatment
4 meth purchase1(q : Int, 5 p : Int) : Lot = 6 new 7 var quantity : Int = q 8 var price : Int = p 9 meth value : Int = ... 10 meth compare(l : Lot) : Int = 11 this.value – l.value
4 meth purchase2(q : Int, 5 p : Int) : Lot = 6 new 7 var quantity : Int = q + 10 8 var price : Int = p 9 meth value : Int = ... 10 meth compare(l : Lot) : Int = 11 this.value – l.value
1 type Lot = 2 meth value : Int 3 meth compare(other : Lot) : Int
55 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Interoperability and Uniform Treatment
4 meth purchase1(q : Int, 5 p : Int) : Lot = 6 new 7 var quantity : Int = q 8 var price : Int = p 9 meth value : Int = ... 10 meth compare(l : Lot) : Int = 11 this.value – l.value
4 meth purchase2(q : Int, 5 p : Int) : Lot = 6 new 7 var quantity : Int = q + 10 8 var price : Int = p 9 meth value : Int = ... 10 meth compare(l : Lot) : Int = 11 this.value – l.value
1 type Lot = 2 meth value : Int 3 meth compare(other : Lot) : Int
12 val lot1 = purchase1(70, 50) 13 val lot2 = purchase2(40, 80) 14 val diff = lot1.compare(lot2)
56 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Full Syntax of Object Oriented Core of Wyvern
57 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
Full Syntax of Object Oriented Core of Wyvern with Classes
58 © Darya Kurilova 2013
[MASPEGHI‘13, Montpellier, France]
top related