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