1use std::fmt;
6use std::fmt::Debug;
7use std::rc::Rc;
8use swamp_types::prelude::*;
9
10#[derive(Debug, Hash, Clone)]
11pub enum IntrinsicFunction {
12 FloatRound,
13 FloatFloor,
14 FloatSqrt,
15 FloatSign,
16 FloatAbs,
17 FloatRnd,
18 FloatCos,
19 FloatSin,
20 FloatAcos,
21 FloatAsin,
22 FloatAtan2,
23 FloatMin,
24 FloatMax,
25 FloatClamp,
26
27 IntAbs,
29 IntRnd,
30 IntMax,
31 IntMin,
32 IntClamp,
33 IntToFloat,
34
35 StringLen,
37
38 VecFromSlice,
40 VecPush,
41 VecPop,
42 VecRemoveIndex,
43 VecRemoveIndexGetValue,
44 VecClear,
45 VecCreate,
46 VecSubscript,
47 VecSubscriptMut,
48 VecSubscriptRange,
49 VecIter,
50 VecIterMut,
51 VecFor,
52 VecWhile,
53 VecFindMap,
54 VecAny,
55 VecAll,
56 VecMap,
57 VecFilter,
58 VecFilterMap,
59 VecFind,
60 VecFold,
61 VecSwap,
62 VecInsert,
63 VecFirst,
64 VecGet,
65 VecLast,
66
67 VecSelfPush,
68 VecSelfExtend,
69
70 MapCreate,
72 MapFromSlicePair,
73 MapHas,
74 MapRemove,
75 MapIter,
76 MapIterMut,
77 MapLen,
78 MapIsEmpty,
79 MapSubscript,
80 MapSubscriptSet,
81 MapSubscriptMut,
82 MapSubscriptMutCreateIfNeeded,
83
84 Map2Create,
86 Map2Insert,
87 Map2Remove,
88 Map2Get,
89 Map2GetColumn,
90 Map2GetRow,
91 Map2Has,
92
93 SparseCreate,
95 SparseFromSlice,
96 SparseIter,
97 SparseIterMut,
98 SparseSubscript,
99 SparseSubscriptMut,
100 SparseHas,
101 SparseRemove,
102
103 GridCreate,
105 GridFromSlice,
106 GridGetColumn,
107 GridSet,
110 GridGet,
111 Float2Magnitude,
113 SparseAdd,
114 VecLen,
115 VecIsEmpty,
116 SparseNew,
117}
118
119pub type IntrinsicFunctionDefinitionRef = Rc<IntrinsicFunctionDefinition>;
120#[derive(Clone, Debug)]
121pub struct IntrinsicFunctionDefinition {
122 pub name: String,
123 pub signature: Signature,
124 pub intrinsic: IntrinsicFunction,
125}
126
127impl fmt::Display for IntrinsicFunction {
128 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129 let name = match self {
130 Self::FloatRound => "float_round",
132 Self::FloatFloor => "float_floor",
133 Self::FloatSqrt => "float_sqrt",
134 Self::FloatSign => "float_sign",
135 Self::FloatAbs => "float_abs",
136 Self::FloatRnd => "float_rnd",
137 Self::FloatCos => "float_cos",
138 Self::FloatSin => "float_sin",
139 Self::FloatAcos => "float_acos",
140 Self::FloatAsin => "float_asin",
141 Self::FloatAtan2 => "float_atan2",
142 Self::FloatMin => "float_min",
143 Self::FloatMax => "float_max",
144 Self::FloatClamp => "float_clamp",
145
146 Self::IntAbs => "int_abs",
148 Self::IntRnd => "int_rnd",
149 Self::IntMax => "int_max",
150 Self::IntMin => "int_min",
151 Self::IntToFloat => "int_to_float",
152 Self::IntClamp => "int_clamp",
153
154 Self::StringLen => "string_len",
156
157 Self::VecFromSlice => "vec_from_slice",
159 Self::VecPush => "vec_push",
160 Self::VecPop => "vec_pop",
161 Self::VecRemoveIndex => "vec_remove_index",
162 Self::VecRemoveIndexGetValue => "vec_remove_index_get_value",
163 Self::VecClear => "vec_clear",
164 Self::VecGet => "vec_get",
165 Self::VecCreate => "vec_create",
166 Self::VecSubscriptMut => "vec_subscript_mut",
167 Self::VecSubscript => "vec_subscript",
168 Self::VecSubscriptRange => "vec_subscript_range",
169 Self::VecIter => "vec_iter",
170 Self::VecIterMut => "vec_iter_mut",
171 Self::VecFor => "vec_for",
172 Self::VecWhile => "vec_while",
173 Self::VecFindMap => "vec_find_map",
174 Self::VecLen => "vec_len",
175 Self::VecIsEmpty => "vec_is_empty",
176 Self::VecAny => "vec_any",
177 Self::VecAll => "vec_all",
178 Self::VecMap => "vec_map",
179 Self::VecFilter => "vec_filter",
180 Self::VecFilterMap => "vec_filter_map",
181 Self::VecFind => "vec_find",
182 Self::VecFold => "vec_fold",
183 Self::VecSwap => "vec_swap",
184 Self::VecInsert => "vec_insert",
185 Self::VecFirst => "vec_first",
186 Self::VecLast => "vec_last",
187
188 Self::VecSelfPush => "vec_self_push",
189 Self::VecSelfExtend => "vec_self_extend",
190
191 Self::MapCreate => "map_create",
193 Self::MapFromSlicePair => "map_from_slice_pair",
194 Self::MapHas => "map_has",
195 Self::MapRemove => "map_remove",
196 Self::MapSubscriptMut => "map_subscript_mut",
197 Self::MapSubscriptMutCreateIfNeeded => "map_subscript_mut_create_if_needed",
198 Self::MapSubscript => "map_subscript",
199 Self::MapSubscriptSet => "map_subscript_set",
200 Self::MapIter => "map_iter",
201 Self::MapIterMut => "map_iter_mut",
202 Self::MapLen => "map_len",
203 Self::MapIsEmpty => "map_is_empty",
204
205 Self::Map2Create => "map2_create",
207 Self::Map2Insert => "map2_insert",
208 Self::Map2Remove => "map2_remove",
209 Self::Map2Has => "map2_has",
210 Self::Map2GetColumn => "map2_get_column",
211 Self::Map2GetRow => "map2_get_row",
212 Self::Map2Get => "map2_get",
213
214 Self::SparseNew => "sparse_new",
216 Self::SparseCreate => "sparse_create",
217 Self::SparseFromSlice => "sparse_from_slice",
218 Self::SparseAdd => "sparse_add",
219 Self::SparseHas => "sparse_has",
220 Self::SparseRemove => "sparse_remove",
221 Self::SparseSubscriptMut => "sparse_subscript_mut",
222 Self::SparseSubscript => "sparse_subscript",
223 Self::SparseIter => "sparse_iter",
224 Self::SparseIterMut => "sparse_iter_mut",
225
226 Self::GridCreate => "grid_new",
228 Self::GridSet => "grid_set",
229 Self::GridGet => "grid_get",
230 Self::GridFromSlice => "grid_from_slice",
231 Self::GridGetColumn => "grid_get_column",
232
233 Self::Float2Magnitude => "float2_magnitude",
235 };
236
237 write!(f, "{name}")
238 }
239}