Skip to main content

wave_compiler/driver/
session.rs

1// Copyright 2026 Ojima Abraham
2// SPDX-License-Identifier: Apache-2.0
3
4//! Compilation session state tracking.
5//!
6//! Maintains state across the compilation pipeline including
7//! configuration, source information, and compilation statistics.
8
9use super::config::CompilerConfig;
10use crate::diagnostics::SourceMap;
11
12/// Compilation session holding all state for a single compilation.
13pub struct Session {
14    /// Compiler configuration.
15    pub config: CompilerConfig,
16    /// Source map for error reporting.
17    pub source_map: Option<SourceMap>,
18    /// Input file path.
19    pub input_path: String,
20    /// Output file path.
21    pub output_path: String,
22}
23
24impl Session {
25    /// Create a new compilation session.
26    #[must_use]
27    pub fn new(config: CompilerConfig, input_path: String, output_path: String) -> Self {
28        Self {
29            config,
30            source_map: None,
31            input_path,
32            output_path,
33        }
34    }
35
36    /// Set the source code for error reporting.
37    pub fn set_source(&mut self, source: String) {
38        self.source_map = Some(SourceMap::new(source));
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_session_creation() {
48        let config = CompilerConfig::default();
49        let session = Session::new(config, "input.py".into(), "output.wbin".into());
50        assert_eq!(session.input_path, "input.py");
51        assert_eq!(session.output_path, "output.wbin");
52        assert!(session.source_map.is_none());
53    }
54
55    #[test]
56    fn test_session_set_source() {
57        let config = CompilerConfig::default();
58        let mut session = Session::new(config, "input.py".into(), "output.wbin".into());
59        session.set_source("gid = thread_id()".into());
60        assert!(session.source_map.is_some());
61    }
62}