Parameterization. Abstracts usually carry parameters. Parameters = dummy identifiers. Replaced by values when abstract invoked. Formal parameters and.

Slides:



Advertisements
Similar presentations
Chapter 5: Abstraction, parameterization, and qualification Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall
Advertisements

CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
1 Compiler Construction Intermediate Code Generation.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
PZ09B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09B - Parameter transmission Programming Language Design.
Slide 1 Vitaly Shmatikov CS 345 Functions. slide 2 Reading Assignment uMitchell, Chapter 7 uC Reference Manual, Chapters 4 and 9.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Subprogram Control - Data sharing Mechanisms to exchange data Arguments - data objects sent to a subprogram to be processed. Obtained through  parameters.
1 CHAPTER 9 SUBPROGRAM. 2 SUBPROGRAM Topics: b Definitions of subprogram b general subprogram characteristics b parameters b Functions and procedures.
Lecture 16 Subroutine Calls and Parameter Passing Semantics Dragon: Sec. 7.5 Fischer: Sec Procedure declaration procedure p( a, b : integer, f :
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
Remote Procedure Call in SR Programming Language By Tze-Kin Tsang 3/20/2000.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
ISBN Chapter 6 Data Types: Structured types.
ISBN Chapter 9 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Introduction Two fundamental abstraction facilities.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
Compound Data Structures Structural decomposition into other values. Lists: domain A* –Constructors: NIL, CONS. –Selectors: HEAD, TAIL. Tuples: domain.
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Imperative Programming
Semantic Analysis Legality checks –Check that program obey all rules of the language that are not described by a context-free grammar Disambiguation –Name.
Values, variables and types © Allan C. Milne v
CS 2104 Prog. Lang. Concepts Subprograms
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
Compiler Construction
Class Example - Rationals Rational numbers are represented by the ratio of two integers, a numerator and a denominator, e.g., 2/3. This is opposed to irrational.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
BİL 744 Derleyici Gerçekleştirimi (Compiler Design)1 Run-Time Environments How do we allocate the space for the generated target code and the data object.
PZ06C Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06C - Polymorphism Programming Language Design and.
Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
SE424 Languages with Context A Block Structured Language.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Slide 1 Dr. Mohammad El-Ramly Fall 2010 Set 7- II - Functions Slides by Vitaly Shmatikov Cairo University Faculty of Computers and Information CS317 Concepts.
Imperative Languages Section 5 Continued.... A Dynamically Typed Language Variable may take on values from different data types. Run­time type checking.
CSC 8505 Compiler Construction Runtime Environments.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
ISBN Chapter 9 Subprograms. Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley.
7. Runtime Environments Zhang Zhizheng
Parameter Passing Mechanisms CS308 Compiler Theory.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
Procedures and Functions Procedures and Functions – subprograms – are named fragments of program they can be called from numerous places  within a main.
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
1 CSC 533: Programming Languages Spring 2014 Subprogram implementation  subprograms (procedures/functions/subroutines)  subprogram linkage  parameter.
Procedure Activations Programming Language. Exploration Name ocurrenceDeclarationLocationValue scopeactivationstate a.From names to their declarations.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Context-Sensitive Analysis
ML: a quasi-functional language with strong typing
Language Design Principles
Organization of Programming Languages
PZ06C - Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3 PZ06C.
Mini Language Interpreter Programming Languages (CS 550)
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Subprograms and Programmer Defined Data Type
FP Foundations, Scheme In Text: Chapter 14.
UNIT V Run Time Environments.
CS 432: Compiler Construction Lecture 11
Chapter 9 Subprograms Fundamentals of Subprograms
Presentation transcript:

Parameterization

Abstracts usually carry parameters. Parameters = dummy identifiers. Replaced by values when abstract invoked. Formal parameters and actual parameters. Formal parameter [[I]] used in positions of B­constructs. Actual parameter bound to [[I]] must be from syntax domain B. Expression parameters, command parameters, type parameters,... Formal parameter to an abstract may be from any syntax domain.

Denotation of Parameters Abstract with body [[V]] and parameters [[I 1 ]]...[[I n ]] has denotation of form ( p 1... p n.V[[V]]...) D ::=... | proc I 1 (I 2 ) = C C ::= C 1 ; C 2 |... | I(E) Proc = Param  Store  Poststore 

D[[proc I 1 (I 2 ) = C]] = e s. ((updateenv [[I 1 ]] inProc( a. C[[C]](updateenv [[I 2 ]] a e)) e), (return s)) C[[I(E)]] = e s. cases (accessenv [[I]] e) of isNatlocn(I)  (signalerr s)… [] isProc(q)  (q (...E[[E]]... ) s) end

Parameter Domains 1. (E[[E]]e s)  Expressible­value –Actual parameter evaluated with environment and store active at point of invocation. –Call­by­value. 2. (E[[E]]e): Store  Expressible­value –Actual parameter uses invocation environment. –Uses store active at occurences of formal pa­ rameters in procedure body. –Call­by­name.

3. E[[E]]: Environ.  Store  Expr.­value –Uses environment and store active at occurences of formal parameters in procedure body. –Call­by­text. 4. Param = Location –Actual parameter must be variable. –Denotation is variable's L­value. –Call­by­reference.

Argument Evaluation 1.Immediate evaluation Value of actual parameter is calculated before its binding to the formal parameter. D[[proc I 1 (I 2 ) = C]] = e s. ((updateenv [[I 1 ]] inProc( a.C[[C]](updateenv [[I 2 ]]a e)) e), (return s))

2. Delayed evaluation –Value of actual parameter need be calculated only upon its use in the procedure body. Call­by­value = immediate evaluation to an expressible value. Call­by­need = delayed evaluation to an expressible value. Other options use immediate evaluation. Questions for all parameter domains.

Parameterized Type Expressions D ::=... | type I 1 (I 2 ) = T |... T ::=... | I(T) |... type STACKOF(T) = record var ST: array [1..k] of T; var TOP: nat end var X: STACKOF(nat) Semantics can be constructed analogously to that of procedures.

Polymorphism and Typing Polymorhpic operations –Take arguments from more than one semantic domain. –Produced answer depends upon domains of arguments. –Example: polymorphic addition on integers and rationals. –(Integer x Integer) U (Rational x Rational)  Integer U Rational Problem: dependence of codomain on domain is not explicitly stated. Polymorphic operations do not fit cleanly into our semantic notation.

Kinds of Polymorphism Ad hoc polymorphism (overloading) –Operator ``behaves differently'' for arguments of different types. –Pascal + on integers, reals and for set union. –C++ overloading. Polymorphic polymorphism –Operator “behaves the same” for all types. –ML operations on  ­lists.

Overloaded Operators E[[E 1 +E 2 ]] = e s. cases (E[[E1 ]]e s) of isNat(n1)  (cases (E[[E 2 ]]e s) of isNat(n2 )  inNat(n 1 plus n 2 )... end)... [] isRat(r1)  (cases (E[[E 2]]e s) of... [] isRat(r2 )  inRat(r1 addrat r 2 )... end)... [] isSet(t 1) ... inSet(t1 union t 2 )... end Pre­execution analysis  actual operation can be determined at compile­time.

Parametric Polymorphic Operations ML hd operator. Exprval = (Nat + Exprval* + (Exprval X Exprval) + (Exprval + Exprval) + (Exprval  Exprval) + Errvalue)  E[[hd E]] = e: let x = E[[E]]e in cases x of isNat(n)  inErrvalue() [] isExprval* (l)  hd l []… end

Polymorphic Parameterized Abstracts Previous parameterized abstracts were untyped. In typed languages, untyped parameterized abstracts would act polymorphically. Formal parameters must be labeled with type expressions. –Label acts as precondition or guard. –Only actual parameters whose type structures match those of formal parameters are allowed as arguments.

Typed Parameters D ::=...| proc I 1 (I 2 :T) = C C ::= …| I(E) |... Two ways to handle semantics of typed parameters: 1. Type information can guard entry to abstract at invocation. 2. Abstract's denotation is restricted at definition to a function whose domain is that specified by the type.

Type­equivalence checker: T': Type­structure  Environment  (Expressible­value + Errvalue) (T'[[T]]e x) –Determines whether x has type [[T]]. –If yes, result is inExpressible­ value(x). –If no, result is inErrvalue().

