Skip to content

SwirlLang/Swirl

Swirl Programming Language

Swirl is a statically and strongly-typed, systems programming language, leveraging the LLVM Infrastructure for optimal native code generation.

Website | Docs | Contributing

vscode extension License Discord

Compiler Architecture Overview

The following text is a brief on the compilation pipeline of the Compiler (details are skipped):

  • CompilerInst: the entry point, this class represents a single contained instantiation of the Compiler, owning resources which are shared across all aspects of a project's compilation.

  • Module: The compiler implements a typical module system, each Swirl file is treated as a "module" which can control the visibility of the symbols it owns (or imports) to other modules (via the export keyword). All modules are owned and managed by an instance of ModuleManager which in turn is owned by CompilerInst.

  • Parser: responsible for building the Abstract Syntax Tree for modules, a Parser is created for each module and invoked to build its AST, then destroyed. The Parser owns the lexer (tokenizer).

  • Sema (Semantic Analysis): sema is a multi-pass step, consisting of the following passes:

    • SymbolRegistrationPass: this pass registers symbols in the SymbolManager and resolves locally-declared symbol references into their concrete IdentInfo*.
    • SymbolResolver: handles bringing imported symbols into a module's scope and resolves all globally-declared symbol references.
    • TypeResolver: this is the pass which owns the Type-System's implementation. It enforces type constrains and performs type-inference.

    Note: unlike parsing, Sema and the succeeding steps are performed in parallel for all modules which belong in the same "batch", a batch consists of modules which do not depend on each other, this topological sorting is done by the helper class ModuleManager which also keeps ownership of every Module object.

  • If no errors were reported in the previous stage, the completion of Sema is followed by a post-sema pipeline which consists of the passes responsible for:

    • Compile-Time Evaluation: evaluates and substitutes all comptime-marked constructs. Resides here.
    • Generic Instantion: monomorphizes generic constructs based on the generic arguments passed in their invocation. Resides here.
  • LLVMBackend: this class owns the codegen logic for generating the LLVM IR, since all the needed information to codegen a Module is already built in previous stages, each Module is codegen'ed in parallel.

Contributing to Swirl

We welcome contributions to Swirl! To start contributing to Swirl, fork the repository, create a new branch, make the changes, and submit a pull request. Read the Docs for more info.

Issues and feature request

If you want to request a new feature or report a bug, you can use the GitHub issues tracker. We will do our best to respond as quickly.

About

An LLVM-based systems programming language for learning and experimentation.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors