# CSc 520 Principles of Programming Languages

Size: px
Start display at page:

## Transcription

1 CSc 520 Principles of Programming Languages 31: Procedures Parameters Christian Collberg Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1]

2 Parameter Passing Value Parameters PROG M; PROC P(X:INT); X:=5 END P; VAR S:INT; S:=6; P(S); END. X=5 S=6 } } P(6) M Value parameters are (usually) copied by the caller into the callee s activation record. Changes to a formal won t affect the actual. [2]

3 arameter Passing Reference Parameter PROG M; PROC P(VAR X:INT); X:=5 END P; VAR S:INT; S:=6; P(S); END. X=5 S=5 } } P(6) M Reference parameters are passed by passing the address (location, l-value) fo the parameter. Changes to a formal affects the actual also. [3]

4 Call-by-Value Parameters 1. The caller computes the arguments r-value. 2. The caller places the r-values in the callee s activation record. The caller s actuals are never affected by the call. Copies may have to be made of large structures. TYPE T = ARRAY OF CHAR; PROC P (a:integer; b:t); a:=10; b[5]:="4" END P; VAR r : INTEGER; X : T; P(r, X) END [4]

5 Call-by-Reference Parameters 1. The caller computes the arguments l-value. 2. Expression actuals (like a + b) are stored in a new location. 3. The caller places the l-values in the callee s activation record. The caller s actuals may be affected by the call. TYPE T = ARRAY OF CHAR; PROC P (VAR a:int; VAR b:t); a:=10; b[5]:="4" END P; VAR r : INTEGER; X : T; P(5 + r, X) END [5]

6 Call-by-Name Parameters (Un-)popularized by Algol 60. A name parameter is (re-)evaluated every time it is referenced, in the callers environment. Algorithm: 1. The caller passes a thunk, a function which computes the argument s l-value and/or r-value, to the callee. 2. The caller also passes a static link to its environment. 3. Every time the callee references the name parameter, the thunk is called to evaluate it. The static link is passed to the thunk. [6]

7 Call-by-Name Parameters... Algorithm: 4. If the parameter is used as an l-value, the thunk should return an l-value, otherwise an r-value. 5. If the parameter is used as an l-value, but the actual parameter has no l-value (it s a constant), the thunk should produce an error. Consequences: Every time a callee references a name parameter, it may produce a different result. [7]

8 Call-by-Name Parameters... VAR i : INTEGER; VAR a : ARRAY 2 OF INTEGER; PROCEDURE P (NAME x:integer); END; i := i + 1; x := x + 1; END i := 1; a[1] := 1; a[2] := 2; P(a[i]); WRITE a[1], a[2]; x := x + 1 becomes a[i] := a[i] + 1. Since i is incremented before x, we get a[2] := a[2] + 1. Print 1,3. [8]

9 Call-by-Name Implementation PROCEDURE P (thunk : PROC()); i := i + 1; thunk() := thunk() + 1; END; PROCEDURE thunk1 () : ADDRESS; RETURN ADDR(a[i]) END; i := 1; a[1] := 1; a[2] := 2; P(thunk1); WRITE a[1], a[2]; END [9]

10 Call-by-Name Jensen s Device PROC Sum (NAME Expr:REAL; NAME Idx:INTEGER; Max:INTEGER):INTEGER; VAR Result : REAL := 0; FOR k := 1 TO Max DO; Idx := k; Result := Result + Expr; ENDFOR; RETURN Result; END; VAR i : END INTEGER; WRITE Sum(i, i, 5); (* 5 i=1 i *) WRITE Sum(i*i, i, 10); (* 10 [10] i=1 i2 *)

11 Large Value Parameters Large value parameters have to be treated specially, so that a change to the formal won t affect the actual. Example: TYPE T = ARRAY [ ] OF CHAR; PROCEDURE P (x : T); x[5] := "f"; END P; VAR L : T; P(L); END. [11]

12 Large Value Parameters... Algorithm 1: Callee Copy OCEDURE P (VAR x : T); R xt : T; GIN copy(xt,x,1000); xt[5]:="f"; D P; R L : T; GIN P(L); D Algorithm 2: Caller Copy PROCEDURE P (VAR x : T); x[5] := "f"; END P; VAR L : T; VAR LT : T; copy(lt, L, 1000); P(LT); END [12]

