mech_interpreter/
lib.rs

1#![allow(warnings)]
2#![feature(step_trait)]
3#![feature(box_patterns)]
4#![feature(trivial_bounds)]
5#![feature(where_clause_attrs)]
6
7#[cfg(feature = "matrix")]
8extern crate nalgebra as na;
9#[macro_use]
10extern crate mech_core;
11
12use mech_core::*;
13#[cfg(feature = "matrix")]
14use mech_core::matrix::{Matrix, ToMatrix};
15use mech_core::kind::Kind;
16use mech_core::{Dictionary, Ref, Value, ValueKind, ValRef, ToValue};
17#[cfg(feature = "io_print")]
18use mech_io::IoPrint;
19#[cfg(feature = "io_println")]
20use mech_io::IoPrintln;
21#[cfg(feature = "map")]
22use mech_core::MechMap;
23#[cfg(feature = "record")]
24use mech_core::MechRecord;
25#[cfg(feature = "set")]
26use mech_core::MechSet;
27#[cfg(feature = "tuple")]
28use mech_core::MechTuple;
29#[cfg(feature = "enum")]
30use mech_core::MechEnum;
31#[cfg(feature = "table")]
32use mech_core::MechTable;
33#[cfg(feature = "f64")]
34use mech_core::F64;
35#[cfg(feature = "f32")]
36use mech_core::F32;
37#[cfg(feature = "complex")]
38use mech_core::ComplexNumber;
39#[cfg(feature = "rational")]
40use mech_core::RationalNumber;
41#[cfg(feature = "stdlib")]
42use crate::stdlib::{
43                    access::*,
44                    assign::*,
45                    convert::*,
46                  };
47#[cfg(feature = "functions")]
48use crate::functions::*;
49#[cfg(feature = "matrix_horzcat")]
50use crate::stdlib::horzcat::*;
51#[cfg(feature = "matrix_vertcat")]
52use crate::stdlib::vertcat::*;
53use mech_core::{MechError, MechErrorKind, hash_str, MResult, nodes::Kind as NodeKind, nodes::Matrix as Mat, nodes::*};
54
55#[cfg(feature = "combinatorics")]
56use mech_combinatorics::*;
57#[cfg(feature = "matrix")]
58use mech_matrix::*;
59#[cfg(feature = "stats")]
60use mech_stats::*;
61#[cfg(feature = "math")]
62use mech_math::*;
63#[cfg(feature = "logic")]
64use mech_logic::*;
65#[cfg(feature = "compare")]
66use mech_compare::*;
67#[cfg(feature = "range_inclusive")]
68use mech_range::inclusive::RangeInclusive;
69#[cfg(feature = "range_exclusive")]
70use mech_range::exclusive::RangeExclusive;
71
72#[cfg(feature = "matrix")]
73use na::DMatrix;
74#[cfg(feature = "set")]
75use indexmap::set::IndexSet;
76#[cfg(any(feature = "map", feature = "table", feature = "record"))]
77use indexmap::map::IndexMap;
78
79pub mod literals;
80pub mod structures;
81pub mod interpreter;
82pub mod stdlib;
83#[cfg(feature = "functions")]
84pub mod functions;
85pub mod statements;
86pub mod expressions;
87pub mod mechdown;
88
89pub use crate::literals::*;
90pub use crate::interpreter::*;
91pub use crate::structures::*;
92#[cfg(feature = "functifons")]
93pub use crate::functions::*;
94pub use crate::statements::*;
95pub use crate::expressions::*;
96pub use crate::mechdown::*;
97
98
99pub fn load_stdkinds(kinds: &mut KindTable) {
100  #[cfg(feature = "u8")]
101  kinds.insert(hash_str("u8"),ValueKind::U8);
102  #[cfg(feature = "u16")]
103  kinds.insert(hash_str("u16"),ValueKind::U16);
104  #[cfg(feature = "u32")]
105  kinds.insert(hash_str("u32"),ValueKind::U32);
106  #[cfg(feature = "u64")]
107  kinds.insert(hash_str("u64"),ValueKind::U64);
108  #[cfg(feature = "u128")]
109  kinds.insert(hash_str("u128"),ValueKind::U128);
110  #[cfg(feature = "i8")]
111  kinds.insert(hash_str("i8"),ValueKind::I8);
112  #[cfg(feature = "i16")]
113  kinds.insert(hash_str("i16"),ValueKind::I16);
114  #[cfg(feature = "i32")]
115  kinds.insert(hash_str("i32"),ValueKind::I32);
116  #[cfg(feature = "i64")]
117  kinds.insert(hash_str("i64"),ValueKind::I64);
118  #[cfg(feature = "i128")]
119  kinds.insert(hash_str("i128"),ValueKind::I128);
120  #[cfg(feature = "f32")]
121  kinds.insert(hash_str("f32"),ValueKind::F32);
122  #[cfg(feature = "f64")]
123  kinds.insert(hash_str("f64"),ValueKind::F64);
124  #[cfg(feature = "c64")]
125  kinds.insert(hash_str("c64"),ValueKind::ComplexNumber);
126  #[cfg(feature = "r64")]
127  kinds.insert(hash_str("r64"),ValueKind::RationalNumber);
128  #[cfg(feature = "string")]
129  kinds.insert(hash_str("string"),ValueKind::String);
130  #[cfg(feature = "bool")]
131  kinds.insert(hash_str("bool"),ValueKind::Bool);
132}
133
134#[cfg(feature = "functions")]
135pub fn load_stdlib(fxns: &mut Functions) {
136
137  // Preload combinatorics functions
138  #[cfg(feature = "combinatorics_n_choose_k")]
139  fxns.function_compilers.insert(hash_str("combinatorics/n-choose-k"), Box::new(CombinatoricsNChooseK{}));
140
141  // Preload stats functions
142  #[cfg(feature = "stats_sum")]
143  fxns.function_compilers.insert(hash_str("stats/sum/row"), Box::new(StatsSumRow{}));
144  #[cfg(feature = "stats_sum")]
145  fxns.function_compilers.insert(hash_str("stats/sum/column"), Box::new(StatsSumColumn{}));
146
147  // Preload math functions
148  #[cfg(feature = "math_add")]
149  fxns.function_compilers.insert(hash_str("math/add"),Box::new(MathAdd{}));
150  #[cfg(feature = "math_sub")]
151  fxns.function_compilers.insert(hash_str("math/sub"),Box::new(MathSub{}));
152  #[cfg(feature = "math_mul")]
153  fxns.function_compilers.insert(hash_str("math/mul"),Box::new(MathMul{}));
154  #[cfg(feature = "math_div")]
155  fxns.function_compilers.insert(hash_str("math/div"),Box::new(MathDiv{}));
156  #[cfg(feature = "math_mod")]
157  fxns.function_compilers.insert(hash_str("math/mod"),Box::new(MathMod{}));
158  #[cfg(feature = "math_exp")]
159  fxns.function_compilers.insert(hash_str("math/exp"),Box::new(MathExp{}));
160  #[cfg(feature = "math_neg")]
161  fxns.function_compilers.insert(hash_str("math/neg"),Box::new(MathNegate{}));
162  #[cfg(feature = "math_sin")]
163  fxns.function_compilers.insert(hash_str("math/sin"),Box::new(MathSin{}));
164  #[cfg(feature = "math_cos")]
165  fxns.function_compilers.insert(hash_str("math/cos"),Box::new(MathCos{}));
166  #[cfg(feature = "math_atan2")]
167  fxns.function_compilers.insert(hash_str("math/atan2"),Box::new(MathAtan2{}));
168  #[cfg(feature = "math_atan")]
169  fxns.function_compilers.insert(hash_str("math/atan"),Box::new(MathAtan{}));
170  #[cfg(feature = "math_acos")]
171  fxns.function_compilers.insert(hash_str("math/acos"),Box::new(MathAcos{}));
172  #[cfg(feature = "math_acosh")]
173  fxns.function_compilers.insert(hash_str("math/acosh"),Box::new(MathAcosh{}));
174  #[cfg(feature = "math_acot")]
175  fxns.function_compilers.insert(hash_str("math/acot"),Box::new(MathAcot{}));
176  #[cfg(feature = "math_acsc")]
177  fxns.function_compilers.insert(hash_str("math/acsc"),Box::new(MathAcsc{}));
178  #[cfg(feature = "math_asec")]
179  fxns.function_compilers.insert(hash_str("math/asec"),Box::new(MathAsec{}));
180  #[cfg(feature = "math_asin")]
181  fxns.function_compilers.insert(hash_str("math/asin"),Box::new(MathAsin{}));
182  #[cfg(feature = "math_sinh")]
183  fxns.function_compilers.insert(hash_str("math/sinh"),Box::new(MathSinh{}));
184  #[cfg(feature = "math_cosh")]
185  fxns.function_compilers.insert(hash_str("math/cosh"),Box::new(MathCosh{}));
186  #[cfg(feature = "math_tanh")]
187  fxns.function_compilers.insert(hash_str("math/tanh"),Box::new(MathTanh{}));
188  #[cfg(feature = "math_atanh")]
189  fxns.function_compilers.insert(hash_str("math/atanh"),Box::new(MathAtanh{}));
190  #[cfg(feature = "math_cot")]
191  fxns.function_compilers.insert(hash_str("math/cot"),Box::new(MathCot{}));
192  #[cfg(feature = "math_csc")]
193  fxns.function_compilers.insert(hash_str("math/csc"),Box::new(MathCsc{}));
194  #[cfg(feature = "math_sec")]
195  fxns.function_compilers.insert(hash_str("math/sec"),Box::new(MathSec{}));
196  #[cfg(feature = "math_tan")]
197  fxns.function_compilers.insert(hash_str("math/tan"),Box::new(MathTan{}));
198
199  // Preload io functions
200  #[cfg(feature = "io_print")]
201  fxns.function_compilers.insert(hash_str("io/print"), Box::new(IoPrint{}));
202  #[cfg(feature = "io_println")]
203  fxns.function_compilers.insert(hash_str("io/println"), Box::new(IoPrintln{}));
204
205  // Matrix functions
206  #[cfg(feature = "matrix_horzcat")]
207  fxns.function_compilers.insert(hash_str("matrix/horzcat"), Box::new(MatrixHorzCat{}));
208  #[cfg(feature = "matrix_vertcat")]
209  fxns.function_compilers.insert(hash_str("matrix/vertcat"), Box::new(MatrixVertCat{}));
210  #[cfg(feature = "matrix_transpose")]
211  fxns.function_compilers.insert(hash_str("matrix/transpose"), Box::new(MatrixTranspose{}));
212  #[cfg(feature = "matrix_matmul")]
213  fxns.function_compilers.insert(hash_str("matrix/matmul"), Box::new(MatrixMatMul{}));
214  #[cfg(feature = "matrix_dot")]
215  fxns.function_compilers.insert(hash_str("matrix/dot"), Box::new(MatrixDot{}));
216
217  // Compare functions
218  #[cfg(feature = "compare_eq")]
219  fxns.function_compilers.insert(hash_str("compare/eq"), Box::new(CompareEqual{}));
220  #[cfg(feature = "compare_neq")]
221  fxns.function_compilers.insert(hash_str("compare/neq"), Box::new(CompareNotEqual{}));
222  #[cfg(feature = "compare_lte")]
223  fxns.function_compilers.insert(hash_str("compare/lte"), Box::new(CompareLessThanEqual{}));
224  #[cfg(feature = "compare_gte")]
225  fxns.function_compilers.insert(hash_str("compare/gte"), Box::new(CompareGreaterThanEqual{}));
226  #[cfg(feature = "compare_lt")]
227  fxns.function_compilers.insert(hash_str("compare/lt"), Box::new(CompareLessThan{}));
228  #[cfg(feature = "compare_gt")]
229  fxns.function_compilers.insert(hash_str("compare/gt"), Box::new(CompareGreaterThan{}));
230
231  // Logic functions
232  #[cfg(feature = "logic_and")]
233  fxns.function_compilers.insert(hash_str("logic/and"), Box::new(LogicAnd{}));
234  #[cfg(feature = "logic_or")]
235  fxns.function_compilers.insert(hash_str("logic/or"), Box::new(LogicOr{}));
236  #[cfg(feature = "logic_not")]
237  fxns.function_compilers.insert(hash_str("logic/not"), Box::new(LogicNot{}));
238  #[cfg(feature = "logic_xor")]
239  fxns.function_compilers.insert(hash_str("logic/xor"), Box::new(LogicXor{}));  
240
241}