جزییات کتاب
Compilers are perceived to be magical artifacts, carefully crafted by the wizards, and unfathomable by the mere mortals. This paper attempts to dispel this myth. We build a simple compiler for a simple language in a step-by-step fashion. The input language accepted by the compiler starts minimal, and grows as our knowledge of how to build compilers grows. The final language is almost Scheme.Although the compiler is written in the Scheme programming language, only minimal knowledge of Scheme is required. Essentially, the reader is assumed to be comfortable reading and writing recursive Scheme functions to the level presented in The Little Schemer. Additionally, we recommend the freely available tutorial Teach Yourself Scheme in Fixnum Days for people familiar with other programming languages but not Scheme. The Scheme Programming Language is an invaluable resource for understanding Scheme’s semantics. You will find it most useful when you give up in thinking how list? detects circular data structures.Our compiler targets the Intel-386 architecture, the dominant architecture for personal computing. The output of our compiler is assembly code that can be assembled by gas, the GNU assembler, which is freely available for most operating systems. No knowledge of assembly language or the Intel-386 architecture is assumed beyond the basics: binary numbers, memory layout, and basic pointers. If you are familiar with arrays in C, and know how the bit-level operations (and, or, xor, and not) work, then you’re good to go.ContentsPreface v1 Basic Concepts 11.1 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Immediate Constants . . . . . . . . . . . . . . . . . . . . . . 61.3 Unary Primitives . . . . . . . . . . . . . . . . . . . . . . . . . 101.4 Conditional Expressions . . . . . . . . . . . . . . . . . . . . . 151.5 Binary Primitives . . . . . . . . . . . . . . . . . . . . . . . . . 181.6 Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 241.7 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271.8 Iteration via Proper Tail Calls . . . . . . . . . . . . . . . . . . 311.9 Heap Allocation . . . . . . . . . . . . . . . . . . . . . . . . . 35A Tables 41A.1 ASCII Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42A.2 Object Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43