D[[proc I 1 (I 2 :T) = C]] = e s. ((updateenv [[I 1 ]] inProc( x: cases (T'[[T]]e x) of isExpressible­value(x)  C[[C]](updateenv [[I]] x e) [] isErrvalue()  signalerr end) e), (return s))

Family of procedure domains: Nat­proc = Nat  Store  Poststore  Array­proc = Array  Store  Poststore  Record­proc = Proc  Store  Poststore  Type­tag = Nat­tag + Array­tag + Record­tag + Err­tag where Nat­tag =... = Unit T': Type­structure ! Environment ! Type­tag

D[[proc I 1 (I 2 :T) = C]] = e s. cases (T'[[T]]e) of isNat­tag()  ((updateenv [[ I 1 ]] inNat­proc( n. C[[C]](updateenv [[ I 2 ]] inNat(n) e)) e), (return s)) isArray­tag() ... isRecord­tag() ... isErr­tag()  (e, (signalerr s)) end

Correspondence For any parameter binding mechanism, there may exist a corresponding definition mechnanism, and vice versa. Elements from domain D may be denotable values of formal parameter identifiers. Elements from D may be also denotable values of declared identifiers. Declared identifiers are used no differently than parameter identifiers.

Qualification Every syntax domain may have a block construct for admitting local declarations. E ::= …| begin D within E end |... D ::= …| begin D1 within D 2 end |... T ::=... | begin D within T end |... M: M  Environment  Store  (M x Poststore) M[[begin D within M end]] = e s let (e’, p) = (D[[D]]e s) in (check (M[[M]]e’ ))(p) Same form for expression command blocks, expression blocks, type blocks, etc.

Classes class STACK­OF­(X) = record begin var ST: array [1..k] of nat; var TOP: nat within proc PUSH(l: nat) =... proc POP =... fcn TOP =... proc INITIALIZE =... end var A: STACK­OF(nat) Classes are record type abstracts that enclose declaration blocks. (Storage is allocated when class variable is defined.)