Skip to main content

Compiler Architecture

This document describes the internal architecture of the Rive compiler.

Overviewโ€‹

The Rive compiler is built in Rust and follows a multi-stage compilation process:

Source Code โ†’ Lexer โ†’ Parser โ†’ AST โ†’ Semantic Analysis โ†’ Code Generation โ†’ Target Code

Componentsโ€‹

Lexerโ€‹

The lexer (tokenizer) converts source code into tokens:

Parserโ€‹

The parser builds an Abstract Syntax Tree (AST) from tokens:

Semantic Analysisโ€‹

Semantic analysis performs type checking and name resolution:

  • Liveness Analysis
  • Escape Analysis
  • Alias Analysis
  • Inliner

Code Generationโ€‹

Code generation produces target code (currently Rust-Oriented IR):

Memory Managementโ€‹

Rive uses Auto Value Semantic (aka. AVS) system for memory safety:

  • No garbage collector
  • Compile-time memory safety
  • Zero-cost abstractions

Error Handlingโ€‹

The compiler provides detailed error messages:

rive::semantic

ร— Variable 'x' type mismatch: expected 'Int', found 'Text'
โ•ญโ”€[main.rive:2:18]
1 โ”‚ fun main() {
2 โ”‚ let x: Int = "hello"
ยท โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€
ยท โ•ฐโ”€โ”€ here
3 โ”‚ }
โ•ฐโ”€โ”€โ”€โ”€

Error: Semantic analysis failed

Target Platformsโ€‹

Currently supported targets:

  • x86_64 Linux
  • x86_64 Windows
  • x86_64 macOS

Developmentโ€‹

Building the Compilerโ€‹

git clone https://github.com/rive-lang/rive
cd rive
cargo build --release

Running Testsโ€‹

cargo test

Code Organizationโ€‹

โ”œโ”€โ”€ crates/
โ”‚ โ”œโ”€โ”€ rive-cli/
โ”‚ โ”œโ”€โ”€ rive-codegen/
โ”‚ โ”œโ”€โ”€ rive-core/
โ”‚ โ”œโ”€โ”€ rive-ir/
โ”‚ โ”œโ”€โ”€ rive-lexer/
โ”‚ โ”œโ”€โ”€ rive-parser/
โ”‚ โ”œโ”€โ”€ rive-semantic/
โ”‚ โ””โ”€โ”€ rive-utils/
โ””โ”€โ”€ Cargo.toml

Contributingโ€‹

See Contributing Guide for details on how to contribute to the compiler.