More on Runtime Environments. Procedure Parameters (in Pascal) Traditional Stack Scheme. Restrictions in C & Pascal. code.

Size: px
Start display at page:

Download "More on Runtime Environments. Procedure Parameters (in Pascal) Traditional Stack Scheme. Restrictions in C & Pascal. code."

Transcription

1 More on Rntime Environments How to efficiently implement procedre call and retrn in the presence of higher-order fnctions? 1. what are higher-order fnctions? 2. how to ext frames to spport higher-order fnctions? 3. efficiency isses (exection time, space sage)? How to efficiently spport memory allocation and de-allocation? 1. what are the data representations? 2. what are the memory layot? 3. explicit vs implicit memory de-allocation? (malloc-free vs. garbage collection) rocedre arameters (in ascal) rocedre parameters permit procedres to be invoked ot-of-scope ; 1 program main(inpt, otpt); 2 3 procedre b(fnction h(n : integer): integer); 4 var m : integer; 5 begin m := 6; writeln(h(2)) ; 6 7 procedre c; 8 var m : integer; 9 fnction f(n: integer): integer; 10 begin f := m + n ; 11 begin m := 0; b(f) ; 12 begin c. Qestion: how to get the correct environment when calling h inside b? Soltion: mst pass static link along with f as if it had been called at the point it was passed (line 11). Copyright Zhong Shao, ale University More on Rntime Environments: age 1 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 2 of 32 Restrictions in C & ascal C does not allow nested procedres --- names in C are either local to some procedre or are global and visible in all procedres. rocedres in C can be passed as argments or retrned as reslts. program conter Traditional Stack Scheme STACK (activation records) parameters and retrned vales ascal (or Modla-2, Modla-3, Algol ) allows procedre declarations to be nested, bt procedre parameters are of restricted se, and procedres cannot be retrned as reslt. Fnctional langages (e.g. ML, Haskell, Scheme, Lisp) spport higherorder fnctions --- spporting both nested procedres and procedres passed as parameters or retrned as reslts. code REGISTERS HEA (dynamic data) STATIC (code and globals) links and saved stats temporaries and local data Activation Record garbage collector spporting it is a big challenge to the compiler writers! Memory Layot Copyright Zhong Shao, ale University More on Rntime Environments: age 3 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 4 of 32

2 rocedre Activations rocedre Activations (cont d) ested Fnctions in ML val BIG = big()... (v,,,y)... in... Q()... val reslt = (BIG,0,0,0) control links v=big w=x=y=0 Q, R access links ested Fnctions in ML val BIG = big()... (v,,,y)... in... Q()... val reslt = (BIG,0,0,0) control links v=big w=x=y=0 Q, R v=v,w= x=,y=y Q, access links Copyright Zhong Shao, ale University More on Rntime Environments: age 5 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 6 of 32 Higher-Order Fnctions Higher-Order Fnctions (cont d) How to create a closre for Q? v=big w=x=y=0 Q lost track of its environment val reslt = S() Q val reslt = S() Q Copyright Zhong Shao, ale University More on Rntime Environments: age 7 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 8 of 32

3 Higher-Order Fnctions (cont d) Higher-Order Fnctions (cont d) Q mst copy the frame! v=big w=x=y=0 Q s environment is in the! val reslt = S() val reslt = S() Copyright Zhong Shao, ale University More on Rntime Environments: age 9 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 10 of 32 Applying Higher-Order Fnctions ested Higher-Order Fnctions Accessing the Closre Q! val reslt = S() Qor S R val reslt = T() Qor S R Copyright Zhong Shao, ale University More on Rntime Environments: age 11 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 12 of 32

4 Linked Closres Flat Closres R or T R or T val reslt = T() R val reslt = T() R w x y copying!!! Fast creation, Slow access! Slow creation, Fast access! Copyright Zhong Shao, ale University More on Rntime Environments: age 13 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 14 of 32 Better Representations? Closres cannot point to frame (different life time, so yo mst copy.) Linked closres --- fast creation, slow access Flat closres --- slow creation, fast access Stack frames with access links are similar to linked closres (accessing non-local variables is slow.) GOAL : We need good closre representations that have both fast access and fast creation! Space Usage Space Leaks for Linked Closres (,w+x+y+3) fn loop (n,res) = if n<1 then res else ( val S = (big(),0,0,0) in loop(n-1,t::res) ) val reslt = loop(,[]) Linked Closres : O( 2 ) R -1 Flat Closres : O() R w x y Copyright Zhong Shao, ale University More on Rntime Environments: age 15 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 16 of 32

