From a884d3d8a9ff51cdc4f2bf217bef80a1aa9c0f90 Mon Sep 17 00:00:00 2001
From: Cookiebowser <lucas.doering@live.de>
Date: Mon, 27 Feb 2023 13:40:05 +0100
Subject: [PATCH] implemented BInteger

---
 .../main/rust_embedded/btypes/src/binteger.rs | 42 ++++++++++++++++++-
 .../stups/codegenerator/RustTemplate_e.stg    |  4 +-
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs b/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs
index 0f5c09b7d..ee58642cf 100644
--- a/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs
+++ b/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs
@@ -1,11 +1,49 @@
+#![allow(non_snake_case)]
 
+use core::convert::TryInto;
 
 pub type BInteger = i128;
 
 pub trait BInt {
-    fn equal(&self, other: Self) -> bool;
+    fn equal(&self, other: &Self) -> bool;
+
+    fn greater(&self, other: &Self) -> bool;
+    fn greaterEqual(&self, other: &Self) -> bool;
+    fn less(&self, other: &Self) -> bool;
+    fn lessEqual(&self, other: &Self) -> bool;
+
+    fn plus(&self, other: &Self) -> Self;
+    fn minus(&self, other: &Self) -> Self;
+    fn multiply(&self, other: &Self) -> Self;
+    fn divide(&self, other: &Self) -> Self;
+    fn modulo(&self, other: &Self) -> Self;
+    fn power(&self, exp: &Self) -> Self;
+
+    fn negative(&self) -> Self;
+    fn pred(&self) -> Self;
+    fn succ(&self) -> Self;
 }
 
 impl BInt for BInteger {
-    fn equal(&self, other: Self) -> bool { self.eq(&other) }
+    fn equal(&self, other: &Self) -> bool { self.eq(&other) }
+
+    fn greater(&self, other: &Self) -> bool { self > other }
+    fn greaterEqual(&self, other: &Self) -> bool { self >= other }
+    fn less(&self, other: &Self) -> bool { self < other }
+    fn lessEqual(&self, other: &Self) -> bool { self <= other }
+
+    fn plus(&self, other: &Self) -> Self { self + other }
+    fn minus(&self, other: &Self) -> Self { self - other }
+    fn multiply(&self, other: &Self) -> Self { self * other }
+    fn divide(&self, other: &Self) -> Self { self / other }
+    fn modulo(&self, other: &Self) -> Self { self % other }
+    fn power(&self, exp: &Self) -> Self {
+        if exp < &0 { panic!("Power with negative exponent!") }
+        let u32_exp: u32 = exp.unsigned_abs().try_into().unwrap();
+        return self.pow(u32_exp);
+    }
+
+    fn negative(&self) -> Self { -self }
+    fn pred(&self) -> Self { self - 1 }
+    fn succ(&self) -> Self { self + 1 }
 }
\ No newline at end of file
diff --git a/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg b/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg
index 2d418f2ad..c8e15220d 100644
--- a/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg
+++ b/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg
@@ -5,15 +5,17 @@ as, break, const, continue, crate, else, enum, extern, false, fn, for, if, impl,
 
 machine(imports, includedMachines, machine, structs, constants_declarations, includes, enums, sets, setDefinitions, declarations, initialization, operations, addition, useBigInteger, getters, lambdaFunctions, forModelChecking, transitions, invariant, copy, modelcheck, transitionCachesDeclaration, hash_equal) ::= <<
 #![ allow( dead_code, unused, non_snake_case, non_camel_case_types, unused_assignments ) ]
+//#![no_std] //std is enabled for the generated machine by default, since without it there is no println which makes unit-testing very difficult
 use btypes::{bset, brel};
-//use btypes::set::{BSet, SetItem, BRelation, RelItem};
 use btypes::bset::BSet;
 use btypes::bset::SetItem;
 use btypes::bset::PowSetItem;
 use btypes::brelation::BRelation;
 use btypes::brelation::RelLeftItem;
 use btypes::bboolean::BBoolean;
+use btypes::bboolean::BBool;
 use btypes::binteger::BInteger;
+use btypes::binteger::BInt;
 
 
 <includedMachines; separator="\n">
-- 
GitLab