generated from PlexSheep/baserepo
make things hopefully ready for v0.1.7
This commit is contained in:
parent
2fb3fc298c
commit
1bdef8c493
|
@ -37,7 +37,7 @@ pyo3 = "0.19"
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "libpt"
|
name = "libpt"
|
||||||
publish.workspace = true
|
publish = true
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
|
@ -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.
|
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
|
## Dependencies
|
||||||
|
|
||||||
- See `cargo.toml`
|
- See `cargo.toml`
|
||||||
|
|
|
@ -21,6 +21,7 @@ use pt_log::*;
|
||||||
use pt_math;
|
use pt_math;
|
||||||
|
|
||||||
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Quick Result with a ccc error
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
//// 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]
|
#[non_exhaustive]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
/// The term has bad syntax
|
||||||
SyntaxError(String)
|
SyntaxError(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Represents some kind of computed value
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
|
/// Variable value
|
||||||
Variable(VarVal),
|
Variable(VarVal),
|
||||||
|
/// Numerical value
|
||||||
Numerical(NumVal),
|
Numerical(NumVal),
|
||||||
|
/// Complex number value
|
||||||
Complex(ComplVal),
|
Complex(ComplVal),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents some kind of numeric value
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NumVal {
|
pub enum NumVal {
|
||||||
|
/// Value > 0
|
||||||
Signed(i128),
|
Signed(i128),
|
||||||
|
/// Value can be negative
|
||||||
Unsigned(u128),
|
Unsigned(u128),
|
||||||
|
/// Value is not an integer
|
||||||
Float(f64)
|
Float(f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Represents a Value with at least one variable,
|
||||||
|
///
|
||||||
|
/// currently not implemented
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct VarVal {
|
pub struct VarVal {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Represents a Value with a complex number,
|
||||||
|
///
|
||||||
|
/// currently not implemented
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ComplVal {
|
pub struct ComplVal {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -44,11 +44,14 @@ use pt_math;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Token {
|
enum Token {
|
||||||
/// Some kind of operator
|
/// Some kind of operator
|
||||||
|
#[allow(unused)] // tmp
|
||||||
Operator(Operator),
|
Operator(Operator),
|
||||||
/// A concrete value that we can calculate something with. May be a constant, integer, float,
|
/// A concrete value that we can calculate something with. May be a constant, integer, float,
|
||||||
/// etc.
|
/// etc.
|
||||||
|
/// The Token has a value that can be used in calculation
|
||||||
Value(super::base::Value),
|
Value(super::base::Value),
|
||||||
/// A variable of some kind that will be present in the result
|
/// A variable of some kind that will be present in the result
|
||||||
|
#[allow(unused)] // tmp
|
||||||
Variable(char),
|
Variable(char),
|
||||||
}
|
}
|
||||||
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -68,6 +71,7 @@ pub struct Term {
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
///// internal values following /////
|
///// internal values following /////
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
|
#[allow(unused)] // tmp
|
||||||
operator_stack: Vec<Operator>,
|
operator_stack: Vec<Operator>,
|
||||||
output_queue: VecDeque<Token>
|
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
|
/// 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.
|
/// marked as "incomplete", meaning that the character cannot be used yet.
|
||||||
|
#[allow(unused)] // tmp
|
||||||
fn to_tok(_s: Vec<char>) -> Result<Token> {
|
fn to_tok(_s: Vec<char>) -> Result<Token> {
|
||||||
Ok(19.into())
|
Ok(19.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ categories.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
[lib]
|
[lib]
|
||||||
name = "_libpt"
|
name = "pt_py"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,18 +1,101 @@
|
||||||
use pyo3::prelude::*;
|
// FIXME: Using a local dependency does not work with maturin as it seems?
|
||||||
// FIXME: simply importing libpt causes maturin to fail,
|
use libpt::{
|
||||||
// -> `liblibpt.so` not found
|
log::*,
|
||||||
// It works without the import
|
};
|
||||||
use libpt;
|
|
||||||
|
|
||||||
/// 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]
|
#[pyfunction]
|
||||||
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
|
pub fn is_loaded() -> bool {
|
||||||
Ok((a + b).to_string())
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Python module implemented in Rust.
|
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ## Python module: logger
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn _libpt(_py: Python, m: &PyModule) -> PyResult<()> {
|
fn py_logger(py: Python, parent: &PyModule) -> PyResult<()> {
|
||||||
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue