diff --git a/src/python_bindings/bindings/boolean_function.cpp b/src/python_bindings/bindings/boolean_function.cpp index a3b57d0bdfc..45a3c20f455 100644 --- a/src/python_bindings/bindings/boolean_function.cpp +++ b/src/python_bindings/bindings/boolean_function.cpp @@ -20,14 +20,42 @@ namespace hal .value("X", BooleanFunction::Value::X, R"(Represents an undefined value.)") .export_values(); - py_boolean_function_value.def( - "__str__", [](const BooleanFunction::Value& v) { return BooleanFunction::to_string(v); }, R"( + py_boolean_function_value.def("__str__", [](const BooleanFunction::Value& v) { return BooleanFunction::to_string(v); }, R"( Translates the Boolean function value into its string representation. :returns: The value as a string. :rtype: str )"); + py_boolean_function.def_static( + "build", + [](const std::vector& nodes) -> std::optional { + std::vector nodes_cloned; + for (const auto& node : nodes) + { + nodes_cloned.push_back(node.clone()); + } + + auto res = BooleanFunction::build(std::move(nodes_cloned)); + if (res.is_ok()) + { + return res.get(); + } + else + { + log_error("python_context", "{}", res.get_error().get()); + return std::nullopt; + } + }, + py::arg("nodes"), + R"( + Builds a Boolean function from a list of nodes. + + :param list[hal_py.BooleanFunction.Node] nodes: The nodes to build the Boolean function from. + :returns: The Boolean function on success, None otherwise. + :rtype: hal_py.BooleanFunction or None + )"); + py_boolean_function.def_static( "to_string", [](const std::vector& value, u8 base = 2) -> std::optional { @@ -1230,8 +1258,7 @@ namespace hal :rtype: set[str] )"); - py_boolean_function.def( - "__str__", [](const BooleanFunction& f) { return f.to_string(); }, R"( + py_boolean_function.def("__str__", [](const BooleanFunction& f) { return f.to_string(); }, R"( Translates the Boolean function into its string representation. :returns: The Boolean function as a string. @@ -1540,8 +1567,7 @@ namespace hal :rtype: hal_py.BooleanFunction.Node )"); - py_boolean_function_node.def( - "__str__", [](const BooleanFunction::Node& n) { return n.to_string(); }, R"( + py_boolean_function_node.def("__str__", [](const BooleanFunction::Node& n) { return n.to_string(); }, R"( Translates the Boolean function node into its string representation. :returns: The Boolean function node as a string.