xur-std 0.1.7

The standard library of the Xur language
Documentation
use hao::dotnet::signature::{MethodSig, TypeSig};
use xur_runtime::registry::ModuleBuilder;

use super::{DotnetMethodSig, DotnetTypeSig};

pub(super) fn register(dotnet: &mut ModuleBuilder<'_>) {
    let mut sig = dotnet.submodule("sig");

    sig.function("void", || DotnetTypeSig(TypeSig::VOID));
    sig.function("bool", || DotnetTypeSig(TypeSig::BOOL));
    sig.function("char", || DotnetTypeSig(TypeSig::CHAR));
    sig.function("int32", || DotnetTypeSig(TypeSig::INT32));
    sig.function("int64", || DotnetTypeSig(TypeSig::INT64));
    sig.function("float64", || DotnetTypeSig(TypeSig::FLOAT64));
    sig.function("string", || DotnetTypeSig(TypeSig::STRING));
    sig.function("object", || DotnetTypeSig(TypeSig::OBJECT));
    sig.function("intptr", || DotnetTypeSig(TypeSig::NATIVE_INT));
    sig.named_function("sz_array", &["elem"], |elem: DotnetTypeSig| {
        DotnetTypeSig(TypeSig::sz_array(elem.0))
    });

    sig.named_function(
        "method_static",
        &["ret", "params"],
        |ret: DotnetTypeSig, params: Vec<DotnetTypeSig>| -> DotnetMethodSig {
            let param_sigs = params.into_iter().map(|p| p.0).collect();
            DotnetMethodSig(MethodSig::new_static(ret.0, param_sigs))
        },
    );

    sig.named_function(
        "method_instance",
        &["ret", "params"],
        |ret: DotnetTypeSig, params: Vec<DotnetTypeSig>| -> DotnetMethodSig {
            let param_sigs = params.into_iter().map(|p| p.0).collect();
            DotnetMethodSig(MethodSig::new_instance(ret.0, param_sigs))
        },
    );
}