38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use crate::namespace::{typedef::TypeDef, GlobalNamespace};
|
|
|
|
pub const TYPE_INTEGER: &str = "int";
|
|
pub const TYPE_FLOAT: &str = "float";
|
|
pub const TYPE_STRING: &str = "string";
|
|
|
|
pub const TRAIT_NUMERIC: &str = "Num";
|
|
|
|
pub const CMD_ADD: &str = "add";
|
|
|
|
#[allow(
|
|
clippy::unwrap_used,
|
|
reason = "Errs can only be returned in case of duplicate names in the same namespace, which will not happen here"
|
|
)]
|
|
#[allow(clippy::missing_panics_doc, reason = "will not panic")]
|
|
pub fn initialise_globals() -> GlobalNamespace {
|
|
let ns = GlobalNamespace::init();
|
|
|
|
let numeric = ns.register_trait(TRAIT_NUMERIC).unwrap();
|
|
|
|
ns.register_type(TYPE_INTEGER).unwrap().add_trait(&numeric);
|
|
ns.register_type(TYPE_FLOAT).unwrap().add_trait(&numeric);
|
|
|
|
ns.register_type(TYPE_STRING).unwrap();
|
|
|
|
// def math add [ Numeric Numeric ] -> Numeric
|
|
ns.register_command(
|
|
CMD_ADD,
|
|
Some(TypeDef::List(vec![
|
|
TypeDef::Trait(numeric),
|
|
TypeDef::Trait(numeric),
|
|
])),
|
|
Some(TypeDef::Trait(numeric)),
|
|
)
|
|
.unwrap();
|
|
|
|
ns
|
|
}
|