Add operators, math, time, string, collection, and HOF builtins to El
This commit is contained in:
@@ -50,6 +50,28 @@ pub fn register(env: &mut TypeEnv) {
|
||||
env.register_fn("array_last", fn_type(vec![arr_int.clone()], Type::Optional(Box::new(Type::Int))));
|
||||
// array_contains([String], String) -> Bool
|
||||
env.register_fn("array_contains", fn_type(vec![arr_str, Type::String], Type::Bool));
|
||||
// New list/stack/queue builtins
|
||||
env.register_fn("list_push", fn_type(vec![arr_unk.clone(), Type::Unknown], arr_unk.clone()));
|
||||
env.register_fn("list_pop", fn_type(vec![arr_unk.clone()], arr_unk.clone()));
|
||||
env.register_fn("list_pop_front", fn_type(vec![arr_unk.clone()], arr_unk.clone()));
|
||||
env.register_fn("list_peek_last", fn_type(vec![arr_unk.clone()], Type::Unknown));
|
||||
env.register_fn("list_range", fn_type(vec![Type::Int, Type::Int], arr_unk.clone()));
|
||||
env.register_fn("list_new", fn_type(vec![], arr_unk.clone()));
|
||||
env.register_fn("list_empty", fn_type(vec![arr_unk.clone()], Type::Bool));
|
||||
env.register_fn("list_map", fn_type(vec![arr_unk.clone(), Type::String], arr_unk.clone()));
|
||||
env.register_fn("list_filter", fn_type(vec![arr_unk.clone(), Type::String], arr_unk.clone()));
|
||||
env.register_fn("list_reduce", fn_type(vec![arr_unk.clone(), Type::Unknown, Type::String], Type::Unknown));
|
||||
env.register_fn("fn_ref", fn_type(vec![Type::String], Type::String));
|
||||
// Stack
|
||||
env.register_fn("stack_push", fn_type(vec![arr_unk.clone(), Type::Unknown], arr_unk.clone()));
|
||||
env.register_fn("stack_pop", fn_type(vec![arr_unk.clone()], arr_unk.clone()));
|
||||
env.register_fn("stack_peek", fn_type(vec![arr_unk.clone()], Type::Unknown));
|
||||
env.register_fn("stack_new", fn_type(vec![], arr_unk.clone()));
|
||||
// Queue
|
||||
env.register_fn("queue_enqueue", fn_type(vec![arr_unk.clone(), Type::Unknown], arr_unk.clone()));
|
||||
env.register_fn("queue_dequeue", fn_type(vec![arr_unk.clone()], arr_unk.clone()));
|
||||
env.register_fn("queue_peek", fn_type(vec![arr_unk.clone()], Type::Unknown));
|
||||
env.register_fn("queue_new", fn_type(vec![], arr_unk));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -27,6 +27,14 @@ pub fn register(env: &mut TypeEnv) {
|
||||
env.register_fn("string_from_float", fn_type(vec![Type::Float], Type::String));
|
||||
env.register_fn("string_is_empty", fn_type(vec![Type::String], Type::Bool));
|
||||
env.register_fn("string_concat", fn_type(vec![Type::String, Type::String], Type::String));
|
||||
// New string builtins
|
||||
env.register_fn("str_char_at", fn_type(vec![Type::String, Type::Int], Type::String));
|
||||
env.register_fn("str_char_code", fn_type(vec![Type::String, Type::Int], Type::Int));
|
||||
env.register_fn("str_from_char_code", fn_type(vec![Type::Int], Type::String));
|
||||
env.register_fn("str_pad_left", fn_type(vec![Type::String, Type::Int, Type::String], Type::String));
|
||||
env.register_fn("str_pad_right", fn_type(vec![Type::String, Type::Int, Type::String], Type::String));
|
||||
env.register_fn("format_float", fn_type(vec![Type::Float, Type::Int], Type::String));
|
||||
env.register_fn("str_format", fn_type(vec![Type::String, Type::Unknown], Type::String));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user