Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions www/notes/diagrams.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#lang racket
(provide make-heap-diagram)
(require pict)
(require pict/code)

(define pi 3.14)


(define n 40)

(define (make-imm-cell i)
(cc-superimpose
(code #,i)
(rectangle n n)))

(define (make-cons-cell)
(cb-superimpose (rectangle n n)
(code cons)))


(define (make-box-cell)
(cb-superimpose (rectangle n n)
(code box)))

(define (make-vect-cell)
(cb-superimpose (rectangle n n)
(code vect)))



(define (fwd-pts-to a b p)
(pin-arrow-line 7 p
a cc-find
b lt-find
#:start-angle (/ pi 2)
#:end-angle (- (/ pi 2))
#:start-pull 1/4
#:end-pull 1/2))


#|
(define rax (make-cons-cell))
(define m
(let ((a (make-imm-cell 1))
(b (make-cons-cell))
(c (make-imm-cell 2))
(d (make-cons-cell))
(e (make-imm-cell 3))
(f (make-imm-cell ''())))
(define pre
(foldr (λ (p1 p2)
(hc-append 0 p1 p2))
(rectangle 0 n)
(list a b c d e f)))
(define heap
(vc-append 0 (fwd-pts-to d e (fwd-pts-to b c pre))
(text "heap")))

(define all
(hc-append n (vc-append 0 rax (text "rax")) heap))

(define q
(fwd-pts-to rax heap all))

(inset q 20)))
|#



(define (make-cell v)
(match v
[`(cons ,_) (make-cons-cell)]
[`(box ,_) (make-box-cell)]
[`(vect ,_) (make-vect-cell)]
[_ (make-imm-cell v)]))

(define (add-arrows spec cells p)
;(printf "~a~n" spec)
(match spec
['() p]
[(cons `(_ ,i) s)
(add-arrows s
cells
(fwd-pts-to (list-ref cells (sub1 (- (length cells) (length s))))
(list-ref cells i)
p))]
[(cons _ s) (add-arrows s cells p)]))

(define (make-heap-diagram spec)
(match spec
[(cons (and `(,_ ,i) r) h)
(define rax (make-cell r))
(define heap (map make-cell h))
(define heap/arrows
(add-arrows (rest spec) heap
(foldr (λ (p1 p2)
(hc-append 0 p1 p2))
(rectangle 0 n)
heap)))

(define heap/arrows/label
(vc-append
0
heap/arrows
(text "heap")))

(define rax/label
(vc-append 0 rax (text "rax")))

(inset
(fwd-pts-to rax (list-ref heap i) (hc-append n rax/label heap/arrows/label))
(* n 2))]))
#;
(make-heap-diagram
'((cons 0)
1
(cons 2)
2
(cons 4)
3
'()))

#;
(make-heap-diagram
'((cons 4)
3
'()
2
(cons 0)
1
(cons 2)))




#;
(let ((a (make-imm-cell 3))
(b (make-imm-cell ''()))
(c (make-imm-cell 2))
(d (make-cons-cell))
(e (make-imm-cell 1))
(f (make-cons-cell))
(g (make-cocell ''())))
(define pre
(foldr (λ (p1 p2)
(hc-append 0 p1 p2))
(rectangle 0 n)
(list a b c d e f g)))
(inset (fwd-pts-to f g (fwd-pts-to d e (fwd-pts-to b c pre))) 20))

12 changes: 4 additions & 8 deletions www/notes/evildoer.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -702,16 +702,12 @@ of @racket[interp/io]:
@ex[
(exec/io (parse '(write-byte (read-byte))) "z")]

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

@ex[
(exec (parse '(eof-object? #f)))]

But it will fail if executing a program that uses I/O:

@ex[
(eval:error (exec (parse '(write-byte 97))))]
(exec (parse '(eof-object? (read-byte))))
(exec (parse '(write-byte 97)))]

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

Expand Down
8 changes: 4 additions & 4 deletions www/notes/fraud.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,10 @@ domain of expressions to be just @bold{closed expressions}, i.e. those
that have no unbound variables.

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

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