13 Parameter Passing In Pascal, parameters are passed either by value or by reference (if the formal is preceeded by the keyword var). In C, all parameters are passed by value. Pass by reference can be simulated by explicitly passing the address of a variable: swap(&x,&y). In FORTRAN, all parameters are passed by reference. A programmer can simulate pass-by-value by explicitly making a local copy of an argument. Unlike most languages, FORTRAN allows r-values to be passed by reference: swap(3+4,7*x). The compiler creates a temporary variable to hold the value. [13]

14 Parameter Passing... In Java, object references are transfered using pass-by-sharing. This means that the actual and formal will refer to the same object. The compiler simply passes the address of the object. In Java, primitive types are passed by value. [14]

15 Parameter Passing... In Pascal and Modula-2 a programmer would use call-by-value to ensure that the callee cannot modify the actual argument. In Pascal and Modula-2 a programmer would use call-by-reference to ensure that the callee can modify the actual argument, or to make sure that a large parameter (which semantically should be passed by value) is not copied. (This is done for efficiency reasons). [15]

16 Parameter Passing... Modula-3 provides a READONLY parameter mode. A READONLY formal parameter cannot be changed by the callee. The formal 1. cannot be on the left-hand-side of an assignment statement, and 2. cannot be passed by reference to another routine. Small READONLY parameters are passed by value. Large READONLY parameters are passed by reference. [16]

17 Parameter Passing in Ada Ada has three modes: 1. in-parameters pass information from the caller to the callee. The callee cannot write to them. 2. out-parameters pass information to the callee from the caller. The callee can read and write them. They start out being uninitialized. 3. in out-parameters pass information from the caller to the callee and back. [17]

18 Parameter Passing in Ada... For scalars and pointers, all modes should be implemented by copying values. Thus 1. in-parameters are passed-by-value. 2. out-parameters are passed-by-result (the formal is copied into the actual when the procedure returns). 3. in out-parameters are passed-by-value/result (On entry, the actual is copied into the formal. On return, the formal is copied back into the actual). [18]

19 Parameter Passing in Ada... For constructed types (records, arrays) an implementation is allowed to pass either values or addresses. If an in out parameter is passed by address an assignment to the formal changes the actual immediately. If an in out parameter is passed by value an assignment to the formal will not affect the actual until the procedure returns (and the formal is copied back into the actual). Ada disallows programs that can tell which implementation a compiler uses. [19]

20 Parameter Passing in Ada... type t is record a, b : r : t; integer; end record; procedure foo (s : begin r.a := r.a + 1; s.a := s.a + 1; end foo; in out t) is r.a := 3; foo(r); if r.a = 4 then put("implementation uses pass-by-value") else put("implementation uses pass-by-address") [20]

21 Exam Problem /96 (A) Show the status of the run-time stack when execution has reached point for the second time in the program on the next slide. Fill in the name of each procedure invocation in the correct activation record. Also fill in the values of local variables and actual parameters, and show where the static links and control links are pointing. Assume that all actual parameters are passed on the stack rather than in registers. [21]

22 [22] PROGRAM M; PROC P ( X:INT); VAR W:INT; PROC Q ( VAR Z:INT); VAR N:INT; PROC R ( V:INT); VAR L:INT; L := W; P(23); END R; N := W; Z := Z+1; R(Z); END Q; W := X + 1; Q(W); END P; P(15); END M. Activ ation Record Stack grows up! Procedure Name: Procedure Name: Procedure Name: Procedure Name: Procedure Name: Local Vars: Actual Params: Control Link Local Vars: Actual Params: Control Link Local Vars: Actual Params: Control Link Local Vars: Actual Params: Control Link Local Vars: Actual Params: Control Link Static Link Static Link Static Link Static Link Static Link Procedure Name: M This is the activation record for the main program. Exam Problem /96 (B)

