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