1#![no_main]
2#![allow(warnings)]
3#[macro_use]
4extern crate mech_core;
5#[cfg(feature = "matrix")]
6extern crate nalgebra as na;
7extern crate paste;
8
9use mech_core::*;
10
11#[cfg(feature = "vector3")]
12use nalgebra::Vector3;
13#[cfg(feature = "vectord")]
14use nalgebra::DVector;
15#[cfg(feature = "vector2")]
16use nalgebra::Vector2;
17#[cfg(feature = "vector4")]
18use nalgebra::Vector4;
19#[cfg(feature = "rowdvector")]
20use nalgebra::RowDVector;
21#[cfg(feature = "row_vectord")]
22use nalgebra::RowDVector;
23#[cfg(feature = "matrix1")]
24use nalgebra::Matrix1;
25#[cfg(feature = "matrix3")]
26use nalgebra::Matrix3;
27#[cfg(feature = "matrix4")]
28use nalgebra::Matrix4;
29#[cfg(feature = "row_vector3")]
30use nalgebra::RowVector3;
31#[cfg(feature = "row_vector4")]
32use nalgebra::RowVector4;
33#[cfg(feature = "row_vector2")]
34use nalgebra::RowVector2;
35#[cfg(feature = "matrixd")]
36use nalgebra::DMatrix;
37#[cfg(feature = "matrix2x3")]
38use nalgebra::Matrix2x3;
39#[cfg(feature = "matrix3x2")]
40use nalgebra::Matrix3x2;
41#[cfg(feature = "matrix2")]
42use nalgebra::Matrix2;
43
44use paste::paste;
45#[cfg(feature = "matrix")]
46use mech_core::matrix::Matrix;
47
48#[cfg(feature = "or")]
49pub mod or;
50#[cfg(feature = "and")]
51pub mod and;
52#[cfg(feature = "not")]
53pub mod not;
54#[cfg(feature = "xor")]
55pub mod xor;
56
57#[cfg(feature = "or")]
58pub use self::or::*;
59#[cfg(feature = "and")]
60pub use self::and::*;
61#[cfg(feature = "not")]
62pub use self::not::*;
63#[cfg(feature = "xor")]
64pub use self::xor::*;
65
66#[macro_export]
71macro_rules! impl_logic_binop {
72 ($struct_name:ident, $arg1_type:ty, $arg2_type:ty, $out_type:ty, $op:ident, $feature_flag:expr) => {
73 #[derive(Debug)]
74 struct $struct_name {
75 lhs: Ref<$arg1_type>,
76 rhs: Ref<$arg2_type>,
77 out: Ref<$out_type>,
78 }
79 impl MechFunctionFactory for $struct_name
80 {
81 fn new(args: FunctionArgs) -> MResult<Box<dyn MechFunction>> {
82 match args {
83 FunctionArgs::Binary(out, arg1, arg2) => {
84 let lhs: Ref<$arg1_type> = unsafe { arg1.as_unchecked() }.clone();
85 let rhs: Ref<$arg2_type> = unsafe { arg2.as_unchecked() }.clone();
86 let out: Ref<$out_type> = unsafe { out.as_unchecked() }.clone();
87 Ok(Box::new(Self {lhs, rhs, out }))
88 },
89 _ => Err(MechError2::new(
90 IncorrectNumberOfArguments { expected: 2, found: args.len() },
91 None
92 ).with_compiler_loc()
93 ),
94 }
95 }
96 }
97 impl MechFunctionImpl for $struct_name
98 {
99 fn solve(&self) {
100 let lhs_ptr = self.lhs.as_ptr();
101 let rhs_ptr = self.rhs.as_ptr();
102 let out_ptr = self.out.as_mut_ptr();
103 $op!(lhs_ptr,rhs_ptr,out_ptr);
104 }
105 fn out(&self) -> Value { self.out.to_value() }
106 fn to_string(&self) -> String { format!("{:#?}", self) }
107 }
108 #[cfg(feature = "compiler")]
109 impl MechFunctionCompiler for $struct_name
110 {
111 fn compile(&self, ctx: &mut CompileCtx) -> MResult<Register> {
112 let name = format!("{}<bool>", stringify!($struct_name));
113 compile_binop!(name, self.out, self.lhs, self.rhs, ctx, $feature_flag);
114 }
115 }
116};}
117
118#[macro_export]
119macro_rules! impl_logic_fxns {
120 ($lib:ident) => {
121 impl_fxns!($lib,bool,bool,impl_logic_binop);
122 }
123}