fetish_lib/
term_reference.rs

1extern crate ndarray;
2extern crate ndarray_linalg;
3
4use ndarray::*;
5
6use crate::array_utils::*;
7use crate::type_id::*;
8use crate::term_pointer::*;
9use crate::displayable_with_state::*;
10use crate::interpreter_state::*;
11use noisy_float::prelude::*;
12
13///A reference to an arbitrary term, which may belong to
14///a function [`Type`] or a vector [`Type`].
15///Vectors are stored inline here, whereas functions
16///are stored as [`TermPointer`]s to the relevant
17///[`crate::term::PartiallyAppliedTerm`]s in an [`InterpreterState`].
18#[derive(Clone, PartialEq, Hash, Eq)]
19pub enum TermReference {
20    ///A [`TermPointer`] reference to a function
21    FuncRef(TermPointer),
22    ///A vector of the given [`TypeId`] with the given elements.
23    VecRef(TypeId, Array1<R32>)
24}
25
26impl TermReference {
27    ///Gets the [`TypeId`] of the term for this [`TermReference`].
28    pub fn get_type(&self) -> TypeId {
29        match (&self) {
30            TermReference::FuncRef(func_ptr) => func_ptr.type_id,
31            TermReference::VecRef(type_id, _) => *type_id
32        }
33    }
34}
35
36impl DisplayableWithState for TermReference {
37    fn display(&self, state : &InterpreterState) -> String {
38        match (self) {
39            TermReference::FuncRef(ptr) => ptr.display(state),
40            TermReference::VecRef(_, vec) => vec.to_string()
41        }
42    }
43}