Runtime Environments I. Basilio B. Fraguela

Similar documents
Concepts Introduced in Chapter 7

Functions and Procedures

CA Compiler Construction

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

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

Run-Time Environments

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

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

Run-Time Environments

Scope, Functions, and Storage Management

Procedure and Object- Oriented Abstraction

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

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

Run-time Environment

Run-time Environments - 2

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

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

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

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

Implementing Subroutines. Outline [1]

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

Chapter 10. Implementing Subprograms

Implementing Subprograms

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

Run Time Environments

Runtime Support for Algol-Like Languages Comp 412

G Programming Languages - Fall 2012

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

The Procedure Abstraction Part I: Basics

Run-time Environments

Run-time Environments

CSE 504: Compiler Design. Runtime Environments

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

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

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

G Programming Languages - Fall 2012

The Procedure Abstraction

Properties of an identifier (and the object it represents) may be set at

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

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

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

The PCAT Programming Language Reference Manual

Compilation /15a Lecture 7. Activation Records Noam Rinetzky

Weeks 6&7: Procedures and Parameter Passing

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

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

Short Notes of CS201

System Software Assignment 1 Runtime Support for Procedures

The Decaf Language. 1 Lexical considerations

CS201 - Introduction to Programming Glossary By

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

Programming Languages

Implementing Subprograms

Run-Time Environements

Chapter 5. Names, Bindings, and Scopes

Memory Management and Run-Time Systems

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

Lecture 23: Object Lifetime and Garbage Collection

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

CS 314 Principles of Programming Languages

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

Programming Languages Third Edition. Chapter 7 Basic Semantics

Garbage Collection: recycling unused memory

Run-Time Data Structures

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

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Storage in Programs. largest. address. address

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

1 Lexical Considerations

Chapter 10 Implementing Subprograms

Run Time Environment

Lexical Considerations

Chapter 5 Object-Oriented Programming

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

The Procedure Abstraction Part I Basics

THEORY OF COMPILATION

What about Object-Oriented Languages?

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

Chapter 10. Implementing Subprograms ISBN

COMPILER DESIGN - RUN-TIME ENVIRONMENT

Chapter 5 Names, Binding, Type Checking and Scopes

Topic 7: Activation Records

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Lexical Considerations

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Chapter 3:: Names, Scopes, and Bindings

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

Run-time Environments - 3

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Optimizer. Defining and preserving the meaning of the program

CS 314 Principles of Programming Languages. Lecture 13

Implementing Subprograms

The Decaf language 1

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

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

Naming in OOLs and Storage Layout Comp 412

Lecture08: Scope and Lexical Address

Chapter 6 Introduction to Defining Classes

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

Transcription:

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 program uses to access data Runtime Environments 2

Data Storage Allocation Mostly dynamic Some things can be done statically Main dynamic allocation possibilities: Stack: data that do not outlive the procedure where it is declared Heap: remaining data Runtime Environments 3

From Names to Values Environment: mapping from (variable) names to store addresses State: mapping from addresses to their values Both mappings can be static or dynamic Declaration vs Definition Declarations specify types, interfaces Definitions provide values, implementations Runtime Environments 4

Scope of a Declaration The scope of a declaration of x is the context in which uses of x refer to this declaration Static or lexical scope: identifiable from program source code Usually relies on code block structure Dynamic scope: otherwise Runtime Environments 5

Static Scope based on Block Structure DECL A A DECL A A Runtime Environments 6

Explicit Access Control Specify who can access fields in a record/class Accessible members are usable in any subclass unless it redefines the member Encapsulation through explicit control using keywords E.g: C++ s public, private and protected Runtime Environments 7

Dynamic Scope Name resolution depends on most recently called function, without there being a redeclaration Macro expansion Polymorphic methods Runtime Environments 8

Stack Management Used for data whose usage is restricted to the procedure where it is declared or procedures it calls Each time a procedure is invoked, it reserves its space at the top of the stack When the procedure returns, its space is popped off the stack The stack structure is adequate because procedure calls (activations) nest in time If p calls q, q must finish before p can call another procedure or finish Runtime Environments 9

Activation Tree Represents the activation of procedures during the execution of the program Activations happen top-to-bottom and leftto-right (preorder traversal) Returns happen bottom-to-top and left-toright (postorder traversal) The activations open when control reaches a node of the tree are its ancestors Runtime Environments 10

Activation Records (or Frames) Stack space allocated for an activation of a procedure in the (control) stack Traditional representation: Root Activation Record Bottom of the stack Proc1 Activation Record Proc2 Activation Record Top of the stack Runtime Environments 11

What s Inside an Activation Record Runtime Environments 12

Procedure Call/Return Implementation The calling sequence fills in the activation record of the procedure called The return sequence restore the state upon return using the activation record Both can be a shared responsibility of the calling procedure (caller) and the called procedure (callee) In general it is better the callee does most work Runtime Environments 13

Usual Disposition of Data in the Activation Record Values communicated between caller and calle are usually put at the beginning Fields with a fixed width come in the middle Variable length data usually go at the end (top) of the record Dynamically sized arrays Top-of-stack pointer usually points to the end of the fixed-length fields Runtime Environments 14

Example Runtime Environments 15

Parameter Passing Mechanisms Association of formal and actual parameters policies: Call-by-value Call-by-reference Call-by-name (obsolete) Runtime Environments 16

Access to non-local data Simple for languages that do not allow nested procedure declarations: Variables are either local to the procedure Or globally/statically declared In languages with nested procedures the declaration for a non-local name can be found statically, but dynamic mechanisms are needed to find the relevant activation record of the caller that contains the data Runtime Environments 17

Access Link Points to most recent activation record for immediately enclosing function. Access links form a chain from the current (highest) nesting level activation record to the lowest one All accessible activation records are in the chain N hops to reach activation record with nesting depth current-n Runtime Environments 18

Access Link Calculation When q calls p: depth p > depth q q immediately encloses p Access link for p points to q s activation record depth p = depth q (mutually) recursive call Access link for p = Access link for q depth p > depth q both are nested inside a common procedure r depth(p) depth(q) hops to find access link for p Runtime Environments 19

Access Link Illustration Function s (depth 1) Function e (depth 2) Function q (depth 2) Function p (depth 3) Runtime Environments 20

Display Array d with one pointer per nesting depth d[i] points to highest activation record for any procedure at nesting level i Any variable defined in a procedure at nesting level i, can be found through d[i] No need to follow a chain of access links When a procedure overwrites d[i], it must first save it, then restore it when it returns Runtime Environments 21

Example of Display Evolution Function s (depth 1) Function e (depth 2) Function q (depth 2) Function p (depth 3) Runtime Environments 22