From 1dc65b4ffd01bc43daca4c68f2d0e7900c58ccf2 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Wed, 14 Apr 2021 21:47:04 -0400 Subject: [PATCH] Answer 5.32 --- ex-5_31-xx.scm | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/ex-5_31-xx.scm b/ex-5_31-xx.scm index af0e8bb..80c7e4e 100644 --- a/ex-5_31-xx.scm +++ b/ex-5_31-xx.scm @@ -1,6 +1,6 @@ (load "util.scm") -(display "\nex-5.31\n") +(display "\nex-5.31 - save-and-restore-for-apply\n") ; 1. save and restore env around operator ; 2. save and restore env around each operand (except last) @@ -28,7 +28,43 @@ (display "[answered]\n") -(display "\nex-5.32\n") +(display "\nex-5.32 - optimize-eceval-application\n") + +'( +ev-application + (save continue) + (assign unev (op operands) (reg exp)) + (assign exp (op operator) (reg exp)) + (assign continue (label ev-appl-did-operator-no-restore)) + (test (op variable?) (reg exp)) + (branch (label ev-variable)) + (save env) + (save unev) + (assign continue (label ev-appl-did-operator)) + (goto (label eval-dispatch)) +ev-appl-did-operator + (restore unev) + (restore env) +ev-appl-did-operator-no-restore + (assign argl (op empty-arglist)) + (assign proc (reg val)) + (test (op no-operands?) (reg unev)) + (branch (label apply-dispatch)) + (save proc) + ) + +(display "[ok]\n") + +; b. Applying all the optimizations make sense, but the compiled code will +; still run faster because the interpreter has to analyze the code every time +; it executes and the analysis itself adds overhead that the compiler can do +; before runtime +(display "[answered]\n") (display "\nex-5.33\n") +(display "CONTINUE at 5.5.3\n") + +(display "\nex-5.34\n") +;(display "\nex-5.35\n") +