swamp_core/
lib.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 */
5
6use source_map_node::Node;
7use swamp_modules::modules::Module;
8use swamp_modules::symtbl::{SymbolTable, TypeGenerator, TypeGeneratorKind};
9use swamp_semantic::prelude::{IntrinsicFunction, IntrinsicFunctionDefinition};
10use swamp_types::{AliasType, Signature, Type, TypeForParameter};
11use tiny_ver::TinyVersion;
12
13pub const PACKAGE_NAME: &str = "core";
14fn add_intrinsic_types(core_ns: &mut SymbolTable) {
15    let int_alias = AliasType {
16        name: Node::default(),
17        assigned_name: "Int".to_string(),
18        referenced_type: Type::Int,
19    };
20    core_ns.add_alias(int_alias).unwrap();
21
22    let float_alias = AliasType {
23        name: Node::default(),
24        assigned_name: "Float".to_string(),
25        referenced_type: Type::Float,
26    };
27    core_ns.add_alias(float_alias).unwrap();
28
29    let string_alias = AliasType {
30        name: Node::default(),
31        assigned_name: "String".to_string(),
32        referenced_type: Type::String,
33    };
34    core_ns.add_alias(string_alias).unwrap();
35
36    let bool_alias = AliasType {
37        name: Node::default(),
38        assigned_name: "Bool".to_string(),
39        referenced_type: Type::Bool,
40    };
41    core_ns.add_alias(bool_alias).unwrap();
42}
43
44#[allow(clippy::too_many_lines)]
45fn add_intrinsic_functions(core_ns: &mut SymbolTable) {
46    add_intrinsic_float_functions(core_ns);
47    add_intrinsic_int_functions(core_ns);
48    add_intrinsic_string_functions(core_ns);
49    add_intrinsic_grid_functions(core_ns);
50    add_intrinsic_vec_functions(core_ns);
51    add_intrinsic_map_functions(core_ns);
52    add_intrinsic_map2_functions(core_ns);
53    add_intrinsic_sparse_functions(core_ns);
54}
55
56#[allow(clippy::too_many_lines)]
57fn add_intrinsic_sparse_functions(core_ns: &mut SymbolTable) {
58    let slice_to_self = Signature {
59        parameters: [TypeForParameter {
60            name: "slice".to_string(),
61            resolved_type: Type::Never,
62            is_mutable: false,
63            node: None,
64        }]
65        .into(),
66        return_type: Box::new(Type::Never),
67    };
68    let slice_to_self_functions = [IntrinsicFunction::SparseFromSlice];
69    for intrinsic_fn in slice_to_self_functions {
70        let name = intrinsic_fn.to_string();
71        core_ns
72            .add_intrinsic_function(IntrinsicFunctionDefinition {
73                name,
74                intrinsic: intrinsic_fn,
75                signature: slice_to_self.clone(),
76            })
77            .unwrap();
78    }
79
80    let unit_to_value = Signature {
81        parameters: [].into(),
82        return_type: Box::new(Type::Never),
83    };
84
85    let unit_to_value_functions = [IntrinsicFunction::SparseCreate];
86
87    for intrinsic_fn in unit_to_value_functions {
88        let name = intrinsic_fn.to_string();
89        core_ns
90            .add_intrinsic_function(IntrinsicFunctionDefinition {
91                name,
92                intrinsic: intrinsic_fn,
93                signature: unit_to_value.clone(),
94            })
95            .unwrap();
96    }
97
98    let self_to_value = Signature {
99        parameters: [TypeForParameter {
100            name: "self".to_string(),
101            resolved_type: Type::Never,
102            is_mutable: false,
103            node: None,
104        }]
105        .into(),
106        return_type: Box::new(Type::Never),
107    };
108
109    let self_to_value_functions = [
110        IntrinsicFunction::SparseIter,
111        IntrinsicFunction::SparseIterMut,
112    ];
113
114    for intrinsic_fn in self_to_value_functions {
115        let name = intrinsic_fn.to_string();
116        core_ns
117            .add_intrinsic_function(IntrinsicFunctionDefinition {
118                name,
119                intrinsic: intrinsic_fn,
120                signature: self_to_value.clone(),
121            })
122            .unwrap();
123    }
124
125    let self_value_to_value = Signature {
126        parameters: [
127            TypeForParameter {
128                name: "self".to_string(),
129                resolved_type: Type::Never,
130                is_mutable: false,
131                node: None,
132            },
133            TypeForParameter {
134                name: "i".to_string(),
135                resolved_type: Type::Never,
136                is_mutable: false,
137                node: None,
138            },
139        ]
140        .into(),
141        return_type: Box::new(Type::Never),
142    };
143
144    let self_value_to_value_functions = [
145        IntrinsicFunction::SparseSubscript,
146        IntrinsicFunction::SparseAdd,
147    ];
148
149    for intrinsic_fn in self_value_to_value_functions {
150        let name = intrinsic_fn.to_string();
151        core_ns
152            .add_intrinsic_function(IntrinsicFunctionDefinition {
153                name,
154                intrinsic: intrinsic_fn,
155                signature: self_value_to_value.clone(),
156            })
157            .unwrap();
158    }
159
160    let self_value_value_mut_to_unit = Signature {
161        parameters: [
162            TypeForParameter {
163                name: "self".to_string(),
164                resolved_type: Type::Never,
165                is_mutable: false,
166                node: None,
167            },
168            TypeForParameter {
169                name: "key".to_string(),
170                resolved_type: Type::Never,
171                is_mutable: false,
172                node: None,
173            },
174            TypeForParameter {
175                name: "value".to_string(),
176                resolved_type: Type::Never,
177                is_mutable: true,
178                node: None,
179            },
180        ]
181        .into(),
182        return_type: Box::new(Type::Never),
183    };
184
185    let self_value_value_mut_to_unit_functions = [IntrinsicFunction::SparseSubscriptMut];
186
187    for intrinsic_fn in self_value_value_mut_to_unit_functions {
188        let name = intrinsic_fn.to_string();
189        core_ns
190            .add_intrinsic_function(IntrinsicFunctionDefinition {
191                name,
192                intrinsic: intrinsic_fn,
193                signature: self_value_value_mut_to_unit.clone(),
194            })
195            .unwrap();
196    }
197
198    let self_value_to_bool = Signature {
199        parameters: [
200            TypeForParameter {
201                name: "self".to_string(),
202                resolved_type: Type::Never,
203                is_mutable: false,
204                node: None,
205            },
206            TypeForParameter {
207                name: "i".to_string(),
208                resolved_type: Type::Never,
209                is_mutable: false,
210                node: None,
211            },
212        ]
213        .into(),
214        return_type: Box::new(Type::Bool),
215    };
216
217    let self_value_to_bool_functions = [IntrinsicFunction::SparseHas];
218
219    for intrinsic_fn in self_value_to_bool_functions {
220        let name = intrinsic_fn.to_string();
221        core_ns
222            .add_intrinsic_function(IntrinsicFunctionDefinition {
223                name,
224                intrinsic: intrinsic_fn,
225                signature: self_value_to_bool.clone(),
226            })
227            .unwrap();
228    }
229
230    let self_value_to_option_value = Signature {
231        parameters: [
232            TypeForParameter {
233                name: "self".to_string(),
234                resolved_type: Type::Never,
235                is_mutable: false,
236                node: None,
237            },
238            TypeForParameter {
239                name: "key".to_string(),
240                resolved_type: Type::Never,
241                is_mutable: false,
242                node: None,
243            },
244        ]
245        .into(),
246        return_type: Box::new(Type::Optional(Box::new(Type::Never))),
247    };
248
249    let self_value_to_option_value_functions = [IntrinsicFunction::SparseRemove];
250
251    for intrinsic_fn in self_value_to_option_value_functions {
252        let name = intrinsic_fn.to_string();
253        core_ns
254            .add_intrinsic_function(IntrinsicFunctionDefinition {
255                name,
256                intrinsic: intrinsic_fn,
257                signature: self_value_to_option_value.clone(),
258            })
259            .unwrap();
260    }
261}
262
263#[allow(clippy::too_many_lines)]
264fn add_intrinsic_map2_functions(core_ns: &mut SymbolTable) {
265    let self_value_value_to_bool = Signature {
266        parameters: [
267            TypeForParameter {
268                name: "self".to_string(),
269                resolved_type: Type::Never,
270                is_mutable: false,
271                node: None,
272            },
273            TypeForParameter {
274                name: "x".to_string(),
275                resolved_type: Type::Never,
276                is_mutable: false,
277                node: None,
278            },
279            TypeForParameter {
280                name: "y".to_string(),
281                resolved_type: Type::Never,
282                is_mutable: false,
283                node: None,
284            },
285        ]
286        .into(),
287        return_type: Box::new(Type::Bool),
288    };
289    let self_value_to_bool_functions = [IntrinsicFunction::Map2Has];
290    for intrinsic_fn in self_value_to_bool_functions {
291        let name = intrinsic_fn.to_string();
292        core_ns
293            .add_intrinsic_function(IntrinsicFunctionDefinition {
294                name,
295                intrinsic: intrinsic_fn,
296                signature: self_value_value_to_bool.clone(),
297            })
298            .unwrap();
299    }
300
301    let self_value_to_vec = Signature {
302        parameters: [
303            TypeForParameter {
304                name: "self".to_string(),
305                resolved_type: Type::Never,
306                is_mutable: false,
307                node: None,
308            },
309            TypeForParameter {
310                name: "x".to_string(),
311                resolved_type: Type::Never,
312                is_mutable: false,
313                node: None,
314            },
315        ]
316        .into(),
317        return_type: Box::new(Type::Never),
318    };
319    let self_value_to_vec_functions = [IntrinsicFunction::Map2GetColumn];
320    for intrinsic_fn in self_value_to_vec_functions {
321        let name = intrinsic_fn.to_string();
322        core_ns
323            .add_intrinsic_function(IntrinsicFunctionDefinition {
324                name,
325                intrinsic: intrinsic_fn,
326                signature: self_value_to_vec.clone(),
327            })
328            .unwrap();
329    }
330
331    let self_value_value_to_value = Signature {
332        parameters: [
333            TypeForParameter {
334                name: "self".to_string(),
335                resolved_type: Type::Never,
336                is_mutable: false,
337                node: None,
338            },
339            TypeForParameter {
340                name: "x".to_string(),
341                resolved_type: Type::Never,
342                is_mutable: false,
343                node: None,
344            },
345            TypeForParameter {
346                name: "y".to_string(),
347                resolved_type: Type::Never,
348                is_mutable: false,
349                node: None,
350            },
351        ]
352        .into(),
353        return_type: Box::new(Type::Never),
354    };
355    let self_value_value_to_value_functions = [IntrinsicFunction::Map2Get];
356    for intrinsic_fn in self_value_value_to_value_functions {
357        let name = intrinsic_fn.to_string();
358        core_ns
359            .add_intrinsic_function(IntrinsicFunctionDefinition {
360                name,
361                intrinsic: intrinsic_fn,
362                signature: self_value_value_to_value.clone(),
363            })
364            .unwrap();
365    }
366
367    let self_value_y_to_vec = Signature {
368        parameters: [
369            TypeForParameter {
370                name: "self".to_string(),
371                resolved_type: Type::Never,
372                is_mutable: false,
373                node: None,
374            },
375            TypeForParameter {
376                name: "y".to_string(),
377                resolved_type: Type::Never,
378                is_mutable: false,
379                node: None,
380            },
381        ]
382        .into(),
383        return_type: Box::new(Type::Never),
384    };
385    let self_value_y_to_vec_functions = [IntrinsicFunction::Map2GetRow];
386    for intrinsic_fn in self_value_y_to_vec_functions {
387        let name = intrinsic_fn.to_string();
388        core_ns
389            .add_intrinsic_function(IntrinsicFunctionDefinition {
390                name,
391                intrinsic: intrinsic_fn,
392                signature: self_value_y_to_vec.clone(),
393            })
394            .unwrap();
395    }
396
397    let self_value_value_to_unit = Signature {
398        parameters: [
399            TypeForParameter {
400                name: "self".to_string(),
401                resolved_type: Type::Never,
402                is_mutable: true,
403                node: None,
404            },
405            TypeForParameter {
406                name: "x".to_string(),
407                resolved_type: Type::Never,
408                is_mutable: false,
409                node: None,
410            },
411            TypeForParameter {
412                name: "y".to_string(),
413                resolved_type: Type::Never,
414                is_mutable: false,
415                node: None,
416            },
417        ]
418        .into(),
419        return_type: Box::new(Type::Unit),
420    };
421    let self_value_value_to_unit_functions = [IntrinsicFunction::Map2Remove];
422    for intrinsic_fn in self_value_value_to_unit_functions {
423        let name = intrinsic_fn.to_string();
424        core_ns
425            .add_intrinsic_function(IntrinsicFunctionDefinition {
426                name,
427                intrinsic: intrinsic_fn,
428                signature: self_value_value_to_unit.clone(),
429            })
430            .unwrap();
431    }
432
433    let self_value_value_value_to_unit = Signature {
434        parameters: [
435            TypeForParameter {
436                name: "self".to_string(),
437                resolved_type: Type::Never,
438                is_mutable: true,
439                node: None,
440            },
441            TypeForParameter {
442                name: "x".to_string(),
443                resolved_type: Type::Never,
444                is_mutable: false,
445                node: None,
446            },
447            TypeForParameter {
448                name: "y".to_string(),
449                resolved_type: Type::Never,
450                is_mutable: false,
451                node: None,
452            },
453            TypeForParameter {
454                name: "v".to_string(),
455                resolved_type: Type::Never,
456                is_mutable: false,
457                node: None,
458            },
459        ]
460        .into(),
461        return_type: Box::new(Type::Unit),
462    };
463    let self_value_value_value_to_unit_functions = [IntrinsicFunction::Map2Insert];
464    for intrinsic_fn in self_value_value_value_to_unit_functions {
465        let name = intrinsic_fn.to_string();
466        core_ns
467            .add_intrinsic_function(IntrinsicFunctionDefinition {
468                name,
469                intrinsic: intrinsic_fn,
470                signature: self_value_value_value_to_unit.clone(),
471            })
472            .unwrap();
473    }
474
475    let to_self = Signature {
476        parameters: [].into(),
477        return_type: Box::new(Type::Never),
478    };
479    let to_self_functions = [IntrinsicFunction::Map2Create];
480    for intrinsic_fn in to_self_functions {
481        let name = intrinsic_fn.to_string();
482        core_ns
483            .add_intrinsic_function(IntrinsicFunctionDefinition {
484                name,
485                intrinsic: intrinsic_fn,
486                signature: to_self.clone(),
487            })
488            .unwrap();
489    }
490}
491
492#[allow(clippy::too_many_lines)]
493fn add_intrinsic_map_functions(core_ns: &mut SymbolTable) {
494    let slice_to_self = Signature {
495        parameters: [TypeForParameter {
496            name: "slice_pair".to_string(),
497            resolved_type: Type::Never,
498            is_mutable: false,
499            node: None,
500        }]
501        .into(),
502        return_type: Box::new(Type::Never),
503    };
504    let slice_to_self_functions = [IntrinsicFunction::MapFromSlicePair];
505    for intrinsic_fn in slice_to_self_functions {
506        let name = intrinsic_fn.to_string();
507        core_ns
508            .add_intrinsic_function(IntrinsicFunctionDefinition {
509                name,
510                intrinsic: intrinsic_fn,
511                signature: slice_to_self.clone(),
512            })
513            .unwrap();
514    }
515
516    let unit_to_value = Signature {
517        parameters: [].into(),
518        return_type: Box::new(Type::Never),
519    };
520
521    let unit_to_value_functions = [IntrinsicFunction::MapCreate];
522
523    for intrinsic_fn in unit_to_value_functions {
524        let name = intrinsic_fn.to_string();
525        core_ns
526            .add_intrinsic_function(IntrinsicFunctionDefinition {
527                name,
528                intrinsic: intrinsic_fn,
529                signature: unit_to_value.clone(),
530            })
531            .unwrap();
532    }
533
534    let self_to_value = Signature {
535        parameters: [TypeForParameter {
536            name: "self".to_string(),
537            resolved_type: Type::Never,
538            is_mutable: false,
539            node: None,
540        }]
541        .into(),
542        return_type: Box::new(Type::Never),
543    };
544
545    let self_to_value_functions = [IntrinsicFunction::MapIter, IntrinsicFunction::MapIterMut];
546
547    for intrinsic_fn in self_to_value_functions {
548        let name = intrinsic_fn.to_string();
549        core_ns
550            .add_intrinsic_function(IntrinsicFunctionDefinition {
551                name,
552                intrinsic: intrinsic_fn,
553                signature: self_to_value.clone(),
554            })
555            .unwrap();
556    }
557
558    let self_value_to_value = Signature {
559        parameters: [
560            TypeForParameter {
561                name: "self".to_string(),
562                resolved_type: Type::Never,
563                is_mutable: false,
564                node: None,
565            },
566            TypeForParameter {
567                name: "i".to_string(),
568                resolved_type: Type::Never,
569                is_mutable: false,
570                node: None,
571            },
572        ]
573        .into(),
574        return_type: Box::new(Type::Never),
575    };
576
577    let self_value_to_value_functions = [IntrinsicFunction::MapSubscript];
578
579    for intrinsic_fn in self_value_to_value_functions {
580        let name = intrinsic_fn.to_string();
581        core_ns
582            .add_intrinsic_function(IntrinsicFunctionDefinition {
583                name,
584                intrinsic: intrinsic_fn,
585                signature: self_value_to_value.clone(),
586            })
587            .unwrap();
588    }
589
590    let self_value_value_mut_to_unit = Signature {
591        parameters: [
592            TypeForParameter {
593                name: "self".to_string(),
594                resolved_type: Type::Never,
595                is_mutable: true,
596                node: None,
597            },
598            TypeForParameter {
599                name: "key".to_string(),
600                resolved_type: Type::Never,
601                is_mutable: false,
602                node: None,
603            },
604        ]
605        .into(),
606        return_type: Box::new(Type::Never),
607    };
608
609    let self_value_value_mut_to_unit_functions = [
610        IntrinsicFunction::MapSubscriptMut,
611        IntrinsicFunction::MapSubscriptMutCreateIfNeeded,
612    ];
613
614    for intrinsic_fn in self_value_value_mut_to_unit_functions {
615        let name = intrinsic_fn.to_string();
616        core_ns
617            .add_intrinsic_function(IntrinsicFunctionDefinition {
618                name,
619                intrinsic: intrinsic_fn,
620                signature: self_value_value_mut_to_unit.clone(),
621            })
622            .unwrap();
623    }
624
625    let self_value_to_bool = Signature {
626        parameters: [
627            TypeForParameter {
628                name: "self".to_string(),
629                resolved_type: Type::Never,
630                is_mutable: false,
631                node: None,
632            },
633            TypeForParameter {
634                name: "i".to_string(),
635                resolved_type: Type::Never,
636                is_mutable: false,
637                node: None,
638            },
639        ]
640        .into(),
641        return_type: Box::new(Type::Bool),
642    };
643
644    let self_value_to_bool_functions = [IntrinsicFunction::MapHas];
645
646    for intrinsic_fn in self_value_to_bool_functions {
647        let name = intrinsic_fn.to_string();
648        core_ns
649            .add_intrinsic_function(IntrinsicFunctionDefinition {
650                name,
651                intrinsic: intrinsic_fn,
652                signature: self_value_to_bool.clone(),
653            })
654            .unwrap();
655    }
656
657    let self_value_to_unit_value = Signature {
658        parameters: [
659            TypeForParameter {
660                name: "self".to_string(),
661                resolved_type: Type::Never,
662                is_mutable: true,
663                node: None,
664            },
665            TypeForParameter {
666                name: "key".to_string(),
667                resolved_type: Type::Never,
668                is_mutable: false,
669                node: None,
670            },
671        ]
672        .into(),
673        return_type: Box::new(Type::Unit),
674    };
675
676    let self_value_to_option_value_functions = [IntrinsicFunction::MapRemove];
677
678    for intrinsic_fn in self_value_to_option_value_functions {
679        let name = intrinsic_fn.to_string();
680        core_ns
681            .add_intrinsic_function(IntrinsicFunctionDefinition {
682                name,
683                intrinsic: intrinsic_fn,
684                signature: self_value_to_unit_value.clone(),
685            })
686            .unwrap();
687    }
688
689    let self_to_int = Signature {
690        parameters: [TypeForParameter {
691            name: "self".to_string(),
692            resolved_type: Type::Never,
693            is_mutable: false,
694            node: None,
695        }]
696        .into(),
697        return_type: Box::new(Type::Int),
698    };
699
700    let self_to_int_functions = [IntrinsicFunction::MapLen];
701
702    for intrinsic_fn in self_to_int_functions {
703        let name = intrinsic_fn.to_string();
704        core_ns
705            .add_intrinsic_function(IntrinsicFunctionDefinition {
706                name,
707                intrinsic: intrinsic_fn,
708                signature: self_to_int.clone(),
709            })
710            .unwrap();
711    }
712
713    let self_to_bool = Signature {
714        parameters: [TypeForParameter {
715            name: "self".to_string(),
716            resolved_type: Type::Never,
717            is_mutable: false,
718            node: None,
719        }]
720        .into(),
721        return_type: Box::new(Type::Bool),
722    };
723
724    let self_to_bool_functions = [IntrinsicFunction::MapIsEmpty];
725
726    for intrinsic_fn in self_to_bool_functions {
727        let name = intrinsic_fn.to_string();
728        core_ns
729            .add_intrinsic_function(IntrinsicFunctionDefinition {
730                name,
731                intrinsic: intrinsic_fn,
732                signature: self_to_bool.clone(),
733            })
734            .unwrap();
735    }
736}
737
738#[allow(clippy::too_many_lines)]
739fn add_intrinsic_grid_functions(core_ns: &mut SymbolTable) {
740    let int_int_value_to_self = Signature {
741        parameters: [
742            TypeForParameter {
743                name: "x".to_string(),
744                resolved_type: Type::Int,
745                is_mutable: false,
746                node: None,
747            },
748            TypeForParameter {
749                name: "y".to_string(),
750                resolved_type: Type::Int,
751                is_mutable: false,
752                node: None,
753            },
754            TypeForParameter {
755                name: "initial_value".to_string(),
756                resolved_type: Type::Never,
757                is_mutable: false,
758                node: None,
759            },
760        ]
761        .into(),
762        return_type: Box::new(Type::Never),
763    };
764    let int_int_value_to_self_functions = [IntrinsicFunction::GridCreate];
765    for intrinsic_fn in int_int_value_to_self_functions {
766        let name = intrinsic_fn.to_string();
767        core_ns
768            .add_intrinsic_function(IntrinsicFunctionDefinition {
769                name,
770                intrinsic: intrinsic_fn,
771                signature: int_int_value_to_self.clone(),
772            })
773            .unwrap();
774    }
775
776    let self_value_int_int_value_to_unit = Signature {
777        parameters: [
778            TypeForParameter {
779                name: "self".to_string(),
780                resolved_type: Type::Never,
781                is_mutable: true,
782                node: None,
783            },
784            TypeForParameter {
785                name: "x".to_string(),
786                resolved_type: Type::Int,
787                is_mutable: false,
788                node: None,
789            },
790            TypeForParameter {
791                name: "y".to_string(),
792                resolved_type: Type::Int,
793                is_mutable: false,
794                node: None,
795            },
796            TypeForParameter {
797                name: "v".to_string(),
798                resolved_type: Type::Never,
799                is_mutable: false,
800                node: None,
801            },
802        ]
803        .into(),
804        return_type: Box::new(Type::Unit),
805    };
806    let self_value_int_int_value_to_unit_functions = [IntrinsicFunction::GridSet];
807    for intrinsic_fn in self_value_int_int_value_to_unit_functions {
808        let name = intrinsic_fn.to_string();
809        core_ns
810            .add_intrinsic_function(IntrinsicFunctionDefinition {
811                name,
812                intrinsic: intrinsic_fn,
813                signature: self_value_int_int_value_to_unit.clone(),
814            })
815            .unwrap();
816    }
817
818    let self_int_int_to_value = Signature {
819        parameters: [
820            TypeForParameter {
821                name: "self".to_string(),
822                resolved_type: Type::Never,
823                is_mutable: false,
824                node: None,
825            },
826            TypeForParameter {
827                name: "x".to_string(),
828                resolved_type: Type::Int,
829                is_mutable: false,
830                node: None,
831            },
832            TypeForParameter {
833                name: "y".to_string(),
834                resolved_type: Type::Int,
835                is_mutable: false,
836                node: None,
837            },
838        ]
839        .into(),
840        return_type: Box::new(Type::Never),
841    };
842    let self_int_int_to_value_functions = [IntrinsicFunction::GridGet];
843    for intrinsic_fn in self_int_int_to_value_functions {
844        let name = intrinsic_fn.to_string();
845        core_ns
846            .add_intrinsic_function(IntrinsicFunctionDefinition {
847                name,
848                intrinsic: intrinsic_fn,
849                signature: self_int_int_to_value.clone(),
850            })
851            .unwrap();
852    }
853
854    let self_int_to_array_value = Signature {
855        parameters: [
856            TypeForParameter {
857                name: "self".to_string(),
858                resolved_type: Type::Never,
859                is_mutable: false,
860                node: None,
861            },
862            TypeForParameter {
863                name: "x".to_string(),
864                resolved_type: Type::Int,
865                is_mutable: false,
866                node: None,
867            },
868        ]
869        .into(),
870        return_type: Box::new(Type::Never),
871    };
872    let self_int_to_array_value_functions = [IntrinsicFunction::GridGetColumn];
873    for intrinsic_fn in self_int_to_array_value_functions {
874        let name = intrinsic_fn.to_string();
875        core_ns
876            .add_intrinsic_function(IntrinsicFunctionDefinition {
877                name,
878                intrinsic: intrinsic_fn,
879                signature: self_int_to_array_value.clone(),
880            })
881            .unwrap();
882    }
883}
884
885#[allow(clippy::too_many_lines)]
886fn add_intrinsic_vec_functions(core_ns: &mut SymbolTable) {
887    let unit_to_value = Signature {
888        parameters: [].into(),
889        return_type: Box::new(Type::Never),
890    };
891
892    let unit_to_value_functions = [IntrinsicFunction::VecCreate];
893
894    for intrinsic_fn in unit_to_value_functions {
895        let name = intrinsic_fn.to_string();
896        core_ns
897            .add_intrinsic_function(IntrinsicFunctionDefinition {
898                name,
899                intrinsic: intrinsic_fn,
900                signature: unit_to_value.clone(),
901            })
902            .unwrap();
903    }
904
905    let self_value_to_unit = Signature {
906        parameters: [
907            TypeForParameter {
908                name: "self".to_string(),
909                resolved_type: Type::Never,
910                is_mutable: true,
911                node: None,
912            },
913            TypeForParameter {
914                name: "v".to_string(),
915                resolved_type: Type::Never,
916                is_mutable: false,
917                node: None,
918            },
919        ]
920        .into(),
921        return_type: Box::new(Type::Unit),
922    };
923
924    let self_value_to_unit_functions = [IntrinsicFunction::VecPush];
925
926    for intrinsic_fn in self_value_to_unit_functions {
927        let name = intrinsic_fn.to_string();
928        core_ns
929            .add_intrinsic_function(IntrinsicFunctionDefinition {
930                name,
931                intrinsic: intrinsic_fn,
932                signature: self_value_to_unit.clone(),
933            })
934            .unwrap();
935    }
936
937    let self_value_to_value = Signature {
938        parameters: [TypeForParameter {
939            name: "self".to_string(),
940            resolved_type: Type::Never,
941            is_mutable: true,
942            node: None,
943        }]
944        .into(),
945        return_type: Box::new(Type::Never),
946    };
947    let self_value_to_option_functions = [IntrinsicFunction::VecPop];
948    for intrinsic_fn in self_value_to_option_functions {
949        let name = intrinsic_fn.to_string();
950        core_ns
951            .add_intrinsic_function(IntrinsicFunctionDefinition {
952                name,
953                intrinsic: intrinsic_fn,
954                signature: self_value_to_value.clone(),
955            })
956            .unwrap();
957    }
958
959    let self_int_to_value = Signature {
960        parameters: [
961            TypeForParameter {
962                name: "self".to_string(),
963                resolved_type: Type::Never,
964                is_mutable: false,
965                node: None,
966            },
967            TypeForParameter {
968                name: "i".to_string(),
969                resolved_type: Type::Int,
970                is_mutable: false,
971                node: None,
972            },
973        ]
974        .into(),
975        return_type: Box::new(Type::Never),
976    };
977    let self_int_to_value_functions = [IntrinsicFunction::VecSubscript];
978    for intrinsic_fn in self_int_to_value_functions {
979        let name = intrinsic_fn.to_string();
980        core_ns
981            .add_intrinsic_function(IntrinsicFunctionDefinition {
982                name,
983                intrinsic: intrinsic_fn,
984                signature: self_int_to_value.clone(),
985            })
986            .unwrap();
987    }
988
989    let self_range_to_self = Signature {
990        parameters: [
991            TypeForParameter {
992                name: "self".to_string(),
993                resolved_type: Type::Never,
994                is_mutable: false,
995                node: None,
996            },
997            TypeForParameter {
998                name: "range".to_string(),
999                resolved_type: Type::Never,
1000                is_mutable: false,
1001                node: None,
1002            },
1003        ]
1004        .into(),
1005        return_type: Box::new(Type::Never),
1006    };
1007    let self_range_to_self_functions = [IntrinsicFunction::VecSubscriptRange];
1008    for intrinsic_fn in self_range_to_self_functions {
1009        let name = intrinsic_fn.to_string();
1010        core_ns
1011            .add_intrinsic_function(IntrinsicFunctionDefinition {
1012                name,
1013                intrinsic: intrinsic_fn,
1014                signature: self_range_to_self.clone(),
1015            })
1016            .unwrap();
1017    }
1018
1019    let self_int_value_mut_to_unit = Signature {
1020        parameters: [
1021            TypeForParameter {
1022                name: "self".to_string(),
1023                resolved_type: Type::Never,
1024                is_mutable: true,
1025                node: None,
1026            },
1027            TypeForParameter {
1028                name: "i".to_string(),
1029                resolved_type: Type::Int,
1030                is_mutable: false,
1031                node: None,
1032            },
1033        ]
1034        .into(),
1035        return_type: Box::new(Type::Never),
1036    };
1037
1038    let self_int_value_mut_to_unit_functions = [IntrinsicFunction::VecSubscriptMut];
1039
1040    for intrinsic_fn in self_int_value_mut_to_unit_functions {
1041        let name = intrinsic_fn.to_string();
1042        core_ns
1043            .add_intrinsic_function(IntrinsicFunctionDefinition {
1044                name,
1045                intrinsic: intrinsic_fn,
1046                signature: self_int_value_mut_to_unit.clone(),
1047            })
1048            .unwrap();
1049    }
1050
1051    let mut_self_int_to_value = Signature {
1052        parameters: [
1053            TypeForParameter {
1054                name: "self".to_string(),
1055                resolved_type: Type::Never,
1056                is_mutable: true,
1057                node: None,
1058            },
1059            TypeForParameter {
1060                name: "i".to_string(),
1061                resolved_type: Type::Int,
1062                is_mutable: false,
1063                node: None,
1064            },
1065        ]
1066        .into(),
1067        return_type: Box::new(Type::Never),
1068    };
1069    let mut_self_int_to_value_functions = [IntrinsicFunction::VecRemoveIndexGetValue];
1070    for intrinsic_fn in mut_self_int_to_value_functions {
1071        let name = intrinsic_fn.to_string();
1072        core_ns
1073            .add_intrinsic_function(IntrinsicFunctionDefinition {
1074                name,
1075                intrinsic: intrinsic_fn,
1076                signature: mut_self_int_to_value.clone(),
1077            })
1078            .unwrap();
1079    }
1080
1081    let self_int_to_unit_value = Signature {
1082        parameters: [
1083            TypeForParameter {
1084                name: "self".to_string(),
1085                resolved_type: Type::Never,
1086                is_mutable: true,
1087                node: None,
1088            },
1089            TypeForParameter {
1090                name: "i".to_string(),
1091                resolved_type: Type::Int,
1092                is_mutable: false,
1093                node: None,
1094            },
1095        ]
1096        .into(),
1097        return_type: Box::new(Type::Unit),
1098    };
1099    let self_int_to_unit_value_functions = [IntrinsicFunction::VecRemoveIndex];
1100    for intrinsic_fn in self_int_to_unit_value_functions {
1101        let name = intrinsic_fn.to_string();
1102        core_ns
1103            .add_intrinsic_function(IntrinsicFunctionDefinition {
1104                name,
1105                intrinsic: intrinsic_fn,
1106                signature: self_int_to_unit_value.clone(),
1107            })
1108            .unwrap();
1109    }
1110
1111    let self_int_to_optional_value = Signature {
1112        parameters: [
1113            TypeForParameter {
1114                name: "self".to_string(),
1115                resolved_type: Type::Never,
1116                is_mutable: false,
1117                node: None,
1118            },
1119            TypeForParameter {
1120                name: "i".to_string(),
1121                resolved_type: Type::Int,
1122                is_mutable: false,
1123                node: None,
1124            },
1125        ]
1126        .into(),
1127        return_type: Box::new(Type::Optional(Box::new(Type::Never))),
1128    };
1129    let self_int_to_optional_value_functions = [IntrinsicFunction::VecGet];
1130    for intrinsic_fn in self_int_to_optional_value_functions {
1131        let name = intrinsic_fn.to_string();
1132        core_ns
1133            .add_intrinsic_function(IntrinsicFunctionDefinition {
1134                name,
1135                intrinsic: intrinsic_fn,
1136                signature: self_int_to_unit_value.clone(),
1137            })
1138            .unwrap();
1139    }
1140
1141    let mut_self_to_unit = Signature {
1142        parameters: [TypeForParameter {
1143            name: "self".to_string(),
1144            resolved_type: Type::Never,
1145            is_mutable: true,
1146            node: None,
1147        }]
1148        .into(),
1149        return_type: Box::new(Type::Unit),
1150    };
1151    let mut_self_to_unit_functions = [IntrinsicFunction::VecClear];
1152    for intrinsic_fn in mut_self_to_unit_functions {
1153        let name = intrinsic_fn.to_string();
1154        core_ns
1155            .add_intrinsic_function(IntrinsicFunctionDefinition {
1156                name,
1157                intrinsic: intrinsic_fn,
1158                signature: mut_self_to_unit.clone(),
1159            })
1160            .unwrap();
1161    }
1162
1163    let self_to_value = Signature {
1164        parameters: [TypeForParameter {
1165            name: "self".to_string(),
1166            resolved_type: Type::Never,
1167            is_mutable: false,
1168            node: None,
1169        }]
1170        .into(),
1171        return_type: Box::new(Type::Never),
1172    };
1173    let self_to_value_functions = [
1174        IntrinsicFunction::VecIter,
1175        IntrinsicFunction::VecIterMut,
1176        IntrinsicFunction::VecFirst,
1177        IntrinsicFunction::VecLast,
1178    ];
1179    for intrinsic_fn in self_to_value_functions {
1180        let name = intrinsic_fn.to_string();
1181        core_ns
1182            .add_intrinsic_function(IntrinsicFunctionDefinition {
1183                name,
1184                intrinsic: intrinsic_fn,
1185                signature: self_to_value.clone(),
1186            })
1187            .unwrap();
1188    }
1189
1190    let self_block_to_unit = Signature {
1191        parameters: [
1192            TypeForParameter {
1193                name: "self".to_string(),
1194                resolved_type: Type::Never,
1195                is_mutable: false,
1196                node: None,
1197            },
1198            TypeForParameter {
1199                name: "block".to_string(),
1200                resolved_type: Type::Never,
1201                is_mutable: false,
1202                node: None,
1203            },
1204        ]
1205        .into(),
1206        return_type: Box::new(Type::Unit),
1207    };
1208    let self_block_to_unit_functions = [IntrinsicFunction::VecFor, IntrinsicFunction::VecWhile];
1209    for intrinsic_fn in self_block_to_unit_functions {
1210        let name = intrinsic_fn.to_string();
1211        core_ns
1212            .add_intrinsic_function(IntrinsicFunctionDefinition {
1213                name,
1214                intrinsic: intrinsic_fn,
1215                signature: self_block_to_unit.clone(),
1216            })
1217            .unwrap();
1218    }
1219
1220    let self_block_to_generic = Signature {
1221        parameters: [
1222            TypeForParameter {
1223                name: "self".to_string(),
1224                resolved_type: Type::Never,
1225                is_mutable: false,
1226                node: None,
1227            },
1228            TypeForParameter {
1229                name: "block".to_string(),
1230                resolved_type: Type::Never,
1231                is_mutable: false,
1232                node: None,
1233            },
1234        ]
1235        .into(),
1236        return_type: Box::new(Type::Never),
1237    };
1238    let self_block_to_generic_functions = [
1239        IntrinsicFunction::VecMap,
1240        IntrinsicFunction::VecFindMap,
1241        IntrinsicFunction::VecFilter,
1242        IntrinsicFunction::VecFilterMap,
1243        IntrinsicFunction::VecFind,
1244    ];
1245    for intrinsic_fn in self_block_to_generic_functions {
1246        let name = intrinsic_fn.to_string();
1247        core_ns
1248            .add_intrinsic_function(IntrinsicFunctionDefinition {
1249                name,
1250                intrinsic: intrinsic_fn,
1251                signature: self_block_to_generic.clone(),
1252            })
1253            .unwrap();
1254    }
1255
1256    let self_element_block_to_generic = Signature {
1257        parameters: [
1258            TypeForParameter {
1259                name: "self".to_string(),
1260                resolved_type: Type::Never,
1261                is_mutable: false,
1262                node: None,
1263            },
1264            TypeForParameter {
1265                name: "element".to_string(),
1266                resolved_type: Type::Never,
1267                is_mutable: false,
1268                node: None,
1269            },
1270            TypeForParameter {
1271                name: "block".to_string(),
1272                resolved_type: Type::Never,
1273                is_mutable: false,
1274                node: None,
1275            },
1276        ]
1277        .into(),
1278        return_type: Box::new(Type::Never),
1279    };
1280    let self_element_block_to_generic_functions = [IntrinsicFunction::VecFold];
1281    for intrinsic_fn in self_element_block_to_generic_functions {
1282        let name = intrinsic_fn.to_string();
1283        core_ns
1284            .add_intrinsic_function(IntrinsicFunctionDefinition {
1285                name,
1286                intrinsic: intrinsic_fn,
1287                signature: self_element_block_to_generic.clone(),
1288            })
1289            .unwrap();
1290    }
1291
1292    let self_block_to_bool = Signature {
1293        parameters: [
1294            TypeForParameter {
1295                name: "self".to_string(),
1296                resolved_type: Type::Never,
1297                is_mutable: false,
1298                node: None,
1299            },
1300            TypeForParameter {
1301                name: "block".to_string(),
1302                resolved_type: Type::Never,
1303                is_mutable: false,
1304                node: None,
1305            },
1306        ]
1307        .into(),
1308        return_type: Box::new(Type::Bool),
1309    };
1310    let self_block_to_bool_functions = [IntrinsicFunction::VecAny, IntrinsicFunction::VecAll];
1311    for intrinsic_fn in self_block_to_bool_functions {
1312        let name = intrinsic_fn.to_string();
1313        core_ns
1314            .add_intrinsic_function(IntrinsicFunctionDefinition {
1315                name,
1316                intrinsic: intrinsic_fn,
1317                signature: self_block_to_bool.clone(),
1318            })
1319            .unwrap();
1320    }
1321
1322    let slice_to_self = Signature {
1323        parameters: [TypeForParameter {
1324            name: "slice".to_string(),
1325            resolved_type: Type::Never, // TODO: Should have proper slice generic
1326            is_mutable: false,
1327            node: None,
1328        }]
1329        .into(),
1330        return_type: Box::new(Type::Never),
1331    };
1332    let slice_to_self_functions = [IntrinsicFunction::VecFromSlice];
1333    for intrinsic_fn in slice_to_self_functions {
1334        let name = intrinsic_fn.to_string();
1335        core_ns
1336            .add_intrinsic_function(IntrinsicFunctionDefinition {
1337                name,
1338                intrinsic: intrinsic_fn,
1339                signature: slice_to_self.clone(),
1340            })
1341            .unwrap();
1342    }
1343
1344    let self_to_int = Signature {
1345        parameters: [TypeForParameter {
1346            name: "self".to_string(),
1347            resolved_type: Type::Never,
1348            is_mutable: false,
1349            node: None,
1350        }]
1351        .into(),
1352        return_type: Box::new(Type::Int),
1353    };
1354
1355    let self_to_int_functions = [IntrinsicFunction::VecLen];
1356
1357    for intrinsic_fn in self_to_int_functions {
1358        let name = intrinsic_fn.to_string();
1359        core_ns
1360            .add_intrinsic_function(IntrinsicFunctionDefinition {
1361                name,
1362                intrinsic: intrinsic_fn,
1363                signature: self_to_int.clone(),
1364            })
1365            .unwrap();
1366    }
1367
1368    let self_to_bool = Signature {
1369        parameters: [TypeForParameter {
1370            name: "self".to_string(),
1371            resolved_type: Type::Never,
1372            is_mutable: false,
1373            node: None,
1374        }]
1375        .into(),
1376        return_type: Box::new(Type::Bool),
1377    };
1378    let self_to_bool_functions = [IntrinsicFunction::VecIsEmpty];
1379    for intrinsic_fn in self_to_bool_functions {
1380        let name = intrinsic_fn.to_string();
1381        core_ns
1382            .add_intrinsic_function(IntrinsicFunctionDefinition {
1383                name,
1384                intrinsic: intrinsic_fn,
1385                signature: self_to_bool.clone(),
1386            })
1387            .unwrap();
1388    }
1389
1390    let mut_self_int_int_to_unit = Signature {
1391        parameters: [
1392            TypeForParameter {
1393                name: "self".to_string(),
1394                resolved_type: Type::Never,
1395                is_mutable: true,
1396                node: None,
1397            },
1398            TypeForParameter {
1399                name: "a".to_string(),
1400                resolved_type: Type::Int,
1401                is_mutable: false,
1402                node: None,
1403            },
1404            TypeForParameter {
1405                name: "b".to_string(),
1406                resolved_type: Type::Int,
1407                is_mutable: false,
1408                node: None,
1409            },
1410        ]
1411        .into(),
1412        return_type: Box::new(Type::Unit),
1413    };
1414    let mut_self_int_int_to_unit_functions = [IntrinsicFunction::VecSwap];
1415    for intrinsic_fn in mut_self_int_int_to_unit_functions {
1416        let name = intrinsic_fn.to_string();
1417        core_ns
1418            .add_intrinsic_function(IntrinsicFunctionDefinition {
1419                name,
1420                intrinsic: intrinsic_fn,
1421                signature: mut_self_int_int_to_unit.clone(),
1422            })
1423            .unwrap();
1424    }
1425
1426    let mut_self_int_value_to_unit = Signature {
1427        parameters: [
1428            TypeForParameter {
1429                name: "self".to_string(),
1430                resolved_type: Type::Never,
1431                is_mutable: true,
1432                node: None,
1433            },
1434            TypeForParameter {
1435                name: "i".to_string(),
1436                resolved_type: Type::Int,
1437                is_mutable: false,
1438                node: None,
1439            },
1440            TypeForParameter {
1441                name: "v".to_string(),
1442                resolved_type: Type::Never,
1443                is_mutable: false,
1444                node: None,
1445            },
1446        ]
1447        .into(),
1448        return_type: Box::new(Type::Unit),
1449    };
1450    let mut_self_int_value_to_unit_functions = [IntrinsicFunction::VecInsert];
1451    for intrinsic_fn in mut_self_int_value_to_unit_functions {
1452        let name = intrinsic_fn.to_string();
1453        core_ns
1454            .add_intrinsic_function(IntrinsicFunctionDefinition {
1455                name,
1456                intrinsic: intrinsic_fn,
1457                signature: mut_self_int_value_to_unit.clone(),
1458            })
1459            .unwrap();
1460    }
1461}
1462
1463#[allow(clippy::too_many_lines)]
1464fn add_intrinsic_string_functions(core_ns: &mut SymbolTable) {
1465    let string_to_int = Signature {
1466        parameters: [TypeForParameter {
1467            name: "self".into(),
1468            resolved_type: Type::String,
1469            is_mutable: false,
1470            node: None,
1471        }]
1472        .into(),
1473        return_type: Box::new(Type::Int),
1474    };
1475
1476    let string_to_int_functions = [IntrinsicFunction::StringLen];
1477
1478    for intrinsic_fn in string_to_int_functions {
1479        let name = intrinsic_fn.to_string();
1480        core_ns
1481            .add_intrinsic_function(IntrinsicFunctionDefinition {
1482                name,
1483                intrinsic: intrinsic_fn,
1484                signature: string_to_int.clone(),
1485            })
1486            .unwrap();
1487    }
1488}
1489
1490#[allow(clippy::too_many_lines)]
1491fn add_intrinsic_int_functions(core_ns: &mut SymbolTable) {
1492    let int_to_int = Signature {
1493        parameters: [TypeForParameter {
1494            name: "self".into(),
1495            resolved_type: Type::Int,
1496            is_mutable: false,
1497            node: None,
1498        }]
1499        .into(),
1500        return_type: Box::new(Type::Int),
1501    };
1502
1503    let int_to_int_functions = [IntrinsicFunction::IntAbs, IntrinsicFunction::IntRnd];
1504
1505    for intrinsic_fn in int_to_int_functions {
1506        let name = intrinsic_fn.to_string();
1507        core_ns
1508            .add_intrinsic_function(IntrinsicFunctionDefinition {
1509                name,
1510                intrinsic: intrinsic_fn,
1511                signature: int_to_int.clone(),
1512            })
1513            .unwrap();
1514    }
1515
1516    let int_int_to_int = Signature {
1517        parameters: [
1518            TypeForParameter {
1519                name: "self".into(),
1520                resolved_type: Type::Int,
1521                is_mutable: false,
1522                node: None,
1523            },
1524            TypeForParameter {
1525                name: "b".into(),
1526                resolved_type: Type::Int,
1527                is_mutable: false,
1528                node: None,
1529            },
1530        ]
1531        .into(),
1532        return_type: Box::new(Type::Int),
1533    };
1534    let int_int_to_int_functions = [IntrinsicFunction::IntMax, IntrinsicFunction::IntMin];
1535
1536    for intrinsic_fn in int_int_to_int_functions {
1537        let name = intrinsic_fn.to_string();
1538        core_ns
1539            .add_intrinsic_function(IntrinsicFunctionDefinition {
1540                name,
1541                intrinsic: intrinsic_fn,
1542                signature: int_int_to_int.clone(),
1543            })
1544            .unwrap();
1545    }
1546
1547    let int_int_int_to_int = Signature {
1548        parameters: [
1549            TypeForParameter {
1550                name: "self".into(),
1551                resolved_type: Type::Int,
1552                is_mutable: false,
1553                node: None,
1554            },
1555            TypeForParameter {
1556                name: "a".into(),
1557                resolved_type: Type::Int,
1558                is_mutable: false,
1559                node: None,
1560            },
1561            TypeForParameter {
1562                name: "b".into(),
1563                resolved_type: Type::Int,
1564                is_mutable: false,
1565                node: None,
1566            },
1567        ]
1568        .into(),
1569        return_type: Box::new(Type::Int),
1570    };
1571    let int_int_int_to_int_functions = [IntrinsicFunction::IntClamp];
1572    for intrinsic_fn in int_int_int_to_int_functions {
1573        let name = intrinsic_fn.to_string();
1574        core_ns
1575            .add_intrinsic_function(IntrinsicFunctionDefinition {
1576                name,
1577                intrinsic: intrinsic_fn,
1578                signature: int_int_int_to_int.clone(),
1579            })
1580            .unwrap();
1581    }
1582
1583    let int_to_float = Signature {
1584        parameters: [TypeForParameter {
1585            name: "self".into(),
1586            resolved_type: Type::Int,
1587            is_mutable: false,
1588            node: None,
1589        }]
1590        .into(),
1591        return_type: Box::new(Type::Float),
1592    };
1593
1594    core_ns
1595        .add_intrinsic_function(IntrinsicFunctionDefinition {
1596            name: IntrinsicFunction::IntToFloat.to_string(),
1597            intrinsic: IntrinsicFunction::IntToFloat,
1598            signature: int_to_float,
1599        })
1600        .unwrap();
1601}
1602
1603#[allow(clippy::too_many_lines)]
1604fn add_intrinsic_float_functions(core_ns: &mut SymbolTable) {
1605    let float_to_float = Signature {
1606        parameters: [TypeForParameter {
1607            name: "self".into(),
1608            resolved_type: Type::Float,
1609            is_mutable: false,
1610            node: None,
1611        }]
1612        .into(),
1613        return_type: Box::new(Type::Float),
1614    };
1615
1616    let float_to_float_functions = [
1617        IntrinsicFunction::FloatSqrt,
1618        IntrinsicFunction::FloatSign,
1619        IntrinsicFunction::FloatAbs,
1620        IntrinsicFunction::FloatRnd,
1621        IntrinsicFunction::FloatCos,
1622        IntrinsicFunction::FloatSin,
1623        IntrinsicFunction::FloatAcos,
1624        IntrinsicFunction::FloatAsin,
1625    ];
1626    for intrinsic_fn in float_to_float_functions {
1627        let name = intrinsic_fn.to_string();
1628        core_ns
1629            .add_intrinsic_function(IntrinsicFunctionDefinition {
1630                name,
1631                intrinsic: intrinsic_fn,
1632                signature: float_to_float.clone(),
1633            })
1634            .unwrap();
1635    }
1636
1637    let float_to_int = Signature {
1638        parameters: [TypeForParameter {
1639            name: "self".into(),
1640            resolved_type: Type::Float,
1641            is_mutable: false,
1642            node: None,
1643        }]
1644        .into(),
1645        return_type: Box::new(Type::Int),
1646    };
1647
1648    let float_to_int_functions = [IntrinsicFunction::FloatRound, IntrinsicFunction::FloatFloor];
1649    for intrinsic_fn in float_to_int_functions {
1650        let name = intrinsic_fn.to_string();
1651        core_ns
1652            .add_intrinsic_function(IntrinsicFunctionDefinition {
1653                name,
1654                intrinsic: intrinsic_fn,
1655                signature: float_to_int.clone(),
1656            })
1657            .unwrap();
1658    }
1659
1660    let float_float_to_float = Signature {
1661        parameters: [
1662            TypeForParameter {
1663                name: "self".into(),
1664                resolved_type: Type::Float,
1665                is_mutable: false,
1666                node: None,
1667            },
1668            TypeForParameter {
1669                name: "other".into(),
1670                resolved_type: Type::Float,
1671                is_mutable: false,
1672                node: None,
1673            },
1674        ]
1675        .into(),
1676        return_type: Box::new(Type::Float),
1677    };
1678
1679    let float_float_to_float_functions = [
1680        IntrinsicFunction::FloatAtan2,
1681        IntrinsicFunction::FloatMin,
1682        IntrinsicFunction::FloatMax,
1683        IntrinsicFunction::Float2Magnitude,
1684    ];
1685    for intrinsic_fn in float_float_to_float_functions {
1686        let name = intrinsic_fn.to_string();
1687        core_ns
1688            .add_intrinsic_function(IntrinsicFunctionDefinition {
1689                name,
1690                intrinsic: intrinsic_fn,
1691                signature: float_float_to_float.clone(),
1692            })
1693            .unwrap();
1694    }
1695
1696    let float_float_float_to_float = Signature {
1697        parameters: [
1698            TypeForParameter {
1699                name: "self".into(),
1700                resolved_type: Type::Float,
1701                is_mutable: false,
1702                node: None,
1703            },
1704            TypeForParameter {
1705                name: "a".into(),
1706                resolved_type: Type::Float,
1707                is_mutable: false,
1708                node: None,
1709            },
1710            TypeForParameter {
1711                name: "b".into(),
1712                resolved_type: Type::Float,
1713                is_mutable: false,
1714                node: None,
1715            },
1716        ]
1717        .into(),
1718        return_type: Box::new(Type::Float),
1719    };
1720
1721    core_ns
1722        .add_intrinsic_function(IntrinsicFunctionDefinition {
1723            name: IntrinsicFunction::FloatClamp.to_string(),
1724            intrinsic: IntrinsicFunction::FloatClamp,
1725            signature: float_float_float_to_float,
1726        })
1727        .unwrap();
1728}
1729
1730/// # Panics
1731/// if `versioned_name` is wrong
1732#[must_use]
1733pub fn create_module(tiny_version: &TinyVersion) -> Module {
1734    let canonical_core_path = [tiny_version.versioned_name(PACKAGE_NAME).unwrap()];
1735    let mut intrinsic_types_symbol_table = SymbolTable::new(&canonical_core_path);
1736    add_intrinsic_types(&mut intrinsic_types_symbol_table);
1737    add_intrinsic_type_generator(&mut intrinsic_types_symbol_table);
1738    add_intrinsic_functions(&mut intrinsic_types_symbol_table);
1739
1740    Module::new(intrinsic_types_symbol_table, None)
1741}
1742
1743fn add_intrinsic_type_generator(core_ns: &mut SymbolTable) {
1744    core_ns
1745        .add_type_generator(
1746            "Slice",
1747            TypeGenerator {
1748                arity: 1,
1749                kind: TypeGeneratorKind::Slice,
1750            },
1751        )
1752        .unwrap();
1753
1754    core_ns
1755        .add_type_generator(
1756            "SlicePair",
1757            TypeGenerator {
1758                arity: 2,
1759                kind: TypeGeneratorKind::SlicePair,
1760            },
1761        )
1762        .unwrap();
1763}