Contents

GNU Free Documentation License
Preface
1 Introduction
 1.1 The Pre-History of Programming Languages
 1.2 A Brief Early History of Languages
 1.3 This Book
2 Operational Semantics
 2.1 A First Look at Operational Semantics
 2.2 BNF grammars and Syntax
  2.2.1 Operational Semantics for Logic Expressions
  2.2.2 Operational Semantics and Interpreters
 2.3 The D Programming Language
  2.3.1 D Syntax
  2.3.2 Variable Substitution
  2.3.3 Operational Semantics for D
  2.3.4 The Expressiveness of D
  2.3.5 Russell’s Paradox and Encoding Recursion
  2.3.6 Call-By-Name Parameter Passing
 2.4 Operational Equivalence
  2.4.1 Defining Operational Equivalence
  2.4.2 Example Equivalences
  2.4.3 Capture-Avoiding Substitution
  2.4.4 Proving Equivalences Hold
3 Tuples, Records, and Variants
 3.1 Tuples
 3.2 Records
  3.2.1 Record Polymorphism
  3.2.2 The DR Language
 3.3 Variants
  3.3.1 Variant Polymorphism
  3.3.2 The DV Language
4 Side Effects: State and Exceptions
 4.1 State
  4.1.1 The DS Language
  4.1.2 Cyclical Stores
  4.1.3 The “Normal” Kind of State
  4.1.4 Automatic Garbage Collection
 4.2 Environment-Based Interpreters
 4.3 The DSR Language
  4.3.1 Multiplication and Factorial
  4.3.2 Merge Sort
 4.4 Exceptions and Other Control Operations
  4.4.1 Interpreting Return
  4.4.2 The DX Language
  4.4.3 Implementing the DX Interpreter
  4.4.4 Efficient Implementation of Exceptions
5 Object-Oriented Language Features
 5.1 Encoding Objects in DSR
  5.1.1 Simple Objects
  5.1.2 Object Polymorphism
  5.1.3 Information Hiding
  5.1.4 Classes
  5.1.5 Inheritance
  5.1.6 Dynamic Dispatch
  5.1.7 Static Fields and Methods
 5.2 The DOB Language
  5.2.1 Concrete Syntax
  5.2.2 A Direct Interpreter
  5.2.3 Translating DOB to DSR
6 Type Systems
 6.1 An Overview of Types
 6.2 TD: A Typed D Variation
  6.2.1 Design Issues
  6.2.2 The TD Language
 6.3 Type Checking
 6.4 Types for an Advanced Language: TDSRX
 6.5 Subtyping
  6.5.1 Motivation
  6.5.2 The STD Type System: TD with Subtyping
  6.5.3 Implementing an STD Type Checker
  6.5.4 Subtyping in Other Languages
 6.6 Type Inference and Polymorphism
  6.6.1 Type Inference and Polymorphism
  6.6.2 An Equational Type System: ED
  6.6.3 PED: ED with Let Polymorphism
 6.7 Constrained Type Inference
7 Compilation by Program Transformation
 7.1 Closure Conversion
  7.1.1 The Official Closure Conversion
 7.2 A-Translation
  7.2.1 The Official A-Translation
 7.3 Function Hoisting
 7.4 Translation to C
  7.4.1 Memory Layout
  7.4.2 The toC translation
  7.4.3 Compilation to Assembly code
 7.5 Summary
 7.6 Optimization
 7.7 Garbage Collection
A DDK: The D Development Kit
 A.1 Installing the DDK
 A.2 Using D and DSR
  A.2.1 The Toplevel
  A.2.2 File-Based Intrepretation
 A.3 The DDK Source Code
  A.3.1 $DDK_SRC/src/ddk.ml
  A.3.2 $DDK_SRC/src/application.ml
  A.3.3 $DDK_SRC/src/D/d.ml
  A.3.4 $DDK_SRC/src/D/dast.ml
  A.3.5 $DDK_SRC/src/D/dpp.ml
  A.3.6 Scanning and Parsing Concrete Syntax
  A.3.7 Writing an Interpreter