File tree Expand file tree Collapse file tree 8 files changed +45
-12
lines changed Expand file tree Collapse file tree 8 files changed +45
-12
lines changed Original file line number Diff line number Diff line change 1
1
#lang racket
2
- (provide Lit Prim1 If)
2
+ (provide Lit Prim1 If Cond )
3
3
;; type Expr = (Lit Datum)
4
4
;; | (Prim1 Op1 Expr)
5
5
;; | (If Expr Expr Expr)
6
- ;; | (Cond [Listof CondClause] Expr)
7
-
8
- ;; type CondClause = (Clause Expr Expr)
6
+ ;; | (Cond [Listof Expr] [Listof Expr] Expr)
9
7
;; type Datum = Integer
10
8
;; | Boolean
11
9
;; type Op1 = 'add1 | 'sub1
14
12
(struct Lit (d) #:prefab )
15
13
(struct Prim1 (p e) #:prefab )
16
14
(struct If (e1 e2 e3) #:prefab )
15
+ (struct Cond (cs es el) #:prefab )
17
16
Original file line number Diff line number Diff line change 16
16
(seq (Cmp rax 0 )
17
17
(Mov rax (value->bits #f ))
18
18
(Mov r9 (value->bits #t ))
19
- (Cmove rax r9))]))
19
+ (Cmove rax r9))]
20
+ ['abs
21
+ ;; TODO
22
+ (seq)]
23
+ ['-
24
+ ;; TODO
25
+ (seq)]
26
+ ['not
27
+ ;; TODO
28
+ (seq)]))
20
29
Original file line number Diff line number Diff line change 22
22
[(Lit d) (compile-value d)]
23
23
[(Prim1 p e) (compile-prim1 p e)]
24
24
[(If e1 e2 e3)
25
- (compile-if e1 e2 e3)]))
25
+ (compile-if e1 e2 e3)]
26
+ [(Cond eqs eas el) ;; TODO
27
+ (seq)]))
26
28
27
29
;; Value -> Asm
28
30
(define (compile-value v)
Original file line number Diff line number Diff line change 8
8
['add1 (add1 v)]
9
9
['sub1 (sub1 v)]
10
10
['zero? (zero? v)]
11
- ['not (not v)]
12
- ['- (- v)]
13
- ['abs (abs v)]))
11
+ ['not
12
+ ;; TODO
13
+ 0 ]
14
+ ['-
15
+ ;; TODO
16
+ 0 ]
17
+ ['abs
18
+ ;; TODO
19
+ 0 ]))
14
20
Original file line number Diff line number Diff line change 15
15
[(If e1 e2 e3)
16
16
(if (interp e1)
17
17
(interp e2)
18
- (interp e3))]))
18
+ (interp e3))]
19
+ [(Cond eqs eas el)
20
+ ;; TODO
21
+ 0 ]))
19
22
Original file line number Diff line number Diff line change 18
18
[(list s1 s2 s3)
19
19
(If (parse s1) (parse s2) (parse s3))]
20
20
[_ (error "if: bad syntax " s)])]
21
+ ['cond
22
+ (parse-cond sr)]
21
23
[_ (error "parse error " s)])]
22
24
[_ (error "parse error " s)]))
23
25
26
+ ;; S-Expr -> Cond
27
+ (define (parse-cond s)
28
+ (match s
29
+ [(list (list 'else s)) (Cond '() '() (parse s))]
30
+ [(cons (list s1 s2) sr)
31
+ (match (parse-cond sr)
32
+ [(Cond qs es e)
33
+ (Cond (cons (parse s1) qs) (cons (parse s2) es) e)])]
34
+ [_ (error "parse error " )]))
35
+
24
36
;; Any -> Boolean
25
37
(define (datum? x)
26
38
(or (exact-integer? x)
Original file line number Diff line number Diff line change 1
1
#lang racket
2
- (provide Lit Prim0 Prim1 Prim2 Prim3 If Eof Begin
2
+ (provide Lit Prim0 Prim1 Prim2 Prim3 If
3
+ Eof Begin
3
4
Let Var Prog Defn App
4
5
Apply FunPlain FunRest FunCase)
5
6
Original file line number Diff line number Diff line change 1
1
#lang racket
2
- (provide Lit Prim0 Prim1 Prim2 Prim3 PrimN If Eof Begin
2
+ (provide Lit Prim0 Prim1 Prim2 Prim3 PrimN If
3
+ Eof Begin
3
4
Let Var Prog Defn App
4
5
Match Box Cons Conj
5
6
List Pred Vect)
You can’t perform that action at this time.
0 commit comments