|
8 | 8 |
|
9 | 9 | (define n 40) |
10 | 10 |
|
| 11 | +(define (make-str-cells s) |
| 12 | + (hc-append |
| 13 | + (foldl (λ (c p) |
| 14 | + (hc-append p |
| 15 | + (cc-superimpose (rectangle (/ n 2) n) ((current-code-tt) (string c))))) |
| 16 | + (cc-superimpose (rectangle n n) (code #,(string-length s))) |
| 17 | + (string->list s)) |
| 18 | + (if (even? (string-length s)) |
| 19 | + (rectangle 0 n) |
| 20 | + (cc-superimpose (rectangle (/ n 2) n) (code 0))))) |
| 21 | + |
11 | 22 | (define (make-imm-cell i) |
12 | 23 | (cc-superimpose |
13 | 24 | (code #,i) |
|
17 | 28 | (cb-superimpose (rectangle n n) |
18 | 29 | (code cons))) |
19 | 30 |
|
| 31 | +(define (make-str-cell) |
| 32 | + (cb-superimpose (rectangle n n) |
| 33 | + (code str))) |
20 | 34 |
|
21 | 35 | (define (make-box-cell) |
22 | 36 | (cb-superimpose (rectangle n n) |
|
72 | 86 | [`(cons ,_) (make-cons-cell)] |
73 | 87 | [`(box ,_) (make-box-cell)] |
74 | 88 | [`(vect ,_) (make-vect-cell)] |
| 89 | + [`(str ,_) (make-str-cell)] |
| 90 | + [(? string?) (make-str-cells v)] |
75 | 91 | [_ (make-imm-cell v)])) |
76 | 92 |
|
77 | 93 | (define (add-arrows spec cells p) |
78 | 94 | ;(printf "~a~n" spec) |
79 | 95 | (match spec |
80 | 96 | ['() p] |
81 | | - [(cons `(_ ,i) s) |
| 97 | + [(cons `(,_ ,(? integer? i)) s) |
| 98 | + |
82 | 99 | (add-arrows s |
83 | 100 | cells |
84 | 101 | (fwd-pts-to (list-ref cells (sub1 (- (length cells) (length s)))) |
|
99 | 116 | heap))) |
100 | 117 |
|
101 | 118 | (define heap/arrows/label |
102 | | - (vc-append |
103 | | - 0 |
104 | | - heap/arrows |
105 | | - (text "heap"))) |
| 119 | + (vc-append 10 |
| 120 | + (vc-append |
| 121 | + 0 |
| 122 | + heap/arrows |
| 123 | + (text "heap")) |
| 124 | + (text "← lower addresses, higher addresses →"))) |
106 | 125 |
|
107 | 126 | (define rax/label |
108 | | - (vc-append 0 rax (text "rax"))) |
| 127 | + (vc-append 10 (vc-append 0 rax (text "rax")) |
| 128 | + (text " "))) |
109 | 129 |
|
110 | 130 | (inset |
111 | | - (fwd-pts-to rax (list-ref heap i) (hc-append n rax/label heap/arrows/label)) |
112 | | - (* n 2))])) |
| 131 | + (fwd-pts-to rax (list-ref heap i) |
| 132 | + (hc-append n rax/label heap/arrows/label)) |
| 133 | + 0 (* n 2) 0 0)])) |
| 134 | + |
| 135 | +#; |
| 136 | +(define cons-quiz |
| 137 | + (list (make-heap-diagram |
| 138 | + '((cons 4) |
| 139 | + 3 |
| 140 | + '() |
| 141 | + 2 |
| 142 | + (cons 0) |
| 143 | + 1 |
| 144 | + (cons 2))) |
| 145 | + (make-heap-diagram |
| 146 | + '((cons 0) |
| 147 | + 1 |
| 148 | + (cons 2) |
| 149 | + 2 |
| 150 | + (cons 4) |
| 151 | + 3 |
| 152 | + '())) |
| 153 | + (make-heap-diagram |
| 154 | + '((cons 4) |
| 155 | + '() |
| 156 | + 3 |
| 157 | + (cons 0) |
| 158 | + 2 |
| 159 | + (cons 2) |
| 160 | + 1)) |
| 161 | + (make-heap-diagram |
| 162 | + '((cons 0) |
| 163 | + (cons 2) |
| 164 | + 1 |
| 165 | + (cons 4) |
| 166 | + 2 |
| 167 | + '() |
| 168 | + 3)) |
| 169 | + )) |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +;(text "← lower addresses, higher addresses →") |
| 174 | + |
113 | 175 | #; |
114 | 176 | (make-heap-diagram |
115 | 177 | '((cons 0) |
|
0 commit comments