### Basic .calc script interpreter in Rust Source: https://github.com/typst/comemo/blob/main/README.md Demonstrates a simple Rust interpreter for a custom `.calc` scripting language. It evaluates expressions and handles nested `eval` statements by recursively reading files. This version lacks incremental capabilities and would recompute everything on any file change. ```rust /// Evaluate a `.calc` script. fn evaluate(script: &str, files: &Files) -> i32 { script .split('+') .map(str::trim) .map(|part| match part.strip_prefix("eval ") { Some(path) => evaluate(&files.read(path), files), None => part.parse::().unwrap(), }) .sum() } impl Files { /// Read a file from storage. fn read(&self, path: &str) -> String { ... } } ``` -------------------------------- ### Integrate comemo for incremental computation in Rust Source: https://github.com/typst/comemo/blob/main/README.md Shows how to modify the `.calc` script interpreter to use `comemo` for constrained memoization. It applies `#[memoize]` to the evaluation function and `#[track]` to the file access implementation, enabling fine-grained dependency tracking for incremental updates. ```rust use comemo::{memoize, track, Tracked}; /// Evaluate a `.calc` script. #[memoize] fn evaluate(script: &str, files: Tracked) -> i32 { ... } #[track] impl Files { /// Read a file from storage. fn read(&self, path: &str) -> String { ... } } ``` -------------------------------- ### Add comemo dependency to Cargo.toml Source: https://github.com/typst/comemo/blob/main/README.md Specifies the comemo library as a dependency in a Rust project's `Cargo.toml` file, enabling its use for incremental computation. ```toml [dependencies] comemo = "0.4" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.