refactor!(py): Boolean semantics should be exposed as function

This commit is contained in:
Anand Balakrishnan 2023-05-03 16:35:27 -07:00
parent e6ef427e2f
commit bfb59c1008
No known key found for this signature in database

View file

@ -82,21 +82,15 @@ impl Trace for PyTrace {
} }
} }
#[pyclass(name = "BooleanSemantics")] #[pyfunction]
struct PyBooleanSemantics; fn eval_bool_semantics(expr: &PyBoolExpr, trace: &PyTrace) -> PyResult<Py<BoolSignal>> {
#[pymethods]
impl PyBooleanSemantics {
#[staticmethod]
fn eval(expr: &PyBoolExpr, trace: &PyTrace) -> PyResult<Py<BoolSignal>> {
let sig = BooleanSemantics::eval(&expr.0, trace, ()).map_err(PyArgusError::from)?; let sig = BooleanSemantics::eval(&expr.0, trace, ()).map_err(PyArgusError::from)?;
Python::with_gil(|py| Py::new(py, (BoolSignal::from(sig), BoolSignal::super_type()))) Python::with_gil(|py| Py::new(py, (BoolSignal::from(sig), BoolSignal::super_type())))
} }
}
pub fn init(_py: Python, m: &PyModule) -> PyResult<()> { pub fn init(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<PyBooleanSemantics>()?;
m.add_class::<PyTrace>()?; m.add_class::<PyTrace>()?;
m.add_function(wrap_pyfunction!(eval_bool_semantics, m)?)?;
Ok(()) Ok(())
} }