Ordering Multiple Continuations on the Stack
Dimitrios Vardoulakis Olin Shivers
Northeastern University 1
Ordering Multiple Continuations on the Stack Dimitrios Vardoulakis - - PowerPoint PPT Presentation
Ordering Multiple Continuations on the Stack Dimitrios Vardoulakis Olin Shivers Northeastern University 1 CPS in practice CPS widely used in functional-language compilation. Multiple continuations (conditionals, exceptions, etc ). Use a stack
Northeastern University 1
2
◮ Syntactic restriction on multi-continuation CPS
◮ Static analysis for efficient multi-continuation CPS. 3
◮ Background:
◮ Restricted CPS (RCPS) ◮ Continuation-age analysis ◮ Evaluation 4
◮ Each function takes a continuation argument,
◮ All intermediate computations are named. ◮ Continuations reified as lambdas. 5
◮ Each function takes a continuation argument,
◮ All intermediate computations are named. ◮ Continuations reified as lambdas.
(define (discr a b c) (- (* b b) (* 4 a c)))
5
◮ Each function takes a continuation argument,
◮ All intermediate computations are named. ◮ Continuations reified as lambdas.
(define (discr a b c) (- (* b b) (* 4 a c)))
CPS
(define (discr a b c k) (%* b b (λ(p1) (%* 4 a c (λ(p2) (%- p1 p2 (λ(d)(k d))))))))
5
(define (discr a b c k) (%* b b (λ(p1) (%* 4 a c (λ(p2) (%- p1 p2 (λ(d)(k d))))))))
◮ Variables, lambdas and calls split into disjoint sets,
◮ Calls classified depending on operator. 6
7
8
(define (add-pos l k-ret k-exn) ... (λ(fst) (%number? fst (λ(num-fst) (%if num-fst (λ() ...) (λ() (k-exn "Not a list of numbers.")))))))
9
10
11
12
12
◮ A user lambda doesn’t contain free continuation variables, ◮ Or it’s α-equivalent to (λ(f cc)(f (λ(x k)(cc x)) cc)) 13
◮ A user lambda doesn’t contain free continuation variables, ◮ Or it’s α-equivalent to (λ(f cc)(f (λ(x k)(cc x)) cc))
13
14
14
15
16
17
18
18
18
19
19
19
19
◮ Reason about continuation variables directly. ◮ Record total orders of continuation variables
20
21
21
◮ {k3}, {k1}, {k2} ◮ u1 bound to (λ4(k4 k5 k6 k7)call) 22
◮ {k3}, {k1}, {k2} ◮ u1 bound to (λ4(k4 k5 k6 k7)call)
22
◮ {k3}, {k1}, {k2} ◮ u1 bound to (λ4(k4 k5 k6 k7)call)
22
◮ {k3}, {k1}, {k2} ◮ u1 bound to (λ4(k4 k5 k6 k7)call)
22
◮ RCPS natural fit for multi-return lambda calculus. ◮ Multi-return lambda calculus CPS
◮ Implementation in Scheme48. 23
24
24
24
◮ Manage multi-continuation CPS with a stack. ◮ RCPS enables better reasoning about stack. ◮ Cage analysis to find youngest continuation statically. 25
◮ Manage multi-continuation CPS with a stack. ◮ RCPS enables better reasoning about stack. ◮ Cage analysis to find youngest continuation statically.
25