CodeBlanks Logo Icon CodeBlanks

Summary - Compiler internals

Combine pipeline, AST and Kernel to write a compiler summary.

Summary: Compiler internals

In this group we covered Dart compiler internals: the compilation pipeline runs source through stages, the AST is the semantic tree of the code, Kernel is the platform-independent IR.

Code generation turns Kernel into target code, and dartaotruntime runs AOT-compiled programs. In this summary you will write a class that combines all of these concepts.

Practice Summary: A CompilationStep class

Define a CompilationStep class with final String input; final String output; CompilationStep(this.input, this.output); field and constructor. Add a String describe() => '$input → $output'; method. In main create final s = CompilationStep('AST', 'Kernel');; print with print(s.describe());.

Starter code

main.dart
void main() {
  // define a CompilationStep class (input, output; describe)
  // create a CompilationStep; print describe()
}

Sample solution

main.dart
class CompilationStep {
  final String input;
  final String output;
  CompilationStep(this.input, this.output);
  String describe() => '$input → $output';
}

void main() {
  final s = CompilationStep('AST', 'Kernel');
  print(s.describe());
}

Expected output

AST → Kernel

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is one of the core compilation pipeline stages?

  • Parsing to AST Correct answer
  • Only UI render
  • Only garbage collection
  • Only package install

Explanation: parsing to AST is a core pipeline stage.

2 Match the compiler parts

Term Meaning
Pipeline Stage flow
AST Semantic tree
Kernel Intermediate
Backend Code generation

3 A backend name

Question
final backend = '____';
print(backend);
Answer
final backend = 'dart2js';
print(backend);

Explanation: dart2js is the backend that produces JavaScript.

All lessons in Expert