|
| 1 | +AGENTS instructions |
| 2 | +=================== |
| 3 | + |
| 4 | +Sagittarius Scheme is a Scheme implementation supporting R6RS and R7RS specifications. |
| 5 | +The runtime is written in C (requires C11). |
| 6 | + |
| 7 | +Repository layout |
| 8 | +----------------- |
| 9 | + |
| 10 | +### Core directories |
| 11 | + |
| 12 | +- `src/`: C source files for the Scheme runtime |
| 13 | + - `src/os/{os}/`: OS-dependent C source files (darwin, linux, win32, etc.) |
| 14 | + - `src/sagittarius/`: Header files |
| 15 | + - `*.stub`: Stub files that generate C code for Scheme-C bindings |
| 16 | +- `boot/`: Bootstrap code (compiler and core libraries) |
| 17 | +- `lib/`: Core Scheme library directory (rnrs, core, clos, compat) |
| 18 | +- `sitelib/`: Utility Scheme libraries (srfi, rfc, crypto, etc.) |
| 19 | +- `ext/`: Extension libraries with native C bindings |
| 20 | + - `threads/`, `socket/`, `crypto/`, `ffi/`, `zlib/`, etc. |
| 21 | + |
| 22 | +### Build and tooling |
| 23 | + |
| 24 | +- `cmake/`: CMake modules and configuration templates |
| 25 | +- `tools/scripts/`: Build scripts and code generators |
| 26 | + - `builtin-keywords.scm`, `builtin-symbols.scm`: Symbol generators |
| 27 | + - `compile-unicode.scm`, `compile-tzdatabase.scm`: Data file generators |
| 28 | + - `r7rs-srfi-gen.scm`: R7RS SRFI library generator |
| 29 | + |
| 30 | +### Testing and documentation |
| 31 | + |
| 32 | +- `test/`: Scheme tests |
| 33 | + - `tests/`: Individual test files organized by category |
| 34 | + - `r6rs-test-suite/`, `r7rs-tests/`: Standard conformance tests |
| 35 | +- `doc/`: Documentation in scribble and markdown formats |
| 36 | + |
| 37 | +How to build |
| 38 | +------------ |
| 39 | + |
| 40 | +### Prerequisites |
| 41 | + |
| 42 | +- CMake (minimum version 3.12) |
| 43 | +- C compiler supporting C11 |
| 44 | +- Latest release of Sagittarius installed (for code generation) |
| 45 | +- Dependencies: Boehm GC, zlib, libffi, OpenSSL |
| 46 | + |
| 47 | +### Build steps |
| 48 | + |
| 49 | +#### For POSIX (Linux, macOS, BSD) |
| 50 | + |
| 51 | +```shell |
| 52 | +# 1. Generate code (requires existing sagittarius binary) |
| 53 | +./dist.sh gen |
| 54 | + |
| 55 | +# 2. Configure with CMake |
| 56 | +cmake . |
| 57 | + |
| 58 | +# 3. Build |
| 59 | +make |
| 60 | +``` |
| 61 | + |
| 62 | +#### For Windows |
| 63 | + |
| 64 | +```cmd |
| 65 | +:: 1. Generate code |
| 66 | +dist.bat gen |
| 67 | +
|
| 68 | +:: 2. Configure with CMake (using Ninja) |
| 69 | +cmake . -G Ninja |
| 70 | +
|
| 71 | +:: 3. Build |
| 72 | +ninja |
| 73 | +``` |
| 74 | + |
| 75 | +### Out-of-tree build (recommended) |
| 76 | + |
| 77 | +```shell |
| 78 | +mkdir build && cd build |
| 79 | +cmake .. |
| 80 | +make |
| 81 | +``` |
| 82 | + |
| 83 | +### Using a custom Sagittarius for code generation |
| 84 | + |
| 85 | +```shell |
| 86 | +env SASH=/path/to/sagittarius ./dist.sh gen |
| 87 | +``` |
| 88 | + |
| 89 | +### Key CMake options |
| 90 | + |
| 91 | +- `-DCMAKE_INSTALL_PREFIX=/path`: Installation prefix |
| 92 | +- `-DLIB_DIR=lib64`: Library directory name |
| 93 | +- `-DINSTALL_SYMLINK=OFF`: Disable sash symlink |
| 94 | +- `-DBUILD_TYPE=Debug`: Build type (default: RelWithDebInfo) |
| 95 | + |
| 96 | +Running the interpreter |
| 97 | +----------------------- |
| 98 | + |
| 99 | +After building, the executable is at `./build/sagittarius`. |
| 100 | + |
| 101 | +### Common options |
| 102 | + |
| 103 | +``` |
| 104 | +sagittarius [options] [file] |
| 105 | +
|
| 106 | +-v, --version Print version and exit |
| 107 | +-h, --help Print help and exit |
| 108 | +-i, --interactive Force interactive mode (REPL) |
| 109 | +-L<path> Add to load path (head) |
| 110 | +-A<path> Add to load path (tail) |
| 111 | +-D<path> Add to dynamic load path |
| 112 | +-e<expr> Evaluate expression before script |
| 113 | +-r6, -r7 Run in strict R6RS/R7RS mode |
| 114 | +-d, --disable-cache Disable compiled cache |
| 115 | +-c, --clean-cache Clean compiled cache |
| 116 | +-n, --no-main Don't call main procedure |
| 117 | +``` |
| 118 | + |
| 119 | +### Running test scripts |
| 120 | + |
| 121 | +```shell |
| 122 | +# Run a script with custom library paths |
| 123 | +./build/sagittarius -L lib -L sitelib script.scm |
| 124 | + |
| 125 | +# Interactive REPL |
| 126 | +./build/sagittarius -i |
| 127 | + |
| 128 | +# Evaluate expression |
| 129 | +./build/sagittarius -e '(display "hello")' |
| 130 | +``` |
| 131 | + |
| 132 | +Run tests |
| 133 | +--------- |
| 134 | + |
| 135 | +Tests use CTest framework. |
| 136 | + |
| 137 | +```shell |
| 138 | +# Run all tests |
| 139 | +ctest |
| 140 | + |
| 141 | +# Run tests matching pattern |
| 142 | +ctest -R {pattern} |
| 143 | + |
| 144 | +# Run with verbose output |
| 145 | +ctest -V |
| 146 | + |
| 147 | +# Run specific test |
| 148 | +ctest -R "srfi" |
| 149 | +``` |
| 150 | + |
| 151 | +Code generation |
| 152 | +--------------- |
| 153 | + |
| 154 | +The `dist.sh gen` command runs these generators: |
| 155 | + |
| 156 | +1. `stub` - Generate C files from `.stub` files (Scheme-C bindings) |
| 157 | +2. `precomp` - Compile core Scheme libraries to C |
| 158 | +3. `srfi` - Generate R7RS-style SRFI library wrappers |
| 159 | +4. `tz` - Generate timezone database |
| 160 | +5. `unicode` - Generate Unicode codepoint tables |
| 161 | +6. `html` - Generate HTML entity tables |
| 162 | + |
| 163 | +Individual generators can be run separately: |
| 164 | +```shell |
| 165 | +./dist.sh stub # Only stub files |
| 166 | +./dist.sh precomp # Only precompiled libraries |
| 167 | +``` |
| 168 | + |
| 169 | +Key source patterns |
| 170 | +------------------- |
| 171 | + |
| 172 | +- `lib_*.c` in `src/`: Generated from `lib_*.stub` or compiled Scheme |
| 173 | +- `*.stub` files: Define C-Scheme bindings using a macro DSL |
| 174 | +- Libraries follow R6RS/R7RS naming: `(library name)` maps to `library/name.scm` |
| 175 | + |
| 176 | +Environment variables |
| 177 | +--------------------- |
| 178 | + |
| 179 | +- `SASH`: Path to Sagittarius executable for code generation |
| 180 | +- `SAGITTARIUS_LOADPATH`: Additional library load paths (`:` separated) |
| 181 | +- `SAGITTARIUS_DYN_LOADPATH`: Additional dynamic library paths |
| 182 | + |
| 183 | +Review checklist |
| 184 | +---------------- |
| 185 | + |
| 186 | +- All tests executed by `ctest` must pass |
| 187 | +- Run `./dist.sh gen` if stub or precompiled library files were modified |
| 188 | +- Rebuild after modifying C source files |
0 commit comments