Working example
This commit is contained in:
41
src/external/num/operators/add.rs
vendored
Normal file
41
src/external/num/operators/add.rs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
use super::super::Numeric;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use crate::representations::interpreted::Clause;
|
||||
|
||||
/// Add function
|
||||
///
|
||||
/// Next state: [Add1]
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Add2;
|
||||
externfn_impl!(Add2, |_: &Self, c: Clause| {Ok(Add1{c})});
|
||||
|
||||
/// Partially applied Add function
|
||||
///
|
||||
/// Prev state: [Add2]; Next state: [Add0]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Add1{ c: Clause }
|
||||
atomic_redirect!(Add1, c);
|
||||
atomic_impl!(Add1);
|
||||
externfn_impl!(Add1, |this: &Self, c: Clause| {
|
||||
let a: Numeric = this.c.clone().try_into()?;
|
||||
Ok(Add0{ a, c })
|
||||
});
|
||||
|
||||
/// Fully applied Add function.
|
||||
///
|
||||
/// Prev state: [Add1]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Add0 { a: Numeric, c: Clause }
|
||||
atomic_redirect!(Add0, c);
|
||||
atomic_impl!(Add0, |Self{ a, c }: &Self| {
|
||||
let b: Numeric = c.clone().try_into()?;
|
||||
Ok((*a + b).into())
|
||||
});
|
||||
41
src/external/num/operators/divide.rs
vendored
Normal file
41
src/external/num/operators/divide.rs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
use super::super::Numeric;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use crate::representations::interpreted::Clause;
|
||||
|
||||
/// Divide function
|
||||
///
|
||||
/// Next state: [Divide1]
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Divide2;
|
||||
externfn_impl!(Divide2, |_: &Self, c: Clause| {Ok(Divide1{c})});
|
||||
|
||||
/// Partially applied Divide function
|
||||
///
|
||||
/// Prev state: [Divide2]; Next state: [Divide0]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Divide1{ c: Clause }
|
||||
atomic_redirect!(Divide1, c);
|
||||
atomic_impl!(Divide1);
|
||||
externfn_impl!(Divide1, |this: &Self, c: Clause| {
|
||||
let a: Numeric = this.c.clone().try_into()?;
|
||||
Ok(Divide0{ a, c })
|
||||
});
|
||||
|
||||
/// Fully applied Divide function.
|
||||
///
|
||||
/// Prev state: [Divide1]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Divide0 { a: Numeric, c: Clause }
|
||||
atomic_redirect!(Divide0, c);
|
||||
atomic_impl!(Divide0, |Self{ a, c }: &Self| {
|
||||
let b: Numeric = c.clone().try_into()?;
|
||||
Ok((*a / b).into())
|
||||
});
|
||||
5
src/external/num/operators/mod.rs
vendored
Normal file
5
src/external/num/operators/mod.rs
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
pub mod add;
|
||||
pub mod divide;
|
||||
pub mod multiply;
|
||||
pub mod remainder;
|
||||
pub mod subtract;
|
||||
41
src/external/num/operators/multiply.rs
vendored
Normal file
41
src/external/num/operators/multiply.rs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
use super::super::Numeric;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use crate::representations::interpreted::Clause;
|
||||
|
||||
/// Multiply function
|
||||
///
|
||||
/// Next state: [Multiply1]
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Multiply2;
|
||||
externfn_impl!(Multiply2, |_: &Self, c: Clause| {Ok(Multiply1{c})});
|
||||
|
||||
/// Partially applied Multiply function
|
||||
///
|
||||
/// Prev state: [Multiply2]; Next state: [Multiply0]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Multiply1{ c: Clause }
|
||||
atomic_redirect!(Multiply1, c);
|
||||
atomic_impl!(Multiply1);
|
||||
externfn_impl!(Multiply1, |this: &Self, c: Clause| {
|
||||
let a: Numeric = this.c.clone().try_into()?;
|
||||
Ok(Multiply0{ a, c })
|
||||
});
|
||||
|
||||
/// Fully applied Multiply function.
|
||||
///
|
||||
/// Prev state: [Multiply1]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Multiply0 { a: Numeric, c: Clause }
|
||||
atomic_redirect!(Multiply0, c);
|
||||
atomic_impl!(Multiply0, |Self{ a, c }: &Self| {
|
||||
let b: Numeric = c.clone().try_into()?;
|
||||
Ok((*a * b).into())
|
||||
});
|
||||
41
src/external/num/operators/remainder.rs
vendored
Normal file
41
src/external/num/operators/remainder.rs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
use super::super::Numeric;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use crate::representations::interpreted::Clause;
|
||||
|
||||
/// Remainder function
|
||||
///
|
||||
/// Next state: [Remainder1]
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Remainder2;
|
||||
externfn_impl!(Remainder2, |_: &Self, c: Clause| {Ok(Remainder1{c})});
|
||||
|
||||
/// Partially applied Remainder function
|
||||
///
|
||||
/// Prev state: [Remainder2]; Next state: [Remainder0]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Remainder1{ c: Clause }
|
||||
atomic_redirect!(Remainder1, c);
|
||||
atomic_impl!(Remainder1);
|
||||
externfn_impl!(Remainder1, |this: &Self, c: Clause| {
|
||||
let a: Numeric = this.c.clone().try_into()?;
|
||||
Ok(Remainder0{ a, c })
|
||||
});
|
||||
|
||||
/// Fully applied Remainder function.
|
||||
///
|
||||
/// Prev state: [Remainder1]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Remainder0 { a: Numeric, c: Clause }
|
||||
atomic_redirect!(Remainder0, c);
|
||||
atomic_impl!(Remainder0, |Self{ a, c }: &Self| {
|
||||
let b: Numeric = c.clone().try_into()?;
|
||||
Ok((*a % b).into())
|
||||
});
|
||||
41
src/external/num/operators/subtract.rs
vendored
Normal file
41
src/external/num/operators/subtract.rs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
use super::super::Numeric;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use crate::representations::interpreted::{Clause};
|
||||
|
||||
/// Subtract function
|
||||
///
|
||||
/// Next state: [Subtract1]
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Subtract2;
|
||||
externfn_impl!(Subtract2, |_: &Self, c: Clause| {Ok(Subtract1{c})});
|
||||
|
||||
/// Partially applied Subtract function
|
||||
///
|
||||
/// Prev state: [Subtract2]; Next state: [Subtract0]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Subtract1{ c: Clause }
|
||||
atomic_redirect!(Subtract1, c);
|
||||
atomic_impl!(Subtract1);
|
||||
externfn_impl!(Subtract1, |this: &Self, c: Clause| {
|
||||
let a: Numeric = this.c.clone().try_into()?;
|
||||
Ok(Subtract0{ a, c })
|
||||
});
|
||||
|
||||
/// Fully applied Subtract function.
|
||||
///
|
||||
/// Prev state: [Subtract1]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct Subtract0 { a: Numeric, c: Clause }
|
||||
atomic_redirect!(Subtract0, c);
|
||||
atomic_impl!(Subtract0, |Self{ a, c }: &Self| {
|
||||
let b: Numeric = c.clone().try_into()?;
|
||||
Ok((*a - b).into())
|
||||
});
|
||||
Reference in New Issue
Block a user