5 Space Usage (cont d) Better Space Usage? Space Leaks for Stack Allocations fn (x) =... fn Q(n) = val = big(n) val v = () val w = hd() in if n > 0 then Q(n-1)+v(w) else... val reslt = Q() Q,v,w n= Q,v,w n=-1 Q,v,w n= Use O( 2 ) Space! is dead after this call! The safe for space complexity rle : Local variable mst be assmed dead after its last se within its scope! Stacks and linked closres are OT safe for space Flat closres are safe for space SML/J : nsafe version = (2 to 80) x safe version Copyright Zhong Shao, ale University More on Rntime Environments: age 17 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 18 of 32 Drawbacks of Stack Allocation inefficient space sage slow access to non-local variables expensive copying between and (activation records cannot be shared by closres) scanning roots is expensive in generational GC very slow first-class continations (call/cc) correct implementation is complicated and messy Efficient Heap-based Compilation An efficient -based scheme has the following advantages: very good space sage (safe for space complexity!) very fast closre creation and closre access closres can be shared with activation records fast call/cc and fast generational GC simple implementation Copyright Zhong Shao, ale University More on Rntime Environments: age 19 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 20 of 32

6 re Heap-based Scheme Safely Linked Closres Safe for Space : se O() space THE TRICK: program conter code REGISTERS HEA (dynamic data) (activation records) STATIC (code and globals) Memory Layot Ideas: no rntime! safely linked closres good se of registers garbage collector (,w+x+y+3) fn loop (n,res) = if n<1 then res else ( val S = (big(),0,0,0) in loop(n-1,t::res) ) val reslt = loop(,[]) Variables w,x,y have same life time! R Q v -1 w x y Copyright Zhong Shao, ale University More on Rntime Environments: age 21 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 22 of 32 Safely Linked Closres (cont d) Shorter Access ath! fn S() = w+x+y+3 in (S,) val T = (big(),0,0,0) THE TRICK: Variables w,x,y have same life time! R Q v S w x y Good Use of Registers To avoid memory traffic, modern compilers often pass argments, retrn reslts, and allocate local variables in machine registers. Typical parameter-passing convention on modern machines: the first k argments ( k = 4 or 6) of a fnction are passed in registers R p,..., R p+k-1, the rest are passed on the. roblem : extra memory traffic cased by passing args. in registers fnction g(x : int, y : int, z :int) : int = x*y*z fnction f(x : int, y : int, z : int) = val a := g(z+3, y+3, x+4) in a*x+y+z The nmber of links traversed is at most Sppose fnction f and g pass their argments 1, R 2, R 3 ; then f mst save R 1, R 2, and R 3 to the memory before calling g, Copyright Zhong Shao, ale University More on Rntime Environments: age 23 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 24 of 32

7 Good Use of Registers (cont d) how to avoid extra memory traffic? Leaf procedres (or fnctions) are procedres that do not call other procedres; e.g, the fnction exchange. The parameters of leaf procedres can be allocated in registers withot casing any extra memory traffic. Closres egisters? o! Modle FOO: (in file foo.sml ) fn pred(x) =...v(w,x)... val reslt = BAR.filter(pred,...) Modle BAR : (in file bar.sml ) pred is an escaping fnction! Its closre mst be bilt on the! Use global register allocation, different fnctions se different set of registers to pass their argments. Use register windows (as on SARC) --- each fnction invocation can allocate a fresh set of registers. Allocate closres in registers or se callee-save registers When all fails --- save to the frame or to the. fn filter(p,l) = fn h(s,z) = if (s=[]) then rev z else ( val a = car s val r = cdr s in if p a then h(r,a::z) else h(r,z) ) in h(l,[]) Escaping fnctions: fnctions whose call sites are not all known at compile time! Copyright Zhong Shao, ale University More on Rntime Environments: age 25 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 26 of 32 Closres egisters? es! Lambda Lifting fn filter(p,l) = Known fnctions: fn filter(p,l) = fn h(s,z) = if (s=[]) then rev z else ( val a = car s val r = cdr s in if p a then h(r,a::z) else h(r,z) ) fnctions whose call sites are all known at compile time! h fn h(s,z,rev,p) = if (s=[]) then rev z else ( val a = car s val r = cdr s in if p a then h(r,a::z,rev,p) else h(r,z,rev,p) ) r 0 r 1 r 2 r 3 s z rev p h s=[] in h(l,[]) h is a known fnction! Its closre can be pt in registers! (e.g., {rev,p}) s=[] p a rev z in h(l,[],rev,p) known fnctions can be rewritten into fnctions that are flly closed! (i.e. with no free variables!) p a rev z Copyright Zhong Shao, ale University More on Rntime Environments: age 27 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 28 of 32

