1use std::fmt;
7use std::fmt::Debug;
8use std::rc::Rc;
9use swamp_script_types::prelude::*;
10
11#[derive(Debug, Hash, Clone)]
12pub enum IntrinsicFunction {
13 FloatRound,
14 FloatFloor,
15 FloatSqrt,
16 FloatSign,
17 FloatAbs,
18 FloatRnd,
19 FloatCos,
20 FloatSin,
21 FloatAcos,
22 FloatAsin,
23 FloatAtan2,
24 FloatMin,
25 FloatMax,
26 FloatClamp,
27
28 IntAbs,
30 IntRnd,
31 IntMax,
32 IntMin,
33 IntClamp,
34 IntToFloat,
35
36 StringLen,
38
39 VecFromSlice,
41 VecPush,
42 VecPop,
43 VecRemoveIndex,
44 VecClear,
45 VecCreate,
46 VecSubscript,
47 VecSubscriptMut,
48 VecIter,
49 VecIterMut,
50
51 VecSelfPush,
52 VecSelfExtend,
53
54 MapCreate,
56 MapFromSlicePair,
57 MapHas,
58 MapRemove,
59 MapIter,
60 MapIterMut,
61 MapLen,
62 MapIsEmpty,
63 MapSubscript,
64 MapSubscriptSet,
65 MapSubscriptMut,
66 MapSubscriptMutCreateIfNeeded,
67
68 SparseCreate,
70 SparseFromSlice,
71 SparseIter,
72 SparseIterMut,
73 SparseSubscript,
74 SparseSubscriptMut,
75 SparseHas,
76 SparseRemove,
77
78 GridCreate,
80 GridFromSlice,
81 GridSubscript,
84 GridSubscriptMut,
85
86 Float2Magnitude,
87 SparseAdd,
88 VecLen,
89 VecIsEmpty,
90 SparseNew,
91}
92
93pub type IntrinsicFunctionDefinitionRef = Rc<IntrinsicFunctionDefinition>;
94#[derive(Clone, Debug)]
95pub struct IntrinsicFunctionDefinition {
96 pub name: String,
97 pub signature: Signature,
98 pub intrinsic: IntrinsicFunction,
99}
100
101impl fmt::Display for IntrinsicFunction {
102 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103 let name = match self {
104 Self::FloatRound => "float_round",
106 Self::FloatFloor => "float_floor",
107 Self::FloatSqrt => "float_sqrt",
108 Self::FloatSign => "float_sign",
109 Self::FloatAbs => "float_abs",
110 Self::FloatRnd => "float_rnd",
111 Self::FloatCos => "float_cos",
112 Self::FloatSin => "float_sin",
113 Self::FloatAcos => "float_acos",
114 Self::FloatAsin => "float_asin",
115 Self::FloatAtan2 => "float_atan2",
116 Self::FloatMin => "float_min",
117 Self::FloatMax => "float_max",
118 Self::FloatClamp => "float_clamp",
119
120 Self::IntAbs => "int_abs",
122 Self::IntRnd => "int_rnd",
123 Self::IntMax => "int_max",
124 Self::IntMin => "int_min",
125 Self::IntToFloat => "int_to_float",
126 Self::IntClamp => "int_clamp",
127
128 Self::StringLen => "string_len",
130
131 Self::VecFromSlice => "vec_from_slice",
133 Self::VecPush => "vec_push",
134 Self::VecPop => "vec_pop",
135 Self::VecRemoveIndex => "vec_remove",
136 Self::VecClear => "vec_clear",
137 Self::VecCreate => "vec_create",
138 Self::VecSubscriptMut => "vec_subscript_mut",
139 Self::VecSubscript => "vec_subscript",
140 Self::VecIter => "vec_iter",
141 Self::VecIterMut => "vec_iter_mut",
142 Self::VecLen => "vec_len",
143 Self::VecIsEmpty => "vec_is_empty",
144
145 Self::VecSelfPush => "vec_self_push",
146 Self::VecSelfExtend => "vec_self_extend",
147
148 Self::MapCreate => "map_create",
150 Self::MapFromSlicePair => "map_from_slice_pair",
151 Self::MapHas => "map_has",
152 Self::MapRemove => "map_remove",
153 Self::MapSubscriptMut => "map_subscript_mut",
154 Self::MapSubscriptMutCreateIfNeeded => "map_subscript_mut_create_if_needed",
155 Self::MapSubscript => "map_subscript",
156 Self::MapSubscriptSet => "map_subscript_set",
157 Self::MapIter => "map_iter",
158 Self::MapIterMut => "map_iter_mut",
159 Self::MapLen => "map_len",
160 Self::MapIsEmpty => "map_is_empty",
161
162 Self::SparseNew => "sparse_new",
164 Self::SparseCreate => "sparse_create",
165 Self::SparseFromSlice => "sparse_from_slice",
166 Self::SparseAdd => "sparse_add",
167 Self::SparseHas => "sparse_has",
168 Self::SparseRemove => "sparse_remove",
169 Self::SparseSubscriptMut => "sparse_subscript_mut",
170 Self::SparseSubscript => "sparse_subscript",
171 Self::SparseIter => "sparse_iter",
172 Self::SparseIterMut => "sparse_iter_mut",
173
174 Self::GridCreate => "grid_new",
176 Self::GridSubscript => "grid_subscript",
177 Self::GridSubscriptMut => "grid_subscript_mut",
178 Self::GridFromSlice => "grid_from_slice",
179
180 Self::Float2Magnitude => "float2_magnitude",
182 };
183
184 write!(f, "{name}")
185 }
186}