3131#include " cel_expr_python/py_cel_env_config.h"
3232#include " cel_expr_python/py_cel_env_internal.h"
3333#include " cel_expr_python/py_cel_expression.h"
34+ #include " cel_expr_python/py_cel_function_decl.h"
3435#include " cel_expr_python/py_cel_type.h"
3536#include " cel_expr_python/py_error_status.h"
3637#include < pybind11/pybind11.h>
@@ -44,10 +45,14 @@ void PyCelEnv::DefinePythonBindings(pybind11::module& m) {
4445 py::class_<PyCelEnv, std::shared_ptr<PyCelEnv>> cel_class (m, " Env" );
4546 m.def (
4647 " NewEnv" ,
47- [](py::object descriptor_pool, std::optional<PyCelEnvConfig> config,
48- std::optional<std::unordered_map<std::string, PyCelType>> variables,
49- std::optional<std::vector<py::object>> extensions,
50- const std::optional<std::string>& container) {
48+ [](py::object descriptor_pool, std::optional<PyCelEnvConfig>& config,
49+ std::optional<std::unordered_map<std::string, PyCelType>>& variables,
50+ std::optional<std::vector<py::object>>& extensions,
51+ const std::optional<std::string>& container,
52+ std::optional<std::vector<std::shared_ptr<PyCelFunctionDecl>>>&
53+ functions,
54+ std::optional<std::unordered_map<std::string, py::object>>&
55+ function_impls) {
5156 PyObject* pool_ptr;
5257 if (descriptor_pool.is_none ()) {
5358 // Replicates python's `descriptor_pool.Default()`
@@ -75,11 +80,16 @@ void PyCelEnv::DefinePythonBindings(pybind11::module& m) {
7580 return PyCelEnv (config.value_or (PyCelEnvConfig ()), pool_ptr,
7681 std::move (variables).value_or (
7782 std::unordered_map<std::string, PyCelType>{}),
78- ext_ptrs, container.value_or (" " ));
83+ ext_ptrs, container.value_or (" " ),
84+ functions.value_or (
85+ std::vector<std::shared_ptr<PyCelFunctionDecl>>{}),
86+ function_impls.value_or (
87+ std::unordered_map<std::string, py::object>{}));
7988 },
8089 py::arg (" descriptor_pool" ) = py::none (), py::arg (" config" ) = py::none (),
8190 py::arg (" variables" ) = py::none (), py::arg (" extensions" ) = py::none (),
82- py::arg (" container" ) = py::none ());
91+ py::arg (" container" ) = py::none (), py::arg (" functions" ) = py::none (),
92+ py::arg (" function_impls" ) = py::none ());
8393 cel_class
8494 .def (" config" ,
8595 [](PyCelEnv& self) { return self.GetEnv ()->GetEnvConfig (); })
@@ -112,13 +122,15 @@ void PyCelEnv::DefinePythonBindings(pybind11::module& m) {
112122 py::arg (" arena" ) = nullptr );
113123}
114124
115- PyCelEnv::PyCelEnv (const PyCelEnvConfig& config, PyObject* descriptor_pool,
116- std::unordered_map<std::string, PyCelType> variable_types,
117- const std::vector<PyObject*>& extensions,
118- std::string container) {
125+ PyCelEnv::PyCelEnv (
126+ const PyCelEnvConfig& config, PyObject* descriptor_pool,
127+ const std::unordered_map<std::string, PyCelType>& variable_types,
128+ const std::vector<PyObject*>& extensions, const std::string& container,
129+ const std::vector<std::shared_ptr<PyCelFunctionDecl>>& functions,
130+ const std::unordered_map<std::string, py::object>& function_impls) {
119131 env_ = ThrowIfError (PyCelEnvInternal::NewCelEnvInternal (
120132 config, descriptor_pool, std::move (variable_types), extensions,
121- std::move (container)));
133+ std::move (container), std::move (functions), std::move (function_impls) ));
122134 ABSL_CHECK (PyGILState_Check ());
123135}
124136
0 commit comments