Skip to content

Commit e9fd2f1

Browse files
authored
Merge pull request #6 from cmsc430/crook
crook
2 parents 6cd0308 + 3ec5533 commit e9fd2f1

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

dupe-plus/ast.rkt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#lang racket
2-
(provide Lit Prim1 If)
2+
(provide Lit Prim1 If Cond)
33
;; type Expr = (Lit Datum)
44
;; | (Prim1 Op1 Expr)
55
;; | (If Expr Expr Expr)
6-
;; | (Cond [Listof CondClause] Expr)
7-
8-
;; type CondClause = (Clause Expr Expr)
6+
;; | (Cond [Listof Expr] [Listof Expr] Expr)
97
;; type Datum = Integer
108
;; | Boolean
119
;; type Op1 = 'add1 | 'sub1
@@ -14,4 +12,5 @@
1412
(struct Lit (d) #:prefab)
1513
(struct Prim1 (p e) #:prefab)
1614
(struct If (e1 e2 e3) #:prefab)
15+
(struct Cond (cs es el) #:prefab)
1716

dupe-plus/compile-ops.rkt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,14 @@
1616
(seq (Cmp rax 0)
1717
(Mov rax (value->bits #f))
1818
(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)]))
2029

dupe-plus/compile.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
[(Lit d) (compile-value d)]
2323
[(Prim1 p e) (compile-prim1 p e)]
2424
[(If e1 e2 e3)
25-
(compile-if e1 e2 e3)]))
25+
(compile-if e1 e2 e3)]
26+
[(Cond eqs eas el) ;; TODO
27+
(seq)]))
2628

2729
;; Value -> Asm
2830
(define (compile-value v)

dupe-plus/interp-prim.rkt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
['add1 (add1 v)]
99
['sub1 (sub1 v)]
1010
['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]))
1420

dupe-plus/interp.rkt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
[(If e1 e2 e3)
1616
(if (interp e1)
1717
(interp e2)
18-
(interp e3))]))
18+
(interp e3))]
19+
[(Cond eqs eas el)
20+
;; TODO
21+
0]))
1922

dupe-plus/parse.rkt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@
1818
[(list s1 s2 s3)
1919
(If (parse s1) (parse s2) (parse s3))]
2020
[_ (error "if: bad syntax" s)])]
21+
['cond
22+
(parse-cond sr)]
2123
[_ (error "parse error" s)])]
2224
[_ (error "parse error" s)]))
2325

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+
2436
;; Any -> Boolean
2537
(define (datum? x)
2638
(or (exact-integer? x)

iniquity-plus/ast.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#lang racket
2-
(provide Lit Prim0 Prim1 Prim2 Prim3 If Eof Begin
2+
(provide Lit Prim0 Prim1 Prim2 Prim3 If
3+
Eof Begin
34
Let Var Prog Defn App
45
Apply FunPlain FunRest FunCase)
56

knock-plus/ast.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#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
34
Let Var Prog Defn App
45
Match Box Cons Conj
56
List Pred Vect)

0 commit comments

Comments
 (0)