12 - Click to edit Master subtitle style Chapter Twelve...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Chapter Twelve Modern Programming Languages, 2nd ed. Memory Locations For Variables Chapter Twelve Modern Programming Languages, 2nd ed. 11 Chapter Twelve Modern Programming Languages, 2nd ed. A Binding Question Variables are bound (dynamically) to values Those values must be stored somewhere Therefore, variables must somehow be bound to memory locations How? Chapter Twelve Modern Programming Languages, 2nd ed. 22 Chapter Twelve Modern Programming Languages, 2nd ed. Functional Meets Imperative Imperative languages expose the concept of memory locations: a := 0 Store a zero in a s memory location Functional languages hide it: val a = 0 Bind a to the value zero But both need to connect variables to values represented in memory So both face the same binding question Chapter Twelve Modern Programming Languages, 2nd ed. 33 Chapter Twelve Modern Programming Languages, 2nd ed. Outline Activation records Static allocation of activation records Stacks of activation records Handling nested function definitions Functions as parameters Long-lived activation records Chapter Twelve Modern Programming Languages, 2nd ed. 44 Chapter Twelve Modern Programming Languages, 2nd ed. Function Activations The lifetime of one execution of a function, from call to corresponding return, is called an activation of the function When each activation has its own binding of a variable to a memory locations, it is an activation-specific variable (Also called dynamic or automatic ) Chapter Twelve Modern Programming Languages, 2nd ed. 55 Chapter Twelve Modern Programming Languages, 2nd ed. Activation-Specific Variables In most modern languages, activation- specific variables are the most common kind: Chapter Twelve Modern Programming Languages, 2nd ed. 66 fun days2ms days = let val hours = days * 24.0 val minutes = hours * 60.0 val seconds = minutes * 60.0 in seconds * 1000.0 end; Chapter Twelve Modern Programming Languages, 2nd ed. Block Activations For block constructs that contain code, we can speak of an activation of the block The lifetime of one execution of the block A variable might be specific to an activation of a particular block within a function: Chapter Twelve Modern Programming Languages, 2nd ed. 77 fun fact n = if (n=0) then 1 else let val b = fact (n-1) in n*b end; Chapter Twelve Modern Programming Languages, 2nd ed. Other Lifetimes For Variables Most imperative languages have a way to declare a variable that is bound to a single memory location for the entire runtime Obvious binding solution: static allocation (classically, the loader allocates these) Chapter Twelve Modern Programming Languages, 2nd ed....
View Full Document

This note was uploaded on 09/30/2011 for the course CS 6371 taught by Professor Hamlen during the Spring '11 term at University of Texas at Dallas, Richardson.

Page1 / 53

12 - Click to edit Master subtitle style Chapter Twelve...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online