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
15 CharToString,
17 CharToInt,
18
19 BoolToString,
21
22 IntAbs,
24 IntRnd,
25 IntMax,
26 IntMin,
27 IntClamp,
28 IntToFloat,
29 IntToString,
30
31 FloatRound,
33 FloatFloor,
34 FloatSqrt,
35 FloatSign,
36 FloatAbs,
37 FloatRnd,
38 FloatCos,
39 FloatSin,
40 FloatAcos,
41 FloatAsin,
42 FloatAtan2,
43 FloatMin,
44 FloatMax,
45 FloatClamp,
46 FloatToString,
47
48 StringLen,
50 StringToString,
51 RangeInit,
55
56 VecPush,
58 VecPop,
59 VecRemoveIndex,
60 VecRemoveIndexGetValue,
61 VecRemoveFirstIndexGetValue,
62 VecClear,
63 VecSwap,
64 VecInsert,
65 VecFirst,
66 VecGet,
67 VecLast,
68 VecLen,
69 VecCapacity,
70 VecIsEmpty,
71
72 TransformerFor,
74 TransformerWhile,
75 TransformerFindMap,
76 TransformerAny,
77 TransformerAll,
78 TransformerMap,
79 TransformerFilter,
80 TransformerFilterMap,
81 TransformerFind,
82 TransformerFold,
83
84 MapIsEmpty,
86 MapHas,
87 MapRemove,
88 MapLen,
89 MapCapacity,
90
91 GridSet,
93 GridGet,
94 GridWidth,
95 GridHeight,
96
97 SparseAdd,
99 SparseRemove,
100 SparseIsAlive,
101
102 Float2Magnitude,
103
104 RuntimePanic,
105 RuntimeHalt,
106 RuntimeStep,
107 ByteToInt,
108}
109
110pub type IntrinsicFunctionDefinitionRef = Rc<IntrinsicFunctionDefinition>;
111
112#[derive(Clone, PartialEq, Eq, Debug)]
113pub struct IntrinsicFunctionDefinition {
114 pub name: String,
115 pub signature: Signature,
116 pub intrinsic: IntrinsicFunction,
117}
118
119impl fmt::Display for IntrinsicFunction {
120 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
121 let name = match self {
122 Self::CharToString => "char_to_string",
124 Self::CharToInt => "char_to_int",
125
126 Self::ByteToString => "byte_to_string",
128 Self::ByteToInt => "byte_to_int",
129
130 Self::BoolToString => "bool_to_string",
132
133 Self::FloatRound => "float_round",
135 Self::FloatFloor => "float_floor",
136 Self::FloatSqrt => "float_sqrt",
137 Self::FloatSign => "float_sign",
138 Self::FloatAbs => "float_abs",
139 Self::FloatRnd => "float_rnd",
140 Self::FloatCos => "float_cos",
141 Self::FloatSin => "float_sin",
142 Self::FloatAcos => "float_acos",
143 Self::FloatAsin => "float_asin",
144 Self::FloatAtan2 => "float_atan2",
145 Self::FloatMin => "float_min",
146 Self::FloatMax => "float_max",
147 Self::FloatClamp => "float_clamp",
148 Self::FloatToString => "float_to_string",
149
150 Self::IntAbs => "int_abs",
152 Self::IntRnd => "int_rnd",
153 Self::IntMax => "int_max",
154 Self::IntMin => "int_min",
155 Self::IntToFloat => "int_to_float",
156 Self::IntClamp => "int_clamp",
157 Self::IntToString => "int_to_string",
158
159 Self::StringLen => "string_len",
161 Self::StringToString => "string_to_string",
162
163 Self::VecPush => "vec_push",
165 Self::VecPop => "vec_pop",
166 Self::VecRemoveIndex => "vec_remove_index",
167 Self::VecRemoveIndexGetValue => "vec_remove_index_get_value",
168 Self::VecRemoveFirstIndexGetValue => "vec_remove_first_get_value",
169 Self::VecClear => "vec_clear",
170 Self::VecGet => "vec_get",
171 Self::TransformerFor => "vec_for",
172 Self::VecIsEmpty => "vec_is_empty",
173 Self::TransformerWhile => "transformer_while",
174 Self::TransformerFindMap => "transformer_find_map",
175 Self::VecLen => "vec_len",
176 Self::VecCapacity => "vec_capacity",
177 Self::TransformerAny => "vec_any",
178 Self::TransformerAll => "vec_all",
179 Self::TransformerMap => "vec_map",
180 Self::TransformerFilter => "vec_filter",
181 Self::TransformerFilterMap => "vec_filter_map",
182 Self::TransformerFind => "vec_find",
183 Self::TransformerFold => "vec_fold",
184 Self::VecSwap => "vec_swap",
185 Self::VecInsert => "vec_insert",
186 Self::VecFirst => "vec_first",
187 Self::VecLast => "vec_last",
188
189 Self::MapHas => "map_has",
191 Self::MapRemove => "map_remove",
192 Self::MapLen => "map_len",
193 Self::MapCapacity => "map_len",
194 Self::MapIsEmpty => "map_is_empty",
195
196 Self::GridSet => "grid_set",
198 Self::GridGet => "grid_get",
199 Self::GridWidth => "grid_width",
200 Self::GridHeight => "grid_height",
201
202 Self::SparseAdd => "sparse_add",
204 Self::SparseRemove => "sparse_remove",
205 Self::SparseIsAlive => "sparse_is_alive",
206
207 Self::Float2Magnitude => "float2_magnitude",
209 Self::RuntimePanic => "runtime_panic",
210 Self::RuntimeHalt => "runtime_halt",
211 Self::RuntimeStep => "runtime_step",
212 Self::RangeInit => "rinit",
213 };
214
215 write!(f, "{name}")
216 }
217}