diff --git a/pEpACIDgen/acid_yml.py b/pEpACIDgen/acid_yml.py index 6da0421..ba5e405 100644 --- a/pEpACIDgen/acid_yml.py +++ b/pEpACIDgen/acid_yml.py @@ -19,6 +19,7 @@ def generate_acid_yml(acid, module_name): def _grammar_header(): grammar = """decl module @name; decl method @name; +decl use @name; decl struct @name; decl field @name; @@ -35,7 +36,7 @@ def _generate_functions(acid): # Main tmpl_main = 'method {name} {{\n' - tmpl_main += ' signature string="{sig}";\n' +# tmpl_main += ' signature string="{sig}";\n' tmpl_main += ' return type="{return_type}";\n' tmpl_main += '{subitems}' tmpl_main += '}};\n\n' @@ -61,12 +62,17 @@ def _generate_functions(acid): for subitem in subitems: subitems_str += tmpl_sub.format(type=subitem["type"], name=subitem["name"]) + "\n" - # (PEP_STATUS(*)(void*,const char*,const char*,const char*,const char*,const char*)) + #e.g: (PEP_STATUS(*)(void*,const char*,const char*,const char*,const char*,const char*)) sig_ret = item["result_type"] + "(*)" sig_parms = "" for subitem in subitems: - sig_parms += subitem["type"] + ", " + # TODO: utter PEP-HACK!!!! FIXME! + type = subitem["type"] + if type == "PEP_SESSION": + type = "void *" + + sig_parms += type + ", " sig_parms = sig_parms[:-2] diff --git a/pEpACIDgen/gen_backend/gen_pybind11.ysl2 b/pEpACIDgen/gen_backend/gen_pybind11.ysl2 index 12bdc60..ecab36b 100644 --- a/pEpACIDgen/gen_backend/gen_pybind11.ysl2 +++ b/pEpACIDgen/gen_backend/gen_pybind11.ysl2 @@ -15,27 +15,84 @@ tstylesheet { template "method" { || - m.def("«@name»",`apply "signature"` &«@name», ""); + + m.def("«@name»", + [](`apply "use", mode="lambda_sig"`) -> `apply return` { + return ::«@name»( + ``apply "use", mode="arg_list" + ); + }, + pybind11::return_value_policy::copy); || + + } + + template "return" { + > «@type» + } + + template "use", mode="arg_list" { + const "name", "@name"; + const "type", "@type"; + choose { + when "$type = 'const char *'" { + |> strdup(«$name»)`if "position()!=last()" > ,` + } otherwise { + |> «$name»`if "position()!=last()" > ,` + } + } + } + + template "use", mode="lambda_sig" { + const "name", "@name"; + const "type", "@type"; + > «$type» «$name»`if "position()!=last()"> , ` } template "signature" { - > «@string» - } + const "string", "@string"; + > «$string» + } template "struct" { - || - pybind11::class_<«@name»>(m, "«@name»") - ``apply "field" - ; - - || + | pybind11::class_<«@name»>(m, "«@name»") + apply "field" { + with "structname", "@name" + } + | ; + | + | } template "field" { + param "structname"; || - .def_readwrite("«@name»", &::«../@name»::«@name») + .def_property("«@name»", + [](::«$structname» &obj) -> «@type» { + //cout << "«$structname»::«@name»: getter called" << endl; + return obj.«@name»; + }, || + choose { + when "@type = 'const char *'" { + || + [](::«$structname» &obj, «@type» cstr) -> void { + //cout << "«$structname»::«@name»: setter called" << cstr << endl; + obj.«@name» = strdup(cstr); + }, + pybind11::return_value_policy::copy) + || + } otherwise { + || + [](::«$structname» &obj, «@type» val) -> void { + //cout << "«$structname»::«@name»: setter called" << endl; + obj.«@name» = val; + }, + pybind11::return_value_policy::copy) + + || + } + } } template "enum" {