Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Code Generator

⚠️ Work in Progress: This section is under development.

This chapter covers the internals of Ursus code generation.

Topics to be Covered

Generator Architecture

  • AST representation
  • Transformation pipeline
  • Code emission
  • Optimization passes

Generation Phases

  1. Parsing - Coq AST to Ursus AST
  2. Analysis - Type checking, dependency analysis
  3. Transformation - Optimization, normalization
  4. Emission - Target code generation

Target Languages

  • Solidity - Ethereum/TON Solidity
  • C++ - TON C++ contracts
  • Rust - Future support

AST Transformations

  • Desugaring
  • Inlining
  • Dead code elimination
  • Constant folding

Code Emission

  • Pretty printing
  • Name mangling
  • Comment generation
  • Metadata

Generator Classes

ExecGenerator

  • Execution code generation
  • State management
  • Function calls

LocalClassGenerator

  • Local state generation
  • Variable declarations
  • Scope management

Extending the Generator

Adding New Constructs

  1. Define AST node
  2. Add transformation rules
  3. Implement emission
  4. Add tests

Custom Optimizations

  • Pattern matching
  • Rewrite rules
  • Cost models

Coming Soon

This section will include:

  • Generator source code walkthrough
  • Extension examples
  • Optimization techniques
  • Debugging generator

See Also