Slide 24
Slide 24 text
(inc -1) Lex
LeftParen, Identifier(inc),
Number(-1), RightParen
Parse Apply “inc” to -1
Type
check
“inc” exists and takes an int
argument, and -1 is an int. Great!
Optimize -1 + 1 = 0, so just emit int 0!
IL
generate
Ldc.i4 0
Optimize Ldc.i4 0 → Ldc.i4.0
Object
code
Produce assembly with entry point
which contains the IL generated
Here’s a simple example… Note Number(-1)?
Optimize 1: Compiler can do arithmetic!
Optimize 2….
All we’ve done is bust hard problem of source code -> optimized EXE into a bunch of relatively small problems. Make sense?
Production compiler engineers will say this is too simple, but their code, like most production code, is probably a mess. You can learn a lot from the simple case!