Compiler Construction Past Paper
remove type information, remove locations
CPS, defunctionalise, etc
stack-oriented intermediate code
(fun x -> e') e''
(i) evaluates e'' and pushes the result on the stack
(ii) creates a closure (c,k) for (fun x -> e') in the heap
and pushes a pointer to it on the stack.
> c = the address of the first instruction in e'
> k = the number of free variables of e' (excluding x)
[pop off k values from the stack and placed in the closure.]
(iii) apply the top of the stack to the argument below.
return
LOOKUP STACK_LOCATION -2 # fetch the argument v from the stack
CALL sum # sum(v)
PUSH 3
ADD # sum(v) + 3
RETURN
Past Papers
(map f l1) @ (map f l2) = map f (l1 @ l2)
(map f) o (map g) = map (f o g)
0 × e
stack-oriented code
.data <- .symtbl -> .strtab
D0: 00 00 00 01 S0: D0 N0 N0: a
N1: \0
^
|
.text <- .rela.text
T8: LOAD R1, 0(R2) # a R0: T8 S0