一键导入
compiler-development
Guide for developing Sagittarius compiler. Use this when you need to develop or optimize the compiler.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide for developing Sagittarius compiler. Use this when you need to develop or optimize the compiler.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Guide for writing Sagittarius documents. Use this when asked to write a user reference manual or other Sagittarius documents.
Guide for developing Scheme libraries for Sagittarius. Use this when creating or modifying Scheme libraries in sitelib/, implementing SRFI, or adding new utility libraries.
Guide for executing Sagittarius tests. Use this when asked to execute tests.
| name | compiler-development |
| description | Guide for developing Sagittarius compiler. Use this when you need to develop or optimize the compiler. |
This guide provides an overview of the Sagittarius Scheme compiler architecture, optimization strategies, and best practices for development.
The Sagittarius compiler is written in Scheme, and consists of several phases:
The compiler source code is located in the boot/ directory
boot/compiler.scm - Main compiler entry pointboot/lib/pass*.scm - Optimization passesboot/lib/compiler-util.scm - Utility library for compilerboot/lib/iform.scm - Intermediate form definitionsboot/lib/smatch.scm - Pattern matching utilities, use include syntax to include in the compiler source filesThe compiler is built by the compiler from the host Sagittarius by running the command below:
For POSIX
./dist.sh precomp
For Windows
dist.bat precomp
This will generate the C code for the compiler in src/ directory. To execute the compiler
you need to build the Sagittarius first by running the command below:
For POSIX
make sash -j$(nproc)
For Windows (Ninja)
ninja sash -j %NUMBER_OF_PROCESSORS%
To analyze the optimisation result, you can use the compile-p* procedure to print the intermediate form of the code after each pass. The below example shows how to use it.
(import (sagittarius compiler))
(compile-p1 '((lambda (x) (+ x 1)) 5)) ;; shows result of pass1
(compile-p2 '((lambda (x) (+ x 1)) 5)) ;; shows result of pass2
(compile-p3 '((lambda (x) (+ x 1)) 5)) ;; shows result of pass3
(compile-p4 '((lambda (x) (+ x 1)) 5)) ;; shows result of pass4
(compile-p5 '((lambda (x) (+ x 1)) 5)) ;; shows result of pass5 (generated VM instructions)
You can run the script with the command below:
POSIX:
./build/sagittarius -Llib -Lsitelib -L'ext/*' -Dbuild ${file}
Windows:
.\build\sash.exe -Llib -Lsitelib -Lext/* -Dbuild %file%