@@ -212,7 +212,7 @@ Here's what this code will compile to, roughly:
212212(asm-interp
213213 (seq (Global 'entry )
214214 (Label 'entry )
215-
215+
216216 ;; calling (f 100), so set up return address,
217217 ;; push argument, then jump
218218 (Lea 'rax 'r1 )
@@ -221,20 +221,20 @@ Here's what this code will compile to, roughly:
221221 (Push 'rax )
222222 (Jmp 'f )
223223 (Label 'r1 )
224-
224+
225225 ;; done with (f 100), return
226226 (Ret)
227-
227+
228228 ;; (define (f x) ...)
229229 (Label 'f )
230230 (Mov 'rax (Offset 'rsp 0 ))
231231 (Cmp 'rax 0 )
232232 (Jne 'if_false )
233-
233+
234234 ;; if-then branch
235235 (Mov 'rax 42 )
236236 (Jmp 'done )
237-
237+
238238 ;; if-else branch
239239 (Label 'if_false )
240240 ;; calling (f (sub1 x)), so set up return address,
@@ -246,7 +246,7 @@ Here's what this code will compile to, roughly:
246246 (Push 'rax )
247247 (Jmp 'f )
248248 (Label 'r2 )
249-
249+
250250 (Label 'done )
251251 (Add 'rsp 8 ) ; pop x
252252 (Ret)))
@@ -348,11 +348,11 @@ You can see where this is going.
348348 | . |
349349 | . |
350350 | . |
351- +----------------------+
351+ +----------------------+
352352 | return to r2 |
353353 +----------------------+
354354 | x : 1 |
355- +----------------------+
355+ +----------------------+
356356 | return to r2 |
357357 +----------------------+
358358rsp ---> | x : 0 |
@@ -422,7 +422,7 @@ We can modify the code to embody these ideas:
422422(asm-interp
423423 (seq (Global 'entry )
424424 (Label 'entry )
425-
425+
426426 ;; calling (f 100), so set up return address,
427427 ;; push argument, then jump
428428 (Lea 'rax 'r1 )
@@ -431,20 +431,20 @@ We can modify the code to embody these ideas:
431431 (Push 'rax )
432432 (Jmp 'f )
433433 (Label 'r1 )
434-
434+
435435 ;; done with (f 100), return
436436 (Ret)
437-
437+
438438 ;; (define (f x) ...)
439439 (Label 'f )
440440 (Mov 'rax (Offset 'rsp 0 ))
441441 (Cmp 'rax 0 )
442442 (Jne 'if_false )
443-
443+
444444 ;; if-then branch
445445 (Mov 'rax 42 )
446446 (Jmp 'done )
447-
447+
448448 ;; if-else branch
449449 (Label 'if_false )
450450 ;; TAIL calling (f (sub1 x)),
@@ -456,7 +456,7 @@ We can modify the code to embody these ideas:
456456 (Add 'rsp 8 ) ; pop x
457457 (Push 'rax ) ; push arg
458458 (Jmp 'f )
459-
459+
460460 (Label 'done )
461461 (Add 'rsp 8 ) ; pop x
462462 (Ret)))
@@ -550,17 +550,17 @@ call:
550550
551551 ;; No need for this since we never come back:
552552 ;; (Ret)
553-
553+
554554 ;; (define (f x) ...)
555555 (Label 'f )
556556 (Mov 'rax (Offset 'rsp 0 ))
557557 (Cmp 'rax 0 )
558558 (Jne 'if_false )
559-
559+
560560 ;; if-then branch
561561 (Mov 'rax 42 )
562562 (Jmp 'done )
563-
563+
564564 ;; if-else branch
565565 (Label 'if_false )
566566 ;; TAIL calling (f (sub1 x)),
@@ -572,7 +572,7 @@ call:
572572 (Add 'rsp 8 ) ; pop x
573573 (Push 'rax ) ; push arg
574574 (Jmp 'f )
575-
575+
576576 (Label 'done )
577577 (Add 'rsp 8 ) ; pop x
578578 (Ret)))
@@ -637,7 +637,7 @@ ready to be made, the stack will look like:
637637 | 3 |
638638 +----------------------+
639639rsp ---> | 5 |
640- +----------------------+
640+ +----------------------+
641641}|
642642
643643At which point we need to remove the @racket[x] and @racket[y] part,
@@ -651,7 +651,7 @@ below the return address, i.e. we want:
651651 | 3 |
652652 +----------------------+
653653rsp ---> | 5 |
654- +----------------------+
654+ +----------------------+
655655}|
656656
657657To accomplish, we rely on the following helper function for generating
@@ -732,6 +732,7 @@ There are two important places where @racket[t?] is seeded to @racket[#t]:
732732@item{The body of every function is in tail position.}
733733]
734734
735+
735736The complete compiler:
736737
737738@codeblock-include["jig/compile.rkt " ]
0 commit comments