Contents

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 Fb Programming Language
  2.3.1 Fb Syntax
  2.3.2 Variable Substitution
  2.3.3 Operational Semantics for Fb
  2.3.4 The Expressiveness of Fb
  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 FbR Language
 3.3 Variants
  3.3.1 Variant Polymorphism
  3.3.2 The FbV Language
4 Side Effects: State and Exceptions
 4.1 State
  4.1.1 The FbS 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 FbSR 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 FbX Language
  4.4.3 Implementing the FbX Interpreter
  4.4.4 Efficient Implementation of Exceptions
5 Object-Oriented Language Features
 5.1 Encoding Objects in FbSR
  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 FbOB Language
  5.2.1 Concrete Syntax
  5.2.2 A Direct Interpreter
  5.2.3 Translating FbOB to FbSR
6 Type Systems
 6.1 An Overview of Types
 6.2 TFb: A Typed Fb Variation
  6.2.1 Design Issues
  6.2.2 The TFb Language
 6.3 Type Checking
 6.4 Types for an Advanced Language: TFbSRX
 6.5 Subtyping
  6.5.1 Motivation
  6.5.2 The STFbR Type System: TFb with Records and Subtyping
  6.5.3 Implementing an STFbR 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: EFb
  6.6.3 PEFb: EFb 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 FbDK: The Fb Development Kit
 A.1 Installing the FbDK
 A.2 Using Fb and FbSR
  A.2.1 The Toplevel
  A.2.2 File-Based Intrepretation
 A.3 The FbDK Source Code
  A.3.1 $FbDK_SRC/src/fbdk.ml
  A.3.2 $FbDK_SRC/src/application.ml
  A.3.3 $FbDK_SRC/src/Fb/fb.ml
  A.3.4 $FbDK_SRC/src/Fb/fbast.ml
  A.3.5 $FbDK_SRC/src/Fb/fbpp.ml
  A.3.6 Scanning and Parsing Concrete Syntax
  A.3.7 Writing an Interpreter
B GNU Free Documentation License