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