Add operators, math, time, string, collection, and HOF builtins to El

This commit is contained in:
Will Anderson
2026-04-29 03:58:16 -05:00
parent a42429012e
commit 8d4d9ed786
15 changed files with 972 additions and 19 deletions
+39
View File
@@ -16,6 +16,45 @@ pub fn register(env: &mut TypeEnv) {
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));
// Trig
env.register_fn("math_sin", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_cos", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_tan", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_asin", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_acos", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_atan2", fn_type(vec![Type::Float, Type::Float], Type::Float));
env.register_fn("math_exp", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_ln", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_log2", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_log10", fn_type(vec![Type::Float], Type::Float));
env.register_fn("math_mod", fn_type(vec![Type::Float, Type::Float], Type::Float));
env.register_fn("math_pi", fn_type(vec![], Type::Float));
env.register_fn("math_e", fn_type(vec![], Type::Float));
// Conversion
env.register_fn("int_to_float", fn_type(vec![Type::Int], Type::Float));
env.register_fn("float_to_int", fn_type(vec![Type::Float], Type::Int));
env.register_fn("is_nil", fn_type(vec![Type::Unknown], Type::Bool));
env.register_fn("unwrap_or", fn_type(vec![Type::Unknown, Type::Unknown], Type::Unknown));
// Decimal
env.register_fn("decimal_add", fn_type(vec![Type::Float, Type::Float], Type::Float));
env.register_fn("decimal_sub", fn_type(vec![Type::Float, Type::Float], Type::Float));
env.register_fn("decimal_mul", fn_type(vec![Type::Float, Type::Float], Type::Float));
env.register_fn("decimal_div", fn_type(vec![Type::Float, Type::Float], Type::Float));
env.register_fn("decimal_round", fn_type(vec![Type::Float, Type::Int], Type::Float));
// Time
env.register_fn("time_now_utc", fn_type(vec![], Type::Int));
env.register_fn("time_to_parts", fn_type(vec![Type::Int], Type::Unknown));
env.register_fn("time_from_parts", fn_type(vec![Type::Unknown], Type::Int));
env.register_fn("time_format", fn_type(vec![Type::Int, Type::String], Type::String));
env.register_fn("time_parse", fn_type(vec![Type::String], Type::Int));
env.register_fn("time_add", fn_type(vec![Type::Int, Type::Int, Type::String], Type::Int));
env.register_fn("time_diff", fn_type(vec![Type::Int, Type::Int, Type::String], Type::Int));
env.register_fn("time_start_of", fn_type(vec![Type::Int, Type::String], Type::Int));
env.register_fn("time_tz_offset", fn_type(vec![Type::String], Type::Int));
env.register_fn("time_to_tz", fn_type(vec![Type::Int, Type::String], Type::Unknown));
// Observer
env.register_fn("observe", fn_type(vec![Type::String, Type::String], Type::Int));
env.register_fn("unobserve", fn_type(vec![Type::Int], Type::Unknown));
}
#[cfg(test)]