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, InputVariance, compile_ast_interpreter_with_options, compile_ast_with_engine,
42 compile_polydat, compile_polydat_checked, compile_polydat_interpreter,
43 compile_polydat_interpreter_with_options, compile_polydat_kernel,
44 compile_polydat_kernel_with_options, compile_polydat_with, compile_polydat_with_engine,
45 eval_const_expr, parse_polydat, parse_polydat_with_tile_defaults,
46};
47
48/// Collect identifier references from an `Expr` tree into `out`.
49///
50/// Walks every `Ident`, function call argument, binary/unary
51/// operand, array element, and field-access source. String-
52/// literal placeholders (`{name}` form) contribute their
53/// identifier-shaped placeholder bodies.
54///
55/// Cross-crate consumers (e.g. the host's context synthesizer,
56/// composition_substrate.md §3) use this to discover transitive wire refs from
57/// a binding's RHS without depending on the private `validate`
58/// module.
59pub fn collect_expr_references(expr: &ast::Expr, out: &mut std::collections::HashSet<String>) {
60 validate::collect_references(expr, out);
61}
62
63/// Return the embedded standard library module sources.
64///
65/// Each entry is `(filename, source_text)` — the same data used by the
66/// compiler's module resolver at build time.
67pub fn stdlib_sources() -> &'static [(&'static str, &'static str)] {
68 compile::stdlib_sources()
69}