kompact-io-landing/content/drafts/unpicking-aiken-air.md

1.8 KiB

Aims:

  • Describe the pipeline, and components getting from aiken to uplc.

Air

Aiken compiles aiken code to uplc via air: Aiken Intermediate Representation.

Trace

Running aiken build...

The cli (See aiken/src/cmd/mod.rs) parses the command, finds the context and calls Project::build (crates/aiken-project/src/lib.rs), which in turn calls Project::compile.

Project::compile

  1. Check dependencies are available eg aiken stdlib.
  2. Read source files.
  3. Walk over ./lib and ./validators and push aiken modules onto Project.sources.
  4. Parse each source in sources:
  5. Generate a ParsedModule containing the ast, docs, etc. The ast here is an UntypedModule, which contains untyped definitions.
  6. Type check each parsed module.
  7. For each untyped module, create a CheckedModule. This includes typed definitions.
  8. compile forks into two depending on whether it's been called with build or check.
  9. From CheckModules construct a CodeGenerator
  10. Pass the generator to construct a new Blueprints.
  11. Blueprints finds validators from checked modules.
  12. From each it constructs a Validator with the constructor Validator::from_checked_module (which returns a vector of validators)
    1. Its here that the magic happens: The method generator.generate(def) is called, where def is the typed validator(s). This method outputs a Program<Name> which contains the UPLC.
    2. These are collected together.
  13. The rest is collecting and handling the errors and warnings and writing the blueprint.

CodeGenerator::generate

  1. Create a new AirStack.

AirStack

Consists of:

  1. An Id
  2. A Scope
  3. A vector of Air

The Scope keeps track of ... [TODO]

Air

Air is a typed language... [TODO]