Components of the Compiler - Spicery/Nutmeg GitHub Wiki

The nutmeg compiler is implemented as a series of components. Most of these are toolchain "filters" that process standard-input to standard-output (although when chained internally avoid the I/O overhead). The last stage, the Dependency Tracker, needs to operate directly on the bundle-file.

Filters

  • Parser - A filter that takes source-code and emits JSON: the output consists of the (optional) parse-tree plus any warnings/errors.
  • Resolver - A filter that consumes the Parser output and decorates the identifiers of the JSON with scope information (i.e. local, captured-local, global or built-in), their last use and whether or not identifiers are ever 'popped'.
  • Simplifier - A filter that consumes the resolved tree and transforms it with critical simplifications needed for the run-time. These will include transforming captured-locals into closures and destructuring pattern-matching.
  • Optimiser - A filter that consumes the simplified tree and locally transforms it with the intention of adding performance enhancements. The simplifier and optimiser are quite likely to be merged into a single simplifier/optimizer.
  • Code generator - A filter that consumes the optimized tree and transforms it into the version to be directly consumed by the runtime-engine. It calculates how many slots are needed for each function and allocates variables to slots.
  • Bundler - A filter that adds or extracts code-trees from the bundle-file.

Bundle File Editors

  • Dependency Tracer - Operates directly on the bundle-file to calculate the order in which to load code. It will be a list of identifiers for each entry-point, where an entry point is function that's been annotated as an entry-point.