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
79 TransformerFor,
81 TransformerWhile,
82 TransformerFindMap,
83 TransformerAny,
84 TransformerAll,
85 TransformerMap,
86 TransformerFilter,
87 TransformerFilterMap,
88 TransformerFind,
89 TransformerFold,
90
91 MapIsEmpty,
93 MapHas,
94 MapRemove,
95 MapLen,
96 MapCapacity,
97
98 GridSet,
100 GridGet,
101 GridWidth,
102 GridHeight,
103
104 SparseAdd,
106 SparseRemove,
107 SparseIsAlive,
108
109 Float2Magnitude,
110
111 RuntimePanic,
112 RuntimeHalt,
113 RuntimeStep,
114}
115
116pub type IntrinsicFunctionDefinitionRef = Rc<IntrinsicFunctionDefinition>;
117
118#[derive(Clone, PartialEq, Eq, Debug)]
119pub struct IntrinsicFunctionDefinition {
120 pub name: String,
121 pub signature: Signature,
122 pub intrinsic: IntrinsicFunction,
123}
124
125impl fmt::Display for IntrinsicFunction {
126 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127 let name = match self {
128 Self::CodepointToString => "codepoint_to_string",
130 Self::CodepointToInt => "codepoint_to_int",
131
132 Self::ByteToString => "byte_to_string",
134 Self::ByteToInt => "byte_to_int",
135 Self::ByteToFloat => "byte_to_float",
136 Self::ByteToCodepoint => "byte_to_char",
137
138 Self::BoolToString => "bool_to_string",
140
141 Self::FloatRound => "float_round",
143 Self::FloatFloor => "float_floor",
144 Self::FloatSqrt => "float_sqrt",
145 Self::FloatSign => "float_sign",
146 Self::FloatAbs => "float_abs",
147 Self::FloatRnd => "float_rnd",
148 Self::FloatCos => "float_cos",
149 Self::FloatSin => "float_sin",
150 Self::FloatAcos => "float_acos",
151 Self::FloatAsin => "float_asin",
152 Self::FloatAtan2 => "float_atan2",
153 Self::FloatMin => "float_min",
154 Self::FloatMax => "float_max",
155 Self::FloatClamp => "float_clamp",
156 Self::FloatToString => "float_to_string",
157
158 Self::IntAbs => "int_abs",
160 Self::IntRnd => "int_rnd",
161 Self::IntMax => "int_max",
162 Self::IntMin => "int_min",
163 Self::IntToFloat => "int_to_float",
164 Self::IntClamp => "int_clamp",
165 Self::IntToString => "int_to_string",
166
167 Self::StringLen => "string_len",
169 Self::StringToString => "string_to_string",
170 Self::StringStartsWith => "string_starts_with",
171 Self::StringToInt => "string_to_int",
172 Self::StringToFloat => "string_to_float",
173
174 Self::VecPush => "vec_push",
176 Self::VecPop => "vec_pop",
177 Self::VecSlice => "vec_slice",
178 Self::VecRemoveIndex => "vec_remove_index",
179 Self::VecRemoveIndexGetValue => "vec_remove_index_get_value",
180 Self::VecRemoveFirstIndexGetValue => "vec_remove_first_get_value",
181 Self::VecClear => "vec_clear",
182 Self::VecGet => "vec_get",
183 Self::TransformerFor => "vec_for",
184 Self::VecIsEmpty => "vec_is_empty",
185 Self::TransformerWhile => "transformer_while",
186 Self::TransformerFindMap => "transformer_find_map",
187 Self::VecLen => "vec_len",
188 Self::VecCapacity => "vec_capacity",
189 Self::TransformerAny => "vec_any",
190 Self::TransformerAll => "vec_all",
191 Self::TransformerMap => "vec_map",
192 Self::TransformerFilter => "vec_filter",
193 Self::TransformerFilterMap => "vec_filter_map",
194 Self::TransformerFind => "vec_find",
195 Self::TransformerFold => "vec_fold",
196 Self::VecSwap => "vec_swap",
197 Self::VecInsert => "vec_insert",
198 Self::VecFirst => "vec_first",
199 Self::VecLast => "vec_last",
200
201 Self::MapHas => "map_has",
203 Self::MapRemove => "map_remove",
204 Self::MapLen => "map_len",
205 Self::MapCapacity => "map_len",
206 Self::MapIsEmpty => "map_is_empty",
207
208 Self::GridSet => "grid_set",
210 Self::GridGet => "grid_get",
211 Self::GridWidth => "grid_width",
212 Self::GridHeight => "grid_height",
213
214 Self::SparseAdd => "sparse_add",
216 Self::SparseRemove => "sparse_remove",
217 Self::SparseIsAlive => "sparse_is_alive",
218
219 Self::Float2Magnitude => "float2_magnitude",
221 Self::RuntimePanic => "runtime_panic",
222 Self::RuntimeHalt => "runtime_halt",
223 Self::RuntimeStep => "runtime_step",
224 Self::RangeInit => "rinit",
225 };
226
227 write!(f, "{name}")
228 }
229}