-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.rs
More file actions
43 lines (35 loc) · 1.03 KB
/
Copy pathplugin.rs
File metadata and controls
43 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! # TechScript Compiler Driver — Compiler Plugins
//!
//! Provides the plugin infrastructure using the EventListener model.
//! Future plugins can be registered with the pipeline to inspect AST, IR, or bytecode.
use crate::events::EventListener;
pub trait CompilerPlugin: EventListener {
/// Returns the unique name of the plugin.
fn name(&self) -> &'static str;
/// Returns the semantic version of the plugin.
fn version(&self) -> &'static str;
}
pub struct PluginRegistry {
plugins: Vec<Box<dyn CompilerPlugin>>,
}
impl Default for PluginRegistry {
fn default() -> Self {
Self::new()
}
}
impl PluginRegistry {
/// Creates an empty plugin registry.
pub fn new() -> Self {
Self {
plugins: Vec::new(),
}
}
/// Registers a plugin.
pub fn register(&mut self, plugin: Box<dyn CompilerPlugin>) {
self.plugins.push(plugin);
}
/// Retrieves all registered plugins.
pub fn plugins(&self) -> &[Box<dyn CompilerPlugin>] {
&self.plugins
}
}