Today's Topics. Last Time Modelling Scopes and Visibility The Run Stack, the Dynamic Pointer Stack, the Display (LL,ON) addressing

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

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

Concepts Introduced in Chapter 7

Special Topics: Programming Languages

CSE 307: Principles of Programming Languages

CS 314 Principles of Programming Languages. Lecture 13

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule

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

CS450: Structure of Higher Level Languages Spring 2018 Assignment 7 Due: Wednesday, April 18, 2018

CIT Week13 Lecture

LECTURE 14. Names, Scopes, and Bindings: Scopes

Semantic Analysis and Type Checking

Special Topics: Programming Languages

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.

Programming Languages Third Edition. Chapter 7 Basic Semantics

CS 345. Functions. Vitaly Shmatikov. slide 1

Parsing Scheme (+ (* 2 3) 1) * 1

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

Names, Scopes, and Bindings II. Hwansoo Han

Lecture 5. Announcements: Today: Finish up functions in MIPS

CSCI312 Principles of Programming Languages!

Project Compiler. CS031 TA Help Session November 28, 2011

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

Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Chapter 5 Names, Binding, Type Checking and Scopes

MIDTERM EXAM (Solutions)

Functions in MIPS. Functions in MIPS 1

CSC 2400: Computer Systems. Using the Stack for Function Calls

Run-time Environments - 2

Lecture08: Scope and Lexical Address

Programming Languages

CS 314 Principles of Programming Languages

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

The compilation process is driven by the syntactic structure of the program as discovered by the parser

CS 4100 Block Structured Languages. Fixed vs Variable. Activation Record. Activation Records. State of an Activation

The Procedure Abstraction Part I: Basics

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

COP5621 Exam 4 - Spring 2005

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Principles of Programming Languages

Acknowledgement. CS Compiler Design. Semantic Processing. Alternatives for semantic processing. Intro to Semantic Analysis. V.

Chapter 8 ( ) Control Abstraction. Subprograms Issues related to subprograms How is control transferred to & from the subprogram?

Systems I. Machine-Level Programming V: Procedures

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

Run-time Environments

Run-time Environments

System Software Assignment 1 Runtime Support for Procedures

Intermediate Representations & Symbol Tables

Today. Putting it all together

Procedures: Advanced Topics Chapter 12

Parameter passing. Parameter: A variable in a procedure that represents some other data from the procedure that invoked the given procedure.

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

Implementing Subprograms

The Compiler So Far. Lexical analysis Detects inputs with illegal tokens. Overview of Semantic Analysis

CA Compiler Construction

Stacks and Function Calls

Weeks 6&7: Procedures and Parameter Passing

Chapter 3:: Names, Scopes, and Bindings (cont.)

CA Compiler Construction

Chapter 3:: Names, Scopes, and Bindings (cont.)

CS1150 Principles of Computer Science Methods

Announcements. Scope, Function Calls and Storage Management. Block Structured Languages. Topics. Examples. Simplified Machine Model.

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

Principles of Programming Languages

CS 230 Programming Languages

G Programming Languages - Fall 2012

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

Functions and Recursion

Implementing Subprograms

LECTURE 18. Control Flow

Segmentation in Assembly Language Programming

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

Programming Languages, Summary CSC419; Odelia Schwartz

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Wednesday, October 15, 14. Functions

Code Generation & Parameter Passing

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

2/6/2018. Let s Act Like Compilers! ECE 220: Computer Systems & Programming. Decompose Finding Absolute Value

22c:111 Programming Language Concepts. Fall Functions

CS213. Machine-Level Programming III: Procedures

Assembly Language: Function Calls

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

CS 211. Project 5 Infix Expression Evaluation

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

The Procedure Abstraction

Memory Management and Run-Time Systems

Chapter 10. Implementing Subprograms ISBN

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

ASSEMBLY III: PROCEDURES. Jo, Heeseung

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

Assembly III: Procedures. Jo, Heeseung

TYPES, VALUES AND DECLARATIONS

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

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

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Run Time Environments

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

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Transcription:

Today's Topics Last Time Modelling Scopes and Visibility The Run Stack, the Dynamic Pointer Stack, the (LL,ON) addressing Today Maintaining the Kinds of parameters and parameter passing

