swamp_semantic/
intr.rs

1/*
2 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/swamp
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 */
5use std::fmt;
6use std::fmt::Debug;
7use std::rc::Rc;
8use swamp_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    // Int
28    IntAbs,
29    IntRnd,
30    IntMax,
31    IntMin,
32    IntClamp,
33    IntToFloat,
34
35    // String
36    StringLen,
37
38    // Vec
39    VecFromSlice,
40    VecPush,
41    VecPop,
42    VecRemoveIndex,
43    VecRemoveIndexGetValue,
44    VecClear,
45    VecCreate,
46    VecSubscript,
47    VecSubscriptMut,
48    VecSubscriptRange,
49    VecIter,
50    VecIterMut,
51    VecFor,
52    VecWhile,
53    VecFindMap,
54    VecAny,
55    VecAll,
56    VecMap,
57    VecFilter,
58    VecFilterMap,
59    VecFind,
60    VecFold,
61    VecSwap,
62    VecInsert,
63    VecFirst,
64    VecGet,
65    VecLast,
66
67    VecSelfPush,
68    VecSelfExtend,
69
70    // Map
71    MapCreate,
72    MapFromSlicePair,
73    MapHas,
74    MapRemove,
75    MapIter,
76    MapIterMut,
77    MapLen,
78    MapIsEmpty,
79    MapSubscript,
80    MapSubscriptSet,
81    MapSubscriptMut,
82    MapSubscriptMutCreateIfNeeded,
83
84    // Map2
85    Map2Create,
86    Map2Insert,
87    Map2Remove,
88    Map2Get,
89    Map2GetColumn,
90    Map2GetRow,
91    Map2Has,
92
93    // Sparse
94    SparseCreate,
95    SparseFromSlice,
96    SparseIter,
97    SparseIterMut,
98    SparseSubscript,
99    SparseSubscriptMut,
100    SparseHas,
101    SparseRemove,
102
103    // Grid
104    GridCreate,
105    GridFromSlice,
106    GridGetColumn,
107    //GridIter,
108    //GridIterMut,
109    GridSet,
110    GridGet,
111    //GridSubscriptMut,
112    Float2Magnitude,
113    SparseAdd,
114    VecLen,
115    VecIsEmpty,
116    SparseNew,
117    RuntimePanic,
118}
119
120pub type IntrinsicFunctionDefinitionRef = Rc<IntrinsicFunctionDefinition>;
121#[derive(Clone, Debug)]
122pub struct IntrinsicFunctionDefinition {
123    pub name: String,
124    pub signature: Signature,
125    pub intrinsic: IntrinsicFunction,
126}
127
128impl fmt::Display for IntrinsicFunction {
129    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130        let name = match self {
131            // Float
132            Self::FloatRound => "float_round",
133            Self::FloatFloor => "float_floor",
134            Self::FloatSqrt => "float_sqrt",
135            Self::FloatSign => "float_sign",
136            Self::FloatAbs => "float_abs",
137            Self::FloatRnd => "float_rnd",
138            Self::FloatCos => "float_cos",
139            Self::FloatSin => "float_sin",
140            Self::FloatAcos => "float_acos",
141            Self::FloatAsin => "float_asin",
142            Self::FloatAtan2 => "float_atan2",
143            Self::FloatMin => "float_min",
144            Self::FloatMax => "float_max",
145            Self::FloatClamp => "float_clamp",
146
147            // Int
148            Self::IntAbs => "int_abs",
149            Self::IntRnd => "int_rnd",
150            Self::IntMax => "int_max",
151            Self::IntMin => "int_min",
152            Self::IntToFloat => "int_to_float",
153            Self::IntClamp => "int_clamp",
154
155            // String
156            Self::StringLen => "string_len",
157
158            // Vec
159            Self::VecFromSlice => "vec_from_slice",
160            Self::VecPush => "vec_push",
161            Self::VecPop => "vec_pop",
162            Self::VecRemoveIndex => "vec_remove_index",
163            Self::VecRemoveIndexGetValue => "vec_remove_index_get_value",
164            Self::VecClear => "vec_clear",
165            Self::VecGet => "vec_get",
166            Self::VecCreate => "vec_create",
167            Self::VecSubscriptMut => "vec_subscript_mut",
168            Self::VecSubscript => "vec_subscript",
169            Self::VecSubscriptRange => "vec_subscript_range",
170            Self::VecIter => "vec_iter",
171            Self::VecIterMut => "vec_iter_mut",
172            Self::VecFor => "vec_for",
173            Self::VecWhile => "vec_while",
174            Self::VecFindMap => "vec_find_map",
175            Self::VecLen => "vec_len",
176            Self::VecIsEmpty => "vec_is_empty",
177            Self::VecAny => "vec_any",
178            Self::VecAll => "vec_all",
179            Self::VecMap => "vec_map",
180            Self::VecFilter => "vec_filter",
181            Self::VecFilterMap => "vec_filter_map",
182            Self::VecFind => "vec_find",
183            Self::VecFold => "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::VecSelfPush => "vec_self_push",
190            Self::VecSelfExtend => "vec_self_extend",
191
192            // Map
193            Self::MapCreate => "map_create",
194            Self::MapFromSlicePair => "map_from_slice_pair",
195            Self::MapHas => "map_has",
196            Self::MapRemove => "map_remove",
197            Self::MapSubscriptMut => "map_subscript_mut",
198            Self::MapSubscriptMutCreateIfNeeded => "map_subscript_mut_create_if_needed",
199            Self::MapSubscript => "map_subscript",
200            Self::MapSubscriptSet => "map_subscript_set",
201            Self::MapIter => "map_iter",
202            Self::MapIterMut => "map_iter_mut",
203            Self::MapLen => "map_len",
204            Self::MapIsEmpty => "map_is_empty",
205
206            // Map2
207            Self::Map2Create => "map2_create",
208            Self::Map2Insert => "map2_insert",
209            Self::Map2Remove => "map2_remove",
210            Self::Map2Has => "map2_has",
211            Self::Map2GetColumn => "map2_get_column",
212            Self::Map2GetRow => "map2_get_row",
213            Self::Map2Get => "map2_get",
214
215            // Sparse
216            Self::SparseNew => "sparse_new",
217            Self::SparseCreate => "sparse_create",
218            Self::SparseFromSlice => "sparse_from_slice",
219            Self::SparseAdd => "sparse_add",
220            Self::SparseHas => "sparse_has",
221            Self::SparseRemove => "sparse_remove",
222            Self::SparseSubscriptMut => "sparse_subscript_mut",
223            Self::SparseSubscript => "sparse_subscript",
224            Self::SparseIter => "sparse_iter",
225            Self::SparseIterMut => "sparse_iter_mut",
226
227            // Grid
228            Self::GridCreate => "grid_new",
229            Self::GridSet => "grid_set",
230            Self::GridGet => "grid_get",
231            Self::GridFromSlice => "grid_from_slice",
232            Self::GridGetColumn => "grid_get_column",
233
234            // Other
235            Self::Float2Magnitude => "float2_magnitude",
236            Self::RuntimePanic => "runtime_panic",
237        };
238
239        write!(f, "{name}")
240    }
241}