# ! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

Size: px
Start display at page:

Download "! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?"

Transcription

1 A Binding Question! Variables are bound (dynamically) to values Subprogram Activation! Those values must be stored somewhere! Therefore, variables must somehow be bound to memory locations! How? Function Activations! The lifetime of one execution of a function, from call to corresponding return, is called an activation of the function! When each activation has its own binding of a variable to a memory locations, it is an activation-specific variable! (Also called dynamic or automatic) Block Activations! For block constructs that contain code, we can speak of an activation of the block! The lifetime of one execution of the block! A variable might be specific to an activation of a particular block within a function: int fact(int n) { if (n=0) then return 1; else return fact(n-1)*n; Other Lifetimes For Variables! Most imperative languages have a way to declare a variable that is bound to a single memory location for the entire runtime! Obvious binding solution: static allocation (classically, the loader allocates these) Scope And Lifetime Differ! In most modern languages, variables with local scope have activation-specific lifetimes, at least by default! However, these two aspects can be separated, as in C: int count = 0; int nextcount() { count = count + 1; return count; int nextcount() { static int count = 0; count = count + 1; return count;

3 Subprogram Activation! (at a minimum)! Subprogram Code! Local Variables! Parameters! Functional value (return value)! Return address!! Layout of non-code storage! Instance (ARI)! Concrete example of an activation record! Collection of data for a particular activation int fun1(float x, int y) { const int IVAL = 2; static int fval = 10; float list[4]; int n = IVAL; return 20*x+list[n]; int fun2(int a) { float b; fun1(b, a); int fun3(float r) { int s, t; s = fun2(s); int main() { float p, r; r = fun3(p);! Static Local Variables and Subprograms main() Application Stack Application Code fun1() Application Memory fun2() fun3() main ARI fun1 ARI fun2 ARI Return Address Return Value Parameters Local Variables fun3 ARI! Static Local Variables and Subprograms! Provides Fast Access and Execution All memory for application and subprograms allocated at load time Compiler can determine addresses at compile time Linker can determine all offsets at link time! Can waste memory Functions might never be called Multiple functions may need large ARI (for array) but only one will ever be active at a time! Cannot Implement Recursion Only a single instance of a subprogram may be active at a time Stacks Of s! To support recursion, we need to allocate a new activation record for each activation! Dynamic allocation: activation record allocated when function is called! For many languages, like C, it can be deallocated when the function returns! A stack of activation records: stack frames pushed on call, popped on return

4 ! Stack-Dynamic Local Variables! More Complex Implementation Compiler must generate code for implicit allocation and deallocation of local variables Recursion must be supported Adds possibility of multiple simultaneous activations mat is static but its size may be dynamic! ARI must be dynamically created when subprogram is called (invoked)! Application Memory Partitioning Static Storage Dynamic Storage Subprogram Code Segments and System Code Segments Program Memory application stack stack growth free space (available for use) heap growth application heap heap bottom Start of Stack Block Allocated by subprogram invocation End of Stack Block Allocated by new operator! Code Segment for Subprogram! Executable Subprogram Code! Subprogram int fun1(float x, int y) { const int IVAL = 2; static int fval = 10; float list[4]; int n = IVAL; return 20*x+list[n]; Information concerning the current call (invocation) of subprogram fun1 is contained in its activation record.! Code Segment for Subprogram fun1! Code produced by compiler for subprogram Prologue Executable Subprogram Code Epilogue Housekeeping code to create an activation record Executable Code for each Subprogram Statement Housekeeping code to delete the activation record Storage for Constants (reverse order)! Memory Organization During Execution! Memory Organization During Execution System Data stack chain pointer dynamic link Program (old stack Call Sequence: pointer) Return point location OpSys! main() Return Value main()! fun3() Formal Parameters fun3()! fun2() fun2()! fun1() Local Variables Temporaries for Expression Evaluation Temporaries for Parameter Transmission Subprogram Code Segments and System Code Segments Activation record storage Activation record storage Activation record storage Activation record storage Free Space application application heap heap Start of Stack Block System Data stack ARI chain of Parent pointer dynamic ARI of Caller link (old stack pointer) Old Return Prog point Counter location (PC) Return int fun1 Value Formal float Parameters x int y (reverse order) float Local Variables list[0] float list[1] float list[2] float list[3] Temporaries for Expression int n = 2 Evaluation Temporaries for Expression Temporaries for Parameter Evaluation and Parameter Transmission Transmission int fun1(float x, int y) { const int IVAL = 2; static int fval = 10; float list[4]; int n = IVAL; return 20*x+list[n];

5 ! Subprogram! Block of storage containing local objects Local variables are accessed by their offset from the beginning of the activation record (local_offset) Compiler can determine local offset of a local variable! Template! s are Dynamic! Each invocation of subprogram results in! Creation of a new activation record! Static code generated by compiler is associated with the new activation record Data Structure of Compiler binds each identifier in subprogram with a storage location offset in activation record Template is stored in Code Segment Prologue fun1 Code Segment Static Storage fun1 fun1 fun1 Dynamic Storage! s Support Recursion int fact(int x) { if (x == 1) return 1; else return x * fact(x-1); Sample Call: fact(3) Scoping Issues : Non-Local Variable Access Dynamic Chains fact() Code Segment Static Storage fact(3) fact(2) fact(1) Dynamic Storage Successive invocations of subprogram Scope and s! First - Quick Review of Scope! Dynamic scope: Scope is determined by the execution of program! Static scope: Scope is dependent on the syntax of the program! Static Nested Scope: A variable is accessible in the function it is declared in, and all procedures internal to that function, except a new declaration of that variable name in an internal function will eliminate the new variable's scope from the scope of the outer variable.! Variable declared in function is local to function Scope and s! Two pointers manage scope in AR! Pointer (DL) Points to activation record that called (invoked) the current activation record! Pointer (SL) Points to the activation record that is global (parent) to the current activation record. Activation record of the subprogram containing the declaration of this subprogram.

6 Dynamically Scoped Languages!! Points to activation record of the caller! Used for returning from the subprogram! Used to access non-locals in Dynamic Scoping! Frequently implemented as old stack pointer! Dynamic Chain! Collection of dynamic links in the stack! Call Chain Dynamically Scoped Languages () () call call call () () () Scope Sub_S Dynamically Scoped Languages () () call call call () Dynamic Chain for Dynamic Chain for Scope Sub_S Dynamically Scoped Languages! Deep Access! Nonlocal references found on dynamic chain Length of chain cannot be statically determined Every ARI must have variable names! Shallow Access! Put locals in central place! Can be one stack for each variable name! Central table with entry for each variable name Dynamically Scoped Languages Scoping Issues : Non-Local Variable Access Static Chains and Displays

7 ! Nested Subprograms! Static semantic rules guarantee that all nonlocal variables that can be referenced have been allocated in some activation record instance that is on the stack when the reference is made! Locating Nonlocal Variables! Find the correct activation record instance! Determine the correct offset within that ARI! Pointer (SL)! Points to the activation record that is global (parent) to the current activation record.! The activation record of the subprogram containing the declaration of this subprogram.! Static Chain! A chain of static links that connect hierarchically related activation record instances! Chain of static links that connects activation record instances based on static ancestors.! Static Chain! Compiler knows static structure! Chains can be generated at compile time (not run-time).! Static Depth! Number of static levels representing the nesting level of the scope of interest.! References for non-local variables are obtained by following the static chain.! Non-Local reference can be slow if static depth is large. (Consistant, but slow)! Static Chain! Chain Offset (Nesting Depth) Difference between the static depth of a reference (to a variable) and the static depth of the scope in which it was declared.! Local Offset Offset in the activation record of the refernced variable.! Reference Pairs for Nonlocal Variables (chain_offset, local_offset) () () call call call () () () Scope Sub_S and exist, but not within static scope of SubS() () () call call call () () () Scope Sub_S

8 () () call call call () Static Chain for Dynamic Chain for Static Chain for Dynamic Chain for! Static Chain Maintenance! Build! is the old! is most recent ARI of static parent Search the dynamic chain until the first ARI for the static parent is found--easy, but slow Store Nesting Depth from Definition to Caller Transit Caller Static Chain to appropriate depth! Issues with Static Chain! Slow nonlocal reference if the number of scopes between reference and declaration is large! Time-critical code is difficult to verify Costs of nonlocal references are not equal Costs can an change with code upgrades and fixes Static Scope and Displays! Displays! Place static links in a separate stack that is part of the activation record. Previous level!s activation record!s display is copied and a pointer to the new activation record is pushed.! Entries are direct links to activation records of declarations.! Display Reference Pairs (display_offset, local_offset) Display Offset is same as Chain Offset Static Scope and Displays! Reference Mechanics:! Use display offset to get pointer to activation record of interest! Use local offset to get to the variable within that particular activation record.! Always a two-step process, independent of static nesting depth! Display can be kept in registers! If there are enough! Speeds up access and maintenance Static Scope and Displays! Comparing Static Chain and Display! References to locals Not much difference! References to nonlocals If it is one level away, they are equal If it is farther away, the display is faster! Display is better for time-critical code All nonlocal references cost the same

9 Static Scope and Displays! Subprogram Calls! One or two levels of depth, static chain is faster! Greater than two levels, display is faster! Subprogram Returns! Both have fixed time, but the static chain is slightly faster! Static chain is better, unless the display can be kept in registers Blocks! Code Blocks can define local scoping! Implementation can vary! Treat blocks as parameterless subprograms Use activation records! Allocate locals in the subprogram ARI { int temp = x; x = y; y = temp;

### Chapter 10. Implementing Subprograms

Chapter 10 Implementing Subprograms Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms

### Chapter 9. Def: The subprogram call and return operations of a language are together called its subprogram linkage

Def: The subprogram call and return operations of a language are together called its subprogram linkage Implementing FORTRAN 77 Subprograms Call Semantics: 1. Save the execution status of the caller 2.

### 12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

Outline Implementing Subprograms In Text: Chapter 10 General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

### Implementing Subroutines. Outline [1]

Implementing Subroutines In Text: Chapter 9 Outline [1] General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

### 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

### 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 10 Implementing Subprograms

Chapter 10 Implementing Subprograms The General Semantics of Calls and Returns - Definition: The subprogram call and return operations of a language are together called its subprogram linkage Implementing

Subprograms Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling Subprograms Indirectly

### 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

### 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

### Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

### Implementing Subprograms

Implementing Subprograms 1 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms Blocks Implementing

### 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

### Run-time Environments - 2

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

### Scope, Functions, and Storage Management

Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)

### 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

### CSE 504: Compiler Design. Runtime Environments

Runtime Environments Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Procedure Abstractions Mechanisms to manage procedures and procedure calls from compiler s perspective Runtime Environment Choices

### 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

### Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Runtime Environment The Procedure Abstraction and Separate Compilation Topics we will cover The procedure abstraction and linkage conventions Runtime storage convention Non-local data access (brief) These

### Procedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End

COMP 412 FALL 2017 Procedure and Function Calls, Part II Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students

### Procedure and Object- Oriented Abstraction

Procedure and Object- Oriented Abstraction Scope and storage management cs5363 1 Procedure abstractions Procedures are fundamental programming abstractions They are used to support dynamically nested blocks

### 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

### CA Compiler Construction

CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is

### The Procedure Abstraction

The Procedure Abstraction Procedure Abstraction Begins Chapter 6 in EAC The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures

### Topic 7: Activation Records

Topic 7: Activation Records Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Storage Organization Stack Free Memory Heap Static Code 2 ELF file format example Executable Object

### 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

### 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

### Run-Time Environments

CS308 Run-Time Environments Li Jiang Department of Computer Science and Engineering Shanghai Jiao Tong University Current Progress Source Language Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate

### Run-Time Data Structures

Run-Time Data Structures Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers, it is used for:

### Run Time Environments

Run Time Environments ALSU Textbook Chapter 7.1 7.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Preliminaries During the execution of a program, the same name in the source

### 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

### Implementing Subprograms

Implementing Subprograms In Text: Chapter 10 Slide 1 Implementing Subprograms Call - Save registers - provide storage for parameters - provide storage for locals - save execution status of caller - provide

### UNIT 3

UNIT 3 Presentation Outline Sequence control with expressions Conditional Statements, Loops Exception Handling Subprogram definition and activation Simple and Recursive Subprogram Subprogram Environment

### Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1

Compilers 8. Run-time Support Laszlo Böszörmenyi Compilers Run-time - 1 Run-Time Environment A compiler needs an abstract model of the runtime environment of the compiled code It must generate code for

### THEORY OF COMPILATION

Lecture 10 Activation Records THEORY OF COMPILATION EranYahav www.cs.technion.ac.il/~yahave/tocs2011/compilers-lec10.pptx Reference: Dragon 7.1,7.2. MCD 6.3,6.4.2 1 You are here Compiler txt Source Lexical

### Module 27 Switch-case statements and Run-time storage management

Module 27 Switch-case statements and Run-time storage management In this module we will discuss the pending constructs in generating three-address code namely switch-case statements. We will also discuss

### Runtime Environments I. Basilio B. Fraguela

Runtime Environments I Basilio B. Fraguela Runtime System Responsibilities Allocation of storage for program data Sometimes also deallocation Garbage collection Management of data structures the compiled

### Chapter 9 Subroutines and Control Abstraction. June 22, 2016

Chapter 9 Subroutines and Control Abstraction June 22, 2016 Stack layout Common to have subroutine activation record allocated on a stack Typical fare for a frame: arguments, return value, saved registers,

### 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

### 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

### The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

SYMBOL TABLE: A symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating

### Compilers and Code Optimization EDOARDO FUSELLA

Compilers and Code Optimization EDOARDO FUSELLA Contents Data memory layout Instruction selection Register allocation Data memory layout Memory Hierarchy Capacity vs access speed Main memory Classes of

### Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces

### Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Binding and Storage Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. What s

### Runtime management. CS Compiler Design. The procedure abstraction. The procedure abstraction. Runtime management. V.

Runtime management CS3300 - Compiler Design Runtime management V Krishna Nandivada IIT Madras Copyright c 2001 by Antony L Hosking Permission to make digital or hard copies of part or all of this work

### Lecture 11: Subprograms & their implementation. Subprograms. Parameters

Lecture 11: Subprograms & their implementation Subprograms Parameter passing Activation records The run-time stack Implementation of static and dynamic scope rules Subprograms A subprogram is a piece of

### Compilation /15a Lecture 7. Activation Records Noam Rinetzky

Compilation 0368-3133 2014/15a Lecture 7 Activation Records Noam Rinetzky 1 Code generation for procedure calls (+ a few words on the runtime system) 2 Code generation for procedure calls Compile time

### Chapter 5. Names, Bindings, and Scopes

Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

### G Programming Languages - Fall 2012

G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

### Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Run-time Environments Lecture 13 by Prof. Vijay Ganesh) Lecture 13 1 What have we covered so far? We have covered the front-end phases Lexical analysis (Lexer, regular expressions,...) Parsing (CFG, Top-down,

### Naming in OOLs and Storage Layout Comp 412

COMP 412 FALL 2018 Naming in OOLs and Storage Layout Comp 412 source IR IR target Front End Optimizer Back End Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in

### An Activation Record for Simple Subprograms. Activation Record for a Language with Stack-Dynamic Local Variables

Activation Records The storage (for formals, local variables, function results etc.) needed for execution of a subprogram is organized as an activation record. An Activation Record for Simple Subprograms.

### 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

### CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table

### Typical Runtime Layout. Tiger Runtime Environments. Example: Nested Functions. Activation Trees. code. Memory Layout

Tiger Runtime Environments Compile-time environments are just symbol tables; they are used to assist static semantic analysis, code generation and code optimization. Run-time environments are about how

### Compiler Theory. (Semantic Analysis and Run-Time Environments)

Compiler Theory (Semantic Analysis and Run-Time Environments) 005 Semantic Actions A compiler must do more than recognise whether a sentence belongs to the language of a grammar it must do something useful

### Run-Time Environements

Run-Time Environements Martin Sulzmann Martin Sulzmann Run-Time Environements 1 / 21 Overview Things to consider Static program code versus dynamic procedure activation. First-order functions (C). Nested

### Informatica 3 Marcello Restelli

Informatica 3 Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Operational Semantics We describe the semantics of a programming language by means of an abstract semantic

### CS 480 Fall Runtime Environments. Mike Lam, Professor. (a.k.a. procedure calls and heap management)

CS 480 Fall 2015 Mike Lam, Professor Runtime Environments (a.k.a. procedure calls and heap management) Subprograms General characteristics Single entry point Caller is suspended while subprogram is executing

Object Oriented Paradigm Languages The central design goal is to build inherent abstraction into the system, moving all the abstract implementation details from the user level (ad-hoc) to the system level

### Run-time Environment

Run-time Environment Prof. James L. Frankel Harvard University Version of 3:08 PM 20-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Storage Organization Automatic objects are

### 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

### CS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers Procedure Abstractions These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Where are we? Well understood Engineering Source Code

### CSE 307: Principles of Programming Languages

1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages

### Principles of Programming Languages

Principles of Programming Languages Lecture 06 Implementation of Block Structured Languages 1 Activations and Environment Aspects of Subroutines: Static vs Dynamic! Static subroutine: code (``reentrant

### 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,

### CIT Week13 Lecture

CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there

### Today's Topics. CISC 458 Winter J.R. Cordy

Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing

### 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

### Functions and Procedures

Functions and Procedures Function or Procedure A separate piece of code Possibly separately compiled Located at some address in the memory used for code, away from main and other functions (main is itself

### 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

### Runtime Support for Algol-Like Languages Comp 412

COMP 412 FALL 2018 Runtime Support for Algol-Like Languages Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students

### The Procedure Abstraction Part I: Basics

The Procedure Abstraction Part I: Basics Procedure Abstraction Begins Chapter 6 in EAC The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing

### COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen

COP4020 Programming Languages Names, Scopes, and Bindings Prof. Robert van Engelen Overview Abstractions and names Binding time Object lifetime Object storage management Static allocation Stack allocation

### Lecture 7: Binding Time and Storage

Lecture 7: Binding Time and Storage COMP 524 Programming Language Concepts Stephen Olivier February 5, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of Lecture The

### Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

### Lecture 9: Procedures & Functions. CS 540 George Mason University

Lecture 9: Procedures & Functions CS 540 George Mason University Procedures/Functions Control Abstraction call/return semantics, parameters, recursion Controlled Namespace Scope (local/non-local), binding,

### Topic 3-a. Calling Convention 2/29/2008 1

Topic 3-a Calling Convention 2/29/2008 1 Calling Convention Calling convention is a standardized method for a program to pass parameters to a procedure and receive result values back from it. 2/29/2008

### 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:

What about Object-Oriented Languages? What is an OOL? A language that supports object-oriented programming How does an OOL differ from an ALL? (ALGOL-Like Language) Data-centric name scopes for values

### Imperative Programming

Naming, scoping, binding, etc. Instructor: Dr. B. Cheng Fall 2004 1 Imperative Programming The central feature of imperative languages are variables Variables are abstractions for memory cells in a Von

### 6. Names, Scopes, and Bindings

Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack

### Names, Bindings, Scopes

Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not

### Optimizer. Defining and preserving the meaning of the program

Where are we? Well understood Engineering Source Code Front End IR Optimizer IR Back End Machine code Errors The latter half of a compiler contains more open problems, more challenges, and more gray areas

### Chapter 3:: Names, Scopes, and Bindings

Chapter 3:: Names, Scopes, and Bindings Programming Language Pragmatics Michael L. Scott Some more things about NFAs/DFAs We said that a regular expression can be: A character (base case) A concatenation

### LECTURE 19. Subroutines and Parameter Passing

LECTURE 19 Subroutines and Parameter Passing ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments behind a simple name. Data abstraction: hide data

### 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/...)

### Procedures and Run-Time Storage

Procedures and Run-Time Storage Compiler Design CSE 504 1 Parameterless Procedures 2 Parameter Passing 3 Storage Organization Last modifled: Mon Mar 21 2016 at 12:11:19 EDT Version: 1.3 20:58:09 2012/04/09

### CSE 3302 Notes 5: Memory Management

CSE 0 Notes 5: Memory Management (Last updated 10/7/15 1:6 PM) References: Gabbrielli-Martini: 5 Wirth: 4 5.1. IMPLEMENTING SIMPLE SUBPROGRAMS Historical FORTRAN and COBOL Simple = no recursion static

### Run-time Environments - 3

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

### The Activation Record (AR)

The Activation Record (AR) [Notes adapted from R. Bodik] Code for function calls and function definitions depends on the layout of the activation record Very simple AR suffices for this language: The result

### 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

### Subroutines and Control Abstraction. CSE 307 Principles of Programming Languages Stony Brook University

Subroutines and Control Abstraction CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Subroutines Why use subroutines? Give a name to a task. We

### The Procedure Abstraction Part I Basics

The Procedure Abstraction Part I Basics Procedure Abstraction The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures Procedures

### Procedures and Run-Time Storage

Procedures and Run-Time Storage Compiler Design CSE 504 1 Parameterless Procedures 2 Parameter Passing 3 Storage Organization Last modifled: Mon Mar 21 2016 at 12:11:19 EDT Version: 1.3 20:58:09 2012/04/09

### Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

### Names and Abstractions: What s in a Name?

Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Names, Scopes, and Bindings Binding time Object lifetime Object storage management Static allocation Stack allocation Heap allocation