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