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