8 Spilled Activation Records Callee-save Registers We do not know how p treats the registers! a::z h r 0 r 1 r 2 r 3 r 4 r 5 s z rev p s=[] r 0 r 1 r 2 r 3 r 4 r 5 r z rev p a Convention : Reserve k special registers! Every fnction promises to always preserve these registers! Example : k=3 (r 4,r 5,r 6 ) f g general registers r 0 r 1 r 2 r 3 g v w g v x callee-save registers r 4 r 5 r 6 A B C w g A B C r 0 r 1 r 2 r 3 r 4 r 5 r rev p a p a Mst save and load everything here! r 0 r 1 r 2 r 3 r 4 r 5 r z rev p a rev z fn f(g,,v,w) = val x = g(,v) val y = g(x,w) in x+y+w g f retrn g x w y w x A B C Copyright Zhong Shao, ale University More on Rntime Environments: age 29 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 30 of 32 Callee-save Registers (cont d) 6 callee-save registers : r 4,r 5,r 6,r 7,r 8,r 9 a::z s=[] r 4 r 5 r 6 r 7 r 8 r 9 p a r rev p a no need to save and load anymore! h r 0 r 1 r 2 r 3 s z rev p r 4 r 5 r 6 r 7 r 8 r 9 s z rev p r 4 r 5 r 6 r 7 r 8 r 9 r z rev p a r 4 r 5 r 6 r 7 r 8 r 9 r z rev p a r 4 r 5 r 6 r 7 r 8 r 9 A B C D E F A B C D E F recover everything! rev z Smmary : A Uniform Soltion Take advantage of variable life time and compiime control flow information! Spilled activation records are also thoght as closres! no rntime everything is sharable all se safely-linked closres to maximize sharing pass argments and retrn reslts in registers allocating most closres in registers good se of callee-save registers Copyright Zhong Shao, ale University More on Rntime Environments: age 31 of 32 Copyright Zhong Shao, ale University More on Rntime Environments: age 32 of 32

CS421 COMPILERS AND INTERPRETERS. the point it was passed (line 11). explicit vs implicit memory de-allocation? (malloc-free vs. garbage collection)

CS421 COMPILERS AND INTERPRETERS. the point it was passed (line 11). explicit vs implicit memory de-allocation? (malloc-free vs. garbage collection) rocedre arameters (in ascal) rocedre parameters permit procedres to be invoked ot-of-scope ; 1 program main(inpt, otpt); 2 3 procedre b(fnction h(n : integer): integer); 4 var m : integer; 5 begin m :=

More information

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

Typical Runtime Layout. Tiger Runtime Environments. Example: Nested Functions. Activation Trees. code. Memory Layout Tiger Runtime Environments Compile-time environments are just symbol tables; they are used to assist static semantic analysis, code generation and code optimization. Run-time environments are about how

More information

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

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8 Subroutines and Control Abstraction Textbook, Chapter 8 1 Subroutines and Control Abstraction Mechanisms for process abstraction Single entry (except FORTRAN, PL/I) Caller is suspended Control returns

More information

Concepts Introduced in Chapter 7

Concepts Introduced in Chapter 7 Concepts Introduced in Chapter 7 Storage Allocation Strategies Static Stack Heap Activation Records Access to Nonlocal Names Access links followed by Fig. 7.1 EECS 665 Compiler Construction 1 Activation

More information

Scope, Functions, and Storage Management

Scope, Functions, and Storage Management Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)

More information

The Volcano Optimizer Generator: Extensibility and Efficient Search

