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