Asking the agent to refactor to reduce spectral complexity, it worked. Trivial change, but this did reduce code complexity.
82 lines
2.1 KiB
Markdown
82 lines
2.1 KiB
Markdown
# swactor
|
|
(S)mall (W)ASM-compatible (actor) library
|
|
|
|
## Useful
|
|
|
|
View code dependency DAG
|
|
|
|
```bash
|
|
cargo run --manifest-path tools/depgraph/Cargo.toml -- --src-dir src/ --output deps
|
|
```
|
|
|
|
## Quick example
|
|
|
|
```rust
|
|
use swactor::{
|
|
Ctx,
|
|
actor::{ActorAddress, ActorInterface},
|
|
runtime::{Runtime, RuntimeConfig},
|
|
};
|
|
|
|
#[derive(Debug, Default)]
|
|
struct Greeter { num_greeted: usize }
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
struct GreetMessage { who: String, return_addr: ActorAddress }
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
struct GreetResponse(String);
|
|
|
|
impl ActorInterface for Greeter {
|
|
type Incoming = GreetMessage;
|
|
type Response = GreetResponse;
|
|
|
|
fn handle(&mut self, ctx: &Ctx, msg: GreetMessage) {
|
|
let res = GreetResponse(format!("Hello, {}!", msg.who));
|
|
self.num_greeted += 1;
|
|
if let Err(_) = ctx.send(msg.return_addr, res) {
|
|
self.num_greeted -= 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let rt = Runtime::new(RuntimeConfig::default());
|
|
let addr = rt.spawn(Greeter::default()).expect("failed to spawn");
|
|
|
|
let inbox = rt.new_inbox::<GreetResponse>().unwrap();
|
|
rt.send_to(addr, GreetMessage {
|
|
who: "world".into(),
|
|
return_addr: *inbox.addr(),
|
|
}).unwrap();
|
|
|
|
for _ in 0..3 { rt.tick(); }
|
|
let resp = inbox.try_recv().expect("should have response");
|
|
println!("{}", resp.0); // "Hello, world!"
|
|
}
|
|
```
|
|
|
|
## Build & test
|
|
|
|
```sh
|
|
cargo build
|
|
cargo test
|
|
cargo test --features stress # stress tests
|
|
cargo run --bin bench --release # benchmarks
|
|
cargo run --example hello
|
|
```
|
|
|
|
## Connectome analysis
|
|
|
|
Spectral analysis of the internal dependency graph, producing a Connectome Complexity Index (CCI) and visual dashboards.
|
|
|
|
```sh
|
|
# Generate the dependency DAG
|
|
cargo run --manifest-path tools/depgraph/Cargo.toml -- --src-dir src/ --output deps
|
|
|
|
# Run spectral analysis (outputs to docs/connectome/)
|
|
source .venv/bin/activate
|
|
python tools/spectral/spectral_analysis.py deps.dot
|
|
```
|
|
|
|
This produces a text report, an interactive HTML dashboard, and a static PNG dashboard in `docs/connectome/`. See [docs/connectome.md](docs/connectome.md) for details on the metrics and interpretation.
|