diff --git a/README.md b/README.md index d86d372..c161e17 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # SICP -**This is currently (2021/06/11) work in progress.** - These are my solutions to the CS classic [Structure and Interpretation of Computer Programs](https://mitpress.mit.edu/sites/default/files/sicp/index.html). I have looked up the answer for some exercises on the @@ -243,6 +241,48 @@ programming concepts to Scheme. # Chapter 5 +Chapter 5 combines the previous chapter's concepts, ultimately implementing a +Scheme interpreter running on physical hardware. + +The first section introduces the concept of register machines. Register machines +are an abstraction of physical machines that control the flow of data and can +execute computations. For example, the following diagram shows a machine that +computes factorials. + +![Factorial Machine Diagram](./shared/draw-factorial-reg-machine.png) + +Based on the diagrams, we learn about an assembly-like language that can +represent register-machines. For example, the following listing shows the same +machine as on the previous graph in assembly form. + +```scheme +'(controller + (assign product (const 1)) + (assign counter (const 1)) + test-counter + (test (op >) (reg counter) (reg n)) + (branch (label factorial-done)) + (assign product (op *) (reg product) (reg counter)) + (assign counter (op +) (reg counter) (const 1)) + (goto (label test-counter)) +``` + +In the following sections, we implement a simulator that can execute +register-machine programs and use it to run a Scheme interpreter written in the +register-machine language. We call this the Explicit-Control-Evaluator. + +Finally, we implement a Scheme compiler that compiles into the register-machine +assembly language. Ultimately, we use the compiler to translate the metacircular +evaluator from chapter 4. We then use the register machine simulator to run the +evaluator. Making that work was indeed a fantastic moment. I cannot explain it +well, but seeing how everything comes together gave me a great sense of +accomplishment. + +The last two exercises in the books are programming projects in their own right. +First, I implement a crude [Scheme interpreter in +Rust](https://git.felixm.de/felixm/schemers), and then I modified the compiler +to generate C code. I have implemented the required runtime support, and it +works, at least for simple programs like computing factorials. # Resources diff --git a/shared/draw-factorial-reg-machine.png b/shared/draw-factorial-reg-machine.png new file mode 100644 index 0000000..5eb2301 Binary files /dev/null and b/shared/draw-factorial-reg-machine.png differ