Skip to main content

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::*;
60#[cfg(feature = "range_inclusive")]
61use mech_range::inclusive_increment::*;
62#[cfg(feature = "range_exclusive")]
63use mech_range::exclusive::*;
64#[cfg(feature = "range_exclusive")]
65use mech_range::exclusive_increment::*;
66#[cfg(feature = "set")]
67use mech_set::*;
68#[cfg(feature = "string")]
69use mech_string::*;
70
71#[cfg(feature = "matrix")]
72use na::DMatrix;
73#[cfg(feature = "set")]
74use indexmap::set::IndexSet;
75#[cfg(any(feature = "map", feature = "table", feature = "record"))]
76use indexmap::map::IndexMap;
77
78pub mod literals;
79pub mod structures;
80pub mod interpreter;
81pub mod stdlib;
82#[cfg(feature = "functions")]
83pub mod functions;
84pub mod statements;
85pub mod expressions;
86pub mod mechdown;
87#[cfg(feature = "functions")]
88pub mod frame;
89
90pub use mech_core::*;
91
92pub use crate::literals::*;
93pub use crate::interpreter::*;
94pub use crate::structures::*;
95#[cfg(feature = "functifons")]
96pub use crate::functions::*;
97pub use crate::statements::*;
98pub use crate::expressions::*;
99pub use crate::mechdown::*;
100#[cfg(feature = "functions")]
101pub use crate::frame::*;
102
103#[cfg(feature = "access")]
104pub use crate::stdlib::access::*;
105#[cfg(feature = "assign")]
106pub use crate::stdlib::assign::*;
107#[cfg(feature = "convert")]
108pub use crate::stdlib::convert::*;
109#[cfg(feature = "matrix_horzcat")]
110pub use crate::stdlib::horzcat::*;
111#[cfg(feature = "matrix_vertcat")]
112pub use crate::stdlib::vertcat::*;
113#[cfg(feature = "combinatorics")]
114pub use mech_combinatorics::*;
115#[cfg(feature = "matrix")]
116pub use mech_matrix::*;
117#[cfg(feature = "stats")]
118pub use mech_stats::*;
119#[cfg(feature = "math")]
120pub use mech_math::*;
121#[cfg(feature = "logic")]
122pub use mech_logic::*;
123#[cfg(feature = "compare")]
124pub use mech_compare::*;
125#[cfg(feature = "set")]
126pub use mech_set::*;
127
128pub fn load_stdkinds(kinds: &mut KindTable) {
129  #[cfg(feature = "u8")]
130  kinds.insert(hash_str("u8"),ValueKind::U8);
131  #[cfg(feature = "u16")]
132  kinds.insert(hash_str("u16"),ValueKind::U16);
133  #[cfg(feature = "u32")]
134  kinds.insert(hash_str("u32"),ValueKind::U32);
135  #[cfg(feature = "u64")]
136  kinds.insert(hash_str("u64"),ValueKind::U64);
137  #[cfg(feature = "u128")]
138  kinds.insert(hash_str("u128"),ValueKind::U128);
139  #[cfg(feature = "i8")]
140  kinds.insert(hash_str("i8"),ValueKind::I8);
141  #[cfg(feature = "i16")]
142  kinds.insert(hash_str("i16"),ValueKind::I16);
143  #[cfg(feature = "i32")]
144  kinds.insert(hash_str("i32"),ValueKind::I32);
145  #[cfg(feature = "i64")]
146  kinds.insert(hash_str("i64"),ValueKind::I64);
147  #[cfg(feature = "i128")]
148  kinds.insert(hash_str("i128"),ValueKind::I128);
149  #[cfg(feature = "f32")]
150  kinds.insert(hash_str("f32"),ValueKind::F32);
151  #[cfg(feature = "f64")]
152  kinds.insert(hash_str("f64"),ValueKind::F64);
153  #[cfg(feature = "c64")]
154  kinds.insert(hash_str("c64"),ValueKind::C64);
155  #[cfg(feature = "r64")]
156  kinds.insert(hash_str("r64"),ValueKind::R64);
157  #[cfg(feature = "string")]
158  kinds.insert(hash_str("string"),ValueKind::String);
159  #[cfg(feature = "bool")]
160  kinds.insert(hash_str("bool"),ValueKind::Bool);
161}
162
163#[cfg(feature = "functions")]
164pub fn load_stdlib(fxns: &mut Functions) {
165
166  for fxn_desc in inventory::iter::<FunctionDescriptor> {
167    fxns.insert_function(fxn_desc.clone());
168  }
169
170  for fxn_comp in inventory::iter::<FunctionCompilerDescriptor> {
171    fxns.function_compilers.insert(hash_str(fxn_comp.name), fxn_comp.ptr);
172  }
173
174}