From 1050d42be711b7a9779da9f064fea841d165d830 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 26 Jan 2021 00:32:50 +0100 Subject: [PATCH] out/inout support - pybind11 gen backend - return ret and all args as tuple --- .../ext/lib_test/lib_test/gen/config.json | 7 ++- examples/ext/lib_test/tests/test_lib_test.py | 37 ++++++++++++++ pEpACIDgen/gen_backend/gen_pybind11.ysl2 | 49 +++++++++++++++---- 3 files changed, 83 insertions(+), 10 deletions(-) diff --git a/examples/ext/lib_test/lib_test/gen/config.json b/examples/ext/lib_test/lib_test/gen/config.json index 90dd6e7..bb1d239 100644 --- a/examples/ext/lib_test/lib_test/gen/config.json +++ b/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", diff --git a/examples/ext/lib_test/tests/test_lib_test.py b/examples/ext/lib_test/tests/test_lib_test.py index 4e09d37..a31ab7a 100644 --- a/examples/ext/lib_test/tests/test_lib_test.py +++ b/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) diff --git a/pEpACIDgen/gen_backend/gen_pybind11.ysl2 b/pEpACIDgen/gen_backend/gen_pybind11.ysl2 index cc68ee8..2643fc7 100644 --- a/pEpACIDgen/gen_backend/gen_pybind11.ysl2 +++ b/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»; }, ||