Deriving a Uniform Compiler and VM       with Low-Level Code   Generation                 Jaiyalas
Term             evaluator                                                TermVal                                         ...
Term             evaluator                                                TermVal                                         ...
Term             evaluator                                                TermVal                                         ...
Term             evaluator                                                TermVal                                         ...
Term             evaluator                                                TermVal                                         ...
Term             evaluator                                                TermVal                                         ...
Term            evaluator                                                  TermVal                  type Compt = [Inst]   ...
Term            evaluator                                                 TermVal    eval        Source Code              ...
Term             evaluator                                                TermVal                                         ...
Term             evaluator                                                TermVal                                         ...
eval      Source Code                  VM Instructions               (Run-Time Computation)   LevelEnvironment            ...
Demo                               feval3.hs                           compile exp6                     run $ compile exp6...
Non-Uniform    Compilation        andFailure of Low-Level  Code Generation
eval       Source Code, Level                  VM Instructions               (Run-Time Computation)   LevelEnvironment    ...
Term             evaluator                 Uniform                        TermVal                                         ...
Term             evaluator                                                   TermVal                                      ...
Term             evaluator                                                TermVal                                         ...
Term   type Compt = [Inst]             evaluator                                              TermVal    data Inst = Numbe...
Enter   compiler   Next , 0PushQNext    compiler   Next , 1
Enter         compiler                              o r m                                  Next , 0                       ...
eval         Source Code, Level L=0      L>0VM InstructionsappC     appCQ High-Level Code appK      appKQHigh-Level Code  ...
VM Instructions    appC            appCQ    appK            appKQInterpretation    Compilation   VM
Demo                  Jainon/nonnifeval3.hs                           compile exp6                     run $ compile exp6r...
Term             evaluator                                                TermVal                                         ...
Term             evaluator                                                TermVal                                         ...
compiler       Source Code, Level L=0    L>0VM Instructions     VM                        | QLit Int        L>0           ...
compiler        Source Code, Level L=0     L>0VM Instructions     VM           o r m       n if              | QLit Int   ...
data Inst = Lv0Numer Int          | Lv0Access Int          | Lv0Lambda Compt          | Lv0...          | Lv1Number Int   ...
data Inst = Lv0Numer Int          | Lv0Access Int          | Lv0Lambda Compt          | Lv0...          | Lv1Number Int   ...
Source Code, Level         compilerInstructions            VMn                VM               Result
Term             evaluator                                                TermVal                                         ...
(Next (Next (Add (Lit 2) (Lit 3))))                 Compiler[Enter,PushQNext,PushQAdd [QLit 2],QLit 3]                    ...
(Next (Next (Add (Lit 2) (Lit 3))))                 Compiler[Enter,PushQNext,PushQAdd [QLit 2],QLit 3]                    ...
dmdq   =   demote   +    deq                    /Jainon/nonnifeval42o.hs
Quot [PushQNext,PushQAdd [QLit 2],QLit 3]                   dmdq      [Enter,PushQAdd [QLit 2],QLit 3]                    ...
Quot [PushQAdd [QLit 2],QLit 3]             dmdq   [Plus [Number 2],Number 3]              VM              Val 5
Demoexp7 = (Next (Next (App   (Abs (Prev (Prev (Add (Lit 11) (Lit 13)))))   (Prev (App       (Abs (Var 0))       (Next (Ad...
Demo                     Jainon/nonnifeval42o.hs                               compile exp7                          run $...
END
Upcoming SlideShare
Loading in …5
×

Deriving a compiler and interpreter for a Multi-level

281 views

Published on

11 Sep 2008

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
281
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Deriving a compiler and interpreter for a Multi-level

  1. 1. Deriving a Uniform Compiler and VM with Low-Level Code Generation Jaiyalas
  2. 2. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  3. 3. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  4. 4. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  5. 5. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  6. 6. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont type Compt = ComptTerm Int -> Env -> Cont -> Val VMVal eval appK for Low-Level Code GenerationCont eval :: Term -> Compt Term appK :: Cont -> Val -> Val Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  7. 7. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  8. 8. Term evaluator TermVal type Compt = [Inst] Val Defunctionalizing Continuations eval appK appC Cont data Inst = Number Int ComptTerm | Access Int VMVal eval appK | Lambda Compt for Low-Level Code GenerationCont | Push Compt Term | Enter Val Currying & | Leave Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  9. 9. Term evaluator TermVal eval Source Code Val Defunctionalizing Continuations eval appK appC Cont VM Instructions ComptTerm appC High-Level Code appK VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  10. 10. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  11. 11. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval eval appK Source Code for Low-Level Code GenerationCont Term VM Instructions Val Currying & eval Primitive Recursive Evaluator appK appC Cont appC VM Instructions appKTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  12. 12. eval Source Code VM Instructions (Run-Time Computation) LevelEnvironment appC VM Instructions appKContinuation VM Instructions (Run-Time Computation) LevelEnvironment appC VM Instructions appKContinuation
  13. 13. Demo feval3.hs compile exp6 run $ compile exp6run $ compile $ deq $ run $ compile exp6 feval42.hs compile exp6 run $ compile exp6 run $ deq $ run $ compile exp6
  14. 14. Non-Uniform Compilation andFailure of Low-Level Code Generation
  15. 15. eval Source Code, Level VM Instructions (Run-Time Computation) LevelEnvironment appC VM Instructions appKContinuation VM Instructions (Run-Time Computation) LevelEnvironment appC VM Instructions appKContinuation
  16. 16. Term evaluator Uniform TermVal Val Defunctionalizing Continuations eval appK appC Cont type Compt = ComptTerm Int -> Env -> Cont -> Val VMVal eval appK for Low-Level Code GenerationCont eval :: Term -> Compt Term appK :: Cont -> Val -> Val Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  17. 17. Term evaluator TermVal Non-Uniform Val Defunctionalizing Continuations eval appK appC Cont ComptTerm type Compt = VMVal eval appK -> Cont -> Val Env for Low-Level Code GenerationCont eval :: Term -> Int ->Compt Term appK :: Cont -> Val -> Val Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  18. 18. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  19. 19. Term type Compt = [Inst] evaluator TermVal data Inst = Number Int Val | Access Int Defunctionalizing eval appK appC Cont Continuations | Lambda Compt | Push Compt ComptTerm | Enter L = 0 VMVal eval LeaveappK for | Low-Level Code GenerationCont | Plus Compt Term | QLit Int Val Currying & Primitive|Recursive Evaluator QVar Int eval appK appC Cont | PushQAbs Compt Int L > 0Term | PushQApp Compt ComptVal eval | PushQNextappK Defunctionalizing Run-Time Computation | PushQPrevCont | PushQAdd Compt
  20. 20. Enter compiler Next , 0PushQNext compiler Next , 1
  21. 21. Enter compiler o r m Next , 0 n if n - UPushQNext N o compiler Next , 1
  22. 22. eval Source Code, Level L=0 L>0VM InstructionsappC appCQ High-Level Code appK appKQHigh-Level Code /Jainon/nonnifeval3.hs
  23. 23. VM Instructions appC appCQ appK appKQInterpretation Compilation VM
  24. 24. Demo Jainon/nonnifeval3.hs compile exp6 run $ compile exp6run $ compile $ deq $ run $ compile exp6
  25. 25. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  26. 26. Term evaluator TermVal Val Defunctionalizing eval appK appC Cont ? Continuations ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  27. 27. compiler Source Code, Level L=0 L>0VM Instructions VM | QLit Int L>0 | QVar Int | PushQAbs Compt Int | PushQApp Compt | PushQNext | PushQPrev | PushQAdd Compt
  28. 28. compiler Source Code, Level L=0 L>0VM Instructions VM o r m n if | QLit Int | QVar Int U L>0 | PushQAbs Compt Int | PushQApp Compt | PushQNext | PushQPrev | PushQAdd Compt
  29. 29. data Inst = Lv0Numer Int | Lv0Access Int | Lv0Lambda Compt | Lv0... | Lv1Number Int | Lv1Access Int | Lv1... | ... | LvnNumber Int | Lvn ...
  30. 30. data Inst = Lv0Numer Int | Lv0Access Int | Lv0Lambda Compt | Lv0... | Lv1Number Int | Lv1Access Int | Lv1... | ... | LvnNumber Int | Lvn ...
  31. 31. Source Code, Level compilerInstructions VMn VM Result
  32. 32. Term evaluator TermVal Val Defunctionalizing Continuations eval appK appC Cont ComptTerm VMVal eval appK for Low-Level Code GenerationCont Term Val Currying & Primitive Recursive Evaluator eval appK appC ContTerm Compt DefunctionalizingVal eval appK Run-Time ComputationCont
  33. 33. (Next (Next (Add (Lit 2) (Lit 3)))) Compiler[Enter,PushQNext,PushQAdd [QLit 2],QLit 3] VMQuot [PushQNext,PushQAdd [QLit 2],QLit 3]
  34. 34. (Next (Next (Add (Lit 2) (Lit 3)))) Compiler[Enter,PushQNext,PushQAdd [QLit 2],QLit 3] VM ? ? ? l = v e eQuot [PushQNext,PushQAdd [QLit 2],QLit 3] L
  35. 35. dmdq = demote + deq /Jainon/nonnifeval42o.hs
  36. 36. Quot [PushQNext,PushQAdd [QLit 2],QLit 3] dmdq [Enter,PushQAdd [QLit 2],QLit 3] VM Quot [PushQAdd [QLit 2],QLit 3]
  37. 37. Quot [PushQAdd [QLit 2],QLit 3] dmdq [Plus [Number 2],Number 3] VM Val 5
  38. 38. Demoexp7 = (Next (Next (App (Abs (Prev (Prev (Add (Lit 11) (Lit 13))))) (Prev (App (Abs (Var 0)) (Next (Add (Lit 1) (Lit 3))))))))
  39. 39. Demo Jainon/nonnifeval42o.hs compile exp7 run $ compile exp7 run $ dmdq $ run $ compile exp7run $ dmdq $ run $ dmdq $ run $ compile exp7
  40. 40. END

×