mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-07 14:44:59 +00:00
38 lines
1.2 KiB
Text
38 lines
1.2 KiB
Text
|
|
## Roc snapshot tool
|
|
|
|
The Roc compiler uses golden snapshots to assist with debugging and verification of the compiler's behavior. The snapshots are generated by running `zig build snapshot`, and individual files can be generated using `zig build snapshot -- <file_path>`. For example, to generate a snapshot for the file `src/snapshots/can_two_decls.md`, run: `zig build snapshot -- src/snapshots/can_two_decls.md`.
|
|
|
|
Here is an example of a snapshot file for a roc program that prints `Hello world!`:
|
|
|
|
```txt
|
|
# META
|
|
~~~ini
|
|
description=Hello world
|
|
type=file
|
|
~~~
|
|
# SOURCE
|
|
~~~roc
|
|
app [main!] { pf: platform "../basic-cli/platform.roc" }
|
|
|
|
import pf.Stdout
|
|
|
|
main! = |_| Stdout.line!("Hello, world!")
|
|
```
|
|
|
|
And another which represents a single expression of a list:
|
|
|
|
```txt
|
|
# META
|
|
~~~ini
|
|
description=List with integer literals
|
|
type=expr
|
|
~~~
|
|
# SOURCE
|
|
~~~roc
|
|
[1, 2, 3]
|
|
```
|
|
|
|
Once the tool is ran, the compiler will generate human readable sections like problems (compiler errors and other diagnostics) and the intermediate representations using a s-expression text format. For example the Parser AST or the Canonical IR representation of the source code.
|
|
|
|
Changes can be reviewed manually to verify the correct behavior before committing the new snapshots to the repository.
|