Skip to main content

sva_engine/
lib.rs

1// Concern: resolves a graph into instances a caller can ask about, and keeps their buffers | Non-concern: parsing (sva-ast), CLI framing (sva-cli) | IO: (&Graph, root) -> Instances, Traced
2
3mod arguments;
4mod bindings;
5mod cache;
6mod cast;
7mod error;
8pub mod flops;
9mod index;
10pub mod instantiate;
11mod loops;
12mod lower;
13mod meaning;
14pub mod overload;
15pub mod query;
16mod recent;
17mod refs;
18pub mod render;
19mod schedule;
20mod source;
21mod time;
22mod trace;
23mod typing;
24mod vocabulary;
25
26pub use arguments::{Argument, Arguments, Called, Chosen};
27pub use bindings::Binding;
28pub use cache::log::cache_log;
29pub use cache::{
30    Backend, Cache, CachePolicy, CacheStats, DEFAULT_CACHE_BYTES, DEFAULT_MARK_EVERY,
31    DEFAULT_STORE_BYTES, Hash, INDEX_NAME, Lookup, NoStore, Outcome, PayloadKind, Persisted,
32    PrunePolicy, STORE_FORMAT, Store, Stored, Through,
33};
34pub use cast::Cast;
35pub use error::{BindingFault, Diagnostic, EngineError, Located, REGISTRY};
36pub use flops::{Row as FlopRow, Tree as FlopTree, Work};
37pub use meaning::{Meaning, meaning};
38pub use query::{Answer, Ask, DEFAULT_FRAME_SECS, Output, Representation};
39pub use refs::{identity, nodes_in, spectral_sum_of, symbolic_hash};
40pub use render::until::{Cmp, Term};
41pub use render::{
42    Block, Built, Change, Changed, Counts, Handle, LATEST, NOTES, Placed, Range, Render,
43    RenderConfig, STREAMED, Stream, StreamConfig, Until, answer, answer_buffer, change, ends, plan,
44    render, render_through, sketch_atom, warm,
45};
46pub use schedule::{Order, Schedule, schedule_from};
47pub use sva_formula::{C64, Codomain, Held, Line, NodeId, SpectralSum, Ty, Var};
48pub use sva_samples::{
49    Alias, AliasBand, BAND_COUNT, BandCrest, BandTrack, Bands, Buffer, Cost, Crest, Detail,
50    EnvelopeFrame, Extent, FormantFrame, Frames, Label, LedgerEntry, Loudness, LoudnessFrame,
51    MAX_PINNED_FRAME, PSYCHOACOUSTIC_V1, PitchFrame, Profile, Pruned, Rule, SignalKind, Source,
52    Spectrum, StereoFrame, StereoImage, measure_alias, pinned_frame,
53};
54pub use trace::{Traced, Up, trace};
55pub use typing::{Typing, Value, When};
56pub use vocabulary::{MAX_WIDTH, named_may_move, recognized_named, shape, shape_name};
57
58use sva_ast::Graph;
59
60pub const DEFAULT_SAMPLE_RATE: u32 = 44_100;
61
62/// One inference, so a lint and a render refuse identically.
63pub fn check_structure(graph: &Graph, root: &str) -> Result<(), EngineError> {
64    types(graph, root).map(|_| ())
65}
66
67/// One `Ty` per node, across refs, over the instances `root` reaches.
68pub fn types(graph: &Graph, root: &str) -> Result<Typing, EngineError> {
69    types_at(graph, root, DEFAULT_SAMPLE_RATE)
70}
71
72/// At `rate`, whose step each `sp` is.
73pub fn types_at(graph: &Graph, root: &str, rate: u32) -> Result<Typing, EngineError> {
74    let instances = instantiate::instantiate(graph, root, rate)?;
75    // A root names the instance its own defaults resolved to, as `render` asks for.
76    let held = instances.instance_of(root)?;
77    let order = schedule::schedule_from(&instances, std::slice::from_ref(&held))?;
78    typing::infer_all(&instances, &order)
79}