File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #lang racket
2+ (require "../random.rkt "
3+ (only-in "../interp.rkt " interp)
4+ (only-in "../compile.rkt " compile)
5+ "../asm/interp.rkt "
6+ "../syntax.rkt "
7+ rackunit)
8+
9+ (define (check-compiler e)
10+ (check-eqv? (asm-interp (compile e))
11+ (interp e)
12+ e))
13+
14+ ;; boy is this slow
15+ (for ([i (in-range 100 )])
16+ (check-compiler (sexpr->ast (random-expr))))
Original file line number Diff line number Diff line change 1+ #lang racket
2+ (require "../compile.rkt " "../asm/interp.rkt " "../syntax.rkt " rackunit)
3+
4+ (define (run e)
5+ (asm-interp (compile (sexpr->ast e))))
6+
7+ (check-equal? (run 7 ) 7 )
8+ (check-equal? (run -8 ) -8 )
9+ (check-equal? (run '(add1 (add1 7 ))) 9 )
10+ (check-equal? (run '(add1 (sub1 7 ))) 7 )
11+
12+
13+ ;; Con examples
14+ (check-equal? (run '(if (zero? 0 ) 1 2 )) 1 )
15+ (check-equal? (run '(if (zero? 1 ) 1 2 )) 2 )
16+ (check-equal? (run '(if (zero? -7 ) 1 2 )) 2 )
17+ (check-equal? (run '(if (zero? 0 )
18+ (if (zero? 1 ) 1 2 )
19+ 7 ))
20+ 2 )
21+ (check-equal? (run '(if (zero? (if (zero? 0 ) 1 0 ))
22+ (if (zero? 1 ) 1 2 )
23+ 7 ))
24+ 7 )
25+
26+ (check-equal? (run '(let ((x 7 )) x)) 7 )
27+ (check-equal? (run '(let ((x 7 )) 2 )) 2 )
28+ (check-equal? (run '(let ((x 7 )) (add1 x))) 8 )
29+ (check-equal? (run '(let ((x (add1 7 ))) x)) 8 )
30+ (check-equal? (run '(let ((x 7 )) (let ((y 2 )) x))) 7 )
31+ (check-equal? (run '(let ((x 7 )) (let ((x 2 )) x))) 2 )
32+ (check-equal? (run '(let ((x 7 )) (let ((x (add1 x))) x))) 8 )
33+
34+ (check-equal? (run '(let ((x 0 ))
35+ (if (zero? x) 7 8 )))
36+ 7 )
37+ (check-equal? (run '(let ((x 1 ))
38+ (add1 (if (zero? x) 7 8 ))))
39+ 9 )
40+
41+ (check-equal? (run '(+ 3 4 )) 7 )
42+ (check-equal? (run '(- 3 4 )) -1 )
43+ (check-equal? (run '(+ (+ 2 1 ) 4 )) 7 )
44+ (check-equal? (run '(+ (+ 2 1 ) (+ 2 2 ))) 7 )
45+
46+
You can’t perform that action at this time.
0 commit comments