plotnik_lib/lib.rs
1//! Plotnik: Query language for tree-sitter AST with type inference.
2//!
3//! # Example
4//!
5//! ```
6//! use plotnik_lib::Query;
7//!
8//! let source = r#"
9//! Expr = [(identifier) (number)]
10//! (assignment left: (Expr) @lhs right: (Expr) @rhs)
11//! "#;
12//!
13//! let query = Query::try_from(source).expect("out of fuel");
14//! eprintln!("{}", query.diagnostics().render(query.source_map()));
15//! ```
16
17#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
18
19// Re-export modules from plotnik-core
20pub use plotnik_core::colors;
21
22// Re-export modules from plotnik-bytecode
23pub use plotnik_bytecode as bytecode;
24pub use plotnik_bytecode::type_system;
25
26// Re-export modules from plotnik-compiler
27pub use plotnik_compiler::analyze;
28pub use plotnik_compiler::compile;
29pub use plotnik_compiler::diagnostics;
30pub use plotnik_compiler::emit;
31pub use plotnik_compiler::parser;
32pub use plotnik_compiler::query;
33pub use plotnik_compiler::typegen;
34
35// Re-export modules from plotnik-vm
36pub use plotnik_vm::engine;
37
38// Re-export key types from core
39pub use plotnik_core::Colors;
40
41// Re-export key types from compiler
42pub use plotnik_compiler::{
43 Diagnostics, DiagnosticsPrinter, Error, PassResult, Result, Severity, Span,
44};
45pub use plotnik_compiler::{Query, QueryBuilder, SourceId, SourceMap};
46
47// Re-export VM types
48pub use plotnik_vm::{
49 EffectLog, FuelLimits, Materializer, NodeHandle, PrintTracer, RuntimeEffect, RuntimeError,
50 Tracer, VM, Value, ValueMaterializer, Verbosity, debug_verify_type,
51};
52
53/// Embed bytecode with 64-byte alignment (zero-copy loading).
54///
55/// Use this instead of `include_bytes!` to ensure the embedded bytecode
56/// is properly aligned for DFA deserialization and cache efficiency.
57///
58/// # Example
59///
60/// ```ignore
61/// use plotnik_lib::{include_query_aligned, bytecode::Module};
62///
63/// let module = Module::from_static(include_query_aligned!("query.ptk.bin"))?;
64/// ```
65#[macro_export]
66macro_rules! include_query_aligned {
67 ($path:expr) => {{
68 #[repr(C, align(64))]
69 struct Aligned<const N: usize>([u8; N]);
70
71 const BYTES: &[u8] = include_bytes!($path);
72 static ALIGNED: Aligned<{ BYTES.len() }> = Aligned(*BYTES);
73 ALIGNED.0.as_slice()
74 }};
75}