diff --git a/Cargo.toml b/Cargo.toml index 9a8f186..89f6d63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ pyo3 = "0.19" [package] name = "libpt" -publish.workspace = true +publish = true version.workspace = true edition.workspace = true authors.workspace = true diff --git a/README.md b/README.md index d1c15d3..4c9a754 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,6 @@ crate, python module or executable. Let's see if I make it a bloated mess or stop committing after 30 hello worlds. -#### But the name `pt` / `libpt` already exists! - -So what? I don't care. Besides, there is not enough names to name everything unique. - ## Dependencies - See `cargo.toml` diff --git a/members/pt-ccc/src/base.rs b/members/pt-ccc/src/base.rs index 8d8ecac..f95f6ca 100644 --- a/members/pt-ccc/src/base.rs +++ b/members/pt-ccc/src/base.rs @@ -21,6 +21,7 @@ use pt_log::*; use pt_math; //// TYPES ///////////////////////////////////////////////////////////////////////////////////////// +/// Quick Result with a ccc error pub type Result = std::result::Result; //// CONSTANTS ///////////////////////////////////////////////////////////////////////////////////// @@ -74,38 +75,54 @@ pub enum Function { } //////////////////////////////////////////////////////////////////////////////////////////////////// +/// Top Level Error Type +/// +/// Contains many variants of other errors, that can occur when using the crate. #[non_exhaustive] #[derive(Debug)] pub enum Error { + /// The term has bad syntax SyntaxError(String) } //////////////////////////////////////////////////////////////////////////////////////////////////// +/// Represents some kind of computed value #[derive(Debug)] pub enum Value { + /// Variable value Variable(VarVal), + /// Numerical value Numerical(NumVal), + /// Complex number value Complex(ComplVal), } +/// Represents some kind of numeric value #[non_exhaustive] #[derive(Debug)] pub enum NumVal { + /// Value > 0 Signed(i128), + /// Value can be negative Unsigned(u128), + /// Value is not an integer Float(f64) } //// STRUCTS /////////////////////////////////////////////////////////////////////////////////////// +/// Represents a Value with at least one variable, +/// +/// currently not implemented #[derive(Debug)] pub struct VarVal { - } //////////////////////////////////////////////////////////////////////////////////////////////////// +/// Represents a Value with a complex number, +/// +/// currently not implemented #[derive(Debug)] pub struct ComplVal { - } //// IMPLEMENTATION //////////////////////////////////////////////////////////////////////////////// diff --git a/members/pt-ccc/src/term.rs b/members/pt-ccc/src/term.rs index 749934c..8d553f5 100644 --- a/members/pt-ccc/src/term.rs +++ b/members/pt-ccc/src/term.rs @@ -44,11 +44,14 @@ use pt_math; #[derive(Debug)] enum Token { /// Some kind of operator + #[allow(unused)] // tmp Operator(Operator), /// A concrete value that we can calculate something with. May be a constant, integer, float, /// etc. + /// The Token has a value that can be used in calculation Value(super::base::Value), /// A variable of some kind that will be present in the result + #[allow(unused)] // tmp Variable(char), } //// STRUCTS /////////////////////////////////////////////////////////////////////////////////////// @@ -68,6 +71,7 @@ pub struct Term { ///////////////////////////////////// ///// internal values following ///// ///////////////////////////////////// + #[allow(unused)] // tmp operator_stack: Vec, output_queue: VecDeque } @@ -124,6 +128,7 @@ impl Term { /// /// Returns: A tuple with a [`Token`] and a [`bool`]. If the bool is false, the [`Token`] is /// marked as "incomplete", meaning that the character cannot be used yet. + #[allow(unused)] // tmp fn to_tok(_s: Vec) -> Result { Ok(19.into()) } diff --git a/members/pt-py/Cargo.toml b/members/pt-py/Cargo.toml index a1c006b..bee9ea9 100644 --- a/members/pt-py/Cargo.toml +++ b/members/pt-py/Cargo.toml @@ -14,7 +14,7 @@ categories.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -name = "_libpt" +name = "pt_py" crate-type = ["cdylib"] [dependencies] diff --git a/members/pt-py/src/lib.rs b/members/pt-py/src/lib.rs index b7cbf07..ab60524 100644 --- a/members/pt-py/src/lib.rs +++ b/members/pt-py/src/lib.rs @@ -1,18 +1,101 @@ -use pyo3::prelude::*; -// FIXME: simply importing libpt causes maturin to fail, -// -> `liblibpt.so` not found -// It works without the import -use libpt; +// FIXME: Using a local dependency does not work with maturin as it seems? +use libpt::{ + log::*, +}; -/// Formats the sum of two numbers as string. +use pyo3::prelude::*; + +//// PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////////////////////// +/// ## Check if [`libpt`](crate) has been loaded +/// +/// Always returns `true` if you can execute it. #[pyfunction] -fn sum_as_string(a: usize, b: usize) -> PyResult { - Ok((a + b).to_string()) +pub fn is_loaded() -> bool { + true } -/// A Python module implemented in Rust. +//// PRIVATE FUNCTIONS ///////////////////////////////////////////////////////////////////////////// +/// ## Python module: logger #[pymodule] -fn _libpt(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; +fn py_logger(py: Python, parent: &PyModule) -> PyResult<()> { + let module = PyModule::new(py, "logger")?; + module.add_class::()?; + + parent.add_submodule(module)?; + Ok(()) +} +// +// //////////////////////////////////////////////////////////////////////////////////////////////////// +// /// ## Python module: common +// #[pymodule] +// fn py_common(py: Python, parent: &PyModule) -> PyResult<()> { +// let module = PyModule::new(py, "common")?; +// py_common_printing(py, module)?; +// +// parent.add_submodule(module)?; +// Ok(()) +// } +// +// //////////////////////////////////////////////////////////////////////////////////////////////////// +// /// ## Python module: common.printing +// #[pymodule] +// fn py_common_printing(py: Python, parent: &PyModule) -> PyResult<()> { +// let module = PyModule::new(py, "printing")?; +// module.add_function(wrap_pyfunction!(common::printing::divider, module)?)?; +// module.add_function(wrap_pyfunction!(common::printing::print_divider, module)?)?; +// +// parent.add_submodule(module)?; +// Ok(()) +// } +// +// //////////////////////////////////////////////////////////////////////////////////////////////////// +// /// ## Python module: networking +// #[pymodule] +// fn py_networking(py: Python, parent: &PyModule) -> PyResult<()> { +// let module = PyModule::new(py, "networking")?; +// py_networking_monitoring(py, module)?; +// +// parent.add_submodule(module)?; +// Ok(()) +// } +// +// //////////////////////////////////////////////////////////////////////////////////////////////////// +// /// ## Python module: networking.monitoring +// #[pymodule] +// fn py_networking_monitoring(py: Python, parent: &PyModule) -> PyResult<()> { +// let module = PyModule::new(py, "monitoring")?; +// py_networking_monitoring_uptime(py, module)?; +// +// parent.add_submodule(module)?; +// Ok(()) +// } +// +// //////////////////////////////////////////////////////////////////////////////////////////////////// +// /// ## Python module: networking.monitoring.uptime +// #[pymodule] +// fn py_networking_monitoring_uptime(py: Python, parent: &PyModule) -> PyResult<()> { +// let module = PyModule::new(py, "uptime")?; +// module.add_class::()?; +// module.add_function(wrap_pyfunction!( +// networking::monitoring::uptime::py_continuous_uptime_monitor, +// module +// )?)?; +// +// parent.add_submodule(module)?; +// Ok(()) +// } + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// ## Python module: root +/// +/// This function is the entry point of [`PyO3`](pyo3). This is where the main module is built. +#[pymodule] +fn _libpt(py: Python, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(is_loaded, m)?)?; + + // load sub modules + // py_common(py, m)?; + py_logger(py, m)?; + // py_networking(py, m)?; Ok(()) }