advice about debugger construction arthur nunes harwitt
play

Advice about Debugger Construction Arthur Nunes-Harwitt Nassau - PDF document

Advice about Debugger Construction Arthur Nunes-Harwitt Nassau Community College One Education Drive Garden City, NY 11530 nunesa@ncc.edu http://www.matcmp.ncc.edu/ ~ nunesa/ 1 Background (define (interp exp env k) (cond ((constant? exp) (k


  1. Advice about Debugger Construction Arthur Nunes-Harwitt Nassau Community College One Education Drive Garden City, NY 11530 nunesa@ncc.edu http://www.matcmp.ncc.edu/ ~ nunesa/ 1

  2. Background (define (interp exp env k) (cond ((constant? exp) (k exp)) ((variable? exp) (k (lookup exp env))) ((quote? exp) (k (unquote exp))) ...)) 2

  3. Goals: Implement debug commands step and next such that... • they are efficient • they are correct 3

  4. ⊲ (fact 5) position: debug command> step ⊲ fact position: debug command> step fact ⊳ position: debug command> step ⊲ 5 position: debug command> step 5 ⊳ position: debug command> step ⊲ (if (= n 0) 1 (* n (fact (- n 1)))) position: debug command> step ⊲ (= n 0) position: debug command> next (= n 0) ⊳ position: debug command> continue value: 120 4

  5. λ -calculus c op ∈ Operators c ∈ Constants ⊃ Operators x ∈ Variables V ∈ Values ::= c | x | ( λx.M ) M, N ∈ Λ ::= V | ( M M ) E ::= [] | E [( V [])] | E [([] M )] Example: (( λx.x ) ( succ ( succ 0))) E = (( λx.x ) ( succ [])) E [( succ 0)] − → E [1] 5

  6. Specification step E [ · ( M N )] − → E [( · M N )] [step 1] step E [ · V ] − → E [ V · ] [step 2] step E [( V · M )] − → E [( V · M )] [step 3] δ ( c op c ) − → V [step 4] step E [( c op c · )] − → E [ V · ] β v (( λx.M ) V ) − → N [step 5] step E [(( λx.M ) V · )] − → E [ · N ] * − → V M [next 1] E [ · M ] next − → E [ V · ] * ( V 1 V 2 ) − → V [next 2] E [( V 1 V 2 · )] next − → E [ V · ] E [( V · M )] next − → E [( V · M )] [next 3] 6

  7. Theoretical Implementation (part 1) CEK-machine E ∈ Env ::= [] | ( x, ( V, E )) :: E K ∈ K ::= k ∅ | fun ( V, E, K ) | arg ( M, E, K ) � ( V, E ) if x = y lookup ( x, ( y, ( V, E )) :: E ′ ) = lookup ( x, E ′ ) otherwise C ∈ C ::= � M, E, K � � ( M N ) , E, K � �− → � M, E, arg ( N, E, K ) � � V, E, arg ( N, E ′ , K ) � �− → � N, E ′ , fun ( V, E, K ) � if V / ∈ Variables � c, E, fun ( c op , E ′ , K ) � �− → � δ ( c op , c ) , [] , K � � V, E, fun (( λx.M ) , E ′ , K ) � �− → � M, ( x, ( V, E )) :: E ′ , K � if V / ∈ Variables � x, E, K � �− → � lookup ( x, E ) 1 , lookup ( x, E ) 2 , K � 7

  8. Theoretical Implementation (part 2) � V, E, K d � �− → � V · , E, K � if V / ∈ Variables step �· ( M N ) , E, K � �− → �· M, E, arg ( N, E, K ) � step �· V, E, K � �− → � V, E, K d � step � V · , E, arg ( N, E ′ , K ) � �− → �· N, E ′ , fun ( V, E, K ) � step � c · , E, fun ( c op , E ′ , K ) � �− → � δ ( c op , c ) · , [] , K � step � V · , E, fun (( λx.M ) , E ′ , K ) � �− → �· M, ( x, ( V, E )) :: E ′ , K � next �· M, E, K � �− → � M, E, K d � next � V · , E, arg ( N, E ′ , K ) � �− → �· N, E ′ , fun ( V, E, K ) � next � c · , E, fun ( c op , E ′ , K ) � �− → � δ ( c op , c ) · , [] , K � next � V · , E, fun (( λx.M ) , E ′ , K ) � �− → � M, ( x, ( V, E )) :: E ′ , K d � 8

  9. Correctness (of step) step E [ · ( M N )] − → E [( · M N )] step �· ( M N ) , E, K � �− → �· M, E, arg ( N, E, K ) � step E [ · V ] − → E [ V · ] step �· V, E, K � �− → � V, E, K d � step E [( V · M )] − → E [( V · M )] step � V · , E, arg ( M, E ′ , K ) � �− → �· M, E ′ , fun ( V, E, K ) � δ ( c op c ) − → V step E [( c op c · )] − → E [ V · ] step � c · , E, fun ( c op , E ′ , K ) � �− → � δ ( c op , c ) · , [] , K � β v (( λx.M ) V ) − → N step E [(( λx.M ) V · )] − → E [ · N ] step � V · , E, fun (( λx.M ) , E ′ , K ) � �− → �· M, ( x, ( V, E )) :: E ′ , K � 9

  10. Correctness (of next) * M − → V E [ · M ] next − → E [ V · ] next �· M, E, K � �− → � M, E, K d � * ( V 1 V 2 ) − → V E [( V 1 V 2 · )] next − → E [ V · ] next � c · , E, fun ( c op , E ′ , K ) � �− → � δ ( c op , c ) · , [] , K � next � V · , E, fun (( λx.M ) , E ′ , K ) � �− → � M, ( x, ( V, E )) :: E ′ , K d � E [( V · M )] next − → E [( V · M )] next � V · , E, arg ( M, E ′ , K ) � �− → �· M, E ′ , fun ( V, E, K ) � 10

  11. Practical Implementation (part 1) RK-machine � [] , eval ( c, E, K ) � �− → � c :: [] , K � � [] , eval ( x, E, K ) � �− → � lookup ( x, E ) :: [] , K � � [] , eval (( λ� x.M ) , E, K ) � �− → � closure ( � x, M, E ) :: [] , K � � [] , eval (( if M 0 M 1 M 2 ) , E, K ) � �− → � [] , eval ( M 0 , E, if ( M 1 , M 2 , E, K )) � � [] , eval (( M 0 M 1 . . . M n ) , E, K ) � �− → � [] , evalapp ([] , [ M 0 , M 1 , . . . , M n ] , E, K ) � � true :: [] , if ( M 1 , M 2 , E, K ) � �− → � [] , eval ( M 1 , E, K ) � � false :: [] , if ( M 1 , M 2 , E, K ) � �− → � [] , eval ( M 2 , E, K ) � � [] , evalapp ( c op :: � R, [] , E, K ) � �− → � δ ( c op , � R ) :: [] , K � x, M, E ) :: � R, [] , E ′ , K ) � � [] , evalapp ( closure ( � �− → x, � � [] , eval ( M, ( � R ) :: E, K ) � 11

  12. Practical Implementation (part 2) � V, E, K d � �− → � V · , E, K � if V / ∈ Variables � R :: [] , K d � �− → � R · :: [] , K � step �· V, E, K � �− → � V, E, K d � step � [] , eval ( · V, E, K ) � �− → � [] , eval ( V, E, K d ) � step � V · , E, fun (( λx.M ) , E ′ , K ) � �− → �· M, ( x, ( V, E )) :: E ′ , K � x, M, E ) :: � R, [] , E ′ , K ) � � R n · :: [] , mevalapp ( closure ( � step x, � �− → � [] , eval ( · M, ( � R @[ R n ]) :: E, K ) � 12

  13. Practical Implementation (part 3) (define (interp exp env k) (cond ((constant? exp) (apply-k k exp)) ((quote? exp) (apply-k k (unquote exp))) ((variable? exp) (apply-k k (lookup exp env))) ((abstraction? exp) (apply-k k (make-closure env exp))) ((if? exp) (interp (if-test exp) env (make-if-cont exp env k))) ((application? exp) (interp (rator exp) env (make-app-cont exp env k))) (else (error "unknown expression")))) 13

  14. Practical Implementation (part 4) I [ [ c ] ] ρκ = κc I [ [ x ] ] ρκ = κρ ( x ) κ ( λι. ( λκ ′ . ( λv.ι [ ] ρ [ x �→ v ] κ ′ ))) I [ [( λx.M )] ] ρκ = [ M ] I [ [( M N )] ] ρκ = I [ [ M ] ] ρ ( λm. I [ [ N ] ] ρ ( λn. ((( m I ) κ ) n ))) I [ [ · M ] ] ρκ = B [ [ M ] ] ρκ step B [ [ c ] ] ρκ = A cκ step B [ [ x ] ] ρκ = A ρ ( x ) κ step B [ [( λx.M )] ] ρκ = A ( λι. ( λκ ′ . ( λv.ι [ ] ρ [ x �→ v ] κ ′ ))) κ [ M ] step B [ [( M N )] ] ρκ = B [ [ M ] ] ρ ( λm. I [ [ N ] ] ρ ( λn. ((( m I ) κ ) n ))) next B [ [ M ] ] ρκ = I [ [ M ] ] ρ ( λv. A vκ ) 14

  15. step A v ( λn. ((( m I ) κ ) n )) = (( λn. ((( m B ) κ ) n )) v ) step A v ( λm. I [ ] ρ ( λn. ((( m I ) κ ) n ))) [ M ] = (( λm. B [ ] ρ ( λn. ((( m I ) κ ) n ))) v ) [ M ] next A v ( λn. ((( m I ) κ ) n )) = (( λn. ((( m I ) ( λv ′ . A v ′ κ )) n )) v ) next A v ( λm. I [ [ M ] ] ρ ( λn. ((( m I ) κ ) n ))) = (( λm. B [ [ M ] ] ρ ( λn. ((( m I ) κ ) n ))) v ) 15

  16. Advice about Debugger Construction Arthur Nunes-Harwitt Nassau Community College One Education Drive Garden City, NY 11530 nunesa@ncc.edu http://www.matcmp.ncc.edu/ ~ nunesa/ 16

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