use std::{
error,
fmt::{self, Debug, Display, Formatter},
};
use dolang::{
compile::Config,
extension,
extension::{Extension, Version},
runtime::vm::Builder,
};
use crate::{global::Global, time};
pub struct TimeExt;
#[derive(Debug)]
pub enum Infallible {}
impl Display for Infallible {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Debug::fmt(self, f)
}
}
impl error::Error for Infallible {}
impl Extension for TimeExt {
type Error = Infallible;
const NAME: &str = "dolang-time";
const VERSION: Version = dolang::package_version!();
const DESCRIPTION: &str = "Do Time Extension";
fn apply_compiler(&self, _config: &mut Config) -> Result<(), Infallible> {
Ok(())
}
fn apply_vm<'v>(&self, builder: &mut Builder<'v>) -> Result<(), Infallible> {
let global = Global::new(builder);
let global = builder.register_state(global);
time::configure_vm(builder, global);
Ok(())
}
}
extension!(TimeExt);