Browse Source

out/inout support - pybind11 gen backend - return ret and all args as tuple

master
heck 4 years ago
parent
commit
1050d42be7
  1. 7
      examples/ext/lib_test/lib_test/gen/config.json
  2. 37
      examples/ext/lib_test/tests/test_lib_test.py
  3. 49
      pEpACIDgen/gen_backend/gen_pybind11.ysl2

7
examples/ext/lib_test/lib_test/gen/config.json

@ -5,7 +5,12 @@
"variables": [
],
"functions": [
"filtertype_to_string"
"func_V_args_V",
"func_P_args_V",
"func_V_args_P",
"func_P_args_P",
"func_V_args_pP",
"func_P_args_P_pP_pP"
],
"debug_ast" : "True",
"debug_acid" : "True",

37
examples/ext/lib_test/tests/test_lib_test.py

@ -3,4 +3,41 @@
# This file is under GNU Affero General Public License 3.0
# see LICENSE.txt
import pytest
import lib_test
from lib_test import *
def test_func_V_args_V():
(ret,) = func_V_args_V()
assert(ret == None)
def test_func_P_args_V():
(ret,) = func_P_args_V()
print("RESULT:", ret)
assert (ret == 23)
def test_func_V_args_P():
(ret,arg1) = func_V_args_P(23)
print("RESULT:", ret, arg1)
assert(ret == None)
assert(arg1 == 23)
def test_func_P_args_P():
(ret,arg1) = func_P_args_P(22)
print("RESULT:", ret, arg1)
assert (ret == 23)
assert (arg1 == 22)
# @pytest.mark.skip("")
def test_func_V_args_pP():
(ret,arg1) = func_V_args_pP(22)
print("RESULT:", ret, arg1)
assert (ret == None)
assert (arg1 == 23)
def test_func_P_args_P_pP_pP():
(ret, arg1, arg2, arg3) = func_P_args_P_pP_pP(23, 22, 22)
print("RESULT:", ret, arg1, arg2, arg3)
assert (ret == 23)
assert (arg1 == 23)
assert (arg2 == 23)
assert (arg3 == 23)

49
pEpACIDgen/gen_backend/gen_pybind11.ysl2

@ -17,19 +17,50 @@ tstylesheet {
||
m.def("«@name»",
[](`apply "use", mode="lambda_sig"`) -> `apply return` {
return ::«@name»(
[](`apply "use", mode="lambda_sig"`) -> pybind11::tuple {
`apply "return", mode="create"`
`apply "return", mode="assign"`::«@name»(
``apply "use", mode="arg_list"
);
return pybind11::make_tuple(
ret`if "count(use)>0" > ,`
``apply "use", mode="return_as_tuple"
);
},
pybind11::return_value_policy::copy);
||
}
template "return" mode="create" {
const "type", "@type";
choose {
when "$type != 'void'" {
> «@type» ret;
} otherwise {
> pybind11::none ret;
}
}
}
template "return" {
> «@type»
template "return" mode="assign" {
const "type", "@type";
choose {
when "$type != 'void'" {
> ret =
}
}
}
template "use", mode="return_as_tuple" {
const "name", "@name";
const "type", "@type";
choose {
when "$type != 'PEP_SESSION'" {
|> «$name»`if "position()!=last()" > ,`
}
}
}
// TODO: UTTTTER PEP-SPECIFIC HACKS (PEP_SESSION)
template "use", mode="arg_list" {
const "name", "@name";
@ -56,10 +87,10 @@ tstylesheet {
}
}
template "signature" {
const "string", "@string";
> «$string»
}
// template "signature" {
// const "string", "@string";
// > «$string»
// }
template "struct" {
| pybind11::class_<«@name»>(m, "«@name»")
@ -76,7 +107,7 @@ tstylesheet {
||
.def_property("«@name»",
[](::«$structname» &obj) -> «@type» {
//cout << "«$structname»::«@name»: getter called" << endl;
//cout << "«$structname» ::«@name»: getter called" << endl;
return obj.«@name»;
},
||

Loading…
Cancel
Save