Skip to content
Brent Yorgey edited this page Oct 7, 2024 · 12 revisions

The Swarm codebase has gotten large enough to be quite intimidating at first glance (currently, as of May 2024, 28K SLOC across 224 modules). This page contains a (work-in-progress) guide to help orient developers to the codebase.

To help with organization and enforce modularity, the codebase is first broken into a number of sublibraries, listed below. Click on a sublibrary to jump to the section outlining its contents.

swarm-util

The swarm-util sublibrary contains various miscellaneous utilities which are used throughout the Swarm codebase.

swarm-lang

The swarm-lang library contains definitions and tools for working with the Swarm programming language. Unless otherwise noted all module names listed below begin with Swarm.Language.

graph

  • Syntax
    • Types: Swarm language types and utilities for working with them.
    • Direction: directions (right, left; north, south; etc.)
    • Syntax: the main module defining the abstract syntax of the Swarm language.
  • Parsing
    • Parser: defines top-level function readTerm for parsing an expression of the Swarm language, returning an AST annotated with source locations and comments.
    • Parser.*: various components of the parser:
      • Util: parsing utilities
      • Core: core parser definitions + utilities
      • Lex: lexing/tokenizing
      • Record: parsing records at both the type and term level
      • Type: parsing Swarm language types
      • Term: parsing Swarm language terms
      • Comment: re-inserting comments into the parsed AST
    • Key: data type, parsing + pretty printing for keys (i.e. key presses).
  • Checking
    • Context: mappings from variables to information about them (types, requirements, ...)
    • Module: a module is a typechecked term together with a context of names defined in that term.
    • Capability: definition of capabilities needed to use certain commands or language features.
    • Requirement: type and functions for dealing with requirements, i.e. what is needed to be able to build a robot executing a certain program. Includes capabilities as well as inventory.
    • Typed: values packaged together with their type and requirements.
    • Typecheck: the main type checking + inference algorithm.
    • unification, i.e. solving equations between types:
  • Elaborate: term elaboration that happens after type checking.
  • Pipeline: the entire term processing pipeline: parse -> type check -> requirements analysis -> elaborate.
  • Pretty: pretty-printing for the Swarm language.
  • Value: runtime values.
  • LSP.*: implementation of the Language Server Protocol.

swarm-topography

  • Location
  • Universe
  • World.Coords
  • Scenario.Topography.*

swarm-scenario

graph

First, some miscellaneous modules.

All the rest of the modules live under the Swarm.Game namespace.

  • Entities + terrain:
    • Display: A Display tracks information needed to render terrain and entities in a single cell.
    • Terrain
    • Entity
    • Entity.Cosmetic
    • Entity.Cosmetic.Assignment
    • Device
    • Ingredients
    • Recipe
    • Land
  • State.Config
  • State.Landscape
  • Robots
    • Robot
    • Robot.Walk
  • World DSL
    • World.*
  • Achievement.Definitions
  • Scenarios
    • Scenario
    • Scenario.*

swarm-engine

swarm-doc

swarm-tui

swarm-web