mech_logic/
lib.rs

1#![no_main]
2#![allow(warnings)]
3#[macro_use]
4extern crate mech_core;
5extern crate nalgebra as na;
6extern crate paste;
7
8use mech_core::*;
9use na::{Vector3, DVector, Vector2, Vector4, RowDVector, Matrix1, Matrix3, Matrix4, RowVector3, RowVector4, RowVector2, DMatrix, Rotation3, Matrix2x3, Matrix3x2, Matrix6, Matrix2};
10use paste::paste;
11use mech_core::matrix::Matrix;
12
13pub mod or;
14pub mod and;
15pub mod not;
16pub mod xor;
17
18pub use self::or::*;
19pub use self::and::*;
20pub use self::not::*;
21pub use self::xor::*;
22
23// ----------------------------------------------------------------------------
24// Logic Library
25// ----------------------------------------------------------------------------
26
27#[macro_export]
28macro_rules! impl_logic_binop {
29  ($struct_name:ident, $arg1_type:ty, $arg2_type:ty, $out_type:ty, $op:ident) => {
30    #[derive(Debug)]
31    struct $struct_name {
32      lhs: Ref<$arg1_type>,
33      rhs: Ref<$arg2_type>,
34      out: Ref<$out_type>,
35    }
36    impl MechFunction for $struct_name {
37      fn solve(&self) {
38        let lhs_ptr = self.lhs.as_ptr();
39        let rhs_ptr = self.rhs.as_ptr();
40        let out_ptr = self.out.as_ptr();
41        $op!(lhs_ptr,rhs_ptr,out_ptr);
42      }
43      fn out(&self) -> Value { self.out.to_value() }
44      fn to_string(&self) -> String { format!("{:#?}", self) }
45    }};}
46
47#[macro_export]
48macro_rules! impl_logic_urnop {
49  ($struct_name:ident, $arg_type:ty, $out_type:ty, $op:ident) => {
50    #[derive(Debug)]
51    struct $struct_name {
52      arg: Ref<$arg_type>,
53      out: Ref<$out_type>,
54    }
55    impl MechFunction for $struct_name {
56      fn solve(&self) {
57        let arg_ptr = self.arg.as_ptr();
58        let out_ptr = self.out.as_ptr();
59        $op!(arg_ptr,out_ptr);
60      }
61      fn out(&self) -> Value { self.out.to_value() }
62      fn to_string(&self) -> String { format!("{:#?}", self) }
63    }};}
64
65#[macro_export]
66macro_rules! impl_logic_fxns {
67  ($lib:ident) => {
68    impl_fxns!($lib,bool,bool,impl_logic_binop);
69  }
70}