aboutsummaryrefslogtreecommitdiff
path: root/crates/divina/src/lib.rs
blob: 2ce057ecf97d5149bad4c07619f4f0959fd8dab1 (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

#![deny(
  warnings,
  nonstandard_style,
  unused,
  future_incompatible,
  rust_2018_idioms,
  unsafe_code
)]
#![deny(clippy::all, clippy::nursery, clippy::pedantic)]
#![recursion_limit = "128"]
#![doc(
  html_logo_url = "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/twitter/282/ribbon_1f380.png",
  html_favicon_url = "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/twitter/282/ribbon_1f380.png"
)]

// #[macro_use]
// extern crate log;

#[cfg(windows)]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[cfg(unix)]
#[global_allocator]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;

mod cli;

use divina_compile::Compiler;
use divina_config::Config;

#[derive(Default)]
pub struct Divina {
  config:   Config,
  compiler: Compiler,
}
impl Divina {
  #[must_use]
  pub fn new() -> Self { Self::default() }

  pub fn perform(&mut self) { crate::cli::execute(self); }

  /// Prepare `self.config` for configuration
  pub fn new_config(&mut self) -> &mut Self {
    self.config = Config::new();
    self
  }

  /// Configure `self.config`
  pub fn configure_config(&mut self) { self.config.configure("Divina.lua"); }

  /// Print `self.config`
  pub fn print_config(&self) {
    println!("{:?}", self.config);
  }

  #[must_use]
  pub const fn expose_config(&self) -> &Config { &self.config }

  pub fn configure_compiler(&mut self, compiler: Compiler) { self.compiler = compiler; }
}

/// Preliminary setup
pub fn setup() {
  dotenv::dotenv().ok();
  human_panic::setup_panic!(Metadata {
    version:  env!("CARGO_PKG_VERSION").into(),
    name:     env!("CARGO_PKG_NAME").into(),
    authors:  env!("CARGO_PKG_AUTHORS").into(),
    homepage: env!("CARGO_PKG_HOMEPAGE").into(),
  });
}