-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterp-Rwhile.rkt
37 lines (32 loc) · 1005 Bytes
/
interp-Rwhile.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#lang racket
(require racket/fixnum)
(require "utilities.rkt")
(require "interp-Rany.rkt")
(provide interp-Rwhile interp-Rwhile-class)
;; Note to maintainers of this code:
;; A copy of this interpreter is in the book and should be
;; kept in sync with this code.
(define interp-Rwhile-class
(class interp-Rany-class
(super-new)
(define/override ((interp-exp env) e)
(verbose "Rwhile/interp-exp" e)
(define recur (interp-exp env))
(define result
(match e
[(SetBang x rhs)
(set-box! (lookup x env) (recur rhs))]
[(WhileLoop cnd body)
(define (loop)
(cond [(recur cnd) (recur body) (loop)]
[else (void)]))
(loop)]
[(Begin es body)
(for ([e es]) (recur e))
(recur body)]
[else ((super interp-exp env) e)]))
(verbose "Rwhile/interp-exp" e result)
result)
))
(define (interp-Rwhile p)
(send (new interp-Rwhile-class) interp-program p))