Skip to content

Commit 4b2da85

Browse files
authored
Merge pull request #204 from cmsc430/fall-2025
Fall 2025
2 parents 21b860f + bc2fd20 commit 4b2da85

File tree

8 files changed

+2039
-519
lines changed

8 files changed

+2039
-519
lines changed

www/notes/diagrams.rkt

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#lang racket
2+
(provide make-heap-diagram)
3+
(require pict)
4+
(require pict/code)
5+
6+
(define pi 3.14)
7+
8+
9+
(define n 40)
10+
11+
(define (make-imm-cell i)
12+
(cc-superimpose
13+
(code #,i)
14+
(rectangle n n)))
15+
16+
(define (make-cons-cell)
17+
(cb-superimpose (rectangle n n)
18+
(code cons)))
19+
20+
21+
(define (make-box-cell)
22+
(cb-superimpose (rectangle n n)
23+
(code box)))
24+
25+
(define (make-vect-cell)
26+
(cb-superimpose (rectangle n n)
27+
(code vect)))
28+
29+
30+
31+
(define (fwd-pts-to a b p)
32+
(pin-arrow-line 7 p
33+
a cc-find
34+
b lt-find
35+
#:start-angle (/ pi 2)
36+
#:end-angle (- (/ pi 2))
37+
#:start-pull 1/4
38+
#:end-pull 1/2))
39+
40+
41+
#|
42+
(define rax (make-cons-cell))
43+
(define m
44+
(let ((a (make-imm-cell 1))
45+
(b (make-cons-cell))
46+
(c (make-imm-cell 2))
47+
(d (make-cons-cell))
48+
(e (make-imm-cell 3))
49+
(f (make-imm-cell ''())))
50+
(define pre
51+
(foldr (λ (p1 p2)
52+
(hc-append 0 p1 p2))
53+
(rectangle 0 n)
54+
(list a b c d e f)))
55+
(define heap
56+
(vc-append 0 (fwd-pts-to d e (fwd-pts-to b c pre))
57+
(text "heap")))
58+
59+
(define all
60+
(hc-append n (vc-append 0 rax (text "rax")) heap))
61+
62+
(define q
63+
(fwd-pts-to rax heap all))
64+
65+
(inset q 20)))
66+
|#
67+
68+
69+
70+
(define (make-cell v)
71+
(match v
72+
[`(cons ,_) (make-cons-cell)]
73+
[`(box ,_) (make-box-cell)]
74+
[`(vect ,_) (make-vect-cell)]
75+
[_ (make-imm-cell v)]))
76+
77+
(define (add-arrows spec cells p)
78+
;(printf "~a~n" spec)
79+
(match spec
80+
['() p]
81+
[(cons `(_ ,i) s)
82+
(add-arrows s
83+
cells
84+
(fwd-pts-to (list-ref cells (sub1 (- (length cells) (length s))))
85+
(list-ref cells i)
86+
p))]
87+
[(cons _ s) (add-arrows s cells p)]))
88+
89+
(define (make-heap-diagram spec)
90+
(match spec
91+
[(cons (and `(,_ ,i) r) h)
92+
(define rax (make-cell r))
93+
(define heap (map make-cell h))
94+
(define heap/arrows
95+
(add-arrows (rest spec) heap
96+
(foldr (λ (p1 p2)
97+
(hc-append 0 p1 p2))
98+
(rectangle 0 n)
99+
heap)))
100+
101+
(define heap/arrows/label
102+
(vc-append
103+
0
104+
heap/arrows
105+
(text "heap")))
106+
107+
(define rax/label
108+
(vc-append 0 rax (text "rax")))
109+
110+
(inset
111+
(fwd-pts-to rax (list-ref heap i) (hc-append n rax/label heap/arrows/label))
112+
(* n 2))]))
113+
#;
114+
(make-heap-diagram
115+
'((cons 0)
116+
1
117+
(cons 2)
118+
2
119+
(cons 4)
120+
3
121+
'()))
122+
123+
#;
124+
(make-heap-diagram
125+
'((cons 4)
126+
3
127+
'()
128+
2
129+
(cons 0)
130+
1
131+
(cons 2)))
132+
133+
134+
135+
136+
#;
137+
(let ((a (make-imm-cell 3))
138+
(b (make-imm-cell ''()))
139+
(c (make-imm-cell 2))
140+
(d (make-cons-cell))
141+
(e (make-imm-cell 1))
142+
(f (make-cons-cell))
143+
(g (make-cocell ''())))
144+
(define pre
145+
(foldr (λ (p1 p2)
146+
(hc-append 0 p1 p2))
147+
(rectangle 0 n)
148+
(list a b c d e f g)))
149+
(inset (fwd-pts-to f g (fwd-pts-to d e (fwd-pts-to b c pre))) 20))
150+

www/notes/evildoer.scrbl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,16 +702,12 @@ of @racket[interp/io]:
702702
@ex[
703703
(exec/io (parse '(write-byte (read-byte))) "z")]
704704

705-
Note that we still provide an @racket[exec] function that works for
706-
programs that don't do I/O:
705+
Note that we still provide an @racket[exec] function, but it
706+
assumes there is no input and it prints all output:
707707

708708
@ex[
709-
(exec (parse '(eof-object? #f)))]
710-
711-
But it will fail if executing a program that uses I/O:
712-
713-
@ex[
714-
(eval:error (exec (parse '(write-byte 97))))]
709+
(exec (parse '(eof-object? (read-byte))))
710+
(exec (parse '(write-byte 97)))]
715711

716712
We can now state the correctness property we want of the compiler:
717713

www/notes/fraud.scrbl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,10 @@ domain of expressions to be just @bold{closed expressions}, i.e. those
899899
that have no unbound variables.
900900

901901
@bold{Compiler Correctness}: @emph{For all @racket[e] @math{∈}
902-
@tt{ClosedExpr}, @racket[i], @racket[o] @math{∈} @tt{String}, and @racket[v]
903-
@math{∈} @tt{Value}, if @racket[(interp/io e i)] equals @racket[(cons
904-
v o)], then @racket[(exec/io e i)] equals
905-
@racket[(cons v o)].}
902+
@tt{ClosedExpr}, @racket[i], @racket[o] @math{∈} @tt{String}, and @racket[A]
903+
@math{∈} @tt{Answer}, if @racket[(interp/io e i)] equals @racket[(cons
904+
a o)], then @racket[(exec/io e i)] equals
905+
@racket[(cons a o)].}
906906

907907
The check for correctness is the same as before, although the check should only be applied
908908
to elements of @tt{ClosedExpr}:

0 commit comments

Comments
 (0)