Extract RTL documentation types
Move `RtlDocEntry`, `RtlRegistration`, and `PipelineGenerator` to a new `docs` module within `src/ast/rtl/` and re-export them. This improves organization and modularity of the RTL component.
This commit is contained in:
+3
-71
@@ -21,13 +21,13 @@ use crate::ast::compiler::macros::{MacroEvaluator, MacroExpander, MacroRegistry}
|
||||
use crate::ast::compiler::optimizer::Optimizer;
|
||||
use crate::ast::compiler::specializer::{FunctionRegistry, MonoCache, RtlLookupFunc, Specializer};
|
||||
use crate::ast::rtl::{self, intrinsics};
|
||||
use crate::ast::rtl::docs::{PipelineGenerator, RtlDocEntry, RtlRegistration};
|
||||
use crate::ast::types::{
|
||||
CommentLine, NativeFunction, NodeIdentity, Purity, SourceLocation, StaticType, Value,
|
||||
};
|
||||
|
||||
use crate::ast::diagnostics::Diagnostics;
|
||||
pub use crate::ast::compiler::CompilationResult;
|
||||
pub type PipelineGenerator = Box<dyn FnMut() -> bool>;
|
||||
|
||||
const SYSTEM_LIB_SOURCE: &str = include_str!("rtl/prelude.myc");
|
||||
const SYSTEM_LIB_PATH: &str = "<embedded>/prelude.myc";
|
||||
@@ -36,62 +36,6 @@ fn make_rtl_lookup() -> RtlLookupFunc {
|
||||
Rc::new(|name: &str, args: &[StaticType]| intrinsics::lookup(name, args))
|
||||
}
|
||||
|
||||
/// Documentation entry for a single RTL symbol (function or constant).
|
||||
/// Populated via the builder returned by `register_native_fn` / `register_constant`.
|
||||
pub struct RtlDocEntry {
|
||||
pub name: String,
|
||||
/// Short one-line description (required).
|
||||
pub one_liner: &'static str,
|
||||
/// Optional longer explanation.
|
||||
pub description: Option<&'static str>,
|
||||
/// Optional Myc code examples.
|
||||
pub examples: Option<&'static [&'static str]>,
|
||||
}
|
||||
|
||||
/// Builder returned by `register_native_fn` and `register_constant`.
|
||||
/// Call `.doc(...)` to attach documentation; optional `.description(...)` and `.examples(...)`
|
||||
/// can be chained. The entry is written to the registry when the builder is dropped.
|
||||
pub struct RtlRegistration {
|
||||
name: String,
|
||||
rtl_docs: Rc<RefCell<Vec<RtlDocEntry>>>,
|
||||
one_liner: Option<&'static str>,
|
||||
description: Option<&'static str>,
|
||||
examples: Option<&'static [&'static str]>,
|
||||
}
|
||||
|
||||
impl RtlRegistration {
|
||||
/// Attach a required one-line description.
|
||||
pub fn doc(mut self, one_liner: &'static str) -> Self {
|
||||
self.one_liner = Some(one_liner);
|
||||
self
|
||||
}
|
||||
|
||||
/// Attach an optional longer description (must call `.doc()` first).
|
||||
pub fn description(mut self, desc: &'static str) -> Self {
|
||||
self.description = Some(desc);
|
||||
self
|
||||
}
|
||||
|
||||
/// Attach optional usage examples as Myc code strings.
|
||||
pub fn examples(mut self, ex: &'static [&'static str]) -> Self {
|
||||
self.examples = Some(ex);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RtlRegistration {
|
||||
fn drop(&mut self) {
|
||||
if let Some(one_liner) = self.one_liner {
|
||||
self.rtl_docs.borrow_mut().push(RtlDocEntry {
|
||||
name: self.name.clone(),
|
||||
one_liner,
|
||||
description: self.description,
|
||||
examples: self.examples,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Environment {
|
||||
pub root_types: Rc<RefCell<Vec<StaticType>>>,
|
||||
pub root_purity: Rc<RefCell<Vec<Purity>>>,
|
||||
@@ -603,24 +547,12 @@ impl Environment {
|
||||
purity: purity_level,
|
||||
}),
|
||||
);
|
||||
RtlRegistration {
|
||||
name: name.to_string(),
|
||||
rtl_docs: Rc::clone(&self.rtl_docs),
|
||||
one_liner: None,
|
||||
description: None,
|
||||
examples: None,
|
||||
}
|
||||
RtlRegistration::new(name.to_string(), Rc::clone(&self.rtl_docs))
|
||||
}
|
||||
|
||||
pub fn register_constant(&self, name: &str, ty: StaticType, val: Value) -> RtlRegistration {
|
||||
self.allocate_slot(name, ty, Purity::Pure, val);
|
||||
RtlRegistration {
|
||||
name: name.to_string(),
|
||||
rtl_docs: Rc::clone(&self.rtl_docs),
|
||||
one_liner: None,
|
||||
description: None,
|
||||
examples: None,
|
||||
}
|
||||
RtlRegistration::new(name.to_string(), Rc::clone(&self.rtl_docs))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
pub mod core;
|
||||
pub mod datetime;
|
||||
pub mod docs;
|
||||
pub mod intrinsics;
|
||||
pub mod math;
|
||||
pub mod series;
|
||||
pub mod streams;
|
||||
pub mod type_registry;
|
||||
|
||||
pub use docs::{PipelineGenerator, RtlDocEntry, RtlRegistration};
|
||||
|
||||
use crate::ast::environment::Environment;
|
||||
|
||||
pub fn register(env: &Environment) {
|
||||
|
||||
Reference in New Issue
Block a user