23 Homework Draw the stack when control reaches point for the third time. Include all actual parameters, local variables, return addresses, and static and dynamic links. PROGRAM M; PROCEDURE P(X:INTEGER); VAR A : INTEGER; PROCEDURE Q(Y : INTEGER); VAR B : INTEGER; B := Y + 1; A := B + 2; P(B); END Q; A:= X + 1; Q(A); END P; P(0); END M. [23]

25 Summary A parameter is often passed by the caller copying it (or its address, in case of VAR parameters) into the callees activation record. On the MIPS, the caller has an area in its own activation record in which it puts actual parameters before it jumps to the callee. For each procedure P the compiler figures out the maximum number of arguments P passes to any procedure it calls. The corresponding amount of memory has to be allocated in P s activation record. [25]

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 28 : Control Structures Parameters Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

### CSc 520 Principles of Programming Languages. ameter Passing Reference Parameter. Call-by-Value Parameters. 28 : Control Structures Parameters

Parameter Passing Value Parameters CSc 520 Principles of Programming Languages 28 : Control Structures Parameters Christian Collberg collberg+520@gmail.com PROG M; PROC P(X:INT); X:=5 VAR S:INT; S:=6;

### Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions

Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions COMP 524 Programming Language Concepts Stephen Olivier February 12, 2008 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos,

### CSc 520 Principles of Programming Languages. Questions. rocedures as Control Abstractions... 30: Procedures Introduction

Procedures as Control Abstractions CSc 520 Principles of Programming Languages 30: Procedures Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 32: Procedures Inlining Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1]

### UNIT V Sub u P b ro r g o r g a r m a s

UNIT V SubPrograms Outline Subprograms Parameter Passing Parameter correspondence Main Issues when designing subroutine in programming languages Parameter passing techniques Characteristics of Subprogram

### Memory Management and Run-Time Systems

TDDD55 Compilers and Interpreters TDDB44 Compiler Construction Memory Management and Run-Time Systems Part of the Attribute Grammar Material Presented at the Beginning of this Lecture Peter Fritzson IDA,

### Principles of Programming Languages

Ting Zhang Iowa State University Computer Science Department Lecture Note 16 October 26, 2010 Control Abstraction: Subroutines 1 / 26 Outline 1 Subroutines 2 Parameter Passing 3 Generic Subroutines 2 /

### G Programming Languages - Fall 2012

G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

### COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages Subroutines and Parameter Passing Prof. Robert van Engelen Overview Parameter passing modes Subroutine closures as parameters Special-purpose parameters Function returns COP4020

### Programming Languages

Programming Languages Tevfik Koşar Lecture - XX April 4 th, 2006 1 Roadmap Subroutines Allocation Strategies Calling Sequences Parameter Passing Generic Subroutines Exception Handling Co-routines 2 1 Review

### G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

### Chap. 8 :: Subroutines and Control Abstraction

Chap. 8 :: Subroutines and Control Abstraction Michael L. Scott Programming Language Theory 2015, kkman@sangji.ac.kr 1 Review Of Stack Layout Allocation strategies Static Code Globals Own variables Explicit

### CSc 520 final exam Wednesday 13 December 2000 TIME = 2 hours

NAME s GRADE Prob 1 2 3 4 5 I II III Σ Max 12 12 12 12 12 26 26 26 100(+... ) Score CSc 520 exam Wednesday 13 December 2000 TIME = 2 hours Write all answers ON THIS EXAMINATION, and submit it IN THE ENVELOPE

### CSc 453. Semantic Analysis III. Basic Types... Basic Types. Structured Types: Arrays. Compilers and Systems Software. Christian Collberg

Slide 11 2 Basic s... Enumeration types TYPE E1 = (white,blue,yellow,green,red); TYPE E2 = (apple=4,pear=9,kumquat=99); Pascal, Ada, Modula-2, C have some variant of enumeration types. Subrange types TYPE

### Chapter 8 ( ) Control Abstraction. Subprograms Issues related to subprograms How is control transferred to & from the subprogram?

Control Abstraction Chapter 8 (81 84) Control Abstraction: Subroutines and parameters Programmer defined control structures Subprograms Procedures Functions Coroutines Exception handlers Processes Subprograms

