compiler

How the atopile compiler builds and links TypeGraphs from `.ato` (ANTLR front-end → AST → TypeGraph → Linker → DeferredExecutor), plus the key invariants and test entrypoints. Use when modifying the compiler pipeline, grammar, AST visitors, or type resolution.

3,147 stars

Best use case

compiler is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

How the atopile compiler builds and links TypeGraphs from `.ato` (ANTLR front-end → AST → TypeGraph → Linker → DeferredExecutor), plus the key invariants and test entrypoints. Use when modifying the compiler pipeline, grammar, AST visitors, or type resolution.

Teams using compiler should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/compiler/SKILL.md --create-dirs "https://raw.githubusercontent.com/atopile/atopile/main/.claude/skills/compiler/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/compiler/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How compiler Compares

Feature / AgentcompilerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

How the atopile compiler builds and links TypeGraphs from `.ato` (ANTLR front-end → AST → TypeGraph → Linker → DeferredExecutor), plus the key invariants and test entrypoints. Use when modifying the compiler pipeline, grammar, AST visitors, or type resolution.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Compiler Module

The compiler builds a **linked, self-contained TypeGraph** from `.ato` sources. Export/manufacturing artifacts are handled later by build steps/exporters; the compiler’s job is parsing + typegraph construction + linking.

Start with:
- `src/atopile/compiler/README.md` (stage overview + example usage)
- `src/atopile/compiler/parser/README.md` (how to regenerate ANTLR output)

## Quick Start

Build a single `.ato` file into a linked TypeGraph (and instantiate its entrypoint):

```python
import faebryk.core.faebrykpy as fbrk
import faebryk.core.graph as graph
import faebryk.core.node as fabll
from atopile.compiler.build import Linker, StdlibRegistry, build_file
from atopile.compiler.deferred_executor import DeferredExecutor
from atopile.config import config

g = graph.GraphView.create()
tg = fbrk.TypeGraph.create(g=g)
stdlib = StdlibRegistry(tg)
linker = Linker(config, stdlib, tg)

result = build_file(g=g, tg=tg, import_path="app.ato", path="path/to/app.ato")
linker.link_imports(g=g, state=result.state)
DeferredExecutor(g=g, tg=tg, state=result.state, visitor=result.visitor).execute()

app_type = result.state.type_roots["ENTRYPOINT"]
app_root = tg.instantiate_node(type_node=app_type, attributes={})
app = fabll.Node.bind_instance(app_root)
```

## Relevant Files

- Core pipeline:
  - `src/atopile/compiler/build.py` (`build_file`, `build_source`, `Linker`, `StdlibRegistry`, stage helpers)
  - `src/atopile/compiler/parse.py` (ANTLR parse + error listener → `UserSyntaxError`)
  - `src/atopile/compiler/antlr_visitor.py` (ANTLR CST → internal AST graph with source info)
  - `src/atopile/compiler/ast_visitor.py` (AST → TypeGraph “preliminary” construction)
  - `src/atopile/compiler/gentypegraph.py` (typegraph generation utilities + import refs)
  - `src/atopile/compiler/deferred_executor.py` (terminal stage: inheritance/retypes/for-loops)
- Parser frontend:
  - `src/atopile/compiler/parser/` (`AtoLexer.g4`, `AtoParser.g4`, generated Python)

## Dependants (Call Sites)

- **CLI (`src/atopile/cli/build.py`)**: Calls the compiler to build the project.
- **LSP (`src/atopile/lsp/lsp_server.py`)**: Builds per-document graphs and keeps the last successful result for completions/hover.

## How to Work With / Develop / Test

### Core Concepts
- **ANTLR front-end**: parse `.ato` into an ANTLR parse tree; syntax errors are converted to `UserSyntaxError`.
- **AST graph**: `ANTLRVisitor` converts ANTLR output into internal AST nodes (FabLL nodes with source info).
- **TypeGraph build**: AST visitor emits a preliminary TypeGraph.
- **Linking**: `Linker` resolves imports, executes inheritance ordering, applies retypes, and prepares a self-contained compilation unit.
- **Deferred execution (terminal)**: `DeferredExecutor.execute()` runs operations that require resolved types (inheritance, retypes, for-loops).

### Development Workflow
1) Grammar changes:
   - edit `src/atopile/compiler/parser/AtoLexer.g4` / `AtoParser.g4`
   - regenerate (see `src/atopile/compiler/parser/README.md`)
2) Language features:
   - CST → AST: `src/atopile/compiler/antlr_visitor.py`
   - AST → TypeGraph: `src/atopile/compiler/ast_visitor.py` / `gentypegraph.py`
3) Linking/terminal behavior:
   - `src/atopile/compiler/build.py` / `src/atopile/compiler/deferred_executor.py`

### Testing
- Compiler tests: `ato dev test --llm test/compiler -q`
- Linker behavior: `ato dev test --llm test/compiler/test_linker.py -q`
- End-to-end smoke: `ato dev test --llm test/test_end_to_end.py -q`

## Best Practices
- Keep errors source-attached: raise `DslRichException`/`UserException` with AST source info when possible.
- Watch graph lifetimes: most entrypoints accept `(g, tg)` explicitly; ensure you destroy `GraphView` in long-running processes (LSP does this).

Related Skills

lsp

3147
from atopile/atopile

How the atopile Language Server works (pygls), how it builds per-document graphs for completion/hover/defs, and the invariants for keeping it fast and crash-proof.

solver

3147
from atopile/atopile

How the Faebryk parameter solver works (Sets/Literals, Parameters, Expressions), the core invariants enforced during mutation, and practical workflows for debugging and extending the solver. Use when implementing or modifying constraint solving, parameter bounds, or debugging expression simplification.

SEXP Benchmark Strategy

3147
from atopile/atopile

## Goal

sexp

3147
from atopile/atopile

How the Zig S-expression engine and typed KiCad models work, how they are exposed to Python (pyzig_sexp), and the invariants around parsing, formatting, and freeing. Use when working with KiCad file parsing, S-expression generation, or layout sync.

pyzig

3147
from atopile/atopile

How the Zig↔Python binding layer works (pyzig), including build-on-import, wrapper generation patterns, ownership rules, and where to add new exported APIs. Use when adding Zig-Python bindings, modifying native extensions, or debugging C-API interactions.

planning

3147
from atopile/atopile

Spec-driven planning for complex design tasks: when to plan, how to write specs as .ato files, and how to verify against requirements.

Package Agent

3147
from atopile/atopile

You are a package specialist.

library

3147
from atopile/atopile

How the Faebryk component library is structured, how `_F.py` is generated, and the conventions/invariants for adding new library modules. Use when adding or modifying library components, traits, or module definitions.

graph

3147
from atopile/atopile

How the Zig-backed instance graph works (GraphView/NodeReference/EdgeReference), the real Python API surface, and the invariants around allocation, attributes, and cleanup. Use when working with low-level graph APIs, memory management, or building systems that traverse the instance graph.

frontend

3147
from atopile/atopile

Frontend standards for atopile extension webviews: architecture, contracts, design system, and testing workflow.

faebryk

3147
from atopile/atopile

How Faebryk's TypeGraph works (GraphView + Zig edges), how to traverse/resolve references, and how FabLL types/traits map onto edge types. Use when working with TypeGraph traversal, edge types, or building type-aware queries.

fabll

3147
from atopile/atopile

How FabLL (faebryk.core.node) maps Python node/trait declarations into the TypeGraph + instance graph, including field/trait invariants and instantiation patterns. Use when defining new components or traits, working with the Node API, or understanding type registration.