evaluating call by need on the control stack
play

Evaluating Call-by-need on the Control Stack Stephen Chang, David - PowerPoint PPT Presentation

Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University Lazy Abstract Machines Sharing implemented with: heap Lazy Abstract Machines Sharing implemented with: heap


  1. Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University �

  2. Lazy Abstract Machines Sharing implemented with: heap �

  3. Lazy Abstract Machines Sharing implemented with: heap stack operations (alternative approach) �

  4. Lazy Abstract Machines Sharing implemented with: heap stack operations (alternative approach) [Garcia et al. 2009] �

  5. Our Paper • New way to resolve variable references in the stack �

  6. Our Paper • New way to resolve variable references in the stack • Reorganize stack structure to allow indexing �

  7. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] �

  8. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed �

  9. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once �

  10. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M ��

  11. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M E = [ ] | E M | (λx.E) M | (λx.E[x]) E ��

  12. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M E = [ ] | E M [ ] | E M [ ] | E M | (λx.E) M | (λx.E[x]) E [ ] | E M ��

  13. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M E = [ ] | E M | (λx.E) M (λx.E) M (λx.E) M (λx.E) M | (λx.E[x]) E ��

  14. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M E = [ ] | E M | (λx.E) M | (λx.E[x]) E (λx.E[x]) E (λx.E[x]) E (λx.E[x]) E ��

  15. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M E = [ ] | E M | (λx.E) M | (λx.E[x]) E deref (β alternative): (λx.E[x]) V (λx.E[V V V V]) V ��

  16. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M E = [ ] | E M | (λx.E) M | (λx.E[x]) E deref (β alternative): (λx.E[x]) V (λx.E[V V V V]) V • One-at-a-time substitution (only when needed) ��

  17. Call-by-need λ-Calculus [Ariola et al. 1995] [Ariola and Felleisen 1997] • Delay evaluation of argument until needed • Evaluate each argument only once M = x | M M | λx.M E = [ ] | E M | (λx.E) M | (λx.E[x]) E deref (β alternative): (λx.E[x]) V (λx.E[V V V V]) V • One-at-a-time substitution (only when needed) • Argument not removed (may need it again) ��

  18. An Initial Abstract Machine ��

  19. An Initial Abstract Machine Standard Reduction = abstract machine SR E[N] E[M] if M N ��

  20. An Initial Abstract Machine Standard Reduction = abstract machine SR E[N] E[M] if M N • Re-partition into E and M after every reduction ��

  21. CK Machine [Felleisen 1986] (For by-value λ calculus) • Separate program into two registers: C = Current subterm being evaluated C C C K = Continuation (equiv. to eval. context) K K K ��

  22. CK Machine [Felleisen 1986] (For by-value λ calculus) • Separate program into two registers: C = Current subterm being evaluated C C C K = Continuation (equiv. to eval. context) K K K Don't need to re-partition program after every reduction ��

  23. CK Machine [Felleisen 1986] (For by-value λ calculus) • Separate program into two registers: C = Current subterm being evaluated C C C K = Continuation (equiv. to eval. context) K K K Don't need to re-partition program after every reduction [Garcia et al. 2009] : lazy CK machine ��

  24. Evaluation Contexts (E) vs Continuations (K) [ ] ~ mt E[[ ] M] ~ (arg M K) E ~ K E[(λx.[ ]) M] ~ (bind x M K) E ~ K E[(λx.E'[x]) [ ]] ~ (op x K' K) K' ~ E', K ~ E ��

  25. Evaluation Contexts (E) vs Continuations (K) [ ] ~ mt [ ] ~ mt [ ] ~ mt [ ] ~ mt E[[ ] M] ~ (arg M K) E ~ K E[(λx.[ ]) M] ~ (bind x M K) E ~ K E[(λx.E'[x]) [ ]] ~ (op x K' K) K' ~ E', K ~ E ��

  26. Evaluation Contexts (E) vs Continuations (K) [ ] ~ mt E[[ ] M] ~ (arg M K) E[[ ] M] ~ (arg M K) E[[ ] M] ~ (arg M K) E[[ ] M] ~ (arg M K) E ~ K E[(λx.[ ]) M] ~ (bind x M K) E ~ K E[(λx.E'[x]) [ ]] ~ (op x K' K) K' ~ E', K ~ E ��

  27. Evaluation Contexts (E) vs Continuations (K) [ ] ~ mt E[[ ] M] ~ (arg M K) E ~ K E[(λx.[ ]) M] ~ (bind x M K) E[(λx.[ ]) M] ~ (bind x M K) E[(λx.[ ]) M] ~ (bind x M K) E[(λx.[ ]) M] ~ (bind x M K) E ~ K E[(λx.E'[x]) [ ]] ~ (op x K' K) K' ~ E', K ~ E ��

  28. Evaluation Contexts (E) vs Continuations (K) [ ] ~ mt E[[ ] M] ~ (arg M K) E ~ K E[(λx.[ ]) M] ~ (bind x M K) E ~ K E[(λx.E'[x]) [ ]] ~ (op x K' K) E[(λx.E'[x]) [ ]] ~ (op x K' K) E[(λx.E'[x]) [ ]] ~ (op x K' K) E[(λx.E'[x]) [ ]] ~ (op x K' K) K' ~ E', K ~ E ��

  29. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 ��

  30. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 ��

  31. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 K K K K = mt ��

  32. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) K K K K = (arg M5) mt ��

  33. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λy.(λz.(y M)) M0 M1 M2) M3 M4 K K K K = (bind x M5) mt ��

  34. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λy.(λz.(y M)) M0 M1 M2) M3 K K K K = (arg M4) (bind x M5) mt ��

  35. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λy.(λz.(y M)) M0 M1 M2) K K K K = (arg M3) (arg M4) (bind x M5) mt ��

  36. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λz.(y M)) M0 M1 M2 K K K K = (bind y M3) (arg M4) (bind x M5) mt ��

  37. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λz.(y M)) M0 M1 K K K K = (arg M2) (bind y M3) (arg M4) (bind x M5) mt ��

  38. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λz.(y M)) M0 K K K K = (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt ��

  39. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (λz.(y M)) K = (arg M0) K K K (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt ��

  40. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = (y M) K = (bind z M0) K K K (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt ��

  41. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K = (arg M) K K (bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt ��

  42. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K = (arg M) K K (arg M) (bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt (arg M) (arg M) ��

  43. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K K = (arg M) K (bind z M0) (bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt (bind z M0) (bind z M0) ��

  44. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K K K = (arg M) (bind z M0) (arg M1) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt (arg M1) (arg M1) ��

  45. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K K K = (arg M) (bind z M0) (arg M1) (arg M2) (arg M2) (bind y M3) (arg M4) (bind x M5) mt (arg M2) (arg M2) ��

  46. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K K = (arg M) K (bind z M0) (arg M1) (arg M2) (bind y M3) (bind y M3) (arg M4) (bind x M5) mt (bind y M3) (bind y M3) ��

  47. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K K = (arg M) K (bind z M0) (arg M1) (arg M2) (bind y M3) (bind y M3) (arg M4) (bind x M5) mt (bind y M3) (bind y M3) ��

  48. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K K = (arg M) K (bind z M0) (arg M1) (arg M2) (bind y M3) (bind y M3) (arg M4) (bind x M5) mt (bind y M3) (bind y M3) ��

  49. Example (Garcia Machine) (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5 C C C C = y K K K = (arg M) K (bind z M0) (arg M1) (arg M2) (bind y M3) (bind y M3) (arg M4) (bind x M5) mt (bind y M3) (bind y M3) ��

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend