Binding Times Binding is an association between two things Examples:

Slides:



Advertisements
Similar presentations
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Advertisements

CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
OS Fall’02 Memory Management Operating Systems Fall 2002.
Names, Bindings, Type Checking, and Scopes
ISBN Chapter 10 Implementing Subprograms.
Run-Time Storage Organization
Run time vs. Compile time
The Concept of Variables
Chapter 9: Subprogram Control
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.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
COP4020 Programming Languages
Name Binding and Object Lifetimes Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Binding Time and Storage Allocation (Section ) CSCI 431 Programming Languages Fall 2003 A modification of slides developed by Felix Hernandez-Campos.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Chapter 5 Names, Bindings, and Scopes. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 5 Topics Introduction Names Variables The Concept.
ISBN Chapter 5 Names, Bindings, and Scopes.
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.
1 Scope Rules (Section 3.3) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael Scott.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
Basic Semantics Associating meaning with language entities.
ISBN Chapter 5 Names, Bindings, and Scopes.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
COMP3190: Principle of Programming Languages
Memory Management Operating Systems CS550. Memory Manager Memory manager - manages allocation and de-allocation of main memory Plays significant impact.
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Programming Languages and Design Lecture 6 Names, Scopes and Binding Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
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
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
LECTURE 13 Names, Scopes, and Bindings: Memory Management Schemes.
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.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
ISBN Chapter 10 Implementing Subprograms.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Chapter 5 Names, Bindings, Type Checking CSCE 343.
Implementing Subprograms
Storage Allocation Mechanisms
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Run-Time Environments Chapter 7
Implementing Subprograms
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Type Checking, and Scopes
Names, Bindings, and Scopes
Chapter 10: Implementing Subprograms Sangho Ha
Implementing Subprograms
Names, Binding, and Scope
Programming Languages
Names and Binding In Text: Chapter 5.
Name Binding and Object Lifetimes
Names, Bindings, and Scopes
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
Types and Related Issues
Implementing Subprograms
Presentation transcript:

Binding Times Binding is an association between two things Examples: Name of a variable and its address Name of the operator and its meaning

Binding Time Language design time Examples: Control flow constructs Primitive types Meaning of the operators Syntactical structures of the language

Binding Time Language implementation time Examples: Sizes of primitive data types (int in C and C++) Sizes of stack, heap I/O facilities

Binding Time Compile time Examples: Mapping the code to the machine language Layout of the static data in memory

Binding Time Link time Example: Linkage between different modules that make up a program (when you use a function such a strcpy in your code, the code of the strcpy is not being linked to your main code until the link time)

Binding Time Run Time Examples: Local variables are bound at the run time Virtual function are bound at the run time

Binding time We normally refer to the binding that occurs before the run time as static binding and the binding that occurs at the run time as a dynamic binding

Binding Time Static binding Efficiency Flexibility Dynamic binding

Object Lifetime Static Objects – have an address that does not get changed through out the execution of the program. Static Objects exist all the time Stack Objects – are created normally when the subroutine in which they are defined is being invoked. Heap Objects – are created on demand from the free storage using something like new and delete

Stack Based Variables The variables that are defined in the functions are being created and put on the stack when the function in which they are defined is being invoked. Another words, we are creating those variables on the stack. When the function returns, those variables are being removed from the stack.

Allocation Each instance of the subroutine is represented on the stack by a frame. Each frame is going to contain the following information: Arguments Return values Local variables Static link Dynamic link

Frame

Recursion One of the main design decisions that is being made by the language designers is whether to allow recursion. If the recursion is not allowed do we really need the stack? Why or why not? What are the advantages and disadvantages of each solution?

Heap Heap is the region where the space is being allocated and deallocated by new and delete

Fragmentation The major issue with heap allocation is fragmentation Internal fragmentation occurs when the allocated block of memory is bigger than the memory needed. Why is this bad? External fragmentation occurs when the free blocks are scattered through out the memory. Why is this bad?

Fragmentation

Allocation Algorithms First fit – might not be optimal, but is very fast Best fit – closer to be optimal, but is more expensive Different block sizes lists can be used to speed up the search of the free block. Two examples are buddy system in which the power of two is used and Fibonacci heaps in which Fibonacci numbers are being used.

Scope The scope of the variable is the area of the program in which a given variable is visible Statically scoped languages define the scope of the variable at the compile time Dynamically scoped languages define the scope of the variable at the run time

Static Scope

Static Link

Dynamic Scope Dynamic Scope - Based on calling sequences of program units, not their textual layout (temporal versus spatial) - References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this Point

Dynamic Scope MAIN begin declaration of x SUB1 declaration of x - call SUB2 end SUB2 reference to x - call SUB1

Dynamic Scope MAIN calls SUB1 SUB1 calls SUB2 SUB2 uses x Static scoping - reference to x is to MAIN's x Dynamic scoping - reference to x is to SUB1's x