### Chapter 9 :: Subroutines and Control Abstraction

Chapter 9 :: Subroutines and Control Abstraction Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter09_Subroutines_and_Control_Abstraction_4e - Tue November

### CS 345. Functions. Vitaly Shmatikov. slide 1

CS 345 Functions Vitaly Shmatikov slide 1 Reading Assignment Mitchell, Chapter 7 C Reference Manual, Chapters 4 and 9 slide 2 Procedural Abstraction Can be overloaded (e.g., binary +) Procedure is a named

### Implementing Subprograms

1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return

### Programming Languages: Lecture 12

1 Programming Languages: Lecture 12 Chapter 10: Implementing Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 10 Topics 2 The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing

### Chapter 10. Implementing Subprograms ISBN

Chapter 10 Implementing Subprograms ISBN 0-321-33025-0 Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables

### Chapter 8 :: Subroutines and Control Abstraction. Final Test. Final Test Review Tomorrow

Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott Administrative Notes Final Test Thursday, August 3 2006 at 11:30am No lecture before or after the mid-term

### Object-Oriented Languages. CSc 453. Compilers and Systems Software. 23 : OO Languages. Department of Computer Science University of Arizona

Object-Oriented Languages CSc 453 Compilers and Systems Software 23 : OO Languages Department of Computer Science University of Arizona Object-oriented languages extend imperative languages with: 1 A classification

### CSc 520. Principles of Programming Languages 45: OO Languages Introduction

CSc 520 Principles of Programming Languages 45: OO Languages Introduction Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg

### CSc 453. OO Languages. Object-Oriented Languages... Object-Oriented Languages. Compiling OO Languages. Compilers and Systems Software

Slide 22 2 Object-Oriented Languages... 3. Polymorphism, which is the ability of a variable to store values of different types. OO languages support a special kind of polymorphism, called inclusion polymorphism,

### Control Abstraction. Hwansoo Han

