1use std::fmt;
6use std::fmt::Debug;
7use std::rc::Rc;
8use swamp_types::prelude::*;
9
10#[derive(Debug, Hash, Eq, PartialEq, Clone)]
11pub enum IntrinsicFunction {
12 ByteToString,
14 ByteToInt,
15 ByteToFloat,
16 ByteToCodepoint,
17
18 CodepointToString,
20 CodepointToInt,
21
22 BoolToString,
24
25 IntAbs,
27 IntRnd,
28 IntMax,
29 IntMin,
30 IntClamp,
31 IntToFloat,
32 IntToString,
33
34 FloatRound,
36 FloatFloor,
37 FloatSqrt,
38 FloatSign,
39 FloatAbs,
40 FloatRnd,
41 FloatCos,
42 FloatSin,
43 FloatAcos,
44 FloatAsin,
45 FloatAtan2,
46 FloatMin,
47 FloatMax,
48 FloatClamp,
49 FloatToString,
50
51 StringLen,
53 StringToString,
54 StringStartsWith,
56 StringToInt,
57 StringToFloat,
58
59 RangeInit,
61
62 VecPush,
64 VecPop,
65 VecRemoveIndex,
66 VecRemoveIndexGetValue,
67 VecRemoveFirstIndexGetValue,
68 VecClear,
69 VecSwap,
70 VecInsert,
71 VecFirst,
72 VecGet,
73 VecSlice,
74 VecLast,
75 VecLen,
76 VecCapacity,
77 VecIsEmpty,
78 VecExtend,
79
80 TransformerFor,
82 TransformerWhile,
83 TransformerFindMap,
84 TransformerAny,
85 TransformerAll,
86 TransformerMap,
87 TransformerFilter,
88 TransformerFilterInPlace,
89 TransformerFilterMap,
90 TransformerFind,
91 TransformerFold,
92
93 MapIsEmpty,
95 MapHas,
96 MapRemove,
97 MapLen,
98 MapCapacity,
99
100 GridSet,
102 GridGet,
103 GridWidth,
104 GridHeight,
105
106 SparseAdd,
108 SparseRemove,
109 SparseIsAlive,
110
111 Float2Magnitude,
112
113 RuntimePanic,
114 RuntimeHalt,
115 RuntimeStep,
116 EnumDiscriminant,
117 EnumFromDiscriminant,
118 PtrFromU32,
119 StringDuplicate,
120 ByteVectorToString,
121 ByteVectorToStringStorage,
122 VecCopy,
123}
124
125pub type IntrinsicFunctionDefinitionRef = Rc<IntrinsicFunctionDefinition>;
126
127#[derive(Clone, PartialEq, Eq, Debug)]
128pub struct IntrinsicFunctionDefinition {
129 pub name: String,
130 pub signature: Signature,
131 pub intrinsic: IntrinsicFunction,
132}
133
134impl fmt::Display for IntrinsicFunction {
135 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136 let name = match self {
137 Self::CodepointToString => "codepoint_to_string",
139 Self::CodepointToInt => "codepoint_to_int",
140
141 Self::ByteToString => "byte_to_string",
143 Self::ByteToInt => "byte_to_int",
144 Self::ByteToFloat => "byte_to_float",
145 Self::ByteToCodepoint => "byte_to_char",
146
147 Self::BoolToString => "bool_to_string",
149
150 Self::FloatRound => "float_round",
152 Self::FloatFloor => "float_floor",
153 Self::FloatSqrt => "float_sqrt",
154 Self::FloatSign => "float_sign",
155 Self::FloatAbs => "float_abs",
156 Self::FloatRnd => "float_rnd",
157 Self::FloatCos => "float_cos",
158 Self::FloatSin => "float_sin",
159 Self::FloatAcos => "float_acos",
160 Self::FloatAsin => "float_asin",
161 Self::FloatAtan2 => "float_atan2",
162 Self::FloatMin => "float_min",
163 Self::FloatMax => "float_max",
164 Self::FloatClamp => "float_clamp",
165 Self::FloatToString => "float_to_string",
166
167 Self::IntAbs => "int_abs",
169 Self::IntRnd => "int_rnd",
170 Self::IntMax => "int_max",
171 Self::IntMin => "int_min",
172 Self::IntToFloat => "int_to_float",
173 Self::IntClamp => "int_clamp",
174 Self::IntToString => "int_to_string",
175
176 Self::StringLen => "string_len",
178 Self::StringToString => "string_to_string",
179 Self::StringStartsWith => "string_starts_with",
180 Self::StringToInt => "string_to_int",
181 Self::StringToFloat => "string_to_float",
182 Self::StringDuplicate => "string_dup",
183 Self::ByteVectorToString => "bytes_to_string",
184 Self::ByteVectorToStringStorage => "bytes_to_string_storage",
185
186 Self::EnumDiscriminant => "enum_discriminant",
188 Self::EnumFromDiscriminant => "enum_from_discriminant",
189
190 Self::VecPush => "vec_push",
192 Self::VecExtend => "vec_extend",
193 Self::VecPop => "vec_pop",
194 Self::VecSlice => "vec_slice",
195 Self::VecRemoveIndex => "vec_remove_index",
196 Self::VecRemoveIndexGetValue => "vec_remove_index_get_value",
197 Self::VecRemoveFirstIndexGetValue => "vec_remove_first_get_value",
198 Self::VecClear => "vec_clear",
199 Self::VecGet => "vec_get",
200 Self::TransformerFor => "vec_for",
201 Self::VecIsEmpty => "vec_is_empty",
202 Self::TransformerWhile => "transformer_while",
203 Self::TransformerFindMap => "transformer_find_map",
204 Self::VecLen => "vec_len",
205 Self::VecCapacity => "vec_capacity",
206 Self::TransformerAny => "vec_any",
207 Self::TransformerAll => "vec_all",
208 Self::TransformerMap => "vec_map",
209 Self::TransformerFilter => "vec_filter",
210 Self::TransformerFilterInPlace => "vec_filter_mut",
211 Self::TransformerFilterMap => "vec_filter_map",
212 Self::TransformerFind => "vec_find",
213 Self::TransformerFold => "vec_fold",
214 Self::VecSwap => "vec_swap",
215 Self::VecInsert => "vec_insert",
216 Self::VecFirst => "vec_first",
217 Self::VecLast => "vec_last",
218 Self::VecCopy => "vec_copy",
219
220 Self::MapHas => "map_has",
222 Self::MapRemove => "map_remove",
223 Self::MapLen => "map_len",
224 Self::MapCapacity => "map_len",
225 Self::MapIsEmpty => "map_is_empty",
226
227 Self::GridSet => "grid_set",
229 Self::GridGet => "grid_get",
230 Self::GridWidth => "grid_width",
231 Self::GridHeight => "grid_height",
232
233 Self::SparseAdd => "sparse_add",
235 Self::SparseRemove => "sparse_remove",
236 Self::SparseIsAlive => "sparse_is_alive",
237
238 Self::Float2Magnitude => "float2_magnitude",
240 Self::RuntimePanic => "runtime_panic",
241 Self::RuntimeHalt => "runtime_halt",
242 Self::RuntimeStep => "runtime_step",
243 Self::RangeInit => "rinit",
244 Self::PtrFromU32 => "ptr_from_u32",
245 };
246
247 write!(f, "{name}")
248 }
249}