make things hopefully ready for v0.1.7

This commit is contained in:
Christoph J. Scherr 2023-09-29 17:50:47 +02:00
parent 2fb3fc298c
commit 1bdef8c493
6 changed files with 120 additions and 19 deletions

View File

@ -37,7 +37,7 @@ pyo3 = "0.19"
[package]
name = "libpt"
publish.workspace = true
publish = true
version.workspace = true
edition.workspace = true
authors.workspace = true

View File

@ -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`

View File

@ -21,6 +21,7 @@ use pt_log::*;
use pt_math;
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
/// Quick Result with a ccc error
pub type Result<T> = std::result::Result<T, Error>;
//// 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 ////////////////////////////////////////////////////////////////////////////////

View File

@ -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<Operator>,
output_queue: VecDeque<Token>
}
@ -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<char>) -> Result<Token> {
Ok(19.into())
}

View File

@ -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]

View File

@ -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<String> {
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::<Logger>()?;
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::<networking::monitoring::uptime::UptimeStatus>()?;
// 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(())
}