@@ -56,12 +56,17 @@ Let's consider some examples:
5656
5757@itemlist[
5858
59- @item{... }
59+ @item{@racket['(if (zero? 0 ) (add1 2 ) 4 )] means @racket[3 ].}
60+ @item{@racket['(if (zero? 1 ) (add1 2 ) 4 )] means @racket[4 ].}
61+ @item{@racket['(if (zero? (if (zero? (sub1 1 )) 1 0 )) (add1 2 ) 4 )] means @racket[4 ].}
62+ @item{@racket['(if (zero? (add1 0 )) (add1 2 ) (if (zero? (sub1 1 )) 1 0 ))] means @racket[1 ].}
6063
6164]
6265
6366
64- The semantics...
67+ The semantics is inductively defined as before. There are @emph{two}
68+ new rules added for handling if-expressions: one for when the test
69+ expression means @racket[0 ] and one for when it doesn't.
6570
6671@(define ((rewrite s) lws)
6772 (define lhs (list-ref lws 2 ))
@@ -135,24 +140,25 @@ according to @render-term[C 𝑪𝒓]:
135140@(show-judgment 𝑪 0 1 )
136141}
137142
138- The interpreter ...
143+ The interpreter has an added case for if-expressions, which
144+ recursively evaluates the test expression and branches based on its
145+ value.
139146
140147@codeblock-include["con/interp.rkt " ]
141148
142149We can confirm the interpreter computes the right result for the
143150examples given earlier:
144151
145152@ex[
146- '...
153+ (interp '(if (zero? 0 ) (add1 2 ) 4 ))
154+ (interp '(if (zero? 1 ) (add1 2 ) 4 ))
155+ (interp '(if (zero? (if (zero? (sub1 1 )) 1 0 )) (add1 2 ) 4 ))
156+ (interp '(if (zero? (add1 0 )) (add1 2 ) (if (zero? (sub1 1 )) 1 0 )))
147157]
148158
149- Correctness...
150- @;{
151- @bold{Interpreter Correctness}: @emph{For all Con expressions
152- @racket[e] and integers @racket[i], if (@racket[e],@racket[i]) in
153- @render-term[C 𝑪], then @racket[(interp e)] equals
154- @racket[i].}
155- }
159+ The argument for the correctness of the interpreter follows the same
160+ structure as for @seclink["Blackmail " ]{Blackmail}, but with an added case for
161+ if-expressions.
156162
157163@section{An Example of Con compilation}
158164
@@ -163,6 +169,12 @@ We already know how to compile the @racket['8], @racket['2], and
163169
164170What needs to happen? ...
165171
172+
173+ @ex[
174+ (asm-display (compile '(if (zero? 8 ) 2 3 )))
175+ ]
176+
177+
166178@codeblock-include["con/asm/ast.rkt " ]
167179
168180We omit the printer code, which is mundane. See
0 commit comments