Skip to main content

dada_lang/
main_lib.rs

1use dada_util::Fallible;
2
3use crate::{Command, GlobalOptions};
4
5mod compile;
6mod run;
7mod test;
8
9pub struct Main {
10    #[allow(dead_code)]
11    global_options: GlobalOptions,
12}
13
14impl Main {
15    pub fn new(global_options: GlobalOptions) -> Self {
16        Self { global_options }
17    }
18
19    pub fn run(mut self, command: Command) -> Fallible<()> {
20        match command {
21            Command::Compile { compile_options } => self.compile(&compile_options, None)?,
22            Command::Test { test_options } => self.test(test_options)?,
23            Command::Run { run_options } => self.run_command(&run_options)?,
24            Command::Debug {
25                debug_options,
26                compile_options,
27            } => {
28                let mut debug_server = debug_options.to_server();
29                let debug_tx = debug_server.launch();
30                eprintln!(
31                    "serving debug results on http://localhost:{port}/",
32                    port = debug_options.port
33                );
34                self.compile(&compile_options, Some(debug_tx))?;
35                eprintln!(
36                    "compilation complete. Debug at http://localhost:{port}/",
37                    port = debug_options.port
38                );
39                debug_server.block_on()?;
40            }
41        }
42        Ok(())
43    }
44}