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