use crate::compiler::{
crust::{ItemSource, Symbol, Type, TypeScheme},
nucleus,
};
pub const STD_CONV: &str = "std::conv";
pub const FLOAT: &str = "float";
pub fn register_conversion_funcs(builder: &mut ItemSource) {
builder.register(
Symbol {
module: STD_CONV.to_string(),
field: FLOAT.to_string(),
},
TypeScheme {
unbound_rows: Default::default(),
unbound_tys: Default::default(),
evidence: Default::default(),
typ: Type::abstraction(Type::Int, Type::Float),
},
);
}
pub fn register_conversion_imports(modules: &mut Vec<(String, String, nucleus::Module)>) {
let module = wat::parse_str(STD_CONV_WAT).expect("blr-std::conv should be a valid wat module");
modules.push((
STD_CONV.to_string(),
"".to_string(),
nucleus::Module {
module,
imports: Default::default(),
externals: Default::default(),
exports: Default::default(),
},
));
}
const STD_CONV_WAT: &str = r#"
(module
(type $float-int-func (func (param i32 i64) (result f64)))
(; TODO make float polymorphic ;)
(export "float" (func $float-int))
(func $float-int (type $float-int-func) (param i32 i64) (result f64)
(f64.convert_i64_s (local.get 1))
)
)
"#;