Control Abstraction Hwansoo Han Review of Static Allocation Static allocation strategies Code Global variables Own variables (live within an encapsulation - static in C) Explicit constants (including strings,

### Run-time Environments -Part 1

Run-time Environments -Part 1 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design Outline of the Lecture Part 1 What is run-time support?

### CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

CSc 520 Principles of Programming Languages 26 : Control Structures Introduction Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

### CS 314 Principles of Programming Languages. Lecture 13

CS 314 Principles of Programming Languages Lecture 13 Zheng Zhang Department of Computer Science Rutgers University Wednesday 19 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:

### CSC 2400: Computer Systems. Using the Stack for Function Calls

CSC 24: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 27 : Control Structures Procedures Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

### Control Structures. Boolean Expressions. CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV

CSc 453 Compilers and Systems Software 16 : Intermediate Code IV Control Structures Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Control Structures

### 1 Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

### System Software Assignment 1 Runtime Support for Procedures

System Software Assignment 1 Runtime Support for Procedures Exercise 1: Nested procedures Some programming languages like Oberon and Pascal support nested procedures. 1. Find a run-time structure for such

### Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

### CSc 453. Compilers and Systems Software. 13 : Intermediate Code I. Department of Computer Science University of Arizona

CSc 453 Compilers and Systems Software 13 : Intermediate Code I Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Introduction Compiler Phases

### CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

CS356: Discussion #6 Assembly Procedures and Arrays Marco Paolieri (paolieri@usc.edu) Procedures Functions are a key abstraction in software They break down a problem into subproblems. Reusable functionality:

### Wednesday, October 15, 14. Functions

Functions Terms void foo() { int a, b;... bar(a, b); void bar(int x, int y) {... foo is the caller bar is the callee a, b are the actual parameters to bar x, y are the formal parameters of bar Shorthand:

### Parameter passing. Parameter: A variable in a procedure that represents some other data from the procedure that invoked the given procedure.

Parameter passing Parameter: A variable in a procedure that represents some other data from the procedure that invoked the given procedure. Parameter transmission: How that information is passed to the

### CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV. Department of Computer Science University of Arizona

CSc 453 Compilers and Systems Software 16 : Intermediate Code IV Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Control Structures Control Structures

### Introduction. Inline Expansion. CSc 553. Principles of Compilation. 29 : Optimization IV. Department of Computer Science University of Arizona

CSc 553 Principles of Compilation 29 : Optimization IV Introduction Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg Inline Expansion I Inline

### Weeks 6&7: Procedures and Parameter Passing

CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45

### CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

### Concepts Introduced in Chapter 7

Concepts Introduced in Chapter 7 Storage Allocation Strategies Static Stack Heap Activation Records Access to Nonlocal Names Access links followed by Fig. 7.1 EECS 665 Compiler Construction 1 Activation

### Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 32 : Control Structures Coroutines Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

### Memory Management. Memory Management... Memory Management... Interface to Dynamic allocation

CSc 453 Compilers and Systems Software 24 : Garbage Collection Introduction Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Dynamic Memory Management

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 50: Semantics Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg

### CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages Lecture 13: Names, Scopes and Bindings Zheng (Eddy) Zhang Rutgers University February 28, 2018 Review: Names, Scopes and Binding What s in a name? Each name means

### Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :

Runtime Environment Relationship between names and data objects (of target machine) Allocation & de-allocation is managed by run time support package Each execution of a procedure is an activation of the

### procedure definition (or declaration - some make a distinction, we generally won t), e.g., void foo(int x) {... }

Parameters Terminology: procedure invocation, e.g., (in different language notations) foo(a*8) x:=goo(19,a) call hoo() actual parameters, e.g., a*8 is an actual parameter of the above inv ocation of foo

### CSC 8400: Computer Systems. Using the Stack for Function Calls

CSC 84: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing

### Parameter Binding. Value: The formal parameter represents a local variable initialized to the value of the corresponding actual parameter.

Parameter Binding Almost all programming languages have some notion of binding an actual parameter (provided at the point of call) to a formal parameter (used in the body of a subprogram). There are many

### CS558 Programming Languages

CS558 Programming Languages Fall 2016 Lecture 4a Andrew Tolmach Portland State University 1994-2016 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

### Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

### Chapter 8. Fundamental Characteristics of Subprograms. 1. A subprogram has a single entry point

Fundamental Characteristics of Subprograms 1. A subprogram has a single entry point 2. The caller is suspended during execution of the called subprogram 3. Control always returns to the caller when the

### Compiler Construction

Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Conceptual Structure of

### 11/29/17. Outline. Subprograms. Subroutine. Subroutine. Parameters. Characteristics of Subroutines/ Subprograms

Outline Subprograms In Text: Chapter 9 Definitions Design issues for subroutines Parameter passing modes and mechanisms Advanced subroutine issues N. Meng, S. Arthur 2 Subroutine A sequence of program

### References and pointers

References and pointers Pointers are variables whose value is a reference, i.e. an address of a store location. Early languages (Fortran, COBOL, Algol 60) had no pointers; added to Fortran 90. In Pascal,

### Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

### Compiler Construction

Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Outline of Lecture 15 Generation

### MIPS Procedure Calls. Lecture 6 CS301

MIPS Procedure Calls Lecture 6 CS301 Function Call Steps Place parameters in accessible location Transfer control to function Acquire storage for procedure variables Perform calculations in function Place

### CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

### Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction

Procedure Abstraction Run Time Environment Records Procedure Linkage Name Translation and Variable Access Copyright 2010, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at

### CSc 372. Comparative Programming Languages. 36 : Scheme Conditional Expressions. Department of Computer Science University of Arizona

1/26 CSc 372 Comparative Programming Languages 36 : Scheme Conditional Expressions Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/26 Comparison

### Topic IV. Block-structured procedural languages Algol and Pascal. References:

References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 10( 2) and 11( 1) of Programming

### Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Subroutines and Control Abstraction Textbook, Chapter 8 1 Subroutines and Control Abstraction Mechanisms for process abstraction Single entry (except FORTRAN, PL/I) Caller is suspended Control returns

### CSc 453 Compilers and Systems Software

CSc 453 Compilers and Systems Software 3 : Lexical Analysis I Christian Collberg Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg August 23, 2009

### Run Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access

Run Time Environment Activation Records Procedure Linkage Name Translation and Variable Access Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 36 : Scheme Conditional Expressions Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701

### CSCI565 Compiler Design

CSCI565 Compiler Design Spring 2011 Homework 4 Solution Due Date: April 6, 2011 in class Problem 1: Activation Records and Stack Layout [50 points] Consider the following C source program shown below.

### CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages Lecture 15: Review and Functional Programming Zheng (Eddy) Zhang Rutgers University March 19, 2018 Class Information Midterm exam forum open in Sakai. HW4 and

### COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

### Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapter 5 of Programming languages: Concepts

### CS 415 Midterm Exam Spring SOLUTION

CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you

### Systems I. Machine-Level Programming V: Procedures

Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp

### Compiler Design. Spring Run-Time Environments. Sample Exercises and Solutions. Prof. Pedro C. Diniz

University of Southern California (USC) Computer Science Department Compiler Design Spring 2014 Run-Time Environments Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute

### IR Generation. May 13, Monday, May 13, 13

IR Generation May 13, 2013 Monday, May 13, 13 Monday, May 13, 13 Monday, May 13, 13 Midterm Results Grades already in Repeal policy Talk to TA by the end of the Tuesday reserve the right to regrade the

### Run-Time Environments

1 Run-Time Environments Chapter 7 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011 2 Procedure Activation and Lifetime A procedure is activated when called

### 9. Subprograms. 9.2 Fundamentals of Subprograms

9. Subprograms 9.2 Fundamentals of Subprograms General characteristics of subprograms A subprogram has a single entry point The caller is suspended during execution of the called subprogram Control always

### CMSC 4023 Chapter 9. Fundamentals of Subprograms Introduction

9. 9.1. Introduction Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized in the1980s 9.2. 9.2.1. General Subprogram Characteristics Each subprogram

### Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.8 and 2.12 Goals for Today Calling Convention for Procedure Calls Enable code to be reused by allowing

### PROCEDURES, METHODS AND FUNCTIONS

Cosc 2P90 PROCEDURES, METHODS AND FUNCTIONS (c) S. Thompson, M. Winters 1 Procedures, Functions & Methods The are varied and complex rules for declaring, defining and calling procedures, methods and functions

### ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design Lecture 6: Procedures Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Overview Procedures have different names in different languages Java:

### CSE 582 Autumn 2002 Exam 11/26/02

Name There are 8 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following reference materials:

### Run-time Environments

Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

### Run-time Environments

Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

### Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized

### COP4020 Fall 2006 Final Exam

COP4020 Fall 2006 Final Exam Name: (Please print) Put the answers on these sheets. You can collect 100 points in total for this exam. 1. Consider the following Ada program fragment: search: loop i := i+1;

### Goals of this Lecture

C Pointers Goals of this Lecture Help you learn about: Pointers and application Pointer variables Operators & relation to arrays 2 Pointer Variables The first step in understanding pointers is visualizing

### CSc 520. Principles of Programming Languages 25: Types Introduction

CSc 520 Principles of Programming Languages 25: Types Introduction Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg April

### Programmiersprachen (Programming Languages)

2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html

### Lecture08: Scope and Lexical Address

Lecture08: Scope and Lexical Address Free and Bound Variables (EOPL 1.3.1) Given an expression E, does a particular variable reference x appear free or bound in that expression? Definition: A variable

### Subroutines. Subroutine. Subroutine design. Control abstraction. If a subroutine does not fit on the screen, it is too long

Subroutines Subroutine = procedure (statement) - no return value - side effects function (expression) - return value - (no side effects in some languages) Subroutine Control abstraction Subroutine design

### CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

### Special Topics: Programming Languages

Lecture #17 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 17 Lecture #17 1 Slide 1 Runtime Representations Variable Names Environment L-values Scope, Extent

### Attributes of Variable. Lecture 13: Run-Time Storage Management. Lifetime. Value & Location

Attributes of Variable Lecture 13 Run-Time Storage Management CSC 131 Kim Bruce Scope Lifetime Location Value Done! Lifetime Value & Location FORTRAN - all allocated statically - Stack-based (C/C++/Java/Pascal/...)