c08 - CS421 COMPILERS AND INTERPRETERS CS421 Tiger Runtime...

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

View Full Document Right Arrow Icon
CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Runtime Environments: Page 1 of 24 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 to map each runtime value into the memory? more specifically, here are the main issues how to implement procedure (or function) call ? --- stack frames (activation records, access to non-local variables, parameter passing,. ..) what are the data representations ? (primitive data type, records, arrays, dynamic data structure, . ..) what are the memory layout (i.e., storage organization) ? (where to put the static data, code segments, stack, heap?) how to do the memory allocation and de-allocation ? (malloc-free package, garbage collection, . ..) CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Runtime Environments: Page 2 of 24 Typical Runtime Layout program counter HEAP (dynamic data) STACK (activation records) STATIC (code and globals) Memory Layout code garbage collector parameters and returned values links and saved status temporaries and local data REGISTERS Activation Record CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Runtime Environments: Page 3 of 24 Example: Nested Functions let type intArray = array of int var a := intArray [9] of 0 function readarray () = . .. function writearray () = . .. function exchange (x : int, y : int) = let var z := a[x] in a[x] := a[y]; a[y] := z end function quicksort (m : int, n : int) = let function partition (y : int, z : int) : int = let var i := y var j := z + 1 in (while (i < j) do (i := i+1; while a[i] < a[y] do i := i+1; j := j-1; while a[j] > a[y] do j := j-1; if i < j then exchange(i,j)); exchange(y,j); j) end in if n > m then (let var i := partition(m,n) in quicksort(m, i-1); quicksort(i+1, n) end) end in readarray(); quicksort(0,8); writearray() end input : 10, 32, 567, -1, 789, 3, 18, 0, -51 CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Runtime Environments: Page 4 of 24 Activation Trees main readarray q(0,8) writearray p(0,8) q(0,3) q(5,8) e (1,8) e (2,7) e (4,5) e (0,4) p(0,3) q(0,2) q(4,3) p(5,8) q(5,7) q(9,8) e (0,3) p(0,2) q(0,0) q(2,2) e (6,9) p(5,7) q(5,5) q(8,8) e (0,1) p -> partition q -> quicksort e (5,6) e -> exchange input : 10, 32, 567, -1, 789, 3, 18, 0, -51
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Runtime Environments: Page 5 of 24 Activations •E a c h f u n
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

c08 - CS421 COMPILERS AND INTERPRETERS CS421 Tiger Runtime...

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

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