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