The Volcano Optimizer Generator: Extensibility and Efficient Search The Volcano Optimizer Generator: Extensibility and Efficient Search - Prithvi Lakshminarayanan - 301313262 Athors Goetz Graefe, Portland State University Won the Most Inflential Paper award in 1993 Worked

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 26: Dynamic Memory (2) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 25: Dynamic Memory (1) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

Weeks 6&7: Procedures and Parameter Passing

Weeks 6&7: Procedures and Parameter Passing CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45

More information

Contents. 8-1 Copyright (c) N. Afshartous

Contents. 8-1 Copyright (c) N. Afshartous Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10 Introduction to Object-Oriented

More information

Control in Sequential Languages

Control in Sequential Languages CS 242 2012 Control in Sequential Languages Reading: Chapter 8, Sections 8.1 8.3 (only) Section 7.3 of The Haskell 98 Report, Exception Handling in the I/O Monad, http://www.haskell.org/onlinelibrary/io-13.html

More information

EXAMINATIONS 2010 END OF YEAR NWEN 242 COMPUTER ORGANIZATION

EXAMINATIONS 2010 END OF YEAR NWEN 242 COMPUTER ORGANIZATION EXAINATIONS 2010 END OF YEAR COPUTER ORGANIZATION Time Allowed: 3 Hors (180 mintes) Instrctions: Answer all qestions. ake sre yor answers are clear and to the point. Calclators and paper foreign langage

More information

Topic 7: Activation Records

Topic 7: Activation Records Topic 7: Activation Records Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Storage Organization Stack Free Memory Heap Static Code 2 ELF file format example Executable Object

More information

Names, Bindings, Scopes

Names, Bindings, Scopes Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not

More information

More eamples with half half(0) handle Zero => 1000; > val it = 1000 : int half(1) handle Zero => 1000; > ncaght eception Odd half(0) handle Zero => 10

More eamples with half half(0) handle Zero => 1000; > val it = 1000 : int half(1) handle Zero => 1000; > ncaght eception Odd half(0) handle Zero => 10 Lectre 4 0 More eamples with half half(0) handle Zero => 1000; > val it = 1000 : int half(1) handle Zero => 1000; > ncaght eception Odd half(0) handle Zero => 1000 Odd => 1001; > val it = 1000 : int half(3)

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

More information

Run-time Environments

Run-time Environments Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

More information

Run-time Environments

Run-time Environments Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

More information

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

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

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction Procedure Abstraction Run Time Environment Records Procedure Linkage Name Translation and Variable Access Copyright 2010, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at

More information

Hardware Design Tips. Outline

Hardware Design Tips. Outline Hardware Design Tips EE 36 University of Hawaii EE 36 Fall 23 University of Hawaii Otline Verilog: some sbleties Simlators Test Benching Implementing the IPS Actally a simplified 6 bit version EE 36 Fall

More information

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

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

More information

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC330 Fall 2018 1 Memory Attributes Memory to store data in programming languages has the following lifecycle

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 8: Threads Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Processes P1 P2 Recall that Bt OS A process

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 4a Andrew Tolmach Portland State University 1994-2016 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

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

Procedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End COMP 412 FALL 2017 Procedure and Function Calls, Part II Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

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

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention Runtime Environment The Procedure Abstraction and Separate Compilation Topics we will cover The procedure abstraction and linkage conventions Runtime storage convention Non-local data access (brief) These

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 9: Synchronization (1) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Cooperation between Threads

More information

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

CS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Procedure Abstractions These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Where are we? Well understood Engineering Source Code

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 2: Historical Perspective Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time What is an OS?

More information

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

Run Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access Run Time Environment Activation Records Procedure Linkage Name Translation and Variable Access Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University

More information

CAPL Scripting Quickstart

