A Func'onal Space Model
|
|
- Juniper Dominic Nicholson
- 5 years ago
- Views:
Transcription
1 A Func'onal Space Model COS 26 David Walker Princeton University slides copyright 2017 David Walker permission granted to reuse these slides for non-commercial educa'onal purposes
2 2 Because Halloween draws nigh: Serial killer or programming languages researcher? hmp://
3 Space Understanding the space complexity of func'onal programs At least two interes'ng components: the amount of live space at any instant in 'me the rate of alloca.on a func'on call may not change the amount of live space by much but may allocate at a substan'al rate because func'onal programs act by genera'ng new data structures and discarding old ones, they ouen allocate a lot» OCaml garbage collector is op'mized with this in mind» interes'ng fact: at the assembly level, the number of writes by a func'onal program is roughly the same as the number of writes by an impera've program
4 Space 4 Understanding the space complexity of func'onal programs At least two interes'ng components: the amount of live space at any instant in 'me the rate of alloca.on a func'on call may not change the amount of live space by much but may allocate at a substan'al rate because func'onal programs act by genera'ng new data structures and discarding old ones, they ouen allocate a lot» OCaml garbage collector is op'mized with this in mind» interes'ng fact: at the assembly level, the number of writes by a func'onal program is roughly the same as the number of writes by an impera've program What takes up space? conven'onal first-order data: tuples, lists, strings, datatypes func'on representa'ons (closures) the call stack
5 CONVENTIONAL DATA 5
6 Type: OCaml Representa'ons for Data Structures type triple = int * char * int Representa'on: (, 'a', 17) 'a' 17
7 Type: OCaml Representa'ons for Data Structures type mylist = int list Representa'on: [ ] [; 4; 5]
8 Type: Space Model 8 type tree = Leaf Node of int * tree * tree Representa'on: Leaf Node(, leu, right) 0 Node leu right
9 Alloca'ng space In C, you allocate when you call malloc In Java, you allocate when you call new What about ML?
10 Alloca'ng space Whenever you use a constructor, space is allocated: 10 let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i)
11 Alloca'ng space Whenever you use a constructor, space is allocated: 11 let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i) Consider: insert t 21 t
12 Alloca'ng space Whenever you use a constructor, space is allocated: 12 let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i) Consider: insert t 21 t
13 Alloca'ng space Whenever you use a constructor, space is allocated: 1 let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i) Consider: insert t 21 t 21
14 Alloca'ng space Whenever you use a constructor, space is allocated: 14 let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i) Consider: insert t 21 t 21
15 Alloca'ng space Whenever you use a constructor, space is allocated: let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i) Consider: insert t 21 t 21
16 Alloca'ng space Whenever you use a constructor, space is allocated: 16 let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i) Consider: insert t 21 t 21
17 Alloca'ng space Whenever you use a constructor, space is allocated: let rec insert (t:tree) (i:int) = match t with Leaf -> Node (i, Leaf, Leaf) Node (j, left, right) -> if i <= j then Node (j, insert left i, right) else Node (j, left, insert right i) Total space allocated is propor'onal to the height of the tree. ~ log n, if tree with n nodes is balanced 17 t 21
18 Net space allocated The garbage collector reclaims unreachable data structures on the heap. 18 let fiddle (t: tree) = insert t 21 t John McCarthy invented g.c
19 Net space allocated The garbage collector reclaims unreachable data structures on the heap. 1 let fiddle (t: tree) = insert t 21 If t is dead (unreachable), t 21
20 Net space allocated The garbage collector reclaims unreachable data structures on the heap. let fiddle (t: tree) = insert t 21 If t is dead (unreachable), 20 t Then all these nodes will be reclaimed! 21
21 Net space allocated 21 The garbage collector reclaims unreachable data structures on the heap. let fiddle (t: tree) = insert t 21 Net new space allocated: 1 node (just like impera've version of binary search trees) t 21
22 Net space allocated But what if you want to keep the old tree? 22 let faddle (t: tree) = (t, insert t 21) faddle(t) t 21
23 Net space allocated But what if you want to keep the old tree? let faddle (t: tree) = (t, insert t 21) faddle(t) Net new space allocated: log(n) nodes but note: impera've version would have to copy the old tree, space cost N new nodes! 2 t 21
24 Compare 24 let check_option (o:int option) : int option = match o with Some _ -> o None -> failwith found none let check_option (o:int option) : int option = match o with Some j -> Some j None -> failwith found none
25 Compare 25 let check_option (o:int option) : int option = match o with Some _ -> o None -> failwith found none allocates nothing when arg is Some i let check_option (o:int option) : int option = match o with Some j -> Some j None -> failwith found none allocates an op'on when arg is Some i
26 Compare 26 let cadd (c1:int*int) (c2:int*int) : int*int = let (x1,y1) = c1 in let (x2,y2) = c2 in (x1+x2, y1+y2) let double (c1:int*int) : int*int = let c2 = c1 in cadd c1 c2 let double (c1:int*int) : int*int = cadd c1 c1 let double (c1:int*int) : int*int = let (x1,y1) = c1 in cadd (x1,y1) (x1,y1)
27 Compare 27 let cadd (c1:int*int) (c2:int*int) : int*int = let (x1,y1) = c1 in let (x2,y2) = c2 in (x1+x2, y1+y2) let double (c1:int*int) : int*int = let c2 = c1 in cadd c1 c2 c1 1 2 c2 let double (c1:int*int) : int*int = cadd c1 c1 let double (c1:int*int) : int*int = let (x1,y1) = c1 in cadd (x1,y1) (x1,y1)
28 Compare 28 let cadd (c1:int*int) (c2:int*int) : int*int = let (x1,y1) = c1 in let (x2,y2) = c2 in (x1+x2, y1+y2) let double (c1:int*int) : int*int = let c2 = c1 in cadd c1 c2 let double (c1:int*int) : int*int = cadd c1 c1 c1 1 2 let double (c1:int*int) : int*int = let (x1,y1) = c1 in cadd (x1,y1) (x1,y1)
29 Compare 2 let cadd (c1:int*int) (c2:int*int) : int*int = let (x1,y1) = c1 in let (x2,y2) = c2 in (x1+x2, y1+y2) let double (c1:int*int) : int*int = let c2 = c1 in cadd c1 c2 let double (c1:int*int) : int*int = cadd c1 c1 let double (c1:int*int) : int*int = let (x1,y1) = c1 in cadd (x1,y1) (x1,y1) c1 arg1 arg
30 Compare 0 let cadd (c1:int*int) (c2:int*int) : int*int = let (x1,y1) = c1 in let (x2,y2) = c2 in (x1+x2, y1+y2) let double (c1:int*int) : int*int = let c2 = c1 in cadd c1 c2 no alloca'on let double (c1:int*int) : int*int = cadd c1 c1 no alloca'on let double (c1:int*int) : int*int = let (x1,y1) = c1 in cadd (x1,y1) (x1,y1) allocates 2 pairs (unless the compiler happens to op'mize )
31 Compare 1 let cadd (c1:int*int) (c2:int*int) : int*int = let (x1,y1) = c1 in let (x2,y2) = c2 in (x1+x2, y1+y2) let double (c1:int*int) : int*int = let (x1,y1) = c1 in cadd c1 c1 double does not allocate extracts components: it is a read
32 FUNCTION CLOSURES 2
33 Closures (A reminder) Nested func'ons like bar ouen contain free variables: let foo y = let bar x = x + y in bar Here's bar on its own: let bar x = x + y y is free in the defini'on of bar To implement bar, the compiler creates a closure, which is a pair of code for the func'on plus an environment holding the free variables.
34 But what about nested, higher-order func'ons? bar again: 4 let bar x = x + y bar's representa'on: code let f2 (n, env) = n + env.y {y = 1} environment closure
35 But what about nested, higher-order func'ons? 5 To es'mate the (heap) space used by a program, we ouen need to es'mate the (heap) space used by its closures. code let f2 (n, env) = n + env.y {y = 1} environment Our es'mate will include the cost of the pair: two pointers = two 4-byte values = 8 bytes total + the cost of the environment (4 bytes in this case).
36 Space Model Summary 6 Understanding space consump'on in FP involves: understanding the difference between live space rate of alloca'on understanding where alloca'on occurs any 'me a constructor is used whenever closures are created understanding the costs of data types (fairly similar to Java) costs of closures (pair + environment)
A Functional Space Model. COS 326 David Walker Princeton University
A Functional Space Model COS 326 David Walker Princeton University Data type representations: Last Time type tree = Leaf Node of int * tree * tree Leaf: Node(i, left, right): 0 Node 3 left right This Time
More informationThinking Induc,vely. COS 326 David Walker Princeton University
Thinking Induc,vely COS 326 David Walker Princeton University slides copyright 2013-2015 David Walker and Andrew W. Appel permission granted to reuse these slides for non-commercial educa,onal purposes
More informationThinking Induc,vely. COS 326 David Walker Princeton University
Thinking Induc,vely COS 326 David Walker Princeton University slides copyright 2017 David Walker permission granted to reuse these slides for non-commercial educa,onal purposes Administra,on 2 Assignment
More informationContents. 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 informationDesign 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 informationCS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons
CS 61C: Great Ideas in Computer Architecture Strings and Func.ons Instructor: Krste Asanovic, Randy H. Katz hdp://inst.eecs.berkeley.edu/~cs61c/sp12 Fall 2012 - - Lecture #7 1 New- School Machine Structures
More informationInstructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer
CS 61C: Great Ideas in Computer Architecture Everything is a Number Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13 9/19/13 Fall 2013 - - Lecture #7 1 New- School Machine Structures
More informationCS 61C: Great Ideas in Computer Architecture Func%ons and Numbers
CS 61C: Great Ideas in Computer Architecture Func%ons and Numbers 9/11/12 Instructor: Krste Asanovic, Randy H. Katz hcp://inst.eecs.berkeley.edu/~cs61c/sp12 Fall 2012 - - Lecture #8 1 New- School Machine
More informationModules and Representa/on Invariants
Modules and Representa/on Invariants COS 326 David Walker Princeton University slides copyright 2017 David Walker permission granted to reuse these slides for non-commercial educa/onal purposes LAST TIME
More informationCMSC 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 informationOCaml Datatypes. COS 326 David Walker Princeton University
OCaml Datatypes COS 326 David Walker Princeton University slides copyright 2013-2015 David Walker and Andrew W. 1 Appel permission granted to reuse these slides for non-commercial educagonal purposes OCaml
More informationCMSC 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 informationWhat the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.
C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of
More informationCMSC 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 informationDynamic Memory Alloca/on: Advanced Concepts
Dynamic Memory Alloca/on: Advanced Concepts CS 485 Systems Programming Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hip://csapp.cs.cmu.edu/public/instructors.html)
More informationCSE 130: Programming Languages. Polymorphism. Ranjit Jhala UC San Diego
CSE 130: Programming Languages Polymorphism Ranjit Jhala UC San Diego Q: What is the value of res? let f g = let x = 0 in g 2 let x = 100 let h y = x + y let res = f h (a) 0 (b) 2 (c) 100 (d) 102 (e) 12
More informationCSE P 501 Compilers. Memory Management and Garbage Collec<on Hal Perkins Winter UW CSE P 501 Winter 2016 W-1
CSE P 501 Compilers Memory Management and Garbage Collec
More informationVerification of an ML compiler. Lecture 3: Closures, closure conversion and call optimisations
Verification of an ML compiler Lecture 3: Closures, closure conversion and call optimisations Marktoberdorf Summer School MOD 2017 Magnus O. Myreen, Chalmers University of Technology Implementing the ML
More informationVariables and Bindings
Net: Variables Variables and Bindings Q: How to use variables in ML? Q: How to assign to a variable? # let = 2+2;; val : int = 4 let = e;; Bind the value of epression e to the variable Variables and Bindings
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 18! Bootstrapping Names in programming languages Binding
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 21 October 21 st, 2015 Transi@on to Java Announcements HW5: GUI & Paint Due Tomorrow, October 22 nd at 11:59pm HW6: Java Programming (Pennstagram)
More informationRun-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 informationScope, 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 informationFrom last time. News. Example. Example. Typechecking let. Typechecking let. Pick up your first two quizzes after class. Assignment #2 due tomorrow
News Pick up your first two quizzes after class Assignment #2 due tomorrow From last time Old: e1:int e2:int e1+e2:int new: Γ e1:int Γ e2:int Γ e1+e2:int Assignment #3 will be up tomorrow night e : T2
More informationRun-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 informationRun-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 informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 7 January 30 th, 2015 Binary Search Trees (Lecture notes Chapter 7) ! Homework #1 feedback dope assignment, got a 96.4 the first time, careless mistake,
More informationCA 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 informationNAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS
NAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS Name Binding and Binding Time Name binding is the associa1on of objects (data and/or code) with names (iden1fiers) Shape S = new Shape(); The binding
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages CMSC330 Fall 2017 OCaml Data Types CMSC330 Fall 2017 1 OCaml Data So far, we ve seen the following kinds of data Basic types (int, float, char, string) Lists
More informationG 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 informationLecture 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 informationProgramming Language Implementation
A Practical Introduction to Programming Language Implementation 2014: Week 10 Garbage Collection College of Information Science and Engineering Ritsumeikan University 1 review of last week s topics dynamic
More informationMemory Management. CS449 Fall 2017
Memory Management CS449 Fall 2017 Life9mes Life9me: 9me from which a par9cular memory loca9on is allocated un9l it is deallocated Three types of life9mes Automa9c (within a scope) Sta9c (dura9on of program)
More informationLecture 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 informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationCon$nuing CPS. COS 326 David Walker Princeton University
Con$nuing CPS COS 326 David Walker Princeton University Last Time We saw that code like this could take up a lot of stack space: let rec sum_to (n:int) : int = if n > 0 then n + sum_to (n-1) else 0 Last
More informationLecture 7 More Memory Management Slab Allocator. Slab Allocator
CS61C L07 More Memory Management (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 More Memory Management 2006-09-13 Lecturer SOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Unbox problems
More informationCSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8
Question 1. (12 points) For each of the following, what value is printed? (Assume that each group of statements is executed independently in a newly reset Scheme environment.) (a) (define x 1) (define
More informationDynamic Memory Alloca/on: Basic Concepts
Dynamic Memory Alloca/on: Basic Concepts 15-213 / 18-213: Introduc2on to Computer Systems 18 th Lecture, March. 26, 2013 Instructors: Anthony Rowe, Seth Goldstein, and Gregory Kesden 1 Today Basic concepts
More informationDynamic Memory Alloca/on: Basic Concepts
Dynamic Memory Alloca/on: Basic Concepts Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hip://csapp.cs.cmu.edu/public/instructors.html) 1 Today Basic concepts
More informationRecap. Recap. If-then-else expressions. If-then-else expressions. If-then-else expressions. If-then-else expressions
Recap Epressions (Synta) Compile-time Static Eec-time Dynamic Types (Semantics) Recap Integers: +,-,* floats: +,-,* Booleans: =,
More informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data
More informationCS 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 informationINF 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 informationCS 345. Garbage Collection. Vitaly Shmatikov. slide 1
CS 345 Garbage Collection Vitaly Shmatikov slide 1 Major Areas of Memory Static area Fixed size, fixed content, allocated at compile time Run-time stack Variable size, variable content (activation records)
More informationOne-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 informationParametric types. map: ( a (a b) a list b list. filter: ( a bool) a list a list. Why? a and b are type variables!
What is the deal with a? Parametric types aka: what s up with those a? These meta-functions have strange types: map: ( a b) a list b list filter: ( a bool) a list a list Why? Polymorphism Poly = many,
More informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationCS153: Compilers Lecture 15: Local Optimization
CS153: Compilers Lecture 15: Local Optimization Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 4 out Due Thursday Oct 25 (2 days) Project 5 out Due Tuesday Nov 13 (21 days)
More informationCS558 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 informationA Func'onal Introduc'on. COS 326 David Walker Princeton University
A Func'onal Introduc'on COS 326 David Walker Princeton University Thinking Func'onally In Java or C, you get (most) work done by changing something temp = pair.x; pair.x = pair.y; pair.y = temp; commands
More informationMutation. COS 326 Andrew W. Appel Princeton University. slides copyright David Walker and Andrew W. Appel
Mutation COS 326 Andrew W. Appel Princeton University slides copyright 2013-2015 David Walker and Andrew W. Appel Mutation? 2 Reasoning about Mutable State is Hard mutable set insert i s1; f x; member
More informationAutomatic 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 informationAdministration 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 informationRecap: Functions as first-class values
Recap: Functions as first-class values Arguments, return values, bindings What are the benefits? Parameterized, similar functions (e.g. Testers) Creating, (Returning) Functions Iterator, Accumul, Reuse
More information2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h)
Problem 1 (20 points) Compilation Perform at least five standard compiler optimizations on the following C code fragment by writing the optimized version (in C) to the right. Assume f is a pure function
More informationLecture 7: Binding Time and Storage
Lecture 7: Binding Time and Storage COMP 524 Programming Language Concepts Stephen Olivier February 5, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of Lecture The
More informationQ1: /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 informationCS558 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 informationCMSC 330: Organization of Programming Languages. Closures (Implementing Higher Order Functions)
CMSC 330: Organization of Programming Languages Closures (Implementing Higher Order Functions) CMSC330 Spring 2018 1 Returning Functions as Results In OCaml you can pass functions as arguments to map,
More informationPerformance of Non-Moving Garbage Collectors. Hans-J. Boehm HP Labs
Performance of Non-Moving Garbage Collectors Hans-J. Boehm HP Labs Why Use (Tracing) Garbage Collection to Reclaim Program Memory? Increasingly common Java, C#, Scheme, Python, ML,... gcc, w3m, emacs,
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 More Memory Management CS 61C L07 More Memory Management (1) 2004-09-15 Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Star Wars
More informationCPSC 213. Introduction to Computer Systems. Instance Variables and Dynamic Allocation. Unit 1c
CPSC 213 Introduction to Computer Systems Unit 1c Instance Variables and Dynamic Allocation 1 Reading For Next 3 Lectures Companion 2.4.4-2.4.5 Textbook Structures, Dynamic Memory Allocation, Understanding
More informationENEE 457: Computer Systems Security. Lecture 16 Buffer Overflow Attacks
ENEE 457: Computer Systems Security Lecture 16 Buffer Overflow Attacks Charalampos (Babis) Papamanthou Department of Electrical and Computer Engineering University of Maryland, College Park Buffer overflow
More informationCS558 Programming Languages. Winter 2013 Lecture 3
CS558 Programming Languages Winter 2013 Lecture 3 1 NAMES AND BINDING One essential part of being a high-level language is having convenient names for things: variables constants types functions etc. classes
More informationDynamic Data Structures. CSCI 112: Programming in C
Dynamic Data Structures CSCI 112: Programming in C 1 It s all about flexibility In the programs we ve made so far, the compiler knows at compile time exactly how much memory to allocate for each variable
More informationG 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 informationCOS 326 David Walker Princeton University
Functional Abstractions over Imperative Infrastructure and Lazy Evaluation COS 326 David Walker Princeton University slides copyright 2013-2015 David Walker and Andrew W. Appel permission granted to reuse
More informationCSC 1600 Memory Layout for Unix Processes"
CSC 16 Memory Layout for Unix Processes" 1 Lecture Goals" Behind the scenes of running a program" Code, executable, and process" Memory layout for UNIX processes, and relationship to C" : code and constant
More informationQualifying Exam in Programming Languages and Compilers
Qualifying Exam in Programming Languages and Compilers University of Wisconsin Fall 1991 Instructions This exam contains nine questions, divided into two parts. All students taking the exam should answer
More informationMemory Allocation II. CSE 351 Autumn Instructor: Justin Hsia
Memory Allocation II CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun
More informationCPSC 213. Introduction to Computer Systems. Winter Session 2017, Term 2. Unit 1c Jan 24, 26, 29, 31, and Feb 2
CPSC 213 Introduction to Computer Systems Winter Session 2017, Term 2 Unit 1c Jan 24, 26, 29, 31, and Feb 2 Instance Variables and Dynamic Allocation Overview Reading Companion: Reference 2.4.4-5 Textbook:
More informationMutation. COS 326 David Walker Princeton University
Mutation COS 326 David Walker Princeton University Mutation? 2 Thus far We have considered the (almost) purely functional subset of Ocaml. We ve had a few side effects: printing & raising exceptions. Two
More information2/12/2018. Recall Why ISAs Define Calling Conventions. ECE 220: Computer Systems & Programming. Recall the Structure of the LC-3 Stack Frame
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Stack Frames Revisited Recall Why ISAs Define Calling Conventions A compiler
More informationINITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS
INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS Pages 792 to 800 Anna Rakitianskaia, University of Pretoria INITIALISING POINTER VARIABLES Pointer variables are declared by putting
More informationAgenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java
CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda
More informationMotivation was to facilitate development of systems software, especially OS development.
A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.
More informationGoal of lecture. Object-oriented Programming. Context of discussion. Message of lecture
Goal of lecture Object-oriented Programming Understand inadequacies of class languages like Ur- Java Extend Ur-Java so it becomes an object-oriented language Implementation in SaM heap allocation of objects
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 6 January 24, 2018 Binary Search Trees (Lecture notes Chapter 7) Announcements Homework 2: Computing Human Evolution due Tuesday, September 19 th Reading:
More informationCompiler Construction Lent Term 2013 Lectures 9 & 10 (of 16)
Compiler Construction ent Term 2013 ectures 9 & 10 (of 16) Assorted topics Tuples/records A peek at universal polymorphism exceptions linking and loading bootstrapping Timothy G. Griffin tgg22@cam.ac.uk
More informationLanguage of the Machine Recursive functions
EECS 322 Computer Architecture Language of the Machine Recursive functions Instructor: Francis G. Wolff wolff@eecs.cwru.edu Case Western Reserve University This presentation uses powerpoint animation:
More informationMuta%on. COS 326 David Walker Princeton University
Muta%on COS 326 David Walker Princeton University slides copyright 2017 David Walker permission granted to reuse these slides for non-commercial educa%onal purposes Reasoning about Mutable State is Hard
More informationCMSC 330: Organization of Programming Languages. OCaml Data Types
CMSC 330: Organization of Programming Languages OCaml Data Types CMSC330 Spring 2018 1 OCaml Data So far, we ve seen the following kinds of data Basic types (int, float, char, string) Lists Ø One kind
More informationImplementation Garbage Collection
CITS 3242 Programming Paradigms Part IV: Advanced Topics Topic 19: Implementation Garbage Collection Most languages in the functional, logic, and object-oriented paradigms include some form of automatic
More informationControl 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 informationG Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing
More informationAnnouncements. 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 informationCS558 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 informationRuntime. The optimized program is ready to run What sorts of facilities are available at runtime
Runtime The optimized program is ready to run What sorts of facilities are available at runtime Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis token stream Syntactic
More informationCS121/IS223. Object Reference Variables. Dr Olly Gotel
CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors CS121/IS223
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More informationCSE 504: Compilers. Expressions. R. Sekar
CSE 504: Compilers Expressions R. Sekar Expression evaluation 1 / 83 Order of evaluation For the abstract syntax tree + + 5 + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 Expression evaluation
More informationBinghamton University Dynamic Memory Alloca/on
Dynamic Memory Alloca/on Slides credit: Presenta/on based on slides by Dave O halloran/csapp 1 Dynamic memory alloca/on Where is this important? Heap Kernel heap Physical memory allocator Problems are
More informationTypes II. Hwansoo Han
Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #5 Memory Management; Intro MIPS 2007-7-2 Scott Beamer, Instructor iphone Draws Crowds www.sfgate.com CS61C L5 Memory Management; Intro
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 20 Feb 29, 2012 Transi@on to Java II DON T PANIC Smoothing the transi@on Eclipse set- up instruc@ons in lab today/tomorrow First Java homework assignment
More informationCS 101: Computer Programming and Utilization
CS 101: Computer Programming and Utilization Jul-Nov 2017 Umesh Bellur (cs101@cse.iitb.ac.in) Lecture 16: Representing variable length entities (introducing new and delete) A programming problem Design
More informationPrograms in memory. The layout of memory is roughly:
Memory 1 Programs in memory 2 The layout of memory is roughly: Virtual memory means that memory is allocated in pages or segments, accessed as if adjacent - the platform looks after this, so your program
More informationTopic 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