gluon_vm 0.18.4

The virtual machine for executing the gluon programming language
Documentation
use crate::{
    ExternModule, Result,
    api::{Generic, OpaqueRef, generic::A},
    thread::Thread,
    value::ValueRepr,
};

fn trace(a: Generic<A>) {
    println!("{:?}", a);
}

fn show(a: Generic<A>) -> String {
    format!("{:?}", a)
}

fn tag(a: OpaqueRef<A>) -> Option<String> {
    match a.get_value().get_repr() {
        ValueRepr::Data(data) => data.poly_tag().map(|s| s.to_string()),
        _ => None,
    }
}

mod std {
    pub use crate::debug;
}

pub fn load(vm: &Thread) -> Result<ExternModule> {
    ExternModule::new(
        vm,
        record! {
            trace => primitive!(1, std::debug::trace),
            show => primitive!(1, std::debug::show),
            tag => primitive!(1, std::debug::tag)
        },
    )
}