CAPL Scripting Quickstart CAPL Scripting Qickstart CAPL (Commnication Access Programming Langage) For CANalyzer and CANoe V1.01 2015-12-03 Agenda Important information before getting started 3 Visal Seqencer (GUI based programming

More information

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

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 23: File Systems (2) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time Abstractions for the

More information

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: Static Data Structures Outline of Lecture 18 Recap:

More information

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

Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; : Runtime Environment Relationship between names and data objects (of target machine) Allocation & de-allocation is managed by run time support package Each execution of a procedure is an activation of the

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 18: Code Generation V (Implementation of Dynamic Data Structures) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC 330 - Spring 2013 1 Memory Attributes! Memory to store data in programming languages has the following lifecycle

More information

Minimum Spanning Trees Outline: MST

Minimum Spanning Trees Outline: MST Minimm Spanning Trees Otline: MST Minimm Spanning Tree Generic MST Algorithm Krskal s Algorithm (Edge Based) Prim s Algorithm (Vertex Based) Spanning Tree A spanning tree of G is a sbgraph which is tree

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

Automatic Memory Management

Automatic Memory Management Automatic Memory Management Why Automatic Memory Management? Storage management is still a hard problem in modern programming Why Automatic Memory Management? Storage management is still a hard problem

More information

C Puzzles The course that gives CMU its Zip! Integer Arithmetic Operations Jan. 25, Unsigned Addition. Visualizing Integer Addition

C Puzzles The course that gives CMU its Zip! Integer Arithmetic Operations Jan. 25, Unsigned Addition. Visualizing Integer Addition 1513 The corse that gies CMU its Zip! Integer Arithmetic Operations Jan. 5, 1 Topics Basic operations Addition, negation, mltiplication Programming Implications Conseqences of oerflow Using shifts to perform

More information

System Software Assignment 1 Runtime Support for Procedures

System Software Assignment 1 Runtime Support for Procedures System Software Assignment 1 Runtime Support for Procedures Exercise 1: Nested procedures Some programming languages like Oberon and Pascal support nested procedures. 1. Find a run-time structure for such

More information

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage Storage 1 Variables and Updating Outline Composite Variables Total and selective updating Array variables Storables Lifetime Local and global variables Heap variables Persistent variables Garbage collection

More information

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

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13 Run-time Environments Lecture 13 by Prof. Vijay Ganesh) Lecture 13 1 What have we covered so far? We have covered the front-end phases Lexical analysis (Lexer, regular expressions,...) Parsing (CFG, Top-down,

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables

More information

Dr Paolo Guagliardo. Fall 2018

Dr Paolo Guagliardo. Fall 2018 The NULL vale Dr Paolo Gagliardo dbs-lectrer@ed.ac.k Fall 2018 NULL: all-prpose marker to represent incomplete information Main sorce of problems and inconsistencies... this topic cannot be described in

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 3: OS model and Architectral Spport Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time/today

More information

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

More information

CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages. Spring 2005 CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

More information

Lecture 13: Complex Types and Garbage Collection

Lecture 13: Complex Types and Garbage Collection Lecture 13: Complex Types and Garbage Collection COMP 524 Programming Language Concepts Stephen Olivier March 17, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from

More information

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

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1 Compilers 8. Run-time Support Laszlo Böszörmenyi Compilers Run-time - 1 Run-Time Environment A compiler needs an abstract model of the runtime environment of the compiled code It must generate code for

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

The Procedure Abstraction Part I Basics

The Procedure Abstraction Part I Basics The Procedure Abstraction Part I Basics Procedure Abstraction The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures Procedures

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 11: Semaphores Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time Worked throgh software implementation

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC 330 Spring 2017 1 Memory Attributes Memory to store data in programming languages has the following lifecycle

More information

One-Slide Summary. Lecture Outine. Automatic Memory Management #1. Why Automatic Memory Management? Garbage Collection.

One-Slide Summary. Lecture Outine. Automatic Memory Management #1. Why Automatic Memory Management? Garbage Collection. Automatic Memory Management #1 One-Slide Summary An automatic memory management system deallocates objects when they are no longer used and reclaims their storage space. We must be conservative and only

More information

Page # CISC360. Integers Sep 11, Encoding Integers Unsigned. Encoding Example (Cont.) Topics. Twoʼs Complement. Sign Bit

Page # CISC360. Integers Sep 11, Encoding Integers Unsigned. Encoding Example (Cont.) Topics. Twoʼs Complement. Sign Bit Topics CISC3 Integers Sep 11, 28 Nmeric Encodings Unsigned & Twoʼs complement Programming Implications C promotion rles Basic operations Addition, negation, mltiplication Programming Implications Conseqences

More information

Lecture 15 Garbage Collection

Lecture 15 Garbage Collection Lecture 15 Garbage Collection I. Introduction to GC -- Reference Counting -- Basic Trace-Based GC II. Copying Collectors III. Break Up GC in Time (Incremental) IV. Break Up GC in Space (Partial) Readings:

More information

Chapter 6: Pipelining

Chapter 6: Pipelining CSE 322 COPUTER ARCHITECTURE II Chapter 6: Pipelining Chapter 6: Pipelining Febrary 10, 2000 1 Clothes Washing CSE 322 COPUTER ARCHITECTURE II The Assembly Line Accmlate dirty clothes in hamper Place in

More information

Putting the dynamic into software security testing

Putting the dynamic into software security testing Ptting the dynamic into software secrity testing Detecting and Addressing Cybersecrity Isses V1.1 2018-03-05 Code ahead! 2 Atomated vlnerability detection and triage + = 3 How did we get here? Vector was

More information

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

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility Informal Semantics of Data semantic specification names (identifiers) attributes binding declarations scope rules visibility 1 Ways to Specify Semantics Standards Documents (Language Definition) Language

More information

Lecture 13: Garbage Collection

Lecture 13: Garbage Collection Lecture 13: Garbage Collection COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer/Mikkel Kringelbach 1 Garbage Collection Every modern programming language allows programmers

More information

Run-Time Environments

Run-Time Environments CS308 Run-Time Environments Li Jiang Department of Computer Science and Engineering Shanghai Jiao Tong University Current Progress Source Language Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate

More information

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

Announcements. Scope, Function Calls and Storage Management. Block Structured Languages. Topics. Examples. Simplified Machine Model. CS 242 2007 Scope, Function Calls and Storage Management John Mitchell Announcements Homework Returned in class Wed; afterwards in 4 th Floor Gates Cabinet SCPD students: attach routing slip, will be returned

More information

Scope. Chapter Ten Modern Programming Languages 1

Scope. Chapter Ten Modern Programming Languages 1 Scope Chapter Ten Modern Programming Languages 1 Reusing Names Scope is trivial if you have a unique name for everything: fun square a = a * a; fun double b = b + b; But in modern languages, we often use

More information

An Introduction to GPU Computing. Aaron Coutino MFCF

An Introduction to GPU Computing. Aaron Coutino MFCF An Introdction to GPU Compting Aaron Cotino acotino@waterloo.ca MFCF What is a GPU? A GPU (Graphical Processing Unit) is a special type of processor that was designed to render and maniplate textres. They

More information

Optimizing Closures in O(0) time

Optimizing Closures in O(0) time Optimizing Closures in O(0 time Andrew W. Keep Cisco Systems, Inc. Indiana Univeristy akeep@cisco.com Alex Hearn Indiana University adhearn@cs.indiana.edu R. Kent Dybvig Cisco Systems, Inc. Indiana University

More information

6. Names, Scopes, and Bindings

6. Names, Scopes, and Bindings Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack

More information

The Procedure Abstraction

The Procedure Abstraction The Procedure Abstraction Procedure Abstraction Begins Chapter 6 in EAC The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures

More information

Run-time Environment

Run-time Environment Run-time Environment Prof. James L. Frankel Harvard University Version of 3:08 PM 20-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Storage Organization Automatic objects are

More information

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A. MIPS Calling Convention Chapter 2.7 Appendix A.6 Procedure Calls Main Procedure Call Procedure Call Procedure Procedure Calls Procedure must from any call Procedure uses that main was using We need a convention

More information

Administration CS 412/413. Advanced Language Support. First-class vs. Second-class. First-class functions. Function Types

Administration CS 412/413. Advanced Language Support. First-class vs. Second-class. First-class functions. Function Types Administration CS 412/413 Introduction to Compilers and Translators Andrew Myers Cornell University Lecture 33: First-class functions 21 April 00 Programming Assignment 6 handed out today register allocation

More information

Names, Scopes, and Bindings II. Hwansoo Han

Names, Scopes, and Bindings II. Hwansoo Han Names, Scopes, and Bindings II Hwansoo Han Scope Rules A scope is textual region where bindings are active A program section of maximal size Bindings become active at the entry No bindings change in the

More information

Compilers and Code Optimization EDOARDO FUSELLA

Compilers and Code Optimization EDOARDO FUSELLA Compilers and Code Optimization EDOARDO FUSELLA Contents Data memory layout Instruction selection Register allocation Data memory layout Memory Hierarchy Capacity vs access speed Main memory Classes of

More information

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100 ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam Three November 20 th 2013 Name: Q1: /8 Q2: /30 Q3: /30 Q4: /32 Total: /100 1/10 For functional call related questions, let s assume

More information

Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary

Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary with contribtions from Dr. Bin Ren, College of William & Mary Addition, negation, mltiplication, shifting 1 Everything is bits The Decimal System and Bases Each bit is or 1 By encoding/interpreting sets

More information

The single-cycle design from last time

The single-cycle design from last time lticycle path Last time we saw a single-cycle path and control nit for or simple IPS-based instrction set. A mlticycle processor fies some shortcomings in the single-cycle CPU. Faster instrctions are not

More information

Structure of Programming Languages Lecture 10

Structure of Programming Languages Lecture 10 Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,

More information

Requirements Engineering. Objectives. System requirements. Types of requirements. FAQS about requirements. Requirements problems

Requirements Engineering. Objectives. System requirements. Types of requirements. FAQS about requirements. Requirements problems Reqirements Engineering Objectives An introdction to reqirements Gerald Kotonya and Ian Sommerville To introdce the notion of system reqirements and the reqirements process. To explain how reqirements

More information

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION Instructors: Crista Lopes Copyright Instructors. Topics Recursion Higher-order functions Continuation-Passing Style Monads (take 1) Identity Monad Maybe

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Chapter 5. Names, Bindings, and Scopes

Chapter 5. Names, Bindings, and Scopes Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

More information

C Puzzles! Taken from old exams. Integers Sep 3, Encoding Integers Unsigned. Encoding Example (Cont.) The course that gives CMU its Zip!

C Puzzles! Taken from old exams. Integers Sep 3, Encoding Integers Unsigned. Encoding Example (Cont.) The course that gives CMU its Zip! 15-13 The corse that gies CMU its Zip! Topics class3.ppt Integers Sep 3,! Nmeric Encodings " Unsigned & Two s complement! Programming Implications " C promotion rles! Basic operations " Addition, negation,

More information

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

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character

More information

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility Quiz Review Q1. What is the advantage of binding things as early as possible? Is there any advantage to delaying binding? Answer: Early binding generally leads to greater efficiency (compilation approach)

More information

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

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

More information

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

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character

More information

Static Program Analysis Part 9 pointer analysis. Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University

Static Program Analysis Part 9 pointer analysis. Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Static Program Analysis Part 9 pointer analysis Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Agenda Introduction to points-to analysis Andersen s analysis Steensgaards s

More information

Once Upon a Polymorphic Type

Once Upon a Polymorphic Type Once Upon a Polymorphic Type Keith Wansbrough Computer Laboratory University of Cambridge kw217@cl.cam.ac.uk http://www.cl.cam.ac.uk/users/kw217/ Simon Peyton Jones Microsoft Research Cambridge 20 January,

More information

TDT4255 Friday the 21st of October. Real world examples of pipelining? How does pipelining influence instruction

TDT4255 Friday the 21st of October. Real world examples of pipelining? How does pipelining influence instruction Review Friday the 2st of October Real world eamples of pipelining? How does pipelining pp inflence instrction latency? How does pipelining inflence instrction throghpt? What are the three types of hazard

More information

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls Princeton University Computer Science 217: Introduction to Programming Systems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent

More information

PART I: Adding Instructions to the Datapath. (2 nd Edition):

PART I: Adding Instructions to the Datapath. (2 nd Edition): EE57 Instrctor: G. Pvvada ===================================================================== Homework #5b De: check on the blackboard =====================================================================

More information

Connecting Definition and Use? Tiger Semantic Analysis. Symbol Tables. Symbol Tables (cont d)

Connecting Definition and Use? Tiger Semantic Analysis. Symbol Tables. Symbol Tables (cont d) Tiger source program Tiger Semantic Analysis lexical analyzer report all lexical errors token get next token parser construct variable deinitions to their uses report all syntactic errors absyn checks

More information

Names and Abstractions: What s in a Name?

Names and Abstractions: What s in a Name? Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Names, Scopes, and Bindings Binding time Object lifetime Object storage management Static allocation Stack allocation Heap allocation

More information

Memory Management. Memory Management... Memory Management... Interface to Dynamic allocation

Memory Management. Memory Management... Memory Management... Interface to Dynamic allocation CSc 453 Compilers and Systems Software 24 : Garbage Collection Introduction Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Dynamic Memory Management

More information

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information