Encoding Self ❞❡❢ factorial = x: ✐♥t -> ✐❢ x == 0 t❤❡♥ 1 ❡❧s❡ s❡❧❢ (x-1) * x ✐♥ s❡❧❢ 5 ⇓ ❞❡❢ factorial = x: ✐♥t & ❵s❡❧❢ s❡❧❢ -> ✐❢ x == 0 t❤❡♥ 1 ❡❧s❡ s❡❧❢ (x-1) * x ✐♥ factorial (5 & ❵s❡❧❢ factorial)
❼ ❼ Encoding Objects ❼ Objects are encoded as onions ❝❧❛ss Point { ✐♥t x = 2; ✐♥t y = 3; ✐♥t l1() { r❡t✉r♥ x+y; } }
❼ Encoding Objects ❼ Objects are encoded as onions ❼ Each field is a labeled value ❝❧❛ss Point { ✐♥t x = 2; ❵① 2 & ✐♥t y = 3; ❵② 3 ✐♥t l1() { r❡t✉r♥ x+y; } }
Encoding Objects ❼ Objects are encoded as onions ❼ Each field is a labeled value ❼ Message handler scapes encode methods ❝❧❛ss Point { ✐♥t x = 2; ❵① 2 & ✐♥t y = 3; ❵② 3 & ✐♥t l1() { ( ❵❧✶ ✭✮ -> r❡t✉r♥ x+y; s❡❧❢ . ① + s❡❧❢ . ② ) } }
Encoding Objects ❼ Objects are encoded as onions ❼ Each field is a labeled value ❼ Message handler scapes encode methods ❝❧❛ss Point { ✐♥t x = 2; ❵① 2 & ✐♥t y = 3; ❵② 3 & ✐♥t l1() { ( ❵❧✶ ✭✮ & r❡t✉r♥ x+y; ❵s❡❧❢ s❡❧❢ -> } s❡❧❢ . ① + s❡❧❢ . ② ) }
Encoding Objects ❞❡❢ o = ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ ∼ = o. ① ( ❵① x -> x) o
Encoding Objects ❞❡❢ o = ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ ∼ = o. ❧✶✭✮ o ( ❵❧✶ ✭✮ & ❵s❡❧❢ o )
❼ Encoding Mixins ❼ Inheritance occurs by onion extension ❞❡❢ mypoint = ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ ❞❡❢ mixinFar = ( ❵✐s❋❛r ✭✮ -> s❡❧❢ . ❧✶✭✮ > 26) ✐♥ ❞❡❢ myFpoint = mypoint & mixinFar ✐♥ myFpoint . ✐s❋❛r ✭✮
Encoding Mixins ❼ Inheritance occurs by onion extension ❼ Mixins are the extension onion ❞❡❢ mypoint = ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ ❞❡❢ mixinFar = ( ❵✐s❋❛r ✭✮ -> s❡❧❢ . ❧✶✭✮ > 26) ✐♥ ❞❡❢ myFpoint = mypoint & mixinFar ✐♥ myFpoint . ✐s❋❛r ✭✮
❼ Encoding Classes ❼ Classes are object factories ❞❡❢ Point = ❵♥❡✇ ( ❵① x & ❵② y) -> ❵① x & ❵② y & ( ❵❧✶ ✭✮ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ . . .
Encoding Classes ❼ Classes are object factories ❼ Subclass factories instantiate and extend ❞❡❢ Point = ❵♥❡✇ ( ❵① x & ❵② y) -> ❵① x & ❵② y & ( ❵❧✶ ✭✮ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ ❞❡❢ Point3D = ❵♥❡✇ (a: ❵① _ & ❵② _ & ❵③ z) -> ❞❡❢ super = (Point . ♥❡✇ a) ✐♥ super & ❵③ 0 & ( ❵❧✶ ✭✮ -> super . ❧✶✭✮ ) + s❡❧❢ . ③ ) ✐♥ Point3D ( ❵♥❡✇ ( ❵① 1 & ❵② 2 & ❵③ 3))
❼ ❼ Encoding Overloading ❼ Overloading is trivial with scapes ❞❡❢ join = (( ❵① x: ✐♥t & ❵② y: ✐♥t ) -> x + y) & (( ❵① _: ✉♥✐t & ❵② _: ✉♥✐t ) -> ✭✮ ) ✐♥ join ( ❵① 1 & ❵② 2) & join ( ❵① ✭✮ & ❵② ✭✮ )
❼ Encoding Overloading ❼ Overloading is trivial with scapes ❼ Onion extension allows incremental overloading ❞❡❢ join = (( ❵① x: ✐♥t & ❵② y: ✐♥t ) -> x + y) & (( ❵① _: ✉♥✐t & ❵② _: ✉♥✐t ) -> ✭✮ ) ✐♥ ❞❡❢ x = join ( ❵① 1 & ❵② 2) & join ( ❵① ✭✮ & ❵② ✭✮ ) ✐♥ ❞❡❢ join = join & (( ❵① x: ✐♥t & ❵② _: ✉♥✐t ) -> x + 1) ✐♥ join ( ❵① 5 & ❵② ✭✮ )
Encoding Overloading ❼ Overloading is trivial with scapes ❼ Onion extension allows incremental overloading ❼ Default arguments are easy too ❞❡❢ inc = a: ❵① x -> ❞❡❢ by = ((_ -> 1) & ( ❵② y -> y)) a ✐♥ x + by ✐♥ inc ( ❵① 1 & ❵② 2) + inc ( ❵① 6)
❼ ❼ s❡❧❢ ❼ ❼ Metaprogramming ❼ BigBang uses TinyBang as a core language
❼ s❡❧❢ ❼ ❼ Metaprogramming ❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for syntax/features
❼ ❼ Metaprogramming ❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for syntax/features ❼ s❡❧❢ , class syntax, etc. defined in this way
❼ Metaprogramming ❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for syntax/features ❼ s❡❧❢ , class syntax, etc. defined in this way ❼ User extensions can be specified
Metaprogramming ❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for syntax/features ❼ s❡❧❢ , class syntax, etc. defined in this way ❼ User extensions can be specified ❼ Similar to Racket (Languages as Libraries [Tobin-Hochstadt et al., 2011])
Typing
❼ ❼ ❼ ❼ ❼ ❼ ❼ ✺ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive
❼ ❼ ❼ ❼ ❼ ❼ ✺ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types
❼ ❼ ❼ ❼ ❼ ✺ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs
❼ ❼ ❼ ❼ ❼ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible
❼ ❼ ❼ ❼ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible
❼ ❼ ❼ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible ❼ Sources of type errors must be clear
❼ ❼ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference
❼ ❼ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference ❩ Efficient
❼ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference ❩ Efficient ❼ Short compile times for dev. iterations
❼ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference ❩ Efficient ❼ Short compile times for dev. iterations ✷ Easy to Use
Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference ❩ Efficient ❼ Short compile times for dev. iterations ✷ Easy to Use ❼ Usable to teach introductory courses
Typing BigBang For BigBang, we choose: ✽ ✷ Subtype inference ✽ Call-Site Polymorphism ✽ ✺ Path sensitivity ✺ ✷ Flow insensitivity ✽ ❩ Asymmetric concatenation ❩ Incremental typechecking ✽ Expressive ✺ Comprehensible ❩ Efficient ✷ Easy to Use
❵① ❵② ✭✮ ❼ ❼ ✽ ✷ Subtype Inference ✷ ✽ ❼ No programmer type declarations
❵① ❵② ✭✮ ❼ ✽ ✷ Subtype Inference ✷ ✽ ❼ No programmer type declarations ❼ Supports duck-typing
❵① ❵② ✭✮ ✽ ✷ Subtype Inference ✷ ✽ ❼ No programmer type declarations ❼ Supports duck-typing ❼ Supports nominal typing (labels as names)
✽ ✷ Subtype Inference ✷ ✽ ❼ No programmer type declarations ❼ Supports duck-typing ❼ Supports nominal typing (labels as names) (e.g. ❵① 1 & ❵② 2 & ‘Point ✭✮ )
❼ ❼ ❼ ✽ Call-Site Polymorphism ✽ ❼ All functions polymorphic; no ❧❡t restriction
❼ ❼ ✽ Call-Site Polymorphism ✽ ❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site
❼ ✽ Call-Site Polymorphism ✽ ❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site ❼ Only one contour for each recursive cycle
✽ Call-Site Polymorphism ✽ ❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site ❼ Only one contour for each recursive cycle ❼ A variant of both n CFA and CPA
❵❆ ❵❆ ✭✮ ❵❆ ❵❇ ❵❈ ✽ Call-Site Polymorphism ✽ ❞❡❢ f = x -> ❵❆ x ✐♥ ❞❡❢ x = f 0 ✐♥ ❞❡❢ y = f ✭✮ ✐♥ ❞❡❢ z = f ( ❵❇ 2 & ❵❈ 3) ✐♥ . . .
✽ Call-Site Polymorphism ✽ ❞❡❢ f = x -> ❵❆ x ✐♥ ❞❡❢ x = f 0 ✐♥ ❞❡❢ y = f ✭✮ ✐♥ ❞❡❢ z = f ( ❵❇ 2 & ❵❈ 3) ✐♥ . . . x = ⇒ ❵❆ 0 y = ⇒ ❵❆ ✭✮ z = ⇒ ❵❆ ( ❵❇ 2 & ❵❈ 3)
❼ ❼ ❼ ✽ ✺ Path Sensitivity ✺ ✽ ❼ Scape application based on pattern match
❼ ❼ ✽ ✺ Path Sensitivity ✺ ✽ ❼ Scape application based on pattern match ❼ Constraints expanded only if input matches
❼ ✽ ✺ Path Sensitivity ✺ ✽ ❼ Scape application based on pattern match ❼ Constraints expanded only if input matches ❼ With polymorphism, gives path sensitivity
✽ ✺ Path Sensitivity ✺ ✽ ❼ Scape application based on pattern match ❼ Constraints expanded only if input matches ❼ With polymorphism, gives path sensitivity ❼ Refines Conditional Types [Aiken et al. ’94]
✽ ✺ Path Sensitivity ✺ ✽ ❞❡❢ f = ( ❵❆ x -> x) & ( ❵❇ y -> ✭✮ ) ✐♥ f ❵❆ 3
✽ ✺ Path Sensitivity ✺ ✽ ❞❡❢ f = ( ❵❆ x -> x) & ( ❵❇ y -> ✭✮ ) ✐♥ f ❵❆ 3 : int
❼ ❼ ❼ ❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant
❼ ❼ ❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant ❼ Flow sensitivity:
❼ ❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant ❼ Flow sensitivity: ❼ Makes variable types less clear
❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant ❼ Flow sensitivity: ❼ Makes variable types less clear ❼ Brittle to refactoring
Recommend
More recommend