polydat-core 0.6.1

Polydat runtime: value model, graph compiler, execution engines, kernels
Documentation
// Copyright 2024-2026 Jonathan Shook
// SPDX-License-Identifier: Apache-2.0

//! The Polydat compiler: from a parsed `.polydat` program to an
//! assembler and a kernel. The language itself (lexer, parser, AST,
//! pretty printer, pragmas, tile templates) lives in
//! `polydat_grammar` and is re-exported here at its old paths.

// The language itself lives in `polydat_grammar`: the lexer, the
// parser, the AST, the pretty-printer, the free-name collector,
// pragmas, the diagnostic types, and the tile template
// parsers. Each is reachable here at the path it always had.
pub use polydat_grammar::{
    ast, error, lexer, parser, pprint, pragmas, refs, tile, tile_structural,
};

pub mod compile;
pub mod const_constraints;
pub mod cursor_sugar;
pub mod events;
pub mod factories;
/// External-facing factory module. Made `pub` (was `pub(crate)`) so
/// crates that host polydat nodes outside the polydat crate
/// (host runtimes) can reach `ConstArg`, `compile_ctx`,
/// and `build_node` from their `register_nodes!` invocations.
pub mod factory;
pub mod registry;
pub mod tile_lower;
pub mod transform;
pub mod traversal;
pub(crate) mod validate;

pub mod stub;

/// Re-exported for external crates that register Polydat nodes via `register_nodes!`.
pub use factory::ConstArg;
mod binding;
mod modules;

pub use compile::{
    CompileOptions, InputVariance, compile_ast_interpreter_with_options, compile_ast_with_engine,
    compile_polydat, compile_polydat_checked, compile_polydat_interpreter,
    compile_polydat_interpreter_with_options, compile_polydat_kernel,
    compile_polydat_kernel_with_options, compile_polydat_with, compile_polydat_with_engine,
    eval_const_expr, parse_polydat, parse_polydat_with_tile_defaults,
};

/// Collect identifier references from an `Expr` tree into `out`.
///
/// Walks every `Ident`, function call argument, binary/unary
/// operand, array element, and field-access source. String-
/// literal placeholders (`{name}` form) contribute their
/// identifier-shaped placeholder bodies.
///
/// Cross-crate consumers (e.g. the host's context synthesizer,
/// composition_substrate.md §3) use this to discover transitive wire refs from
/// a binding's RHS without depending on the private `validate`
/// module.
pub fn collect_expr_references(expr: &ast::Expr, out: &mut std::collections::HashSet<String>) {
    validate::collect_references(expr, out);
}

/// Return the embedded standard library module sources.
///
/// Each entry is `(filename, source_text)` — the same data used by the
/// compiler's module resolver at build time.
pub fn stdlib_sources() -> &'static [(&'static str, &'static str)] {
    compile::stdlib_sources()
}