%TOPIC%
From LRDE
This page contains the log of the topics of
- the Compiler Construction Course 1 (CMP1),
- the Compiler Construction Course 2 (CMP2), and
- the Typology of Programming Languages Course (TYLA)
for Ing1 students of class EPITA 2014 (i.e., from November 2011 to May 2012). The topic was started with the Formal Languages Lecture (THL).
CMP1
Lecture 1: 2011-11-21 (Grp. B & A), 2 hours: Introduction to the Project (%roland%)
- The Tiger Project. See the lecture notes:
tiger-project-intro.pdf, tiger-project-intro-handout.pdf and tiger-project-intro-handout-4.pdf.
- Ressources (http://www.lrde.epita.fr/~akim/ccmp/).
- Assignments (http://www.lrde.epita.fr/~akim/ccmp/assignments.html).
- Appel's books.
- Tiger Compiler Reference Manual (http://www.lrde.epita.fr/~akim/ccmp/tiger.html).
- epita.cours.compile.
- Goals (C++, OO, DP, Management, Several Iterations, Testing, Documenting, Maintaining, Fixing, Understanding Computers, English).
- Non goals (Compiler Construction).
- Rules of the Game.
- No copy between groups.
- Tests are part of the project (test cases and frameworks should not be exchanged).
- Fixing mistakes earlier is better.
- Work between groups is encouraged as long as they don't cheat.
- Tests.
- Tests matter.
- Rules.
- A bug => a test.
- A suspicious behavior => one or several tests to isolate it.
- Don't throw away tests!
- Don't exchange tests! (bis repetita).
- C Compilation model (cpp, cc1, as, ld).
- Tiger Compiler pipeline (front end only)
- Compilers handling multiple input (sources languages) and multiple outputs (target assembly languages/processors).
- The case of GCC.
- Factoring the compiler components: intermediate representation(s).
- Front-end and back-ends.
- Other compilation strategies.
- The Tiger Compiler pipe (annotated with tools and steps).
- Front-end: TC-0 - TC-3 (mandatory part), TC-4 - TC-5 (optional part).
- Back-end: TC-6 - TC-9 (optional part).
- Misc: students should overcome Make, Makefiles and seperate compilation, etc.
- Ressources (http://www.lrde.epita.fr/~akim/ccmp/).
Lecture 2: 2011-12-05 (Grp. B & A), 2 hours: Architecture of tc (tasks), Scanner and Parser hints, Abstract Syntax (%roland%)
- Architecture of the Tiger Compiler (tc).
- Modules: parse, ast, bind, etc.
- Pure libraries providing actual services.
- Tasks (non-pure services) using a declarative system: Development Tools, section 1 (tc Tasks). See the lecture notes:
- Modules: parse, ast, bind, etc.
dev-tools.pdf, dev-tools-handout.pdf and dev-tools-handout-4.pdf.
- Command-line options.
- Declaration of dependencies.
- Actual computations delegated to pure libraries.
- Driver (tc.cc).
- Instantiates a tasks manager, used to record all existing tasks at start-up and later compute the steps to performe according to the dependencies of the invoked tasks.
- Workflow computed by the task manager from the options passed to the driver, triggering corresponding tasks and their dependencies (à la Make).
- Error management: catches exceptions (including misc::error) and displays error messages.
- Additional details and hints about the scanner and the parser: The Scanner and the Parser. See the lecture notes:
scanner.pdf, scanner-handout.pdf and scanner-handout-4.pdf.
- Symbols (light-weight, shared and non-mutable strings used to represent identifiers).
- Extra information (in addition to tokens/terminals) passed between the scanner and the parser:
- Semantic values.
- Locations.
- Various improvements on the scanner and the parser.
- Error recovery by deletion (using the error symbol).
- Pure (reentrant) parser and scanner.
- Abstract Syntax. See the lecture notes,
ast.pdf, ast-handout.pdf and ast-handout-4.pdf (sections 1.1 and 1.2).
Lecture 3: 2011-12-12 (Grp. A & B), 2 hours: Abstract Syntax (%roland%)
- Abstract Syntax. See the lecture notes, ast.pdf, ast-handout.pdf and ast-handout-4.pdf (from section 1.3 to the middle of section 2.4 (``Sugaring Visitors 2)).
Lecture 4: 2012-01-30 (Grp. A & B), 2 hours: Development Tools: Autoconf and Automake (%roland%)
- Autoconf and Automake
- History: Unix, Unices, configuration systems (imake, configure), portability issues (broken tools, broken/missing functions, libraries, etc.).
- Generating configure with Autoconf
- The choice of (a subset of) the Bourne Shell for portability reasons.
- Generating to encapsulate tests, simplify, shorten and reuse shell script bits.
- Using the M4 macro language.
- Autotools Diagram: Autoconf.
- Generating Makefile (s) with Automake and configure.
- Generating to simplify and shorten portable Makefile bits.
- Substituting variables (@VAR@) in Makefile.in using configure (BTW: variables listed in configure --help).
- Completing the Autotools diagram: Automake.
- Developer side vs User side.
- A word on aclocal.
- Hands-on example.
- A simple program.
- Writing hello-world.cc.
- Adding Makefile.am.
- Running autoscan.
- Adjusting config.scan to create config.ac (initializing Automake, avoiding autoheader).
- Running alocal, automake -a -c (and installing helpers) and autoconf.
- Running ./configure.
- Running make.
- Running ./hello-world.
- Adding a (static) library.
- Writing the client (hello.cc) and the library (greet.hh and greet.cc).
- Adjusting Makefile.am (lib_LIBRARIES vs noinst_LIBRARIES), and configure.ac (AC_PROG_RANLIB).
- Updating by running make (and not the Autotools).
- Compiling the client (hello) by adjusting Makefile.am (in particular, link to libgreet.a using hello_LDADD).
- Running make again.
- Running ./hello.
- Adding tests.
- TESTS in Makefile.am and make check.
- Compiling test-only (not installed) programs: check_PROGRAMS.
- Distributing.
- make dist.
- make distcheck.
- Don't forget to adjust the arguments of AC_INIT in configure.ac.
- Installing.
- make install.
- configure --prefix, $prefix, $bindir, $libdir, etc. and bin_, lib_ prefixes of primaries (PROGRAMS, LIBRARIES, etc.).
- make uninstall (careful, very limited).
- A simple program.
- Misc.
- Generating tests with configure (e.g. so that they can find $srcdir).
- Changing variables (e.g. CXXFLAGS) at the configuration step (=./configure CXXFLAGS...=; global) or at the build step (=make CXXFLAGS...=; local).
- autoheader and config.h: getting rid of limitations of using -D options to pass options to the compiler.
- Pros and cons of using multiple Makefile s in a multi-directory project.
- srcdir vs builddir, running configure from a directory other than the source dir.
Lecture 5: 2012-02-02 (Grp. A & B), 2 hours: C++ 2011, Development Tools, Abstract Syntax (%roland%)
- New features from C++ 2011 used in the Tiger Project.
- nullptr.
- Range-based for loops.
- consecutive right angle brackets (>>).
- auto typed variables.
- Defaulted and deleted functions.
- Abstract Syntax, up to the end. See the lecture notes,
ast.pdf, ast-handout.pdf and ast-handout-4.pdf.
- Development Tools, sections 2 (rapidly) and 3. See the lecture notes:
dev-tools.pdf, dev-tools-handout.pdf and dev-tools-handout-4.pdf.
Lecture 6: 2012-02-03 (Grp. A & B), 2 hours: Names, Identifiers and Bindings (%roland%)
- Names, Identifiers and Bindings (except some slides in section 3, ``Complications). See the lecture notes, names.pdf, names-handout.pdf and names-handout-4.pdf.
CMP2
Lecture 1: 2012-02-21, 2 hours: Type-checking (%roland%)
- Types. See the lecture notes (sections 1 and 2):
type-checking.pdf, type-checking-handout.pdf and type-checking-handout-4.pdf.
- Some details on the implementation of types and type-checking within the Tiger Compiler.
- Hierarchy of types (src/type/)
- src/type/README.
- Implementing atomic types: singletons.
- Resolving aliased types: Named and actual().
- Hierarchy of types (src/type/)
Lecture 2: 2012-02-28, 2 hours: Type-checking, Intermediate languages (%roland%)
- Sequent Calculus
- In English: "If alpha is of type Int in the context Gamma and beta is of type Int in the context Gamma,
then alpha + beta is of type Int in the context Gamma."
- Using symbols (where ⊢ ("tee" or "turnstile") is the symbol meaning "yields" or "proves"):
Failed to parse (syntax error): {\displaystyle <semantics> <mfrac> <mrow> <mo stretchy="false">Γ</mo> <mi>⊢</mi> <mo stretchy="false">α</mo> <mi mathvariant="normal">:</mi> <mtext>Int</mtext> <mi/> <mo stretchy="false">Γ</mo> <mi>⊢</mi> <mi mathvariant="italic">β</mi> <mi mathvariant="normal">:</mi> <mtext>Int</mtext> </mrow> <mrow> <mo stretchy="false">Γ</mo> <mi>⊢</mi> <mrow> <mo stretchy="false">α</mo> <mo stretchy="false">+</mo> <mi mathvariant="italic">β</mi> </mrow> <mi mathvariant="normal">:</mi> <mtext>Int</mtext> </mrow> </mfrac> </semantics> }
- Examples of type rules: addition of 2 integers, if-then-else, if-then, addition of 3 integers, comparison of two variables, etc.
- Type inference
- (a_ ? _b : _c_) > 0
- (a_ ? _b : f_ (_b)) > 0
- (a_ ? _b : f_ (_c)) > 0
- Intermediate languages. See the lecture notes (up to section 1.2 (included)):
intermediate.pdf, intermediate-handout.pdf and intermediate-handout-4.pdf.
Lecture 3: 2012-03-06, 2 hours: Intermediate languages (%roland%)
- Intermediate languages. See the lecture notes (section 1.3 to section 4.1 (included)): intermediate.pdf, intermediate-handout.pdf and intermediate-handout-4.pdf.
Lecture 4: 2012-03-20, 1 hour: Canonization (%roland%)
- Canonization. See the lecture notes (section 4.2): intermediate.pdf, intermediate-handout.pdf and intermediate-handout-4.pdf.
Lecture 5: 2012-04-26, 1 hour: Microprocessors, Instruction Selection (%roland%)
- Microprocessors, Instruction Selection. See the lecture notes (up to the beginning of section 4): instr-selection.pdf, instr-selection-handout.pdf and instr-selection-handout-4.pdf.
Lecture 6: 2012-05-15, 2 hours: Instruction Selection, Liveness Analysis, Register Allocation (%roland%)
- Instruction Selection. See the lecture notes (up to the end): instr-selection.pdf, instr-selection-handout.pdf and instr-selection-handout-4.pdf.
- Examples of MonoBURG input files from the Tiger Compiler (Tree to MIPS).
- Liveness Analysis. See the lecture notes: liveness.pdf, liveness-handout.pdf and liveness-handout-4.pdf.
- Register Allocation: Coloring by Simplification, Spilling. See the lecture notes (up to section 2.1): regalloc.pdf, regalloc-handout.pdf and regalloc-handout-4.pdf.
Lecture 7: 2012-05-31, 2 hours: Register Allocation, Dynamic Dispatch Implementation (%roland%)
- Register Allocation: Coalescing, Precolored Nodes, Caller- and Callee-Saved Registers, Implementation, Alternatives to Graph Coloring. See the lecture notes (up to the end): regalloc.pdf, regalloc-handout.pdf and regalloc-handout-4.pdf.
- Alternatives to Graph Coloring: an example of register allocation on trees.
- Dynamic Dispatch Implementation in Object-Oriented Languages.
- The C++ approach (virtual function tables).
- The SmartEiffel approach (ids and switches/tests).
TYLA
Lecture 1: 2012-04-30, 3 hours: History of Computing, History of Programming Languages (%roland%)
- History of Computing. See the lecture notes, history.pdf, history-handout.pdf and history-handout-4.pdf.
- History of Programming Languages: The Very First Ones (FORTRAN, Algol, COBOL) (section 1). See the lecture notes, early-languages.pdf, early-languages-handout.pdf and early-languages-handout-4.pdf.
Lecture 2: 2012-05-14, 3 hours: History of Programming Languages, Object Oriented History (%roland%)
- History of Programming Languages: The Second Wave (APL, PL/I, BASIC, Pascal & Heirs), the Finale (sections 2 and 3). See the lecture notes, early-languages.pdf, early-languages-handout.pdf and early-languages-handout-4.pdf.
- Object Oriented History: Simula, Smalltalk, C++. See the lecture notes, object.pdf, object-handout.pdf and object-handout-4.pdf.
Lecture 3: 2012-05-21, 3 hours: Subprograms, Some Traits of Functional Programming Languages (%roland%)
- Subprograms. See the lecture notes, subprograms.pdf, subprograms-handout.pdf and subprograms-handout-4.pdf.
- In-depth explanation of the example of the numerical differentiation in Haskell.
- Some Traits of Functional Programming Languages.
- Currying, partially applied functions, closures.
- Pure vs impure languages.
- Lazy vs strict evaluation, equational reasoning, infinite lists.
- loop.hs (lazy evaluation, terminates)
- loop.ml (strict evaluation, does not terminate)
- loop-lazy.ml (local/partial lazy evaluation, terminates)
loop.hs:
1main =
2 let y = 0
3 loop z = if z > 0 then z else loop z
4 f x = if y > 8 then x else -y
5 in
6 f (loop y)
loop.ml:
1let y = 0 in
2let rec loop z = if z > 0 then z else loop z in
3let f x = if y > 8 then x else -y in
4f (loop y)
5;;
loop-lazy.ml:
1let y = 0 in
2let rec loop z = if z > 0 then z else loop z in
3let f x = if y > 8 then (Lazy.force x) else -y in
4f (lazy (loop y))
5;;
Lecture 4: 2012-05-28, 3 hours: Generic Programming, the Standard Template Library (STL) and Template Metaprogramming, Concepts, Mixing OOP and GP (%roland%)
- Generic Programming, the Standard Template Library (STL), and Template Metaprogramming. See the lecture notes,
generic.pdf, generic-handout.pdf and generic-handout-4.pdf.
- More on GP, concepts and links between GP and OOP.
- OOP vs OOP
- OOP: two levels: Interfaces and classes (compile time), instances (run time).
- GP: three levels: Concepts (documentation/design time), models/types (compile time) and instances (run time).
- Single algorithm "instantiation"/compilation (OOP) vs several (GP).
- 1-time compiling/loose coupling between compiled algorithms and data structures (OOP) vs many-time compiling/strong coupling between compiled algorithms and data structures (GP).
- No or little compile-time optimization (OOP, cost of virtual) vs opportunities for compile-time optimizations (GP).
- Constraint through interface inheritance (OOP) vs lack of explicit constraint (classic GP) or implicit/explicit concept checking (C++ concept proposal)
- Some elements of the "Concepts" proposal for C++
- Intent: make concepts part of the language.
- Writing concepts with concept.
- Enforcing concept constraints on templates (require).
- Mapping models to concepts with concept_map.
- Adapting models to concepts with concept_map.
- Setting up implicit links based on structural conformance between models and concepts using auto concept.
- Mixing OOP and GP
- The Curiously Recurring Template Pattern (CRTP).
- Mixing two kinds of relations between a base class (top) and a derived class (bottom), in opposite ways:
- Inheritance (top-down).
- Parameter passing (bottom-up).
- Generalizing the Curiously Recurring Template Pattern to whole hierarchies (static hierarchies).
- Mixing two kinds of relations between a base class (top) and a derived class (bottom), in opposite ways:
- Using abstractions (Abstraction<T>) to constrain algorithms.
- Static knowledge of the exact type of the argument
- Static conversion to exact type (instead of dynamic_cast in traditional OOP)
- Implementing static dispatch based on abstractions.
- Implementing static multiple dispatch based on sets of abstractions (static multimethods).
- The Curiously Recurring Template Pattern (CRTP).
- OOP vs OOP
-- %roland% - 01 Jun 2012