1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Names and Bindings.
CSE 5317/4305 L7: Run-Time Storage Organization1 Run-Time Storage Organization Leonidas Fegaras.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
PSUCS322 HM 1 Languages and Compiler Design II Runtime System Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Chapter 10 Storage management
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)
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
ISBN Chapter 10 Implementing Subprograms.
Runtime Environments Source language issues Storage organization
Run-Time Storage Organization
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Run time vs. Compile time
The Concept of Variables
Semantics of Calls and Returns
Chapter 9: Subprogram Control
Run-time Environment and Program Organization
ISBN Chapter 10 Implementing Subprograms –Semantics of Calls and Returns –Implementing “Simple” Subprograms –Implementing Subprograms with.
1 CSCI 360 Survey Of Programming Languages 9 – Implementing Subprograms Spring, 2008 Doug L Hoffman, PhD.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
COP4020 Programming Languages
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
ISBN Chapter 10 Implementing Subprograms.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Runtime Environments Compiler Construction Chapter 7.
Compiler Construction
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
Storage Bindings Allocation is the process by which the memory cell or collection of memory cells is assigned to a variable. These cells are taken from.
Basic Semantics Associating meaning with language entities.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
Programming Languages and Paradigms Imperative Programming.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
COMP3190: Principle of Programming Languages
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
國立台灣大學 資訊工程學系 薛智文 98 Spring Run Time Environments (textbook ch# 7.1–7.3 )
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
Names, Scope, and Bindings Programming Languages and Paradigms.
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
ISBN Chapter 10 Implementing Subprograms.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
ISBN Chapter 10 Implementing Subprograms.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Object Lifetime and Pointers
Data Types In Text: Chapter 6.
Binding Times Binding is an association between two things Examples:
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
UNIT V Run Time Environments.
Programming Languages
Run Time Environments 薛智文
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Run-time environments
Presentation transcript:

1 Contents

2 Run-Time Storage Organization

3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static. In many early languages, notably assembly and FORTRAN, all storage allocation is static. Space for data objects is allocated in a fixed location for the lifetime of a program. Space for data objects is allocated in a fixed location for the lifetime of a program. The number and size of all objects to be allocated is known at compile-time. The number and size of all objects to be allocated is known at compile-time. Static allocation is used both for global variables and constants. Static allocation is used both for global variables and constants. Static allocation is also used for local variables, e.g., static and extern in C Static allocation is also used for local variables, e.g., static and extern in C Disadvantage Disadvantage Wasteful of space Wasteful of space

4 Stack Allocation (Cont’d.) Recursive procedures, a feature that requires dynamic allocation. Recursive procedures, a feature that requires dynamic allocation. Each recursive call requires the allocation of a new copy of a procedure’s local variables. Each recursive call requires the allocation of a new copy of a procedure’s local variables. The number of data objects required during program execution is not known at compile-time. The number of data objects required during program execution is not known at compile-time. Activation record (AR) Activation record (AR) An AR is used to store all the data space required for a procedure or function. An AR is used to store all the data space required for a procedure or function. An AR is pushed onto a run-time stack when the procedure or function is called An AR is pushed onto a run-time stack when the procedure or function is called When is subporgram returns, the AR is popped. When is subporgram returns, the AR is popped.

5 Stack Allocation (Cont’d.)

6

7 Dynamic arrays Dynamic arrays The bounds of dynamic arrays are determined at run-time rather than compile-time, hence these arrays cannot be allocated within an AR. The bounds of dynamic arrays are determined at run-time rather than compile-time, hence these arrays cannot be allocated within an AR. Dynamic arrays can be allocated as soon as their associated declarations are elaborated. Dynamic arrays can be allocated as soon as their associated declarations are elaborated.

8 Stack Allocation (Cont’d.)

9

10 Stack Allocation (Cont’d.)

11 Stack Allocation (Cont’d.)

12 Stack Allocation (Cont’d.)

13 Stack Allocation (Cont’d.)

14 Stack Allocation (Cont’d.)

15 Stack Allocation (Cont’d.)

16 Stack Allocation (Cont’d.)

17 Heap Allocation

18 Heap Allocation (Cont’d.) Three methods for deallocation Three methods for deallocation No deallocation No deallocation Explicit deallocation Explicit deallocation

19 Heap Allocation (Cont’d.)

20 Program Layout in Memory

21 Program Layout in Memory (Cont’d.)

22 Static and Dynamic Chains

23 Static and Dynamic Chains (Cont’d.)

24 Formal Procedures

25 Formal Procedures (Cont’d.)

26 Formal Procedures (Cont’d.)

27 Formal Procedures (Cont’d.)

28 Formal Procedures (Cont’d.)

29 Formal Procedures (Cont’d.)

30 Chapter 10 Processing Declarations Declaration Processing Fundamentals Declaration Processing Fundamentals Action Routines for Simple Declarations Action Routines for Simple Declarations Action Routines for Advanced Features Action Routines for Advanced Features

31 Chapter 11 Processing Expressions and Data Structure References Action Routines for Simple Names, Expressions, and Structures Action Routines for Simple Names, Expressions, and Structures Array References and Records Array References and Records Action Routines for Advantage Features Action Routines for Advantage Features

32 Chapter 12 Translating Control Structures if Statements if Statements loops loops while loops while loops for loops for loops The case Statement The case Statement Short-circuit Boolean Expressions Short-circuit Boolean Expressions

33 Chapter 13 Translating Procedures and Functions Simple Subprograms Simple Subprograms Passing Parameters to Subprograms Passing Parameters to Subprograms Processing Subprogram Calls and Parameter Lists Processing Subprogram Calls and Parameter Lists Subprogram Invocation Subprogram Invocation