python: Named argument support

Signed-off-by: David Shah <dave@ds0.me>
This commit is contained in:
David Shah 2019-03-31 17:28:45 +01:00
parent f5bfd557b6
commit 30f0c582e4
3 changed files with 32 additions and 0 deletions

View File

@ -241,6 +241,7 @@ void init_python(const char *executable, bool first)
Py_Initialize();
if (first)
PyImport_ImportModule(TOSTRING(MODULE_NAME));
PyRun_SimpleString("from " TOSTRING(MODULE_NAME) " import *");
} catch (boost::python::error_already_set const &) {
// Parse and output the exception
std::string perror_str = parse_python_exception();

View File

@ -250,6 +250,11 @@ template <typename Class, typename FuncT, FuncT fn, typename arg1_conv> struct f
}
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, Ta a = arg("arg1"))
{
cls_.def(name, wrapped_fn, a);
}
};
// Two parameters, one return
@ -267,6 +272,11 @@ template <typename Class, typename FuncT, FuncT fn, typename arg1_conv, typename
}
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
{
cls_.def(name, wrapped_fn, a);
}
};
// Three parameters, no return
@ -286,6 +296,11 @@ struct fn_wrapper_3a_v
}
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
{
cls_.def(name, wrapped_fn, a);
}
};
// Four parameters, no return
@ -309,6 +324,11 @@ struct fn_wrapper_4a_v
}
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
{
cls_.def(name, wrapped_fn, a);
}
};
// Five parameters, no return
@ -333,6 +353,11 @@ struct fn_wrapper_5a_v
}
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
{
cls_.def(name, wrapped_fn, a);
}
};
// Six parameters, no return
@ -358,6 +383,11 @@ struct fn_wrapper_6a_v
}
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
{
cls_.def(name, wrapped_fn, a);
}
};
// Wrapped getter

View File

@ -30,6 +30,7 @@ NEXTPNR_NAMESPACE_BEGIN
void arch_wrap_python()
{
using namespace PythonConversion;
auto arch_cls = class_<Arch, Arch *, bases<BaseCtx>, boost::noncopyable>("Arch", init<ArchArgs>());
auto ctx_cls = class_<Context, Context *, bases<Arch>, boost::noncopyable>("Context", no_init)
.def("checksum", &Context::checksum)