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};
17use mech_core::{hash_str, MResult, nodes::Kind as NodeKind, nodes::Matrix as Mat, nodes::*};
18#[cfg(feature = "map")]
19use mech_core::MechMap;
20#[cfg(feature = "record")]
21use mech_core::MechRecord;
22#[cfg(feature = "set")]
23use mech_core::MechSet;
24#[cfg(feature = "tuple")]
25use mech_core::MechTuple;
26#[cfg(feature = "enum")]
27use mech_core::MechEnum;
28#[cfg(feature = "table")]
29use mech_core::MechTable;
30#[cfg(feature = "complex")]
31use mech_core::C64;
32#[cfg(feature = "rational")]
33use mech_core::R64;
34#[cfg(feature = "functions")]
35use crate::functions::*;
36#[cfg(feature = "access")]
37use crate::stdlib::access::*;
38#[cfg(feature = "assign")]
39use crate::stdlib::assign::*;
40#[cfg(feature = "convert")]
41use crate::stdlib::convert::*;
42#[cfg(feature = "matrix_horzcat")]
43use crate::stdlib::horzcat::*;
44#[cfg(feature = "matrix_vertcat")]
45use crate::stdlib::vertcat::*;
46#[cfg(feature = "combinatorics")]
47use mech_combinatorics::*;
48#[cfg(feature = "matrix")]
49use mech_matrix::*;
50#[cfg(feature = "stats")]
51use mech_stats::*;
52#[cfg(feature = "math")]
53use mech_math::*;
54#[cfg(feature = "logic")]
55use mech_logic::*;
56#[cfg(feature = "compare")]
57use mech_compare::*;
58#[cfg(feature = "range_inclusive")]
59use mech_range::inclusive::RangeInclusive;
60#[cfg(feature = "range_exclusive")]
61use mech_range::exclusive::RangeExclusive;
62#[cfg(feature = "set")]
63use mech_set::*;
64
65#[cfg(feature = "matrix")]
66use na::DMatrix;
67#[cfg(feature = "set")]
68use indexmap::set::IndexSet;
69#[cfg(any(feature = "map", feature = "table", feature = "record"))]
70use indexmap::map::IndexMap;
71
72pub mod literals;
73pub mod structures;
74pub mod interpreter;
75pub mod stdlib;
76#[cfg(feature = "functions")]
77pub mod functions;
78pub mod statements;
79pub mod expressions;
80pub mod mechdown;
81
82pub use mech_core::*;
83
84pub use crate::literals::*;
85pub use crate::interpreter::*;
86pub use crate::structures::*;
87#[cfg(feature = "functifons")]
88pub use crate::functions::*;
89pub use crate::statements::*;
90pub use crate::expressions::*;
91pub use crate::mechdown::*;
92
93#[cfg(feature = "access")]
94pub use crate::stdlib::access::*;
95#[cfg(feature = "assign")]
96pub use crate::stdlib::assign::*;
97#[cfg(feature = "convert")]
98pub use crate::stdlib::convert::*;
99#[cfg(feature = "matrix_horzcat")]
100pub use crate::stdlib::horzcat::*;
101#[cfg(feature = "matrix_vertcat")]
102pub use crate::stdlib::vertcat::*;
103#[cfg(feature = "combinatorics")]
104pub use mech_combinatorics::*;
105#[cfg(feature = "matrix")]
106pub use mech_matrix::*;
107#[cfg(feature = "stats")]
108pub use mech_stats::*;
109#[cfg(feature = "math")]
110pub use mech_math::*;
111#[cfg(feature = "logic")]
112pub use mech_logic::*;
113#[cfg(feature = "compare")]
114pub use mech_compare::*;
115#[cfg(feature = "set")]
116pub use mech_set::*;
117
118pub fn load_stdkinds(kinds: &mut KindTable) {
119  #[cfg(feature = "u8")]
120  kinds.insert(hash_str("u8"),ValueKind::U8);
121  #[cfg(feature = "u16")]
122  kinds.insert(hash_str("u16"),ValueKind::U16);
123  #[cfg(feature = "u32")]
124  kinds.insert(hash_str("u32"),ValueKind::U32);
125  #[cfg(feature = "u64")]
126  kinds.insert(hash_str("u64"),ValueKind::U64);
127  #[cfg(feature = "u128")]
128  kinds.insert(hash_str("u128"),ValueKind::U128);
129  #[cfg(feature = "i8")]
130  kinds.insert(hash_str("i8"),ValueKind::I8);
131  #[cfg(feature = "i16")]
132  kinds.insert(hash_str("i16"),ValueKind::I16);
133  #[cfg(feature = "i32")]
134  kinds.insert(hash_str("i32"),ValueKind::I32);
135  #[cfg(feature = "i64")]
136  kinds.insert(hash_str("i64"),ValueKind::I64);
137  #[cfg(feature = "i128")]
138  kinds.insert(hash_str("i128"),ValueKind::I128);
139  #[cfg(feature = "f32")]
140  kinds.insert(hash_str("f32"),ValueKind::F32);
141  #[cfg(feature = "f64")]
142  kinds.insert(hash_str("f64"),ValueKind::F64);
143  #[cfg(feature = "c64")]
144  kinds.insert(hash_str("c64"),ValueKind::C64);
145  #[cfg(feature = "r64")]
146  kinds.insert(hash_str("r64"),ValueKind::R64);
147  #[cfg(feature = "string")]
148  kinds.insert(hash_str("string"),ValueKind::String);
149  #[cfg(feature = "bool")]
150  kinds.insert(hash_str("bool"),ValueKind::Bool);
151}
152
153#[cfg(feature = "functions")]
154pub fn load_stdlib(fxns: &mut Functions) {
155
156  for fxn_desc in inventory::iter::<FunctionDescriptor> {
157    fxns.insert_function(fxn_desc.clone());
158  }
159
160  for fxn_comp in inventory::iter::<FunctionCompilerDescriptor> {
161    fxns.function_compilers.insert(hash_str(fxn_comp.name), fxn_comp.ptr);
162  }
163
164}