Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Chapter 5 ( ) of Programming Languages by Ravi Sethi
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
ISBN Chapter 10 Implementing Subprograms.
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)
ISBN Chapter 10 Implementing Subprograms.
Runtime Environments Source language issues Storage organization
Chapter 10 Storage Management Implementation details beyond programmer’s control Storage/CPU time trade-off Binding times to storage.
Run-Time Storage Organization
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Run time vs. Compile time
Catriel Beeri Pls/Winter 2004/5 environment 68  Some details of implementation As part of / extension of type-checking: Each declaration d(x) associated.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
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.
Presented by Dr Ioanna Dionysiou
CSC321: Programming Languages1 Programming Languages Tucker and Noonan Chapter 9: Functions 9.1 Basic Terminology 9.2 Function Call and Return 9.3 Parameters.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 9 Functions It is better to have 100 functions.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
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.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
Runtime Environments Compiler Construction Chapter 7.
Compiler Construction
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
1 Run-Time Environments. 2 Procedure Activation and Lifetime A procedure is activated when called The lifetime of an activation of a procedure is the.
Basic Semantics Associating meaning with language entities.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Programming Languages and Paradigms Imperative Programming.
ISBN Chapter 10 Implementing Subprograms.
BİL 744 Derleyici Gerçekleştirimi (Compiler Design)1 Run-Time Environments How do we allocate the space for the generated target code and the data object.
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,
Copyright © 2006 The McGraw-Hill Companies, Inc. Basic Terminology Value-returning functions: –known as “non-void functions/methods” in C/C++/Java –called.
國立台灣大學 資訊工程學系 薛智文 98 Spring Run Time Environments (textbook ch# 7.1–7.3 )
CSC 8505 Compiler Construction Runtime Environments.
7. Runtime Environments Zhang Zhizheng
1 Run-Time Environments Chapter 7 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
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.
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
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?
Run-Time Environments Chapter 7
Functions.
Names and Attributes Names are a key programming language feature
Subject Name Compiler Design Subject Code: 10CS63
Run-Time Storage Organization
Run-Time Storage Organization
Run-Time Environments
Run-Time Environments
Binding Times Binding is an association between two things Examples:
UNIT V Run Time Environments.
Programming Languages
Run Time Environments 薛智文
Run-time environments
Presentation transcript:

Chapter 7 Runtime Environments

Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures, variables, etc. Execution of a procedure -> activiation of the procedure Data objects (variables) within an activitaions The same procedure may have several activations alive at the same time (e.g. recursive)

Procedure Definition: a declaration associates an Idetifier with statements –The id is a procedure name –The body is statements –Optional parameters Formal parameters (definition) Actual parameters (arguments) –Local variables –References to global scope

Activation Tree: Procedure executions Each node represents an activation of procedure The root represents the activation of the main program The node for a is the parent of the node for b, if and only if control flows from a to b and The node for a is to the left of the node b if and only if the lifetime of a occurs before the life time of b (show examples in fig 7.2, 7.3)

Control Stack for Activation Tree Depth first traversal that starts from the root We can use stack to keep track of live procedure activations Can be extended to the stack storage- allocation technique (C or Pascal) (show figure 7.4 and the current control and activation life s, q(1,9), q(1,3) and 1(2,3)

The Scope of a Declaration Declaration a syntactic construct associating information with a name Scope rules determine which declarations of a name applies when the name appears in the program –Local –None-local –Special, static, volatile, final etc..

Name Bindings Data object is a storage location that can hold values Name storage value Programming language, –environment is a function that maps a name to a storage location –State is a function that maps a storage location to the value –L-value (name), l-value to r-value Binding is the dynamic counterpart of a declaration

Name Bindings Static NotionDynamic Notion Defintion of a procedure Activation of the procedure Declaration of a name Bindings of the name Scope of a declLifetime of a binding

Storage organization Runtime Storage can be subdevided as follows: –The generated target code –Data object –Control stack (keep track of procedure activitation)

Storage organization Code Static Data Stack data objects’ life in activations of procedure) Heap (other DOs,e.g dynamic mem allocation)

Activation Record A contiguous block of storage for maintaining info during a procedure activation Returned value Actual parameters Optional control link Optional access link (none-local) Saved machine status Local data temporaries

Storage Allocation Strategies Static allocation lays out storage for all Data objects during compile time Stack allocation manages the run-time storage as a stack Heap allocation allocates and deallocates stoages as needed at runtime from heap area Watchout for a dangling reference (garbage collections)

Parameter passing Call by value –A formal parameter is treated just like a local name. Its storage is in the activation record of the called procedure –The caller evaluates the actual parameter and place the r-value in the storage for the formals Call by reference Copy-Restore

Parameter passing Call by reference –If an actual parameter is a name or expression having L-value, then that l-value itself is passed –However, if it is not (e.g. a+b or 2) that has no l-value, then expression is evaluated in the new location and its address is passed.

Parameter passing Copy-Restore: Hybird between call-by- value and call-by-ref (copy in, copy out) –Actual parms evaluated, its r-value is passed and l-value of the actuals are determined –When the called procedure is done, r-value of the formals are copied back to the l-value of the actuals