@@ -77,10 +77,10 @@ The grammar of abstract Backmail expressions is:
7777
7878@centered{@render-language[B]}
7979
80- So, @racket[(Int 0 )], @racket[(Int 120 )], and
81- @racket[(Int -42 )] are Blackmail AST expressions, but so are
82- @racket[(Prim1 'add1 (Int 0 ))], @racket[(Sub1 (Int 120 ))],
83- @racket[(Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Int -42 ))))].
80+ So, @racket[(Lit 0 )], @racket[(Lit 120 )], and
81+ @racket[(Lit -42 )] are Blackmail AST expressions, but so are
82+ @racket[(Prim1 'add1 (Lit 0 ))], @racket[(Sub1 (Lit 120 ))],
83+ @racket[(Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Lit -42 ))))].
8484
8585A datatype for representing expressions can be defined as:
8686
@@ -129,7 +129,7 @@ contrast to the first rule, which applies unconditionally.
129129
130130We can understand these rules as saying the following:
131131@itemlist[
132- @item{For all integers @math{i}, @math{((Int i),i)} is in @render-term[B 𝑩].}
132+ @item{For all integers @math{i}, @math{((Lit i),i)} is in @render-term[B 𝑩].}
133133
134134@item{For expressions @math{e_0} and all integers @math{i_0} and
135135@math{i_1}, if @math{(e_0,i_0)} is in @render-term[B 𝑩] and @math{i_1
@@ -157,11 +157,11 @@ interpreter, one for each form of expression:
157157@codeblock-include["blackmail/interp.rkt " ]
158158
159159@examples[#:eval ev
160- (interp (Int 42 ))
161- (interp (Int -7 ))
162- (interp (Prim1 'add1 (Int 42 )))
163- (interp (Prim1 'sub1 (Int 8 )))
164- (interp (Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Int 8 )))))
160+ (interp (Lit 42 ))
161+ (interp (Lit -7 ))
162+ (interp (Prim1 'add1 (Lit 42 )))
163+ (interp (Prim1 'sub1 (Lit 8 )))
164+ (interp (Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Lit 8 )))))
165165]
166166
167167Here's how to connect the dots between the semantics and interpreter:
@@ -172,7 +172,7 @@ expression, which determines which rule of the semantics applies.
172172
173173@itemlist[
174174
175- @item{if @math{e} is an integer @math{(Int i)}, then we're done: this is the
175+ @item{if @math{e} is an integer @math{(Lit i)}, then we're done: this is the
176176right-hand-side of the pair @math{(e,i)} in @render-term[B 𝑩].}
177177
178178@item{if @math{e} is an expression @RACKET[(Prim1 'add1 (UNSYNTAX
@@ -241,9 +241,9 @@ recursion, much like the interpreter.
241241We can now try out a few examples:
242242
243243@ex[
244- (compile (Prim1 'add1 (Prim1 'add1 (Int 40 ))))
245- (compile (Prim1 'sub1 (Int 8 )))
246- (compile (Prim1 'add1 (Prim1 'add1 (Prim1 'sub1 (Prim1 'add1 (Int -8 ))))))
244+ (compile (Prim1 'add1 (Prim1 'add1 (Lit 40 ))))
245+ (compile (Prim1 'sub1 (Lit 8 )))
246+ (compile (Prim1 'add1 (Prim1 'add1 (Prim1 'sub1 (Prim1 'add1 (Lit -8 ))))))
247247]
248248
249249And give a command line wrapper for parsing, checking, and compiling
@@ -264,9 +264,9 @@ the same @racket[asm-interp] function to encapsulate running
264264assembly code:
265265
266266@ex[
267- (asm-interp (compile (Prim1 'add1 (Prim1 'add1 (Int 40 )))))
268- (asm-interp (compile (Prim1 'sub1 (Int 8 ))))
269- (asm-interp (compile (Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Int -8 )))))))
267+ (asm-interp (compile (Prim1 'add1 (Prim1 'add1 (Lit 40 )))))
268+ (asm-interp (compile (Prim1 'sub1 (Lit 8 ))))
269+ (asm-interp (compile (Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Prim1 'add1 (Lit -8 )))))))
270270]
271271
272272@section{Correctness and random testing}
@@ -332,10 +332,10 @@ x86 does. Let's see:
332332@ex[
333333(define max-int (sub1 (expt 2 63 )))
334334(define min-int (- (expt 2 63 )))
335- (asm-interp (compile (Int max-int)))
336- (asm-interp (compile (Prim1 'add1 (Int max-int))))
337- (asm-interp (compile (Int min-int)))
338- (asm-interp (compile (Prim1 'sub1 (Int min-int))))]
335+ (asm-interp (compile (Lit max-int)))
336+ (asm-interp (compile (Prim1 'add1 (Lit max-int))))
337+ (asm-interp (compile (Lit min-int)))
338+ (asm-interp (compile (Prim1 'sub1 (Lit min-int))))]
339339
340340Now there's a fact you didn't learn in grade school: in the
341341first example, adding 1 to a number made it smaller; in the
@@ -344,18 +344,18 @@ second, subtracting 1 made it bigger!
344344This problem doesn't exist in the interpreter:
345345
346346@ex[
347- (interp (Int max-int))
348- (interp (Prim1 'add1 (Int max-int)))
349- (interp (Int min-int))
350- (interp (Prim1 'sub1 (Int min-int)))
347+ (interp (Lit max-int))
348+ (interp (Prim1 'add1 (Lit max-int)))
349+ (interp (Lit min-int))
350+ (interp (Prim1 'sub1 (Lit min-int)))
351351]
352352
353353So we have found a counter-example to the claim of compiler
354354correctness:
355355
356356@ex[
357- (check-compiler (Prim1 'add1 (Int max-int)))
358- (check-compiler (Prim1 'sub1 (Int min-int)))
357+ (check-compiler (Prim1 'add1 (Lit max-int)))
358+ (check-compiler (Prim1 'sub1 (Lit min-int)))
359359]
360360
361361What can we do? This is the basic problem of a program not
0 commit comments