polydat_core/dsl/mod.rs
1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! The Polydat compiler: from a parsed `.polydat` program to an
5//! assembler and a kernel. The language itself (lexer, parser, AST,
6//! pretty printer, pragmas, tile templates) lives in
7//! `polydat_grammar` and is re-exported here at its old paths.
8
9// The language itself lives in `polydat_grammar`: the lexer, the
10// parser, the AST, the pretty-printer, the free-name collector,
11// pragmas, the diagnostic types, and the tile template
12// parsers. Each is reachable here at the path it always had.
13pub use polydat_grammar::{
14 ast, error, lexer, parser, pprint, pragmas, refs, tile, tile_structural,
15};
16
17pub mod compile;
18pub mod const_constraints;
19pub mod cursor_sugar;
20pub mod events;
21pub mod factories;
22/// External-facing factory module. Made `pub` (was `pub(crate)`) so
23/// crates that host polydat nodes outside the polydat crate
24/// (host runtimes) can reach `ConstArg`, `compile_ctx`,
25/// and `build_node` from their `register_nodes!` invocations.
26pub mod factory;
27pub mod registry;
28pub mod tile_lower;
29pub mod transform;
30pub mod traversal;
31pub(crate) mod validate;
32
33pub mod stub;
34
35/// Re-exported for external crates that register Polydat nodes via `register_nodes!`.
36pub use factory::ConstArg;
37mod binding;
38mod modules;
39
40pub use compile::{
41 CompileOptions, compile_ast_with_engine, compile_ast_with_options, compile_polydat,
42 compile_polydat_checked, compile_polydat_kernel, compile_polydat_kernel_with_options,
43 compile_polydat_kernel_with_tiles, compile_polydat_with, compile_polydat_with_engine,
44 compile_polydat_with_options, eval_const_expr,
45};
46// The deprecated forms stay reachable at their old paths; a caller sees
47// the deprecation at its own use.
48#[allow(deprecated)]
49pub use compile::{
50 compile_polydat_strict, compile_polydat_with_libs, compile_polydat_with_libs_and_limit,
51 compile_polydat_with_outputs, compile_polydat_with_path,
52};
53
54/// Collect identifier references from an `Expr` tree into `out`.
55///
56/// Walks every `Ident`, function call argument, binary/unary
57/// operand, array element, and field-access source. String-
58/// literal placeholders (`{name}` form) contribute their
59/// identifier-shaped placeholder bodies.
60///
61/// Cross-crate consumers (e.g. the host's SRD-13f
62/// synthesizer) use this to discover transitive wire refs from
63/// a binding's RHS without depending on the private `validate`
64/// module.
65pub fn collect_expr_references(expr: &ast::Expr, out: &mut std::collections::HashSet<String>) {
66 validate::collect_references(expr, out);
67}
68
69/// Return the embedded standard library module sources.
70///
71/// Each entry is `(filename, source_text)` — the same data used by the
72/// compiler's module resolver at build time.
73pub fn stdlib_sources() -> &'static [(&'static str, &'static str)] {
74 compile::stdlib_sources()
75}