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