Archived
rename crates/ to engrams/; add el-compiler el package with bootstrap artifact
- crates/ → engrams/ (Rust engrams live here)
- el-compiler/ added: el self-hosting compiler as an el package
- src/{compiler,lexer,parser,codegen}.el
- bootstrap/el-compiler.elc (114KB, Rust-compiled seed)
- el.toml Cargo.toml workspace paths updated
- neuron-rs cross-repo path deps fixed (were pointing to products/ instead of foundation/)
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
//! Math operations: abs, max, min, floor, ceil, pow, sqrt, clamp.
|
||||
|
||||
use el_types::{Type, TypeEnv};
|
||||
use super::fn_type;
|
||||
|
||||
pub fn register(env: &mut TypeEnv) {
|
||||
env.register_fn("math_abs", fn_type(vec![Type::Float], Type::Float));
|
||||
env.register_fn("math_max", fn_type(vec![Type::Float, Type::Float], Type::Float));
|
||||
env.register_fn("math_min", fn_type(vec![Type::Float, Type::Float], Type::Float));
|
||||
env.register_fn("math_floor", fn_type(vec![Type::Float], Type::Int));
|
||||
env.register_fn("math_ceil", fn_type(vec![Type::Float], Type::Int));
|
||||
env.register_fn("math_round", fn_type(vec![Type::Float], Type::Int));
|
||||
env.register_fn("math_pow", fn_type(vec![Type::Float, Type::Float], Type::Float));
|
||||
env.register_fn("math_sqrt", fn_type(vec![Type::Float], Type::Float));
|
||||
env.register_fn("math_clamp", fn_type(vec![Type::Float, Type::Float, Type::Float], Type::Float));
|
||||
env.register_fn("math_abs_int", fn_type(vec![Type::Int], Type::Int));
|
||||
env.register_fn("math_max_int", fn_type(vec![Type::Int, Type::Int], Type::Int));
|
||||
env.register_fn("math_min_int", fn_type(vec![Type::Int, Type::Int], Type::Int));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn env() -> TypeEnv {
|
||||
let mut e = TypeEnv::with_builtins();
|
||||
register(&mut e);
|
||||
e
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_math_abs_registered() {
|
||||
assert!(env().lookup_fn("math_abs").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_math_sqrt_returns_float() {
|
||||
let e = env();
|
||||
let ty = e.lookup_fn("math_sqrt").unwrap();
|
||||
assert!(matches!(ty, Type::Fn { return_type, .. } if matches!(return_type.as_ref(), Type::Float)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_math_floor_returns_int() {
|
||||
let e = env();
|
||||
let ty = e.lookup_fn("math_floor").unwrap();
|
||||
assert!(matches!(ty, Type::Fn { return_type, .. } if matches!(return_type.as_ref(), Type::Int)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user