mica_std/builtins/
mod.rs

1mod dict;
2mod list;
3mod number;
4mod string;
5
6use mica_hl::language::value::Dict;
7use mica_hl::{RawValue, StandardLibrary, TypeBuilder};
8
9/// Converts a function that takes a `self` parameter to one that takes a `&self` parameter.
10fn ref_self1<A, R>(mut f: impl FnMut(A) -> R) -> impl FnMut(&A) -> R
11where
12   A: Copy,
13{
14   move |x| f(*x)
15}
16
17/// Converts a function that takes a `self` and one arbitrary parameter to one that takes a `&self`
18/// and one arbitrary parameter.
19fn ref_self2<A, B, R>(mut f: impl FnMut(A, B) -> R) -> impl FnMut(&A, B) -> R
20where
21   A: Copy,
22{
23   move |x, y| f(*x, y)
24}
25
26struct Lib;
27
28impl StandardLibrary for Lib {
29   fn define_nil(&mut self, builder: TypeBuilder<()>) -> TypeBuilder<()> {
30      builder
31   }
32
33   fn define_boolean(&mut self, builder: TypeBuilder<bool>) -> TypeBuilder<bool> {
34      builder
35   }
36
37   fn define_number(&mut self, builder: TypeBuilder<f64>) -> TypeBuilder<f64> {
38      number::define(builder)
39   }
40
41   fn define_string(&mut self, builder: TypeBuilder<String>) -> TypeBuilder<String> {
42      string::define(builder)
43   }
44
45   fn define_list(&mut self, builder: TypeBuilder<Vec<RawValue>>) -> TypeBuilder<Vec<RawValue>> {
46      list::define(builder)
47   }
48
49   fn define_dict(&mut self, builder: TypeBuilder<Dict>) -> TypeBuilder<Dict> {
50      dict::define(builder)
51   }
52}
53
54pub fn lib() -> impl StandardLibrary {
55   Lib
56}