type environment updated subtype sound
|
|
- Baldric Cooper
- 5 years ago
- Views:
Transcription
1 #1 Type Checkg
2 #2 One-Slide Summary A type environment gives types for free variables. You typecheck a let-body with an environment that has been updated to conta the new let-variable. If an object of type X could be used when one of type Y is acceptable then we say X is a subtype of Y, also written X Y. A type system is sound if E. dynamic_type(e) static_type(e)
3 #3 Lecture Outle Typg Rules Typg Environments Let Rules Subtypg Wrong Rules
4 #4 Example: ` 1 : Int ` : Int ` 2 : Int
5 If we can prove it, then it's true! Soundness A type system is sound if Whenever ` e : T Then e evaluates to a value of type T We only want sound rules But some sound rules are better than others: (i is an teger) ` i : Object #5
6 #6 Type Checkg Proofs Type checkg proves facts e : T One type rule is used for each kd of expression In the type rule used for a node e The hypotheses are the proofs of types of e s subexpressions The conclusion is the proof of type of e itself
7 #7 Rules for Constants ` false : Bool [Bool] ` s : Strg [Strg] (s is a strg constant)
8 #8 Rule for New new T produces an object of type T Ignore SELF_TYPE for now... ` new T : T [New]
9 #9 Two More Rules ` e : Bool ` not e : Bool [Not] ` e 1 : Bool ` e 2 : T ` while e 1 loop e 2 pool : Object [Loop]
10 #10 Typg: Example Typg for while not false loop * 3 pool while loop pool
11 #11 Typg: Example Typg for while not false loop * 3 pool while loop pool not false
12 #12 Typg: Example Typg for while not false loop * 3 pool while loop pool not false : Bool
13 #13 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool
14 #14 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool 1
15 #15 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool 1 : Int
16 #16 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool 1 : Int * 2
17 #17 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool 1 : Int * 2 : Int
18 #18 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool 1 : Int * 2 : Int 3
19 #19 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool 1 : Int * 2 : Int 3 : Int
20 #20 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + false : Bool 1 : Int * : Int 2 : Int 3 : Int
21 #21 Typg: Example Typg for while not false loop * 3 pool while loop pool not : Bool + : Int false : Bool 1 : Int * : Int 2 : Int 3 : Int
22 #22 Typg: Example Typg for while not false loop * 3 pool while loop pool : Object not : Bool + : Int false : Bool 1 : Int * : Int 2 : Int 3 : Int
23 Typg Derivations The typg reasong can be expressed as a tree: ` 2 : Int ` 3 : Int ` false : Bool ` 1 : Int ` 2 * 3 : Int ` not false : Bool ` * 3: Int ` while not false loop * 3 : Object The root of the tree is the whole expression Each node is an stance of a typg rule Leaves are the rules with no hypotheses #23
24 #24 A Problem What is the type of a variable reference? ` x :? [Var] (x is an identifier) The local structural rule does not carry enough formation to give x a type. Fail.
25 #25 A Solution: Put more formation the rules! A type environment gives types for free variables A type environment is a mappg from Object_Identifiers to Types A variable is free an expression if: The expression contas an occurrence of the variable that refers to a declaration outside the expression the expression x, the variable x is free let x : Int x + y only y is free x + let x : Int x + y both x, y are free
26 #26 Type Environments Let O be a function from Object_Identifiers to Types The sentence O ` e : T is read: Under the assumption that variables have the types given by O, it is provable that the expression e has the type T
27 #27 Modified Rules The type environment is added to the earlier rules: O ` i : Int [Int] (i is an teger) O ` e 1 : Int O ` e 2 : Int O ` e 1 + e 2 : Int [Add]
28 #28 New Rules And we can write new rules: O ` x : T [Var] (O(x) = T) Equivalently: O(x) = T O ` x : T [Var]
29 Let e 1 : T 1 O ` let x : T 0 e 1 : T 1 [Let-No-Init] /x] means O modified to map x to T 0 and behavg as O on all other arguments : /x] (x) = T 0 /x] (y) = O(y) (You can write O[x/T 0 ] on tests/assignments.) #29
30 #30 Let Example Consider the Cool expression let x : T 0 (let y : T 1 E x, y ) + (let x : T 2 F x, y ) (where E x, y and F x, y are some Cool expression that conta occurrences of x and y ) Scope of y is E x, y of outer x is E x, y of ner x is F x, y This is captured precisely the typg rule.
31 #31 Example of Typg let AST let x : T 0 + let y : T 1 let x : T 2 E x, y Fx, y x
32 #32 Example of Typg let AST Type env. O ` let x : T 0 + let y : T 1 let x : T 2 E x, y Fx, y x
33 #33 Example of Typg let AST Type env. O ` let x : T 0 + let y : T 1 let x : T 2 E x, y Fx, y x
34 #34 Example of Typg let AST Type env. O ` let x : T 0 + let y : T 1 let x : T 2 E x, y x Fx, y
35 #35 Example of Typg let AST Type env. O ` let x : T 0 + let y : T 1 let x : T 2 ( /x])[t 1 /y] ` E x, y Fx, y x
36 #36 Example of Typg let AST Type env. O ` let x : T 0 + let y : T 1 let x : T 2 ( /x])[t 1 /y] ` E x, y Fx, y ( /x])[t 1 /y] ` x
37 #37 Example of Typg let AST Type env. O ` let x : T 0 + let y : T 1 let x : T 2 ( /x])[t 1 /y] ` E x, y ( /x])[t 2 Fx, y ( /x])[t 1 /y] ` x
38 #38 Example of Typg let AST Type env. Types O ` let x : T 0 + let y : T 1 let x : T 2 ( /x])[t 1 /y] ` E x, y ( /x])[t 2 Fx, y ( /x])[t 1 /y] ` x : T 0
39 #39 Example of Typg let AST Type env. Types O ` let x : T 0 + let y : T 1 let x : T 2 ( /x])[t 1 /y] ` E x, y : t ( /x])[t 2 Fx, y ( /x])[t 1 /y] ` x : T 0
40 #40 Example of Typg let AST Type env. Types O ` let x : T 0 + let y : T 1 : t let x : T 2 ( /x])[t 1 /y] ` E x, y : t ( /x])[t 2 Fx, y ( /x])[t 1 /y] ` x : T 0
41 #41 Example of Typg let AST Type env. Types O ` let x : T 0 + let y : T 1 : t let x : T 2 ( /x])[t 1 /y] ` E x, y : t ( /x])[t 2 Fx, y : t ( /x])[t 1 /y] ` x : T 0
42 #42 Example of Typg let AST Type env. Types O ` let x : T 0 + let y : T 1 : t let x : T 2 : t ( /x])[t 1 /y] ` E x, y : t ( /x])[t 2 Fx, y : t ( /x])[t 1 /y] ` x : T 0
43 #43 Example of Typg let AST Type env. O ` let x : T 0 Types + : t let y : T 1 : t let x : T 2 : t ( /x])[t 1 /y] ` E x, y : t ( /x])[t 2 Fx, y : t ( /x])[t 1 /y] ` x : T 0
44 #44 Example of Typg let AST Type env. O ` let x : T 0 : t Types + : t let y : T 1 : t let x : T 2 : t ( /x])[t 1 /y] ` E x, y : t ( /x])[t 2 Fx, y : t ( /x])[t 1 /y] ` x : T 0
45 #45 Notes The type environment gives types to the free identifiers 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
46 Q: Movies (362 / 842) In this 1992 comedy Dana Carvey and Mike Myers reprise a Saturday Night Live skit, sg Bohemian Rhapsody and say of a guitar: "Oh yes, it will be me."
47 Q: General (455 / 842) This numerical technique for fdg solutions to boundary-value problems was itially developed for use structural analysis the 1940's. The subject is represented by a model consistg of a number of lked simplified representations of discrete regions. It is often used to determe stress and displacement mechanical systems.
48 Q: Movies (377 / 842) Identify the subject or the speaker 2 of the followg 3 Star Wars quotes. "Aren't you a little short to be a stormtrooper?" "I felt a great disturbance the Force... as if millions of voices suddenly cried out terror and were suddenly silenced." "I recognized your foul stench when I was brought on board."
49 #49 Let with Initialization Now consider let with itialization: O ` e 0 : T 0 e 1 : T 1 [Let-Init] O ` let x : T 0 Ã e 0 e 1 : T 1 This rule is weak. Why?
50 #50 Let with Initialization Consider the example: class C herits P { } let x : P Ã new C The previous let rule does not allow this code We say that the rule is too weak or complete
51 Subtypg Defe a relation X Y on classes to say that: An object of type X could be used when one of type Y is acceptable, or equivalently X conforms with Y In Cool this means that X is a subclass of Y Defe a relation on classes X X X Y if X herits from Y X Z if X Y and Y Z #51
52 #52 Let With Initialization (Better) O ` e 0 : T T T 0 e 1 : T 1 [Let-Init] O ` let x : T Ã e e : T Both rules for let are sound But more programs type check with this new rule (it is more complete)
53 #53 Type System Tug-of-War There is a tension between Flexible rules that do not constra programmg Restrictive rules that ensure safety of execution
54 #54 Expressiveness of Static Type Systems A static type system enables a compiler to detect many common programmg errors The cost is that some correct programs are disallowed Some argue for dynamic type checkg stead Others argue for more expressive static type checkg But more expressive type systems are also more complex
55 #55 Dynamic And Static Types The dynamic type of an object is the class C that is used the new C expression that creates the object A run-time notion Even languages that are not statically typed have the notion of dynamic type The static type of an expression is a notation that captures all possible dynamic types the expression could take A compile-time notion
56 #56 Dynamic and Static Types. (Cont.) In early type systems the set of static types correspond directly with the dynamic types Soundness theorem: for all expressions E dynamic_type(e) = static_type(e) ( all executions, E evaluates to values of the type ferred by the compiler) This gets more complicated advanced type systems (e.g., Java, Cool)
57 Dynamic and Static Types COOL x has static type A class A { } class B herits A { } class Ma { A x new A; x new B; } Here, x s value has dynamic type A Here, x s value has dynamic type B A variable of static type A can hold values of static type B, if B A #57
58 #58 Dynamic and Static Types Soundness theorem for the Cool type system: E. dynamic_type(e) static_type(e) Why is this Ok? For E, compiler uses static_type(e) All operations that can be used on an object of type C can also be used on an object of type C C Such as fetchg the value of an attribute Or vokg a method on the object Subclasses can only add attributes or methods Methods can be redefed but with the same types!
59 #59 Subtypg Example Consider the followg Cool class defitions Class A { a() : t { 0 }; } Class B herits A { b() : t { 1 }; } An stance of B has methods a and b An stance of A has method a A type error occurs if we try to voke method b on an stance of A
60 #60 Example of Wrong Let Rule (1) Now consider a hypothetical wrong let rule: O ` e : T T T O ` e : T O ` let x : T Ã e e : T How is it different from the correct rule?
61 #61 Example of Wrong Let Rule (1) Now consider a hypothetical wrong let rule: O ` e : T T T O ` e : T O ` let x : T à e e : T How is it different from the correct rule? The followg good program does not typecheck let x : Int à 0 x + 1 Why?
62 #62 Example of Wrong Let Rule (2) Now consider a hypothetical wrong let rule: O ` e : T T T O[T e : T O ` let x : T Ã e e : T How is it different from the correct rule?
63 #63 Example of Wrong Let Rule (2) Now consider a hypothetical wrong let rule: O ` e : T T T O[T e : T O ` let x : T Ã e e : T How is it different from the correct rule? The followg bad program is well typed let x : B Ã new A x.b() Why is this program bad?
64 #64 Example of Wrong Let Rule (3) Now consider a hypothetical wrong let rule: O ` e : T T T O[T e : T O ` let x : T Ã e e : T How is it different from the correct rule?
65 #65 Example of Wrong Let Rule (3) Now consider a hypothetical wrong let rule: O ` e : T T T O[T e : T O ` let x : T à e e : T How is it different from the correct rule? The followg good program is not well typed let x : A à new B { x à new A; x.a(); } Why is this program not well typed?
66 #66 Typg Rule Notation The typg rules use very concise notation They are very carefully constructed Virtually any change a rule either: Makes the type system unsound (bad programs are accepted as well typed) Or, makes the type system less usable (complete) (good programs are rejected) But some good programs will be rejected anyway The notion of a good program is undecidable
67 #67 Assignment More uses of subtypg: O(id) = T 0 O ` e 1 : T 1 T 1 T 0 [Assign] O ` id à e 1 : T 1
68 Initialized Attributes Let O C (x) = T for all attributes x:t class C O C represents the class-wide scope Attribute itialization is similar to let, except for the scope of names O C (id) = T 0 O C ` e 1 : T 1 T 1 T 0 O C ` id : T 0 Ã e 1 ; [Attr-Init] #68
69 #69 If-Then-Else Consider: if e 0 then e 1 else e 2 fi The result can be either e 1 or e 2 The dynamic type is either e 1 s or e 2 s type The best we can do statically is the smallest supertype larger than the type of e 1 and e 2
70 #70 If-Then-Else example Consider the class hierarchy P A B and the expression if then new A else new B fi Its type should allow for the dynamic type to be both A or B Smallest supertype is P
71 #71 Least Upper Bounds Defe: lub(x,y) to be the least upper bound of X and Y. lub(x,y) is Z if X Z Æ Y Z Z is an upper bound X Z Æ Y Z Z Z Z is least among upper bounds In Cool, the least upper bound of two types is their least common ancestor the heritance tree
72 #72 If-Then-Else Revisited O ` e : Bool 0 O ` e : T 1 1 O ` e : T 2 2 O ` if e then e else e fi : lub(t, T ) [If-Then-Else]
73 #73 Case The rule for case expressions takes a lub over all branches O ` e 0 : T 0 O[T 1 /x 1 ] ` e 1 : T 1 O[T n /x n ] ` e n : T n [Case] O ` case e 0 of x 1 :T 1 ) e 1 ; ; x n : T n ) e n ; esac : lub(t 1,,T n )
74 #74 Next Time Type checkg method dispatch Type checkg with SELF_TYPE COOL
75 #75 Homework Today: WA3 due Get started on PA4 Checkpot due Oct 14 Before Next Class: Read Chapter 7.2
Scoping rules match identifier uses with identifier definitions. A type is a set of values coupled with a set of operations on those values.
#1 Type Checking Previously, in PL Scoping rules match identifier uses with identifier definitions. A type is a set of values coupled with a set of operations on those values. A type system specifies which
More informationPassing Out Review Forms
Type Checking #1 Passing Out Review Forms #2 One-Slide Summary A type environment gives types for free variables. You typecheck a let-body with an environment that has been updated to contain the new let-variable.
More informationtype environment updated subtype sound
Type Checking #1 One-Slide Summary A type environment gives types for free variables. You typecheck a let-body with an environment that has been updated to contain the new let-variable. If an object of
More informationMore Static Semantics. Static. One-Slide Summary. Lecture Outline. Typing Rules. Dispatch Rules SELF_TYPE
More Static Semantics #1 One-Slide Summary Typing rules formalize the semantics checks necessary to validate a program. Well-typed programs do not go wrong. Subtyping relations ( ) and least-upper-bounds
More informationMore Static Semantics
#1 More Static Semantics #2 One-Slide Summary Typing rules formalize the semantics checks necessary to validate a program. Well-typed programs do not go wrong. Subtyping relations ( ) and least-upper-bounds
More informationMore Static Semantics
#1 More Static Semantics #2 One-Slide Summary Typing rules formalize the semantics checks necessary to validate a program. Well-typed programs do not go wrong. Subtyping relations ( ) and least-upper-bounds
More informationLecture Outline. Type systems and their expressiveness. Type Checking in COOL (II) Type checking with SELF_TYPE in COOL
Lecture Outline Type systems and their expressiveness Type Checking in COOL (II) Lecture 10 Type checking with SELF_TYPE in COOL Error recovery in semantic analysis Prof. Aiken CS 143 Lecture 10 1 Prof.
More informationOverview of Semantic Analysis. Lecture 9
Overview of Semantic Analysis Lecture 9 1 Midterm Thursday In class SCPD students come to campus for the exam Material through lecture 8 Open note Laptops OK, but no internet or computation 2 Outline The
More informationType Checking in COOL (II) Lecture 10
Type Checking in COOL (II) Lecture 10 1 Lecture Outline Type systems and their expressiveness Type checking with SELF_TYPE in COOL Error recovery in semantic analysis 2 Expressiveness of Static Type Systems
More informationLecture Outline. Type systems and their expressiveness. Type Checking in COOL (II) Type checking with SELF_TYPE in COOL
Lecture Outline Type systems and their expressiveness Type Checking in COOL (II) Type checking with SELF_TYPE in COOL Error recovery in semantic analysis Adapted from Lectures by Profs. Alex Aiken and
More informationType Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.
Outline Type Checking General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time
More informationOutline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference
Type Checking Outline General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time
More informationTypes. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus
Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type
More informationOperational Semantics. One-Slide Summary. Lecture Outline
Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:
More informationOperational Semantics of Cool
Operational Semantics of Cool Key Concepts semantics: the meaning of a program, what does program do? how the code is executed? operational semantics: high level code generation steps of calculating values
More informationLecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.
Lecture Outline Operational Semantics of Cool COOL operational semantics Motivation Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Notation The rules CS781(Prasad) L24CG 1 CS781(Prasad)
More informationLecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far
Lecture Outline Operational Semantics of Cool Lecture 13 COOL operational semantics Motivation Notation The rules Prof. Aiken CS 143 Lecture 13 1 Prof. Aiken CS 143 Lecture 13 2 Motivation We must specify
More informationSemantic Analysis. Lecture 9. February 7, 2018
Semantic Analysis Lecture 9 February 7, 2018 Midterm 1 Compiler Stages 12 / 14 COOL Programming 10 / 12 Regular Languages 26 / 30 Context-free Languages 17 / 21 Parsing 20 / 23 Extra Credit 4 / 6 Average
More informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly
More informationOperational Semantics
Operational Semantics #1 One-Slide Summary Operational semantics is a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:
More informationSubtyping: An introduction
Subtypg: An troduction Brigitte Pientka November 26, 2007 We will briefly describe the basics about subtypg. Up to now, we have shown how to enrich a language by addg new language constructs together with
More informationCSci 4223 Principles of Programming Languages
Review CSci 4223 Prciples of Programmg Languages Lecture 8 Features learned: functions, tuples, lists, let expressions, options, records, datatypes, case expressions, type synonyms, pattern matchg, exceptions
More informationContextual Analysis (2) Limitations of CFGs (3)
G53CMP: Lecture 5 Contextual Analysis: Scope I Henrik Nilsson University of Nottgham, UK This Lecture Limitations of context-free languages: Why checkg contextual constrats is different from checkg syntactical
More informationSupplementary Notes on Concurrent ML
Supplementary Notes on Concurrent ML 15-312: Foundations of Programmg Languages Frank Pfenng Lecture 25 November 21, 2002 In the last lecture we discussed the π-calculus, a mimal language with synchronous
More informationGrade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline
Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken
More informationType checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39
Type checking Jianguo Lu November 27, 2014 slides adapted from Sean Treichler and Alex Aiken s Jianguo Lu November 27, 2014 1 / 39 Outline 1 Language translation 2 Type checking 3 optimization Jianguo
More informationFunctional Programming. Introduction To Cool
Functional Programming Introduction To Cool #1 Cunning Plan ML Functional Programming Fold Sorting Cool Overview Syntax Objects Methods Types #2 This is my final day... as your... companion... through
More informationAnnouncements. Written Assignment 2 Due Monday at 5:00PM. Midterm next Wednesday in class, 11:00 1:00. Midterm review session next Monday in class.
Type-Checking II Announcements Written Assignment 2 Due Monday at 5:00PM. Office hours today, Sunday, and Monday. Ask questions on Piazzza! Email the staff list with questions! Midterm next Wednesday in
More informationCunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language
Functional Programming Introduction to COOL #1 Cunning Plan Functional Programming Types Pattern Matching Higher-Order Functions Classroom Object-Oriented Language Methods Attributes Inheritance Method
More informationFrom IMP to Java. Andreas Lochbihler. parts based on work by Gerwin Klein and Tobias Nipkow ETH Zurich
From IMP to Java Andreas Lochbihler ETH Zurich parts based on work by Gerwin Klein and Tobias Nipkow 2015-07-14 1 Subtyping 2 Objects and Inheritance 3 Multithreading 1 Subtyping 2 Objects and Inheritance
More informationMidterm II CS164, Spring 2006
Midterm II CS164, Spring 2006 April 11, 2006 Please read all instructions (including these) carefully. Write your name, login, SID, and circle the section time. There are 10 pages in this exam and 4 questions,
More informationObject-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007
Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007 (These notes are very rough, and differ somewhat from what I presented in class; I am posting them here to supplemental
More information(How Not To Do) Global Optimizations
(How Not To Do) Global Optimizations #1 One-Slide Summary A global optimization changes an entire method (consisting of multiple basic blocks). We must be conservative and only apply global optimizations
More informationCSCE 314 Programming Languages. Type System
CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be
More informationCSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a
More informationCS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 23 Advanced Concepts in Object-Oriented Programming Dan Grossman Spring 2011 So far... The difference between OOP and records of functions with shared private state
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language
More informationCoolAid: The Cool Reference Manual
CoolAid: The Cool Reference Manual 1 Introduction This manual describes the programming language Cool: the Classroom Object-Oriented Language. Cool is a small language that can be implemented with reasonable
More informationImplementing a VSOP Compiler. March 20, 2018
Implementing a VSOP Compiler Cyril SOLDANI, Pr. Pierre GEURTS March 20, 2018 Part III Semantic Analysis 1 Introduction In this assignment, you will do the semantic analysis of VSOP programs, according
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and
More informationCS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e
More informationCMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics
Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End
More informationType Systems. Pierce Ch. 3, 8, 11, 15 CSE
Type Systems Pierce Ch. 3, 8, 11, 15 CSE 6341 1 A Simple Language ::= true false if then else 0 succ pred iszero Simple untyped expressions Natural numbers encoded as succ succ
More informationFall Lecture 3 September 4. Stephen Brookes
15-150 Fall 2018 Lecture 3 September 4 Stephen Brookes Today A brief remark about equality types Using patterns Specifying what a function does equality in ML e1 = e2 Only for expressions whose type is
More informationThe Cool Reference Manual
The Cool Reference Manual Contents 1 Introduction 3 2 Getting Started 3 3 Classes 4 3.1 Features.............................................. 4 3.2 Inheritance............................................
More informationAbout coding style Spring February 9, 2004
About codg style 15-212 Sprg 2004 February 9, 2004 Contents 1 Correctness 2 2 Specification 2 3 Style 2 3.1 if-then- Expressions... 3 3.1.1 Boolean if-then- Expressions... 3 3.1.2 if-then- stead of Pattern
More informationComputer Science 312 Fall Prelim 2 SOLUTIONS April 18, 2006
Computer Science 312 Fall 2006 Prelim 2 SOLUTIONS April 18, 2006 1 2 3 4 5 6 7 8 Total Grade /xx /xx /xx /xx /xx /xx /xx /xx /100 Grader 1 1. (xx pots) A. The bary representation of a natural number is
More informationGlobal Optimization. Lecture Outline. Global flow analysis. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization
Lecture Outline Global Optimization Global flow analysis Global constant propagation Liveness analysis Compiler Design I (2011) 2 Local Optimization Recall the simple basic-block optimizations Constant
More informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationSemantic Analysis Type Checking
Semantic Analysis Type Checking Maryam Siahbani CMPT 379 * Slides are modified version of Schwarz s compiler course at Stanford 4/8/2016 1 Type Checking Type errors arise when operations are performed
More informationType Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413
Type Inference Systems CS412/CS413 Introduction to Compilers Tim Teitelbaum Type inference systems define types for all legal programs in a language Type inference systems are to type-checking: As regular
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationCIS 341 Final Examination 4 May 2017
CIS 341 Final Examination 4 May 2017 1 /14 2 /15 3 /12 4 /14 5 /34 6 /21 7 /10 Total /120 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 14 pages
More informationVersion 4, 12 October 2004 Project handed out on 12 October. Complete Java implementation due on 2 November.
CS 351 Programmg Paradigms, Fall 2004 1 Project 2: gnuplot Version 4, 12 October 2004 Project handed out on 12 October. Compe Java implementation due on 2 November. 2.1 The task Implement a utility for
More informationCS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 23 Types for OOP; Static Overloading and Multimethods Dan Grossman 2012 So far... Last lecture (among other things): The difference between OOP and records
More informationBNDN F2013: Software Development in Large Teams with International Collaboration C# Quiz
1 IT University of Copenhagen Outle 1 2.sln) 3 4 5 6 7 Type Inference 8 Extensions 9 Anonymous Objects 2 IT University of Copenhagen Why a Have a little fun with C# Be a little prepared for F# later this
More informationProgramming Languages
CSE 130 : Fall 2008 Programmg Languages Lecture 4: Variables, Environments, Scope News PA 1 due Frida 5pm PA 2 out esterda (due net Fi) Fri) Ranjit Jhala UC San Diego Variables and Bdgs Q: How to use variables
More informationSimply-Typed Lambda Calculus
#1 Simply-Typed Lambda Calculus #2 Back to School What is operational semantics? When would you use contextual (small-step) semantics? What is denotational semantics? What is axiomatic semantics? What
More informationLocal Optimizations #1
#1 Local Optimizations #2 One-Slide Summary An optimization changes a program so that it computes the same answer in less time (or using less of some other resource). We represent the program using a special
More informationTradeoffs. CSE 505: Programming Languages. Lecture 15 Subtyping. Where shall we add useful completeness? Where shall we add completeness?
Tradeoffs CSE 505: Programming Languages Lecture 15 Subtyping Zach Tatlock Autumn 2017 Desirable type system properties (desiderata): soundness - exclude all programs that get stuck completeness - include
More information7. Introduction to Denotational Semantics. Oscar Nierstrasz
7. Introduction to Denotational Semantics Oscar Nierstrasz Roadmap > Syntax and Semantics > Semantics of Expressions > Semantics of Assignment > Other Issues References > D. A. Schmidt, Denotational Semantics,
More informationRecursive Types and Subtyping
Recursive Types and Subtyping #1 One-Slide Summary Recursive types (e.g., list) make the typed lambda calculus as powerful as the untyped lambda calculus. If is a subtype of then any expression of type
More informationScoping and Type Checking
#1 Scoping and Type Checking #2 #3 Recall: Review Sets Exist Ask me to look at your answers! Derivations and parse trees are closely related, but if we ask you to draw a parse tree you must draw the parse
More informationOperational Semantics of Cool
Operational Semantics of Cool Lecture 22 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 3 due on Friday Project 4 assigned on Friday. Due June 5, 11:55pm Office Hours this week are Wed at 4pm and
More informationCompilers. Cool Semantics II. Alex Aiken
Compilers Informal semantics of new T Allocate locations to hold all attributes of an object of class T Essentially, allocate a new object Set attributes with their default values Evaluate the initializers
More informationTypical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated
Typical workflow concrete synta (string) "(fn => + ) 4" Parsing CSE341: Programming Languages abstract synta (tree) Lecture 17 Implementing Languages Including Closures Function Constant + 4 Var Var Type
More informationSeparate Compilation. Comparison. Single Source File Programs Programs where all the code is contained within 1 file.
Separate 1 Comparison 2 Table of Contents Sgle Source File Programs Programs where all code is contaed with 1 file. Comparison Large s results problems. Files Module Structure Security Issues Global Concerns
More informationImplementing objects as in Javascript, Lua, 164 is expensive because object attributes are implemented as hashtable accesses:
Lectures Page 1 L18 Monday, November 23, 2009 10:22 PM Implementing objects as in Javascript, Lua, 164 is expensive because object attributes are implemented as hashtable accesses: x = { f=1 } x.f -->
More informationFormal Semantics of Programming Languages
Formal Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html Benefits of formal
More information6. Asymptotics: The Big-O and Other Notations
Chapter 7 SEARCHING 1. Introduction, Notation 2. Sequential Search 3. Binary Search 4. Comparison Trees 5. Lower Bounds 6. Asymptotics: The Big-O and Other Notations Outline Transp. 1, Chapter 7, Searching
More informationSubsumption. Principle of safe substitution
Recap on Subtyping Subsumption Some types are better than others, in the sense that a value of one can always safely be used where a value of the other is expected. Which can be formalized as by introducing:
More informationTail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)
CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)
More informationIntroduction to Axiomatic Semantics (1/2)
#1 Introduction to Axiomatic Semantics (1/2) How s The Homework Going? Remember that you can t just define a meaning function in terms of itself you must use some fixed point machinery. #2 #3 Observations
More informationFormal Semantics of Programming Languages
Formal Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html Benefits of formal
More informationAn Introduction to Subtyping
An Introduction to Subtyping Type systems are to me the most interesting aspect of modern programming languages. Subtyping is an important notion that is helpful for describing and reasoning about type
More informationOutline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context
Types 1 / 15 Outline Introduction Concepts and terminology The case for static typing Implementing a static type system Basic typing relations Adding context 2 / 15 Types and type errors Type: a set of
More informationOperational Semantics of Cool
Operational Semantics of Cool Lecture 23 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 3 due on Friday Project 4 assigned on Friday. Due June 5, 11:55pm Office Hours this week Fri at 11am No Class
More informationCSEP505 Programming Languages, Autumn 2016, Final Exam December, Programming Languages for a World of Change
CSEP505 Programming Languages, Autumn 2016, Final Exam December, 2016 Programming Languages for a World of Change Rules: See http://courses.cs.washington.edu/courses/csep505/16au/exam_info.html. This is
More informationFunctions. Lecture 6 COP 3014 Spring February 11, 2018
Functions Lecture 6 COP 3014 Spring 2018 February 11, 2018 Functions A function is a reusable portion of a program, sometimes called a procedure or subroutine. Like a mini-program (or subprogram) in its
More information7.3.3 A Language With Nested Procedure Declarations
7.3. ACCESS TO NONLOCAL DATA ON THE STACK 443 7.3.3 A Language With Nested Procedure Declarations The C family of languages, and many other familiar languages do not support nested procedures, so we troduce
More informationSecond-Order Type Systems
#1 Second-Order Type Systems Homework 5 Summary Student : 37.9704 Student : 44.4466 ORIGINAL : 50.2442 Student : 50.8275 Student : 50.8633 Student : 50.9181 Student : 52.1347 Student : 52.1633 Student
More informationThe Compiler So Far. Lexical analysis Detects inputs with illegal tokens. Overview of Semantic Analysis
The Compiler So Far Overview of Semantic Analysis Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Lexical analysis Detects inputs with illegal tokens Parsing Detects inputs with ill-formed
More informationIntroduction to Axiomatic Semantics (1/2)
#1 Introduction to Axiomatic Semantics (1/2) How s The Homework Going? Remember: just do the counterexample guided abstraction refinement part of DPLL(T). If you notice any other errors, those are good
More informationConcurrency Problem. Thread Synchronization: Too Much Milk. The Fundamental Issue. Critical Sections. Order of thread execution is non-deterministic
Concurrency Problem Synchronization: oo Much Milk Order of thread execution is non-determistic Multiprocessg v A system may conta multiple processors Ë cooperatg threads/processes can execute simultaneously
More informationReview. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals
Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:
More informationRecursive Types and Subtyping
Recursive Types and Subtyping #1 One-Slide Summary Recall: Recursive types (e.g., τ list) make the typed lambda calculus as powerful as the untyped lambda calculus. If τ is a subtype of σ then any expression
More informationCOMP520 - GoLite Type Checking Specification
COMP520 - GoLite Type Checking Specification Vincent Foley April 8, 2018 1 Introduction This document presents the typing rules for all the language constructs (i.e. declarations, statements, expressions)
More informationPrograms as data first-order functional language type checking
Programs as data first-order functional language type checking Copyright 2013-18, Peter Sestoft and Cesare Tinelli. Created by Cesare Tinelli at the University of Iowa from notes originally developed by
More informationWritten Assignment 5 Due??
Written Assignment 5 Due?? This assignment asks you to prepare written answers to questions on type checking. Each of the questions has a short answer. You may discuss this assignment with other students
More informationAnnouncements. Working on requirements this week Work on design, implementation. Types. Lecture 17 CS 169. Outline. Java Types
Announcements Types Working on requirements this week Work on design, implementation Lecture 17 CS 169 Prof. Brewer CS 169 Lecture 16 1 Prof. Brewer CS 169 Lecture 16 2 Outline Type concepts Where do types
More informationPierce Ch. 3, 8, 11, 15. Type Systems
Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using
More informationFeatherweight Java (FJ)
x = 1 let x = 1 in... x(1).!x(1) x.set(1) Programming Language Theory Featherweight Java (FJ) Ralf Lämmel This lecture is based on David Walker s lecture: Computer Science 441, Programming Languages, Princeton
More informationCSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures
CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught
More informationMetaprogramming assignment 3
Metaprogramming assignment 3 Optimising embedded languages Due at noon on Thursday 29th November 2018 This exercise uses the BER MetaOCaml compiler, which you can install via opam. The end of this document
More informationA Crash Course on Standard ML
A Crash Course on Standard ML Hongwei Xi Version of November 23, 2004 1 Start Type sml-cm at a Unix wdow to get an teractive terpreter for Standard ML (SML). You can later quit the terpreter by typg ctrl-d.
More informationThe Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.
The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees
More informationLecture 15 CIS 341: COMPILERS
Lecture 15 CIS 341: COMPILERS Announcements HW4: OAT v. 1.0 Parsing & basic code generation Due: March 28 th No lecture on Thursday, March 22 Dr. Z will be away Zdancewic CIS 341: Compilers 2 Adding Integers
More informationThe Phases of a Compiler. Course Overview. In Chapter 4. Syntax Analysis. Syntax Analysis. Multi Pass Compiler. PART I: overview material
Course Overview The Phases of a Compiler PART I: overview material Introduction 2 Language processors (tombstone diagrams, bootstrappg) 3 Architecture of a compiler PART II: side a compiler 4 Sntax analsis
More informationAnnouncements. Written Assignment 2 due today at 5:00PM. Programming Project 2 due Friday at 11:59PM. Please contact us with questions!
Type-Checking Announcements Written Assignment 2 due today at 5:00PM. Programming Project 2 due Friday at 11:59PM. Please contact us with questions! Stop by office hours! Email the staff list! Ask on Piazza!
More information