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 MapSubscript,
63 MapSubscriptSet,
64 MapSubscriptMut,
65 MapSubscriptMutCreateIfNeeded,
66
67 SparseCreate,
69 SparseFromSlice,
70 SparseIter,
71 SparseIterMut,
72 SparseSubscript,
73 SparseSubscriptMut,
74 SparseHas,
75 SparseRemove,
76
77 GridCreate,
79 GridFromSlice,
80 GridSubscript,
83 GridSubscriptMut,
84
85 Float2Magnitude,
86 SparseAdd,
87 VecLen,
88 VecIsEmpty,
89 SparseNew,
90}
91
92pub type IntrinsicFunctionDefinitionRef = Rc<IntrinsicFunctionDefinition>;
93#[derive(Clone, Debug)]
94pub struct IntrinsicFunctionDefinition {
95 pub name: String,
96 pub signature: Signature,
97 pub intrinsic: IntrinsicFunction,
98}
99
100impl fmt::Display for IntrinsicFunction {
101 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102 let name = match self {
103 Self::FloatRound => "float_round",
105 Self::FloatFloor => "float_floor",
106 Self::FloatSqrt => "float_sqrt",
107 Self::FloatSign => "float_sign",
108 Self::FloatAbs => "float_abs",
109 Self::FloatRnd => "float_rnd",
110 Self::FloatCos => "float_cos",
111 Self::FloatSin => "float_sin",
112 Self::FloatAcos => "float_acos",
113 Self::FloatAsin => "float_asin",
114 Self::FloatAtan2 => "float_atan2",
115 Self::FloatMin => "float_min",
116 Self::FloatMax => "float_max",
117 Self::FloatClamp => "float_clamp",
118
119 Self::IntAbs => "int_abs",
121 Self::IntRnd => "int_rnd",
122 Self::IntMax => "int_max",
123 Self::IntMin => "int_min",
124 Self::IntToFloat => "int_to_float",
125 Self::IntClamp => "int_clamp",
126
127 Self::StringLen => "string_len",
129
130 Self::VecFromSlice => "vec_from_slice",
132 Self::VecPush => "vec_push",
133 Self::VecPop => "vec_pop",
134 Self::VecRemoveIndex => "vec_remove",
135 Self::VecClear => "vec_clear",
136 Self::VecCreate => "vec_create",
137 Self::VecSubscriptMut => "vec_subscript_mut",
138 Self::VecSubscript => "vec_subscript",
139 Self::VecIter => "vec_iter",
140 Self::VecIterMut => "vec_iter_mut",
141 Self::VecLen => "vec_len",
142 Self::VecIsEmpty => "vec_is_empty",
143
144 Self::VecSelfPush => "vec_self_push",
145 Self::VecSelfExtend => "vec_self_extend",
146
147 Self::MapCreate => "map_create",
149 Self::MapFromSlicePair => "map_from_slice_pair",
150 Self::MapHas => "map_has",
151 Self::MapRemove => "map_remove",
152 Self::MapSubscriptMut => "map_subscript_mut",
153 Self::MapSubscriptMutCreateIfNeeded => "map_subscript_mut_create_if_needed",
154 Self::MapSubscript => "map_subscript",
155 Self::MapSubscriptSet => "map_subscript_set",
156 Self::MapIter => "map_iter",
157 Self::MapIterMut => "map_iter_mut",
158 Self::MapLen => "map_len",
159
160 Self::SparseNew => "sparse_new",
162 Self::SparseCreate => "sparse_create",
163 Self::SparseFromSlice => "sparse_from_slice",
164 Self::SparseAdd => "sparse_add",
165 Self::SparseHas => "sparse_has",
166 Self::SparseRemove => "sparse_remove",
167 Self::SparseSubscriptMut => "sparse_subscript_mut",
168 Self::SparseSubscript => "sparse_subscript",
169 Self::SparseIter => "sparse_iter",
170 Self::SparseIterMut => "sparse_iter_mut",
171
172 Self::GridCreate => "grid_new",
174 Self::GridSubscript => "grid_subscript",
175 Self::GridSubscriptMut => "grid_subscript_mut",
176 Self::GridFromSlice => "grid_from_slice",
177
178 Self::Float2Magnitude => "float2_magnitude",
180 };
181
182 write!(f, "{name}")
183 }
184}