(LL,ON) Address Calculation At run time, the address of a variable in the Run Stack is computed from its (LL,ON) [ [LL] + ON] is the storage for variable (LL,ON) [LL] is the base of the storage for the scope, and ON is the displacement of the particular variable within that storage w u z y x var x: integer; procedure p; var y: integer;, z: integer;, procedure q; var w: integer; end q; procedure r; var u : integer; q; end r; r; end p; p; DPS procedure q procedure r procedure p global

Maintaining the On entry to q, must set [] to the space for q On exit from q, must reset [] to the space for r In this simple case, not so difficult since DPS has it directly w u z y x var x: integer; procedure p; var y: integer; z: integer; procedure q; var w: integer; end q; procedure r; var u : integer; q; end r; r; end p; p; DPS procedure q procedure r procedure p global

var x: integer; procedure m; var s; end m; procedure p; var y: integer; z: integer; procedure r; var u : integer; m; end r; r; end p; p; s Maintaining the u z y x Not always so easy - when calls are made "uplevel", restoring the may not be so simple Example: When we leave m, we must restore [] to point to the frame for p Somehow we must keep track of which is the previous scope at the same lexical level DPS procedure m procedure r procedure p global

var x: integer; procedure m; var s; end m; procedure p; var y: integer; z: integer; procedure r; var u : integer; m; end r; r; end p; p; s Maintaining the u z y x There are many ways we could keep track - one of the simplest is to store the lexical level for each scope in the DPS Now when we leave m, we look down the DPS for the next entry with the same lexical level - in this case it is the scope of procedure p procedure m procedure r procedure p global DPS LL

Maintaining the In practical solutions, the previous entry at the lexical level is stored in the DPS, eliminating the search On entry to a scope at LL, the previous [LL] pointer is stored in the DPS before setting [LL] to the new scope base On exit from a scope at LL, [LL] is simply set to the previous [LL] entry stored in the DPS s u z procedure m procedure r y x procedure p global DPS Prev LL

Maintaining the Optimized solutions do even better, storing the previous DPS pointer and pointers for a new scope directly in the itself, eliminating the DPS entirely This is called dynamic chaining (for the DPS pointers) and static chaining (for the pointers) s u z y x

Parameters Languages have several kinds of parameter passing: Pass by Value A copy of the argument value is passed Changes to parameter do not affect the original argument variable Expressions may be used as arguments - value is computed and passed as the value of the parameter Java, default parameter in Pascal Pass by Reference A reference (pointer) to the original argument variable is passed Inside the procedure, the pointer is implicitly dereferenced, changes to the parameter change the original argument variable Argument must be a variable, expressions are not allowed var parameter in Pascal, Turing, PL/I

Parameters (cont'd) Languages have several kinds of parameter passing: Pass by Name The actual source text of the argument expression is passed Substituted and evaluated in the context of its use inside the procedure Can be useful, but confusing and not used in recent languages Available in Algol 6, Algol 68 - not in Pascal Pass by Value-Result Similar to pass by value, but at the end of the procedure the final parameter value is assigned back to the original argument variable Algol W, Euclid, Ada

Value Parameters Parameters are modeled in the abstract machine as the first local variables in the procedure's scope in the We push them on to the Run Stack before calling the procedure, then set up the DPS and to point at them as the base of the scope (makes setting up and DPS slightly more complicated) Order Numbers (ON) of local variables start with the parameters of the procedure var a,b: integer; procedure p (y: integer); var x: integer; x := 4; end p; a := 7; b := 3; p(a); 4 7 7 x (,) y (,) 3 b (,) a (,)

Reference Parameters Pass by reference means passing the address ( stack index) of the argument variable as the value of the parameter Inside the procedure, we interpret the value of the parameter as a memory address ( stack index) of the real parameter var a,b: integer; procedure p (var y: integer); var x: integer; x := 4; end p; a := 7; b := 3; p(a); 4 x (,) y (,) 3 b (,) 7 a (,)

Parameter Passing Parameter passing requires some new instructions for our abstract machine model Two new instructions are needed: pushaddress (LL,ON) like push, but pushes the address of the variable onto the ES instead of its value passparameter To pass variable z as a value parameter : push (LLz,ONz) passparameter To pass z as a reference parameter : pushaddress (LLz, ONz) passparameter pops the top value in the ES and pushes it onto the push the value of z onto the ES pop z's value from ES and push it on push the index of z onto ES pop z's address from ES and push it on

Summary Modelling Scopes and Visibility Maintaining the Kinds of parameters and parameter passing Next Model for procedures and functions