From 6d12b4444281efd70c85aa727df434ef91d7d04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Wed, 27 May 2020 14:46:41 +0200 Subject: [PATCH 01/33] add native semantics (WIP) --- CMakeLists.txt | 97 ++++++ src/semantics/native/action.cpp | 63 ++++ src/semantics/native/action.h | 77 +++++ src/semantics/native/arithmetic.cpp | 40 +++ src/semantics/native/arithmetic.h | 30 ++ src/semantics/native/boilerplate.pl | 337 +++++++++++++++++++ src/semantics/native/compound_expression.cpp | 23 ++ src/semantics/native/compound_expression.h | 41 +++ src/semantics/native/domain.cpp | 25 ++ src/semantics/native/domain.h | 42 +++ src/semantics/native/effect_axiom.cpp | 26 ++ src/semantics/native/effect_axiom.h | 37 ++ src/semantics/native/execution.cpp | 94 ++++++ src/semantics/native/execution.h | 64 ++++ src/semantics/native/fluent.cpp | 38 +++ src/semantics/native/fluent.h | 56 +++ src/semantics/native/formula.cpp | 125 +++++++ src/semantics/native/formula.h | 33 ++ src/semantics/native/history.cpp | 34 ++ src/semantics/native/history.h | 49 +++ src/semantics/native/list_expression.cpp | 24 ++ src/semantics/native/list_expression.h | 31 ++ src/semantics/native/procedural.cpp | 50 +++ src/semantics/native/procedural.h | 55 +++ src/semantics/native/reference.cpp | 42 +++ src/semantics/native/reference.h | 103 ++++++ src/semantics/native/scope.cpp | 24 ++ src/semantics/native/scope.h | 38 +++ src/semantics/native/semantics.cpp | 57 ++++ src/semantics/native/semantics.h | 107 ++++++ src/semantics/native/string.cpp | 25 ++ src/semantics/native/string.h | 52 +++ src/semantics/native/utilities.cpp | 24 ++ src/semantics/native/utilities.h | 49 +++ src/semantics/native/value.cpp | 26 ++ src/semantics/native/value.h | 47 +++ src/semantics/native/variable.cpp | 27 ++ src/semantics/native/variable.h | 45 +++ src/tools/nativegpp-test.cpp | 71 ++++ 39 files changed, 2228 insertions(+) create mode 100644 src/semantics/native/action.cpp create mode 100644 src/semantics/native/action.h create mode 100644 src/semantics/native/arithmetic.cpp create mode 100644 src/semantics/native/arithmetic.h create mode 100644 src/semantics/native/boilerplate.pl create mode 100644 src/semantics/native/compound_expression.cpp create mode 100644 src/semantics/native/compound_expression.h create mode 100644 src/semantics/native/domain.cpp create mode 100644 src/semantics/native/domain.h create mode 100644 src/semantics/native/effect_axiom.cpp create mode 100644 src/semantics/native/effect_axiom.h create mode 100644 src/semantics/native/execution.cpp create mode 100644 src/semantics/native/execution.h create mode 100644 src/semantics/native/fluent.cpp create mode 100644 src/semantics/native/fluent.h create mode 100644 src/semantics/native/formula.cpp create mode 100644 src/semantics/native/formula.h create mode 100644 src/semantics/native/history.cpp create mode 100644 src/semantics/native/history.h create mode 100644 src/semantics/native/list_expression.cpp create mode 100644 src/semantics/native/list_expression.h create mode 100644 src/semantics/native/procedural.cpp create mode 100644 src/semantics/native/procedural.h create mode 100644 src/semantics/native/reference.cpp create mode 100644 src/semantics/native/reference.h create mode 100644 src/semantics/native/scope.cpp create mode 100644 src/semantics/native/scope.h create mode 100644 src/semantics/native/semantics.cpp create mode 100644 src/semantics/native/semantics.h create mode 100644 src/semantics/native/string.cpp create mode 100644 src/semantics/native/string.h create mode 100644 src/semantics/native/utilities.cpp create mode 100644 src/semantics/native/utilities.h create mode 100644 src/semantics/native/value.cpp create mode 100644 src/semantics/native/value.h create mode 100644 src/semantics/native/variable.cpp create mode 100644 src/semantics/native/variable.h create mode 100644 src/tools/nativegpp-test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 80148c08..275b6434 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -447,6 +447,88 @@ endif(BUILD_TAPTENC_SEMANTICS) +###################################################################################### +# The golog++ native semantics: libnativegolog++.so +###################################################################################### + +if (${ECLIPSE_FOUND}) + option(BUILD_NATIVE_IMPL "Build the native golog++ semantics" OFF) +endif() +if (${BUILD_NATIVE_IMPL}) + set(NATIVE_SRC + src/semantics/native/action.cpp + src/semantics/native/variable.cpp + src/semantics/native/value.cpp + src/semantics/native/domain.cpp + src/semantics/native/arithmetic.cpp + src/semantics/native/execution.cpp + src/semantics/native/fluent.cpp + src/semantics/native/formula.cpp + src/semantics/native/procedural.cpp + src/semantics/native/scope.cpp + src/semantics/native/semantics.cpp + src/semantics/native/utilities.cpp + src/semantics/native/string.cpp + src/semantics/native/history.cpp + src/semantics/native/reference.cpp + src/semantics/native/effect_axiom.cpp + src/semantics/native/compound_expression.cpp + src/semantics/native/list_expression.cpp + ) + + link_directories(${ECLIPSE_LIBRARY_DIRS}) + add_library(nativegolog++ SHARED ${NATIVE_SRC}) + target_compile_definitions(nativegolog++ PUBLIC + -DECLIPSE_DIR=\"${ECLIPSE_DIR}\" + -DUSES_NO_ENGINE_HANDLE + -DSEMANTICS_INSTALL_DIR=\"${CMAKE_INSTALL_PREFIX}/${SEMANTICS_INSTALL_DIR}\" + ) + target_include_directories(nativegolog++ PUBLIC ${ECLIPSE_INCLUDE_DIRS}) + target_link_libraries(nativegolog++ golog++ ${ECLIPSE_LIBRARIES} stdc++fs) + set_property(TARGET nativegolog++ PROPERTY CXX_STANDARD 14) + set_property(TARGET nativegolog++ PROPERTY SOVERSION ${GOLOGPP_VERSION}) + install(TARGETS nativegolog++ DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(FILES + src/semantics/native/semantics.h + src/semantics/native/formula.h + src/semantics/native/effect_axiom.h + src/semantics/native/variable.h + src/semantics/native/value.h + src/semantics/native/domain.h + src/semantics/native/arithmetic.h + src/semantics/native/procedural.h + src/semantics/native/scope.h + src/semantics/native/fluent.h + src/semantics/native/action.h + src/semantics/native/execution.h + src/semantics/native/utilities.h + src/semantics/native/reference.h + src/semantics/native/string.h + src/semantics/native/history.h + src/semantics/native/compound_expression.h + src/semantics/native/list_expression.h + + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/golog++/semantics/native + ) + + install(FILES + src/semantics/native/boilerplate.pl + DESTINATION ${SEMANTICS_INSTALL_DIR}/native + ) + + get_target_property(NATIVEGPP_CXXFLAGS_L readylog++ INTERFACE_COMPILE_OPTIONS) + set(NATIVEGPP_CXXFLAGS "-I${ECLIPSE_INCLUDE_DIRS}") + if (${NATIVEGPP_CXXFLAGS_L}) + foreach(i IN LISTS ${NATIVEGPP_CXXFLAGS_L}) + set(NATIVEGPP_CXXFLAGS "${NATIVEGPP_CXXFLAGS} ${i}") + endforeach() + endif() + set(NATIVEGPP_LDFLAGS "${ECLIPSE_LDFLAGS}") + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nativegolog++.pc.in ${CMAKE_CURRENT_BINARY_DIR}/nativegolog++.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nativegolog++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endif() + + ###################################################################################### # Testing (requires parser & readylog semantics) ###################################################################################### @@ -487,3 +569,18 @@ if (BUILD_PARSER AND BUILD_READYLOG_SEMANTICS) endif() + +if (${BUILD_NATIVE_IMPL}) + set(NATIVE_TEST_SRC + src/tools/nativegpp-test.cpp) + add_executable(nativegpp-test ${NATIVE_TEST_SRC}) + target_link_libraries(nativegpp-test nativegolog++ parsegolog++) + set_property(TARGET nativegpp-test PROPERTY CXX_STANDARD 14) + + if (USE_LIBASAN) + target_link_libraries(nativegpp-test asan) + endif() + + install(TARGETS nativegpp-test RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + diff --git a/src/semantics/native/action.cpp b/src/semantics/native/action.cpp new file mode 100644 index 00000000..0caf28a0 --- /dev/null +++ b/src/semantics/native/action.cpp @@ -0,0 +1,63 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include + +#include "action.h" +#include "effect_axiom.h" +#include "scope.h" +#include "execution.h" +#include "variable.h" +#include "value.h" + +#include + +namespace gologpp { + + +template<> +unique_ptr Semantics::trans(const Binding &b, History &h) { + while (!element()->precondition().semantics().evaluate(b, h)) + this->context().drain_exog_queue_blocking(); + + vector> arg_vals; + Binding b1(b); + for (const auto ¶m : element()->params()) { + Value v = element().arg_for_param(param).semantics().evaluate(b, h); + arg_vals.emplace_back(new Value( + param->type(), + v + )); + // TODO: Meh. Dangerous object lifetime here. + b1.bind(param, *arg_vals.back()); + } + + shared_ptr trans_start = std::make_shared( + element()->shared_from_this(), + arg_vals, + Transition::Hook::START + ); + + // TODO: eliminate Transition object here + shared_ptr a = context().backend().start_activity(*trans_start); + h.semantics().append(trans_start); + context().backend().wait_for_end(*a); +} + + + +} // namespace gologpp diff --git a/src/semantics/native/action.h b/src/semantics/native/action.h new file mode 100644 index 00000000..422207b4 --- /dev/null +++ b/src/semantics/native/action.h @@ -0,0 +1,77 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_ACTION_H_ +#define READYLOG_ACTION_H_ + +#include "semantics.h" +#include "reference.h" + +#include +#include +#include + +namespace gologpp { + +class Action; + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; +}; + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; +}; + + +template<> +class Semantics> +: public Semantics +, public GeneralSemantics> +{ +public: + using GeneralSemantics>::GeneralSemantics; +}; + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; +}; + + + +} // namespace gologpp + + +#endif diff --git a/src/semantics/native/arithmetic.cpp b/src/semantics/native/arithmetic.cpp new file mode 100644 index 00000000..9f279a4e --- /dev/null +++ b/src/semantics/native/arithmetic.cpp @@ -0,0 +1,40 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include +#include + +#include "arithmetic.h" +#include "semantics.h" + +namespace gologpp { + + +template<> +Value Semantics::evaluate(const Binding &b, const History &h) +{ + switch (element().op()) { + case ArithmeticOperation::Operator::POWER: + return element().lhs().semantics().evaluate(h).pow( + element().lhs().semantics().evaluate(h) + ); + } +} + + + +} diff --git a/src/semantics/native/arithmetic.h b/src/semantics/native/arithmetic.h new file mode 100644 index 00000000..e33f8479 --- /dev/null +++ b/src/semantics/native/arithmetic.h @@ -0,0 +1,30 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_ARITHMETIC_H_ +#define READYLOG_ARITHMETIC_H_ + +#include "semantics.h" + +namespace gologpp { + + + + +} + +#endif // READYLOG_ARITHMETIC_H_ diff --git a/src/semantics/native/boilerplate.pl b/src/semantics/native/boilerplate.pl new file mode 100644 index 00000000..b25b35f2 --- /dev/null +++ b/src/semantics/native/boilerplate.pl @@ -0,0 +1,337 @@ +:- external(exog_fluent_getValue/3, p_exog_fluent_getValue). +:- dynamic managed_term/2. +:- dynamic durative_action/1, durative_poss/2, durative_causes_val/4. +:- lib(listut). + +% resolve name clash with lib(listut) +:- import delete/3 from eclipse_language. + +should_progress(H) :- length(H, L), L >= 10. + +% execute/3 is useless in golog++. Just ignore it and log a message +execute(Action, _Sr, _H) :- printf("Dummy execute %W%n", [Action]). + +function(strcat(X, Y), R, concat_atoms(X, Y, R)). +function(to_string(V), R, + and(sprintf(S, "%w", V), atom_string(R, S)) +). + + +function(gpp_field_value(Name, Compound), Value, + once(pl_field_value(Name, Compound, Value)) +). +pl_field_value(Name, Compound, Value) :- + ( + atom(Name), var(Value) + , Compound = gpp_compound(_Type, Fields) + , Field_term =.. [Name, Value] + , member(Field_term, Fields) + ; + sprintf(Msg, "Invalid function call: %W", [gpp_field_value(Name, Compound)]) + , throw(Msg) + ) +. + + +function(gpp_mixed_assign(Members, Value, Lhs), Result, + once(pl_mixed_assign(Members, Value, Lhs, Result)) +). +pl_mixed_assign(Members, Value, Lhs, Result) :- + Members = [M|Rest_mems] + , (number(M) -> + % List access + ( Lhs = gpp_list(Type, List), length(List, _) + ; sprintf(Msg, "gpp_mixed_assign: Invalid argument %W", [gpp_mixed_assign(Members, Value, Lhs)]) + , throw(Msg) + ) + , ( nth0(M, List, Mem_current, List_without) + ; sprintf(Msg, "Accessing %W: Index %W is out of bounds", [List, M]) + , throw(Msg) + ) + , ( length(Rest_mems) > 0 -> + % Additional nesting levels: recurse down + pl_mixed_assign(Rest_mems, Value, Mem_current, Val_new) + ; + Val_new = Value + ) + , nth0(M, List_new, Val_new, List_without) + , Result = gpp_list(Type, List_new) + + ; atom(M) -> + % Compound field access + ( Lhs = gpp_compound(Type, Fields), length(Fields, _) + ; sprintf(Msg, "gpp_mixed_assign: Invalid argument %W", [gpp_mixed_assign(Members, Value, Lhs)]) + , throw(Msg) + ) + , Field_acc =.. [M, Field_cur_value] + , delete(Field_acc, Fields, Fields_without) + , ( length(Rest_mems) > 0 -> + % Additional nesting levels: recurse down + pl_mixed_assign(Rest_mems, Value, Field_cur_value, Val_new) + , Field_new =.. [M, Val_new] + ; + Field_new =.. [M, Value] + ) + , Result = gpp_compound(Type, [Field_new | Fields_without]) + ; + sprintf(Msg, "gpp_mixed_assign: %W is not a list index or a field name", [M]) + , throw(Msg) + ) +. + +function(gpp_list_access(Lhs, Idx), Result, + once(pl_list_access(Lhs, Idx, Result)) +). +pl_list_access(Lhs, Idx, Result) :- + ( + Lhs = gpp_list(_Type, List) + , length(List, _) + , number(Idx) + ; + sprintf(Msg, "Invalid function call: %W", [pl_list_access(Lhs, Idx, Result)]) + , throw(Msg) + ) + , nth0(Idx, List, Result) +. + +function(gpp_list_length(Lhs), Result, + once(pl_list_length(Lhs, Result)) +). +pl_list_length(Lhs, Result) :- + ( + Lhs = gpp_list(_Type, List) + , length(List, Result) + ; + sprintf(Msg, "Invalid function call: %W", [pl_list_length(Lhs, Result)]) + , throw(Msg) + ) +. + +function(gpp_list_pop_front(Lhs), Result, + once(pl_list_pop_front(Lhs, Result)) +). +pl_list_pop_front(Lhs, Result) :- + ( + Lhs = gpp_list(Type, List) + , length(List, _) + ; throw("gpp_list_pop_front: Arg must be a list") + ) + , List_new = [_ | Result] + , Result = gpp_list(Type, List_new) +. + +function(gpp_list_pop_back(Lhs), Result, + once(pl_list_pop_back(Lhs, Result)) +). +pl_list_pop_back(Lhs, Result) :- + ( + Lhs = gpp_list(Type, List) + , length(List, _) + ; throw("gpp_list_pop_back: Arg must be a list") + ) + , length(List, Len) + , nth1(Len, List, _, List_new) + , Result = gpp_list(Type, List_new) +. + +function(gpp_list_push_front(Lhs, Elem), Result, + once(pl_list_push_front(Lhs, Elem, Result)) +). +pl_list_push_front(Lhs, Elem, Result) :- + ( + Lhs = gpp_list(Type, List) + , length(List, _) + ; throw("gpp_list_push_front: First arg must be a list") + ) + , ( number(Elem) + ; throw("gpp_list_push_front: Second arg must be instantiated") + ) + , Result = gpp_list(Type, [Elem | List]) +. + +function(gpp_list_push_back(Lhs, Elem), Result, + once(pl_list_push_back(Lhs, Elem, Result)) +). +pl_list_push_back(Lhs, Elem, Result) :- + ( + Lhs = gpp_list(Type, List) + , length(List, _) + ; throw("gpp_list_push_back: First arg must be a list") + ) + , ( number(Elem) + ; throw("gpp_list_push_back: Second arg must be instantiated") + ) + , append(List, [Elem], List_new) + , Result = gpp_list(Type, List_new) +. + + +/******************************** + * Durative Action semantics + * ******************************/ + +exog_prim_fluent(now). + +prim_fluent(state(A)) :- durative_action(A). +initial_val(state(A), idle) :- durative_action(A). +reserved_fluent(state(_A)). + +exog_action(exog_state_change(A, _T, State)) :- durative_action(A). +poss(exog_state_change(A, _T, State), true) :- durative_action(A). +causes_val(exog_state_change(A, _T, State), state(A), State, true) :- durative_action(A). + + +% start action +% ============ +prim_action(start(A, _T)) :- durative_action(A). + +% Precondition only applies to starting a durative action +poss(start(A, T), + and([ + not(state(A) = running) + , now >= T + , C + ]) +) :- + durative_action(A) + , durative_poss(A, C) +. +causes_val(start(A, _T), state(A), running, true) :- durative_action(A). + + +% finish action +% ============ +prim_action(finish(A, _T)) :- durative_action(A). +poss(finish(A, T), + and( + lif(online = true + % Online: Wait for real action to complete + , state(A) = final + % Offline: Final immediately + , true + ) + , now >= T + ) +) :- durative_action(A). +causes_val(finish(A, _T), state(A), final, true) :- durative_action(A). + +% Only the finish action applies a durative action's effects: +causes_val(finish(A, T), F, V, C) :- durative_causes_val(A, F, V, C). + + +% end action +% ========== +prim_action(end(A, _T)) :- durative_action(A). +poss(end(A, T), + and( + lif(online + % Online: Wait for real action to complete + , or( [ + state(A) = final + , state(A) = failed + , state(A) = cancelled + ] ) + % Offline: Final immediately + , true + ) + , now >= T + ) +) :- durative_action(A). + +% ONLY During planning end(A) puts A in the final state. +% Online this happens exogenously. +causes_val(end(A, _T), state(A), final, not(online)) :- durative_action(A). + +% Offline: Just apply effect & disregard state because state is changed +% by another effect. +% Online: Apply effect only if state is final +causes_val( + end(A, _T) + , F, V + , lif(online + , and(state(A) = final, C) + , C + ) +) :- + durative_causes_val(A, F, V, C) +. + + +% stop action +% =========== +prim_action(stop(A, _T)) :- durative_action(A). +poss(stop(A, T), + and( + lif(online = true + , state(A) = running + , true + ) + , now >= T + ) +) :- durative_action(A). +causes_val(stop(A, _T), state(A), cancelled, true) :- durative_action(A). + + +% fail action +% ============= +prim_action(fail(A, _T)) :- durative_action(A). +poss(fail(A, T), + and([ + online = true + , state(A) = failed + , now >= T + ]) +) :- durative_action(A). +causes_val(fail(A, _T), state(A), failed, true) :- durative_action(A). + + + +/********************************/ + + +ssa( online, false, [clipOnline|_69485] ) :- !, true. +ssa( online, true, [setOnline|_69524] ) :- !, true. +ssa( sit_start_time, T, [setTime(T)|_69563] ) :- !, true. +ssa( sit_start_time, T, [ccUpdate(_69409, T)|_69585] ) :- !, true. +ssa( Fluent, Value, [set(Fluent, Value)|_69607] ) :- !, true. + +ssa( eval_exog_functions, _69895, [set(eval_exog_functions, _69895)|_] ) :- !. +ssa( eval_registers, _69906, [set(eval_registers, _69906)|_] ) :- !. +ssa( online, _69917, [set(online, _69917)|_] ) :- !. +ssa( sit_start_time, _69928, [set(sit_start_time, _69928)|_] ) :- !. +ssa( useAbstraction, _69939, [set(useAbstraction, _69939)|_] ) :- !. +ssa( bel(_69762), _69950, [set(bel(_69762), _69950)|_] ) :- !. +ssa( ltp(_69766), _69961, [set(ltp(_69766), _69961)|_] ) :- !. + +ssa( lookahead(_69755, _69756, _69757, _69758), _70148, [set(lookahead(_69755, _69756, _69757, _69758), _70148)|_] ) :- !. +ssa( pll(_69743, _69744, _69745, _69746), _70159, [set(pll(_69743, _69744, _69745, _69746), _70159)|_] ) :- !. +ssa( eval_exog_functions, _70170, [_70174|_70175] ) :- !, has_val(eval_exog_functions, _70170, _70175). +ssa( eval_registers, _70190, [_70194|_70195] ) :- !, has_val(eval_registers, _70190, _70195). +ssa( online, _70210, [_70214|_70215] ) :- !, has_val(online, _70210, _70215). +ssa( sit_start_time, _70230, [_70234|_70235] ) :- !, has_val(sit_start_time, _70230, _70235). +ssa( useAbstraction, _70250, [_70254|_70255] ) :- !, has_val(useAbstraction, _70250, _70255). +ssa( bel(_69762), _70270, [_70274|_70275] ) :- !, has_val(bel(_69762), _70270, _70275). +ssa( ltp(_69766), _70290, [_70294|_70295] ) :- !, has_val(ltp(_69766), _70290, _70295). + +ssa( lookahead(_69755, _69756, _69757, _69758), _70630, [_70634|_70635] ) :- !, has_val(lookahead(_69755, _69756, _69757, _69758), _70630, _70635). +ssa( pll(_69743, _69744, _69745, _69746), _70650, [_70654|_70655] ) :- !, has_val(pll(_69743, _69744, _69745, _69746), _70650, _70655). + +prolog_poss( send(_R, _70692) ). +prolog_poss( send(_R, _70692), _71116 ) :- true. +prolog_poss( reply(_R, _70701) ). +prolog_poss( reply(_R, _70701), _71133 ) :- true. +prolog_poss( setOnline ). +prolog_poss( setOnline, _71150 ) :- true. +prolog_poss( clipOnline ). +prolog_poss( clipOnline, _71167 ) :- true. +prolog_poss( setTime(_70719) ). +prolog_poss( setTime(_70719), _71184 ) :- true. +prolog_poss( clipAbstraction ). +prolog_poss( clipAbstraction, _71201 ) :- true. +prolog_poss( setAbstraction ). +prolog_poss( setAbstraction, _71218 ) :- true. +prolog_poss( set(_Fluent, _Value) ). +prolog_poss( set(_Fluent, _Value), _71235 ) :- true. +prolog_poss( exogf_Update ). +prolog_poss( exogf_Update, _71252 ) :- true. + diff --git a/src/semantics/native/compound_expression.cpp b/src/semantics/native/compound_expression.cpp new file mode 100644 index 00000000..09536ba5 --- /dev/null +++ b/src/semantics/native/compound_expression.cpp @@ -0,0 +1,23 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "compound_expression.h" + +namespace gologpp { + + +} // namespace gologpp diff --git a/src/semantics/native/compound_expression.h b/src/semantics/native/compound_expression.h new file mode 100644 index 00000000..34a4b7df --- /dev/null +++ b/src/semantics/native/compound_expression.h @@ -0,0 +1,41 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_COMPOUND_EXPRESSION_H_ +#define READYLOG_COMPOUND_EXPRESSION_H_ + +#include "semantics.h" + +#include + +namespace gologpp { + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual Value evaluate(const AbstractReference &context, const History &h) override; +}; + + +} + +#endif // READYLOG_COMPOUND_EXPRESSION_H_ diff --git a/src/semantics/native/domain.cpp b/src/semantics/native/domain.cpp new file mode 100644 index 00000000..53b74836 --- /dev/null +++ b/src/semantics/native/domain.cpp @@ -0,0 +1,25 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "domain.h" +#include "value.h" +#include "utilities.h" + +namespace gologpp { + + +} diff --git a/src/semantics/native/domain.h b/src/semantics/native/domain.h new file mode 100644 index 00000000..c1c6380f --- /dev/null +++ b/src/semantics/native/domain.h @@ -0,0 +1,42 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_DOMAIN_H_ +#define READYLOG_DOMAIN_H_ + +#include "semantics.h" + +#include +#include + +namespace gologpp { + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual Value evaluate(const Binding &b, const History &h) override; +}; + + + +} + +#endif // READYLOG_DOMAIN_H_ diff --git a/src/semantics/native/effect_axiom.cpp b/src/semantics/native/effect_axiom.cpp new file mode 100644 index 00000000..617e0a43 --- /dev/null +++ b/src/semantics/native/effect_axiom.cpp @@ -0,0 +1,26 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "effect_axiom.h" +#include "procedural.h" + + + +namespace gologpp { + + +} diff --git a/src/semantics/native/effect_axiom.h b/src/semantics/native/effect_axiom.h new file mode 100644 index 00000000..124caf14 --- /dev/null +++ b/src/semantics/native/effect_axiom.h @@ -0,0 +1,37 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_EFFECTAXIOM_H_ +#define READYLOG_EFFECTAXIOM_H_ + +#include "semantics.h" + +#include +#include "reference.h" +#include +#include +#include "scope.h" +#include "execution.h" + + +namespace gologpp { + + + +} /* namespace gologpp */ + +#endif /* READYLOG_EFFECTAXIOM_H_ */ diff --git a/src/semantics/native/execution.cpp b/src/semantics/native/execution.cpp new file mode 100644 index 00000000..0153f987 --- /dev/null +++ b/src/semantics/native/execution.cpp @@ -0,0 +1,94 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "execution.h" + +#include + +#include "action.h" +#include "procedural.h" +#include "fluent.h" +#include "utilities.h" +#include "history.h" + +#include + +namespace filesystem = std::experimental::filesystem; + +namespace gologpp { + + +unique_ptr NativeContext::instance_; + + +void NativeContext::init(unique_ptr &&exec_backend) +{ instance_ = unique_ptr(new NativeContext(std::move(exec_backend))); } + +void NativeContext::shutdown() +{ + instance_.reset(); +} + + +NativeContext::NativeContext(unique_ptr &&exec_backend) +: AExecutionContext(std::make_unique(), std::move(exec_backend)) +{ + // TODO +} + + +NativeContext::~NativeContext() +{} + + +NativeContext &NativeContext::instance() +{ return *instance_; } + + +void NativeContext::compile(const Block &block) +{ +} + + +void NativeContext::compile(const AbstractAction &aa) +{ + +} + + +void NativeContext::compile(const Fluent &fluent) +{ +} + + +void NativeContext::compile(const Function &function) +{ +} + + +void NativeContext::postcompile() +{ +} + +void NativeContext::run(Block &&program) +{ + +} + + + +} // namespace gologpp diff --git a/src/semantics/native/execution.h b/src/semantics/native/execution.h new file mode 100644 index 00000000..8cbbf120 --- /dev/null +++ b/src/semantics/native/execution.h @@ -0,0 +1,64 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_EXECUTION_H_ +#define READYLOG_EXECUTION_H_ + +#include + +#include + +#include "semantics.h" +#include "history.h" + + +namespace gologpp { + + +class NativeContext : public AExecutionContext { +public: + virtual ~NativeContext() override; + static void init(unique_ptr &&backend = nullptr); + static void shutdown(); + static NativeContext &instance(); + + virtual void precompile() override {} + virtual void compile(const Block &block) override; + virtual void compile(const AbstractAction &action) override; + virtual void compile(const Fluent &fluent) override; + virtual void compile(const Function &function) override; + virtual void compile(const Procedure &proc) override; + virtual void postcompile() override; + + shared_ptr wait_for_end(Activity &a); + + virtual void run(Block &&program) override; + +private: + NativeContext(unique_ptr &&exec_backend); + + static unique_ptr instance_; +}; + + +class NativeFailure { +}; + + +} // namespace gologpp + +#endif // READYLOG_EXECUTION_H_ diff --git a/src/semantics/native/fluent.cpp b/src/semantics/native/fluent.cpp new file mode 100644 index 00000000..03a7a7f3 --- /dev/null +++ b/src/semantics/native/fluent.cpp @@ -0,0 +1,38 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "fluent.h" +#include "execution.h" +#include "scope.h" +#include "utilities.h" +#include "value.h" +#include "semantics.h" +#include "variable.h" + +#include +#include + +#include + + + + +namespace gologpp { + + + +} // namespace gologpp diff --git a/src/semantics/native/fluent.h b/src/semantics/native/fluent.h new file mode 100644 index 00000000..6cb7e6f5 --- /dev/null +++ b/src/semantics/native/fluent.h @@ -0,0 +1,56 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_FLUENT_H_ +#define READYLOG_FLUENT_H_ + +#include "semantics.h" +#include + + +namespace gologpp { + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; +}; + + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; +}; + + + +} // namespace gologpp + + + +#endif // READYLOG_FLUENT_H_ diff --git a/src/semantics/native/formula.cpp b/src/semantics/native/formula.cpp new file mode 100644 index 00000000..24a93112 --- /dev/null +++ b/src/semantics/native/formula.cpp @@ -0,0 +1,125 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "formula.h" +#include "variable.h" + +#include +#include +#include + +namespace gologpp { + +template<> +Value Semantics::evaluate(const Binding &b, const History &h) +{ return !element().expression().semantics().evaluate(b, h); } + + + +template<> +Value gologpp::Semantics::evaluate(const Binding &b, const History &h) +{ + switch(element().op()) { + case Comparison::Operator::EQ: + return Value( + get_type(), + element().lhs().semantics().evaluate(b, h) + == element().lhs().semantics().evaluate(b, h) + ); + case Comparison::Operator::NEQ: + return Value( + get_type(), + element().lhs().semantics().evaluate(b, h) + != element().lhs().semantics().evaluate(b, h) + ); + case Comparison::Operator::GE: + return Value( + get_type(), + element().lhs().semantics().evaluate(b, h) + >= element().lhs().semantics().evaluate(b, h) + ); + case Comparison::Operator::LE: + return Value( + get_type(), + element().lhs().semantics().evaluate(b, h) + <= element().lhs().semantics().evaluate(b, h) + ); + case Comparison::Operator::GT: + return Value( + get_type(), + element().lhs().semantics().evaluate(b, h) + > element().lhs().semantics().evaluate(b, h) + ); + case Comparison::Operator::LT: + return Value( + get_type(), + element().lhs().semantics().evaluate(b, h) + < element().lhs().semantics().evaluate(b, h) + ); + } +} + + + +template<> +Value gologpp::Semantics::evaluate(const Binding &b, const History &h) +{ + bool lhs = static_cast(element().lhs().semantics().evaluate(b, h)); + bool rhs = static_cast(element().rhs().semantics().evaluate(b, h)); + + switch (element().op()) { + case BooleanOperator::OR: + return Value(get_type(), lhs || rhs); + case BooleanOperator::AND: + return Value(get_type(), lhs && rhs); + case BooleanOperator::IFF: + return Value(get_type(), lhs == rhs); + case BooleanOperator::XOR: + return Value(get_type(), lhs != rhs); + case BooleanOperator::IMPLIES: + return Value(get_type(), !lhs || rhs); + } +} + + + +template<> +Value gologpp::Semantics::evaluate(const Binding &b, const History &h) { + switch (element().op()) { + case Quantification::Operator::FORALL: + for (const auto &val : element().variable().domain().elements()) { + // TODO: What if domain empty? + Binding b1(b); + b1.bind(element().variable().shared(), *val); + if (!static_cast(element().expression().semantics().evaluate(b1, h))) + return Value(get_type(), false); + } + return Value(get_type(), true); + case Quantification::Operator::EXISTS: + for (const auto &val : element().variable().domain().elements()) { + Binding b1(b); + b1.bind(element().variable().shared(), *val); + if (static_cast(element().expression().semantics().evaluate(b1, h))) + return Value(get_type(), true); + } + return Value(get_type(), false); + } +} + + + +} diff --git a/src/semantics/native/formula.h b/src/semantics/native/formula.h new file mode 100644 index 00000000..b9fc7a07 --- /dev/null +++ b/src/semantics/native/formula.h @@ -0,0 +1,33 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_FORMULA_H_ +#define READYLOG_FORMULA_H_ + +#include "semantics.h" +#include +#include + +namespace gologpp { + + + + +} // namespace gologpp + + +#endif diff --git a/src/semantics/native/history.cpp b/src/semantics/native/history.cpp new file mode 100644 index 00000000..e67b8b42 --- /dev/null +++ b/src/semantics/native/history.cpp @@ -0,0 +1,34 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include + +#include "history.h" +#include "action.h" +#include "execution.h" +#include "utilities.h" +#include "value.h" + +#include +#include + +namespace gologpp { + + + +} // namespace gologpp + diff --git a/src/semantics/native/history.h b/src/semantics/native/history.h new file mode 100644 index 00000000..f896df9f --- /dev/null +++ b/src/semantics/native/history.h @@ -0,0 +1,49 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_HISTORY_H_ +#define READYLOG_HISTORY_H_ + +#include "semantics.h" +#include "utilities.h" +#include + + +namespace gologpp { + + +template<> +class Semantics : public GeneralSemantics { +public: + Semantics(History &); + virtual ~Semantics() override = default; + + virtual shared_ptr get_last_transition() override; + virtual void append(shared_ptr> exog) override; + virtual void append_sensing_result(shared_ptr) override; + virtual bool should_progress() const override; + virtual void progress() override; + +private: + +}; + + + +} // namespace gologpp + +#endif // READYLOG_HISTORY_H_ diff --git a/src/semantics/native/list_expression.cpp b/src/semantics/native/list_expression.cpp new file mode 100644 index 00000000..9e67e948 --- /dev/null +++ b/src/semantics/native/list_expression.cpp @@ -0,0 +1,24 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "list_expression.h" + +namespace gologpp { + + + +} // namespace gologpp diff --git a/src/semantics/native/list_expression.h b/src/semantics/native/list_expression.h new file mode 100644 index 00000000..7011c973 --- /dev/null +++ b/src/semantics/native/list_expression.h @@ -0,0 +1,31 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_LIST_EXPRESSION_H_ +#define READYLOG_LIST_EXPRESSION_H_ + +#include "semantics.h" + +#include + +namespace gologpp { + + + +} + +#endif // READYLOG_LIST_EXPRESSION_H_ diff --git a/src/semantics/native/procedural.cpp b/src/semantics/native/procedural.cpp new file mode 100644 index 00000000..7f25efaf --- /dev/null +++ b/src/semantics/native/procedural.cpp @@ -0,0 +1,50 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "scope.h" +#include "procedural.h" +#include "reference.h" +#include "execution.h" +#include "value.h" +#include "action.h" + +#include + + +namespace gologpp { + + +template<> +unique_ptr Semantics::trans(const Binding &b, History &h) +{ + for (const unique_ptr &instr : element().elements()) + instr->semantics().trans(b, h); +} + +template<> +unique_ptr Semantics::plan(const Binding &b, History &h) +{ + unique_ptr rv; + for (const unique_ptr &instr : element().elements()) { + + } +} + + + + +} diff --git a/src/semantics/native/procedural.h b/src/semantics/native/procedural.h new file mode 100644 index 00000000..a592de66 --- /dev/null +++ b/src/semantics/native/procedural.h @@ -0,0 +1,55 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_PROCEDURE_H_ +#define READYLOG_PROCEDURE_H_ + +#include "semantics.h" +#include "scope.h" +#include "variable.h" +#include "utilities.h" +#include "fluent.h" +#include "reference.h" + +#include +#include + +namespace gologpp { + + + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual unique_ptr trans(const Binding &b, History &h) override; + virtual unique_ptr plan(const Binding &b, History &h) override; + +private: + vector>::const_iterator ip; +}; + + + +} // namespace gologpp + + +#endif // READYLOG_PROCEDURE_H_ diff --git a/src/semantics/native/reference.cpp b/src/semantics/native/reference.cpp new file mode 100644 index 00000000..595ca784 --- /dev/null +++ b/src/semantics/native/reference.cpp @@ -0,0 +1,42 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "reference.h" +#include "variable.h" +#include "history.h" +#include "execution.h" +#include "formula.h" +#include "action.h" + +#include + + +namespace gologpp { + + +unique_ptr Semantics>::trans(const Binding &b, History &h) { +} + + +unique_ptr Semantics>::plan(const Binding &b, History &h) { + Binding merged = element().binding().ground(b); + if (element()->precondition().general_semantics().evaluate(merged, h) != Value(get_type(), true)) + throw NotPossible(); +} + + +} // namespace gologpp diff --git a/src/semantics/native/reference.h b/src/semantics/native/reference.h new file mode 100644 index 00000000..70089797 --- /dev/null +++ b/src/semantics/native/reference.h @@ -0,0 +1,103 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_REFERENCE_H_ +#define READYLOG_REFERENCE_H_ + +#include + +#include +#include +#include +#include + +#include "semantics.h" +#include "utilities.h" +#include "variable.h" + + +namespace gologpp { + +template class Reference; + +class NativeContext; + +template<> +class Semantics> +: public Semantics +, public GeneralSemantics> +{ +public: + using GeneralSemantics>::GeneralSemantics; + virtual Value evaluate(const Binding &b, const History &h) override; +}; + + + +template<> +class Semantics> +: public GeneralSemantics> +, public Semantics +{ +public: + using GeneralSemantics>::GeneralSemantics; + virtual Value evaluate(const Binding &b, const History &h) override; +}; + + + +template<> +class Semantics> +: public GeneralSemantics> +, public Semantics +{ +public: + using GeneralSemantics>::GeneralSemantics; + unique_ptr trans(const Binding &b, History &h) override; +}; + + + +template<> +class Semantics> +: public GeneralSemantics> +, public Semantics +{ +public: + using GeneralSemantics>::GeneralSemantics; + unique_ptr trans(const Binding &b, History &h) override; + unique_ptr plan(const Binding &b, History &h) override; +}; + + + +template<> +class Semantics>; + +template<> +class Semantics>; + +template<> +class Semantics>; + + + +} // namespace gologpp + + + +#endif // READYLOG_REFERENCE_H_ diff --git a/src/semantics/native/scope.cpp b/src/semantics/native/scope.cpp new file mode 100644 index 00000000..2263cbe7 --- /dev/null +++ b/src/semantics/native/scope.cpp @@ -0,0 +1,24 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "scope.h" +#include "variable.h" + +namespace gologpp { + + +} // namespace gologpp diff --git a/src/semantics/native/scope.h b/src/semantics/native/scope.h new file mode 100644 index 00000000..3e1b7337 --- /dev/null +++ b/src/semantics/native/scope.h @@ -0,0 +1,38 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef BACKENDS_READYLOG_SCOPE_H_ +#define BACKENDS_READYLOG_SCOPE_H_ + +#include +#include + +#include "semantics.h" + +namespace gologpp { + + +template<> +class Semantics : public GeneralSemantics { +public: + using GeneralSemantics::GeneralSemantics; +}; + + +} // namespace gologpp + +#endif // BACKENDS_READYLOG_SCOPE_H_ diff --git a/src/semantics/native/semantics.cpp b/src/semantics/native/semantics.cpp new file mode 100644 index 00000000..434cb7f2 --- /dev/null +++ b/src/semantics/native/semantics.cpp @@ -0,0 +1,57 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "semantics.h" +#include "effect_axiom.h" +#include "action.h" +#include "fluent.h" +#include "variable.h" +#include "value.h" +#include "formula.h" +#include "procedural.h" +#include "reference.h" +#include "scope.h" +#include "arithmetic.h" +#include "execution.h" +#include "domain.h" +#include "string.h" +#include "history.h" +#include "compound_expression.h" +#include "list_expression.h" + +namespace gologpp { + + + +#define GOLOGPP_DEFINE_MAKE_SEMANTICS_IMPL(_r, _data, GologT) \ +unique_ptr> NativeSemanticsFactory::make_semantics(GologT &obj) \ +{ return unique_ptr>(new Semantics(obj, context())); } + +BOOST_PP_SEQ_FOR_EACH(GOLOGPP_DEFINE_MAKE_SEMANTICS_IMPL, (), GOLOGPP_SEMANTIC_TYPES) + + +unique_ptr Semantics::plan(const Binding &b, History &h) +{ + +} + + + +} // namespace gologpp + + + diff --git a/src/semantics/native/semantics.h b/src/semantics/native/semantics.h new file mode 100644 index 00000000..3d622a77 --- /dev/null +++ b/src/semantics/native/semantics.h @@ -0,0 +1,107 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_IMPLEMENTATION_H_ +#define READYLOG_IMPLEMENTATION_H_ + +#include +#include + +#include + +namespace gologpp { + + +template +using enable_if_subclass = std::enable_if < + std::is_base_of::value, + TArg +>; + + +template<> +class Semantics +: public virtual GeneralSemantics +{ +public: + virtual ~Semantics() override = default; +}; + + +template<> +class Semantics +: public GeneralSemantics +, public Semantics +{ +public: + virtual Value evaluate(const Binding &context, const History &h) override; + virtual const Expression &expression() const override; +}; + + +template<> +class Semantics +: public GeneralSemantics +, public Semantics +{ +public: + virtual unique_ptr plan(const Binding &b, History &h); + virtual bool final(const Binding &b, const History &h) override; + virtual const Instruction &instruction() const override; +}; + + +template +class Semantics +: public Semantics +{ +public: + typename std::enable_if < std::is_base_of::value, + Value + >::type evaluate(const Binding &b, const History &h) override; + + typename enable_if_subclass< GologT, Instruction, + unique_ptr + >::type trans(const Binding &b, History &h) override; + + const GologT &element() const; +}; + + + +using EvaluationSemantics = Semantics; +using TransitionSemantics = Semantics; + +#define GOLOGPP_DECL_MAKE_SEMANTICS_OVERRIDE(_r, _data, GologT) \ + virtual unique_ptr> make_semantics(GologT &) override; + + +class NativeSemanticsFactory : public SemanticsFactory { +public: + NativeSemanticsFactory(unique_ptr &&psf); + virtual ~NativeSemanticsFactory() override = default; + + BOOST_PP_SEQ_FOR_EACH(GOLOGPP_DECL_MAKE_SEMANTICS_OVERRIDE, (), GOLOGPP_SEMANTIC_TYPES) +}; + + + +} // namespace gologpp + + + +#endif diff --git a/src/semantics/native/string.cpp b/src/semantics/native/string.cpp new file mode 100644 index 00000000..3c206127 --- /dev/null +++ b/src/semantics/native/string.cpp @@ -0,0 +1,25 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "string.h" + +namespace gologpp { + + + + +} diff --git a/src/semantics/native/string.h b/src/semantics/native/string.h new file mode 100644 index 00000000..57e085ce --- /dev/null +++ b/src/semantics/native/string.h @@ -0,0 +1,52 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_STRING_CONCATENATION_H_ +#define READYLOG_STRING_CONCATENATION_H_ + +#include "semantics.h" + +#include + +namespace gologpp { + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual Value evaluate(const History &h) override; +}; + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual Value evaluate(const History &h) override; +}; + + +} + +#endif // READYLOG_STRING_CONCATENATION_H_ diff --git a/src/semantics/native/utilities.cpp b/src/semantics/native/utilities.cpp new file mode 100644 index 00000000..2b77b7e5 --- /dev/null +++ b/src/semantics/native/utilities.cpp @@ -0,0 +1,24 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "utilities.h" + + +namespace gologpp { + + +} diff --git a/src/semantics/native/utilities.h b/src/semantics/native/utilities.h new file mode 100644 index 00000000..e0d7a532 --- /dev/null +++ b/src/semantics/native/utilities.h @@ -0,0 +1,49 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_UTILITIES_H_ +#define READYLOG_UTILITIES_H_ + +#include +#include +#include + +namespace gologpp { + + +template inline +T &access(T *ptr) +{ return *ptr; } + +template inline +T &access(const unique_ptr &ptr) +{ return *ptr; } + +template inline +const Expression &access(const SafeExprOwner &ptr) +{ return *ptr; } + +template inline +typename std::enable_if::value, T>::type +&access(T &&ptr) +{ return std::forward(ptr); } + + + +} // namespace gologpp + +#endif // READYLOG_UTILITIES_H_ diff --git a/src/semantics/native/value.cpp b/src/semantics/native/value.cpp new file mode 100644 index 00000000..23a249f1 --- /dev/null +++ b/src/semantics/native/value.cpp @@ -0,0 +1,26 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "value.h" +#include "execution.h" +#include + +namespace gologpp { + + + +} // namespace gologpp diff --git a/src/semantics/native/value.h b/src/semantics/native/value.h new file mode 100644 index 00000000..45e4c4bf --- /dev/null +++ b/src/semantics/native/value.h @@ -0,0 +1,47 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_CONSTANT_H_ +#define READYLOG_CONSTANT_H_ + +#include "semantics.h" + +#include +#include + + +namespace gologpp { + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; + + virtual Value evaluate(const Binding &b, const History &h) override; + virtual GeneralSemantics *copy(const Value &target_element) const override; +}; + + + +} // namespace gologpp + +#endif // READYLOG_CONSTANT_H_ diff --git a/src/semantics/native/variable.cpp b/src/semantics/native/variable.cpp new file mode 100644 index 00000000..17cc9a69 --- /dev/null +++ b/src/semantics/native/variable.cpp @@ -0,0 +1,27 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "variable.h" +#include "reference.h" +#include "domain.h" + +namespace gologpp { + + + + +} // namespace gologpp diff --git a/src/semantics/native/variable.h b/src/semantics/native/variable.h new file mode 100644 index 00000000..48d29bd9 --- /dev/null +++ b/src/semantics/native/variable.h @@ -0,0 +1,45 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#ifndef READYLOG_VARIABLE_H_ +#define READYLOG_VARIABLE_H_ + +#include "semantics.h" + +#include +#include + + +namespace gologpp { + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual Value evaluate(const Binding &b, const History &h) override; +}; + + + + +} // namespace gologpp + +#endif // READYLOG_VARIABLE_H_ diff --git a/src/tools/nativegpp-test.cpp b/src/tools/nativegpp-test.cpp new file mode 100644 index 00000000..ae2600dc --- /dev/null +++ b/src/tools/nativegpp-test.cpp @@ -0,0 +1,71 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + + +using namespace gologpp; + + +void test_parser(const string &filename) +{ + Instruction *mainproc = parser::parse_file(filename).release(); + + for (shared_ptr g : global_scope().globals()) + std::cout << g->str() << std::endl; + + std::cout << mainproc->str() << std::endl; + + NativeContext::init(); + NativeContext &ctx = NativeContext::instance(); + + ctx.run(Block( + new Scope(global_scope()), + { mainproc } + )); + + NativeContext::shutdown(); +} + + + +int main(int argc, const char **argv) +{ + string filename = SOURCE_DIR "/examples/blocksworld.gpp"; + if (argc > 1) + filename = argv[1]; + test_parser(filename); + + return 0; +} + + + + + From 820e7b8c1754ec55731142234af16de471e82954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Sat, 30 Jan 2021 01:45:38 +0100 Subject: [PATCH 02/33] cmake: fix native semantics integration --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 275b6434..1d7355bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -451,9 +451,7 @@ endif(BUILD_TAPTENC_SEMANTICS) # The golog++ native semantics: libnativegolog++.so ###################################################################################### -if (${ECLIPSE_FOUND}) - option(BUILD_NATIVE_IMPL "Build the native golog++ semantics" OFF) -endif() +option(BUILD_NATIVE_IMPL "Build the native golog++ semantics" OFF) if (${BUILD_NATIVE_IMPL}) set(NATIVE_SRC src/semantics/native/action.cpp @@ -516,7 +514,7 @@ if (${BUILD_NATIVE_IMPL}) DESTINATION ${SEMANTICS_INSTALL_DIR}/native ) - get_target_property(NATIVEGPP_CXXFLAGS_L readylog++ INTERFACE_COMPILE_OPTIONS) + get_target_property(NATIVEGPP_CXXFLAGS_L nativegolog++ INTERFACE_COMPILE_OPTIONS) set(NATIVEGPP_CXXFLAGS "-I${ECLIPSE_INCLUDE_DIRS}") if (${NATIVEGPP_CXXFLAGS_L}) foreach(i IN LISTS ${NATIVEGPP_CXXFLAGS_L}) From 5765fe717ce6056e28173f83918248bb6af19c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Sat, 30 Jan 2021 01:46:33 +0100 Subject: [PATCH 03/33] cmake: rename NATIVE_IMPL -> NATIVE_SEMANTICS --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d7355bc..4f3e773b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -451,8 +451,8 @@ endif(BUILD_TAPTENC_SEMANTICS) # The golog++ native semantics: libnativegolog++.so ###################################################################################### -option(BUILD_NATIVE_IMPL "Build the native golog++ semantics" OFF) -if (${BUILD_NATIVE_IMPL}) +option(BUILD_NATIVE_SEMANTICS "Build the native golog++ semantics" OFF) +if (${BUILD_NATIVE_SEMANTICS}) set(NATIVE_SRC src/semantics/native/action.cpp src/semantics/native/variable.cpp @@ -568,7 +568,7 @@ endif() -if (${BUILD_NATIVE_IMPL}) +if (${BUILD_NATIVE_SEMANTICS}) set(NATIVE_TEST_SRC src/tools/nativegpp-test.cpp) add_executable(nativegpp-test ${NATIVE_TEST_SRC}) From c8cfc04d789d45bb7f6eac47b58ccaf523bff1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 26 Jul 2021 00:49:12 +0200 Subject: [PATCH 04/33] model: cleanup old/unused code --- CMakeLists.txt | 132 ++++++++++++++++++++++-------------------- src/model/gologpp.h | 25 -------- src/model/reference.h | 13 ----- 3 files changed, 69 insertions(+), 101 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f3e773b..a0d21e8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -383,69 +383,6 @@ if (${BUILD_READYLOG_SEMANTICS}) endif() -if (BUILD_TAPTENC_SEMANTICS) - set(TAPTENC_SRC - external/taptenc/src/constraints/constraints.cpp - external/taptenc/src/encoder/direct_encoder.cpp - external/taptenc/src/encoder/enc_interconnection_info.cpp - external/taptenc/src/encoder/encoder_utils.cpp - external/taptenc/src/encoder/filter.cpp - external/taptenc/src/encoder/modular_encoder.cpp - external/taptenc/src/encoder/plan_ordered_tls.cpp - external/taptenc/src/parser/utap_trace_parser.cpp - external/taptenc/src/printer/xml_printer.cpp - external/taptenc/src/printer/xta_printer.cpp - external/taptenc/src/timed-automata/timed_automata.cpp - external/taptenc/src/timed-automata/vis_info.cpp - external/taptenc/src/platform_model_generator.cpp - external/taptenc/src/transformation.cpp - external/taptenc/src/uppaal_calls.cpp - external/taptenc/src/utils.cpp - ) - - set(TAPTENC_SEMANTICS_SRC - src/semantics/platform/taptenc/semantics.cpp - src/semantics/platform/taptenc/clock_formula.cpp - src/semantics/platform/taptenc/component.cpp - src/semantics/platform/taptenc/constraint.cpp - src/semantics/platform/taptenc/reference.cpp - src/semantics/platform/taptenc/transformation.cpp - ) - - set(TAPTENC_INCLUDE_PATHS - external/taptenc/src/constraints - external/taptenc/src/encoder - external/taptenc/src/parser - external/taptenc/src/printer - external/taptenc/src/timed-automata - external/taptenc/src - ) - - add_library(taptenc-golog++ SHARED ${TAPTENC_SRC} ${TAPTENC_SEMANTICS_SRC}) - target_include_directories(taptenc-golog++ PUBLIC ${TAPTENC_INCLUDE_PATHS}) - set_property(TARGET taptenc-golog++ PROPERTY SOVERSION ${GOLOGPP_VERSION}) - target_include_directories(taptenc-golog++ PUBLIC external) - target_compile_options(taptenc-golog++ PRIVATE -std=c++17) - set(TEST_LIBS ${TEST_LIBS} taptenc-golog++) - - add_executable(taptenc_rcll_perception external/taptenc/src/rcll_perception.cpp ${TAPTENC_SRC}) - target_include_directories(taptenc_rcll_perception PRIVATE ${TAPTENC_INCLUDE_PATHS}) - target_compile_options(taptenc_rcll_perception PRIVATE -std=c++17) - if (USE_LIBASAN) - target_link_libraries(taptenc_rcll_perception asan) - endif() - - target_link_libraries(golog++ taptenc-golog++) - - set_property(TARGET taptenc-golog++ PROPERTY SOVERSION ${GOLOGPP_VERSION}) - install(TARGETS taptenc-golog++ DESTINATION ${CMAKE_INSTALL_LIBDIR}) - -else(BUILD_TAPTENC_SEMANTICS) - target_compile_definitions(golog++ PRIVATE USE_DUMMY_PLATFORM) - -endif(BUILD_TAPTENC_SEMANTICS) - - ###################################################################################### # The golog++ native semantics: libnativegolog++.so @@ -527,6 +464,75 @@ if (${BUILD_NATIVE_SEMANTICS}) endif() + +###################################################################################### +# The taptenc semantics for platform modeling +###################################################################################### + +if (BUILD_TAPTENC_SEMANTICS) + set(TAPTENC_SRC + external/taptenc/src/constraints/constraints.cpp + external/taptenc/src/encoder/direct_encoder.cpp + external/taptenc/src/encoder/enc_interconnection_info.cpp + external/taptenc/src/encoder/encoder_utils.cpp + external/taptenc/src/encoder/filter.cpp + external/taptenc/src/encoder/modular_encoder.cpp + external/taptenc/src/encoder/plan_ordered_tls.cpp + external/taptenc/src/parser/utap_trace_parser.cpp + external/taptenc/src/printer/xml_printer.cpp + external/taptenc/src/printer/xta_printer.cpp + external/taptenc/src/timed-automata/timed_automata.cpp + external/taptenc/src/timed-automata/vis_info.cpp + external/taptenc/src/platform_model_generator.cpp + external/taptenc/src/transformation.cpp + external/taptenc/src/uppaal_calls.cpp + external/taptenc/src/utils.cpp + ) + + set(TAPTENC_SEMANTICS_SRC + src/semantics/platform/taptenc/semantics.cpp + src/semantics/platform/taptenc/clock_formula.cpp + src/semantics/platform/taptenc/component.cpp + src/semantics/platform/taptenc/constraint.cpp + src/semantics/platform/taptenc/reference.cpp + src/semantics/platform/taptenc/transformation.cpp + ) + + set(TAPTENC_INCLUDE_PATHS + external/taptenc/src/constraints + external/taptenc/src/encoder + external/taptenc/src/parser + external/taptenc/src/printer + external/taptenc/src/timed-automata + external/taptenc/src + ) + + add_library(taptenc-golog++ SHARED ${TAPTENC_SRC} ${TAPTENC_SEMANTICS_SRC}) + target_include_directories(taptenc-golog++ PUBLIC ${TAPTENC_INCLUDE_PATHS}) + set_property(TARGET taptenc-golog++ PROPERTY SOVERSION ${GOLOGPP_VERSION}) + target_include_directories(taptenc-golog++ PUBLIC external) + target_compile_options(taptenc-golog++ PRIVATE -std=c++17) + set(TEST_LIBS ${TEST_LIBS} taptenc-golog++) + + add_executable(taptenc_rcll_perception external/taptenc/src/rcll_perception.cpp ${TAPTENC_SRC}) + target_include_directories(taptenc_rcll_perception PRIVATE ${TAPTENC_INCLUDE_PATHS}) + target_compile_options(taptenc_rcll_perception PRIVATE -std=c++17) + if (USE_LIBASAN) + target_link_libraries(taptenc_rcll_perception asan) + endif() + + target_link_libraries(golog++ taptenc-golog++) + + set_property(TARGET taptenc-golog++ PROPERTY SOVERSION ${GOLOGPP_VERSION}) + install(TARGETS taptenc-golog++ DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +else(BUILD_TAPTENC_SEMANTICS) + target_compile_definitions(golog++ PRIVATE USE_DUMMY_PLATFORM) + +endif(BUILD_TAPTENC_SEMANTICS) + + + ###################################################################################### # Testing (requires parser & readylog semantics) ###################################################################################### diff --git a/src/model/gologpp.h b/src/model/gologpp.h index dbca2eaf..f73253e9 100644 --- a/src/model/gologpp.h +++ b/src/model/gologpp.h @@ -286,31 +286,6 @@ class SemanticsFactory; GOLOGPP_OTHER -/* -using elem_types = boost::mpl::map < -boost::mpl::pair>, Instruction>, -boost::mpl::pair>, Instruction>, -boost::mpl::pair, Instruction>, -boost::mpl::pair, Instruction>, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, -boost::mpl::pair, Instruction>, -boost::mpl::pair, -boost::mpl::pair, Instruction>, -boost::mpl::pair, Instruction>, -boost::mpl::pair, -boost::mpl::pair, Instruction>, -boost::mpl::pair, -boost::mpl::pair - ->;*/ } // namespace gologpp diff --git a/src/model/reference.h b/src/model/reference.h index 814ab926..b7bb31fe 100644 --- a/src/model/reference.h +++ b/src/model/reference.h @@ -312,19 +312,6 @@ class Reference } } - unique_ptr> ground_args(const Binding &b, const History &h) const - { - Binding gb; - for (auto &pair : this->binding().map()) - gb.bind( - pair.first, - unique_ptr(new Value( - std::move(pair.second->general_semantics().evaluate(b, h)) - )) - ); - return unique_ptr>(new Reference(this->target(), std::move(gb))); - } - }; ///////////////////////////////////////////////////////////////////////////////////////////////// From b714fe92249cc18a78e857241febeeb08146d654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 26 Jul 2021 00:51:09 +0200 Subject: [PATCH 05/33] model: refactor semantics interface In preparation for the native semantics, we need more flexibility in defining generic template instantiations for the Semantics classes. This brings some minor incompatibilities for semantics implementations that use partial specializations for things like Reference and EffectAxiom. --- src/model/effect_axiom.h | 4 +- src/model/gologpp.h | 8 +-- src/model/model_element.h | 2 +- src/model/reference.cpp | 3 ++ src/model/reference.h | 1 + src/model/semantics.h | 100 +++++++++++++++++++++++++++++++++++++- 6 files changed, 110 insertions(+), 8 deletions(-) diff --git a/src/model/effect_axiom.h b/src/model/effect_axiom.h index 628ac0f7..a9130127 100644 --- a/src/model/effect_axiom.h +++ b/src/model/effect_axiom.h @@ -39,6 +39,8 @@ class AbstractEffectAxiom : public virtual AbstractLanguageElement { public: + using ElementType = ModelElement; + AbstractEffectAxiom(); AbstractEffectAxiom(AbstractEffectAxiom &&) = default; virtual ~AbstractEffectAxiom(); @@ -63,8 +65,6 @@ class EffectAxiom , public LanguageElement> { public: - using ElementType = ModelElement; - EffectAxiom() {} diff --git a/src/model/gologpp.h b/src/model/gologpp.h index f73253e9..5eb7260c 100644 --- a/src/model/gologpp.h +++ b/src/model/gologpp.h @@ -43,6 +43,8 @@ template using optional = std::optional; using std::nullopt; +template +using enable_if = typename std::enable_if::type; using string = std::string; @@ -143,8 +145,8 @@ class ListExpression; class History; -template class Semantics; -template class GeneralSemantics; +template class Semantics; +template class GeneralSemantics; class SemanticsFactory; @@ -216,6 +218,7 @@ class SemanticsFactory; (DurativeCall) \ (Reference) \ (ListPop) \ + (Transition) \ (ListPush) #define GOLOGPP_EXPRESSIONS \ @@ -251,7 +254,6 @@ class SemanticsFactory; (Procedure) \ (Action) \ (Activity) \ - (Transition) \ (ExogAction) \ (Scope) \ (History) diff --git a/src/model/model_element.h b/src/model/model_element.h index 2596c724..1e4d6c4a 100644 --- a/src/model/model_element.h +++ b/src/model/model_element.h @@ -48,7 +48,7 @@ class ModelElement { /// @return The implementation-specific semantics of this model element. /// This method cannot be called (or even instantiated) from the code model context. It /// can only be instantiated and called from the semantics implementation. - template + template Semantics &semantics() const { return dynamic_cast &>(*semantics_); } diff --git a/src/model/reference.cpp b/src/model/reference.cpp index 87d63ccf..a788a29e 100644 --- a/src/model/reference.cpp +++ b/src/model/reference.cpp @@ -102,6 +102,9 @@ void Reference::attach_semantics(SemanticsFactory &implementor) semantics_ = implementor.make_semantics(*this); } +const ModelElement &GeneralSemantics::model_element() const +{ return *element_; } + } diff --git a/src/model/reference.h b/src/model/reference.h index b7bb31fe..f27d9042 100644 --- a/src/model/reference.h +++ b/src/model/reference.h @@ -77,6 +77,7 @@ class GeneralSemantics const Binding &element() const; void update_element(const Binding *new_element); virtual AExecutionController &context() const override; + virtual const ModelElement &model_element() const override; virtual GeneralSemantics *copy(const Binding &target_element) const = 0; diff --git a/src/model/semantics.h b/src/model/semantics.h index c5ab1eab..9fc66156 100644 --- a/src/model/semantics.h +++ b/src/model/semantics.h @@ -23,17 +23,112 @@ #include "expressions.h" #include +#include #include namespace gologpp { +/** + * @brief Partially specialize this to true for certain templated GologTs (i.e. Reference, EffectAxiom...) + * if you have generic definitions for Semantics, but also want to supply certain + * partial specializations. + * Use it as a condition in the enable_if that gives Cond to prevent the ambiguous partial specialization + * errors that would otherwise occur. + */ +template +static constexpr bool partially_specialized = false; + +template +static constexpr bool is_instruction = std::is_base_of::value; + +template +static constexpr bool is_expression = std::is_base_of::value; + + ///////////////////////////////////////////////////////////////////////////////////////////////// /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// template -class GeneralSemantics +class GeneralSemantics>> +: public virtual GeneralSemantics +{ +public: + GeneralSemantics(const GologT &elem, AExecutionController &context) + : element_(&elem) + , context_(context) + {} + + virtual ~GeneralSemantics() = default; + + /// @return A reference to the concrete language element (code model element) covered by this + /// semantics instance + template + const GologT &element() const + { return *element_; } + + virtual AExecutionController &context() const override + { return context_; } + + void update_element(const GologT *new_element) + { element_ = new_element; } + + virtual const ModelElement &model_element() const override + { return *element_; } + + virtual const Instruction &instruction() const override + { return *element_; } + +private: + const GologT *element_; + AExecutionController &context_; +}; + + + +template +class GeneralSemantics>> +: public virtual GeneralSemantics +{ +public: + GeneralSemantics(const GologT &elem, AExecutionController &context) + : element_(&elem) + , context_(context) + {} + + virtual ~GeneralSemantics() = default; + + /// @return A reference to the concrete language element (code model element) covered by this + /// semantics instance + template + const GologT &element() const + { return *element_; } + + virtual AExecutionController &context() const override + { return context_; } + + void update_element(const GologT *new_element) + { element_ = new_element; } + + virtual const ModelElement &model_element() const override + { return *element_; } + + virtual const Expression &expression() const override + { return *element_; } + +private: + const GologT *element_; + AExecutionController &context_; +}; + + + +template +class GeneralSemantics + && !is_instruction +> > : public virtual GeneralSemantics { public: @@ -42,7 +137,7 @@ class GeneralSemantics , context_(context) {} - virtual ~GeneralSemantics() = default; + virtual ~GeneralSemantics() = default; /// @return A reference to the concrete language element (code model element) covered by this /// semantics instance @@ -68,6 +163,7 @@ class GeneralSemantics /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// +/// declare pure virtual make_semantics(...) #define GOLOGPP_DECLARE_ABSTRACT_MAKE_SEMANTICS(r, data, T) \ virtual unique_ptr> make_semantics(T &) = 0; From 0187cdb6f0b4414621d7023371e17d780043386f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 26 Jul 2021 01:16:04 +0200 Subject: [PATCH 06/33] ReadylogSemantics: adapt to changed semantics interface some cleanup along the way --- src/semantics/readylog/action.cpp | 10 +--- src/semantics/readylog/action.h | 10 +--- src/semantics/readylog/activity.h | 2 +- src/semantics/readylog/domain.h | 2 +- src/semantics/readylog/effect_axiom.cpp | 8 +-- src/semantics/readylog/effect_axiom.h | 14 ++--- src/semantics/readylog/execution.h | 2 +- src/semantics/readylog/fluent.cpp | 1 + src/semantics/readylog/fluent.h | 15 +---- src/semantics/readylog/history.cpp | 4 +- src/semantics/readylog/history.h | 2 +- src/semantics/readylog/procedural.h | 6 +- src/semantics/readylog/reference.cpp | 16 ++++-- src/semantics/readylog/reference.h | 43 +++++--------- src/semantics/readylog/semantics.cpp | 19 ++----- src/semantics/readylog/semantics.h | 74 ++++++++++++++++++------- src/semantics/readylog/value.h | 5 +- src/semantics/readylog/variable.h | 3 +- 18 files changed, 113 insertions(+), 123 deletions(-) diff --git a/src/semantics/readylog/action.cpp b/src/semantics/readylog/action.cpp index d507a1d8..ca6aeb6f 100644 --- a/src/semantics/readylog/action.cpp +++ b/src/semantics/readylog/action.cpp @@ -65,7 +65,7 @@ vector Semantics::durative_causes_vals() { vector rv; for (const unique_ptr &effect : element().effects()) - rv.push_back(effect->semantics().plterm()); + rv.push_back(effect->semantics().plterm()); return rv; } @@ -109,7 +109,7 @@ vector Semantics::causes_vals() { vector rv; for (const unique_ptr &effect : element().effects()) - rv.push_back(effect->semantics().plterm()); + rv.push_back(effect->semantics().plterm()); return rv; } @@ -124,11 +124,5 @@ EC_word Semantics::poss() -template<> -EC_word Semantics>::plterm() -{ return reference_term(element()); } - - - } // namespace gologpp diff --git a/src/semantics/readylog/action.h b/src/semantics/readylog/action.h index 23f51c74..6d756c5c 100644 --- a/src/semantics/readylog/action.h +++ b/src/semantics/readylog/action.h @@ -28,15 +28,9 @@ namespace gologpp { -template<> -class Semantics -: public ReadylogSemantics { -}; - - template<> class Semantics -: public Semantics +: public Semantics , public GeneralSemantics { public: @@ -54,7 +48,7 @@ class Semantics template<> class Semantics -: public Semantics +: public Semantics , public GeneralSemantics { public: diff --git a/src/semantics/readylog/activity.h b/src/semantics/readylog/activity.h index 32d36d8b..30926557 100644 --- a/src/semantics/readylog/activity.h +++ b/src/semantics/readylog/activity.h @@ -25,7 +25,7 @@ namespace gologpp { template<> class Semantics -: public Semantics +: public Semantics , public GeneralSemantics { public: diff --git a/src/semantics/readylog/domain.h b/src/semantics/readylog/domain.h index 267d4163..4d6d982c 100644 --- a/src/semantics/readylog/domain.h +++ b/src/semantics/readylog/domain.h @@ -28,7 +28,7 @@ namespace gologpp { template<> class Semantics -: public ReadylogSemantics +: public Semantics , public GeneralSemantics { public: diff --git a/src/semantics/readylog/effect_axiom.cpp b/src/semantics/readylog/effect_axiom.cpp index 2774f417..da0e3cd8 100644 --- a/src/semantics/readylog/effect_axiom.cpp +++ b/src/semantics/readylog/effect_axiom.cpp @@ -50,8 +50,8 @@ EC_word Semantics>>::plterm() } return ::term(EC_functor(cv_functor(element()).c_str(), 4), - element().action().semantics().plterm(), - element().lhs().semantics>().plterm_free_args(), + element().action().semantics().plterm(), + element().lhs().special_semantics().plterm_free_args(), element().value().semantics().plterm(), condition_term ); @@ -75,7 +75,7 @@ EC_word Semantics>::plterm() } return ::term(EC_functor(cv_functor(element()).c_str(), 4), - element().action().semantics().plterm(), + element().action().semantics().plterm(), fluent_access.first->special_semantics().plterm_free_args(), ::term(EC_functor("gpp_mixed_assign", 3), fluent_access.second, @@ -104,7 +104,7 @@ EC_word Semantics>::plterm() } return ::term(EC_functor(cv_functor(element()).c_str(), 4), - element().action().semantics().plterm(), + element().action().semantics().plterm(), fluent_access.first->special_semantics().plterm_free_args(), ::term(EC_functor("gpp_mixed_assign", 3), fluent_access.second, diff --git a/src/semantics/readylog/effect_axiom.h b/src/semantics/readylog/effect_axiom.h index 98876b4b..ab52396d 100644 --- a/src/semantics/readylog/effect_axiom.h +++ b/src/semantics/readylog/effect_axiom.h @@ -34,16 +34,12 @@ namespace gologpp { -template<> -class Semantics -: public ReadylogSemantics -{ -}; - +template +bool partially_specialized> = true; template -class Semantics> -: public Semantics +class Semantics, void> +: public Semantics , public GeneralSemantics> { public: @@ -52,6 +48,8 @@ class Semantics> virtual EC_word plterm() override; }; + + } /* namespace gologpp */ #endif /* READYLOG_EFFECTAXIOM_H_ */ diff --git a/src/semantics/readylog/execution.h b/src/semantics/readylog/execution.h index a12a944f..f428a3d5 100644 --- a/src/semantics/readylog/execution.h +++ b/src/semantics/readylog/execution.h @@ -69,7 +69,7 @@ class ReadylogContext : public ExecutionController { unique_ptr &&transformation ); - virtual void compile_term(const EC_word &term); + void compile_term(const EC_word &term); std::string find_readylog(); std::string find_boilerplate(); void mark_vars_dead(); diff --git a/src/semantics/readylog/fluent.cpp b/src/semantics/readylog/fluent.cpp index e02ea8f8..9a4015a4 100644 --- a/src/semantics/readylog/fluent.cpp +++ b/src/semantics/readylog/fluent.cpp @@ -62,6 +62,7 @@ int p_exog_fluent_getValue() namespace gologpp { +template<> EC_word Semantics::plterm() { EC_word fluent_inst; diff --git a/src/semantics/readylog/fluent.h b/src/semantics/readylog/fluent.h index 5e0ec352..ec7cbe1d 100644 --- a/src/semantics/readylog/fluent.h +++ b/src/semantics/readylog/fluent.h @@ -27,27 +27,16 @@ namespace gologpp { -template<> -class Semantics -: public ReadylogSemantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - - virtual EC_word plterm() override; -}; - - template<> class Semantics : public GeneralSemantics +, public Semantics { public: using GeneralSemantics::GeneralSemantics; virtual ~Semantics() override = default; - EC_word plterm(); + virtual EC_word plterm() override; vector initially(); EC_word prim_fluent(); }; diff --git a/src/semantics/readylog/history.cpp b/src/semantics/readylog/history.cpp index c0ce60c4..52f7bd9d 100644 --- a/src/semantics/readylog/history.cpp +++ b/src/semantics/readylog/history.cpp @@ -64,10 +64,10 @@ shared_ptr Semantics::get_last_transition() void Semantics::append(const Transition &trans) -{ extend_history(::list(trans.semantics().plterm(), plterm())); } +{ extend_history(::list(trans.semantics().plterm(), plterm())); } void Semantics::append(const Reference &trans) -{ extend_history(::list(trans.semantics().plterm(), plterm())); } +{ extend_history(::list(trans.semantics().plterm(), plterm())); } void Semantics::append_sensing_result( diff --git a/src/semantics/readylog/history.h b/src/semantics/readylog/history.h index f92efe8b..46a9b627 100644 --- a/src/semantics/readylog/history.h +++ b/src/semantics/readylog/history.h @@ -30,7 +30,7 @@ namespace gologpp { template<> class Semantics : public GeneralSemantics -, public ReadylogSemantics +, public Semantics { public: Semantics(History &, ReadylogContext &context); diff --git a/src/semantics/readylog/procedural.h b/src/semantics/readylog/procedural.h index 39dab27a..89ee0ceb 100644 --- a/src/semantics/readylog/procedural.h +++ b/src/semantics/readylog/procedural.h @@ -42,7 +42,7 @@ namespace gologpp { template<> class Semantics -: public ReadylogSemantics +: public Semantics , public GeneralSemantics { public: @@ -59,7 +59,7 @@ class Semantics template<> class Semantics -: public ReadylogSemantics +: public Semantics , public GeneralSemantics { public: @@ -73,7 +73,7 @@ class Semantics template<> class Semantics -: public ReadylogSemantics +: public Semantics , public GeneralSemantics { public: diff --git a/src/semantics/readylog/reference.cpp b/src/semantics/readylog/reference.cpp index 13fce4c8..dc9f7c3a 100644 --- a/src/semantics/readylog/reference.cpp +++ b/src/semantics/readylog/reference.cpp @@ -41,7 +41,14 @@ EC_word Semantics>::plterm() } -EC_word gologpp::Semantics::plterm() + +template<> +EC_word Semantics>::plterm() +{ return reference_term(element()); } + + + +EC_word Semantics::plterm() { if (this->element().map().empty()) return EC_atom("true"); @@ -63,9 +70,6 @@ EC_word gologpp::Semantics::plterm() Semantics *Semantics::copy(const Binding &target_element) const { return new Semantics(target_element, rl_context()); } -const Binding &Semantics::model_element() const -{ return this->element(); } - EC_word pl_binding_chain(const BindingChain &bc) @@ -81,10 +85,10 @@ EC_word pl_binding_chain(const BindingChain &bc) EC_word Semantics >::plterm() { return reference_term(this->element()); } -Value gologpp::Semantics >::evaluate(const BindingChain &bc, const History &h) +Value Semantics >::evaluate(const BindingChain &bc, const History &h) { return GeneralSemantics>::evaluate(bc, h); } -const Expression &gologpp::Semantics >::expression() const +const Expression &Semantics >::expression() const { return GeneralSemantics>::expression(); } diff --git a/src/semantics/readylog/reference.h b/src/semantics/readylog/reference.h index 222ab2ab..dc99d3ea 100644 --- a/src/semantics/readylog/reference.h +++ b/src/semantics/readylog/reference.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "semantics.h" #include "utilities.h" @@ -36,8 +37,6 @@ namespace gologpp { -template class Reference; - EC_word pl_binding_chain(const BindingChain &b); @@ -45,14 +44,13 @@ EC_word pl_binding_chain(const BindingChain &b); template<> class Semantics : public GeneralSemantics -, public ReadylogSemantics +, public Semantics { public: using GeneralSemantics::GeneralSemantics; virtual EC_word plterm() override; virtual Semantics *copy(const Binding &target_element) const override; - virtual const Binding &model_element() const override; }; @@ -72,18 +70,16 @@ EC_word reference_term(const ReferenceBase &ref) EC_word reference_term(const Reference &ref); -template<> -class Semantics -{ -public: - virtual EC_word plterm() = 0; -}; +/// Disambiguate this against the generic Semantics, which +/// is also a partial specialization but requires this to be false in Cond. +template +bool partially_specialized> = true; template -class ReferenceSemantics +class Semantics> : public GeneralSemantics> -, public Semantics +, public Semantics::ElementType> { public: using GeneralSemantics>::GeneralSemantics; @@ -134,16 +130,19 @@ class ReferenceSemantics return ::term(EC_functor("and", 1), list); } + + virtual EC_word plterm() override + { return reference_term(this->element()); } }; template<> class Semantics> -: public ReferenceSemantics -, public Semantics::ElementType> +: public GeneralSemantics> +, public Semantics { public: - using ReferenceSemantics::ReferenceSemantics; + using GeneralSemantics>::GeneralSemantics; virtual EC_word plterm() override; virtual Value evaluate(const BindingChain &bc, const History &h) override; @@ -153,20 +152,6 @@ class Semantics> -template -class Semantics> -: public ReferenceSemantics -, public Semantics::ElementType> -{ -public: - using ReferenceSemantics::ReferenceSemantics; - - virtual EC_word plterm() override - { return reference_term(this->element()); } -}; - - - } // namespace gologpp diff --git a/src/semantics/readylog/semantics.cpp b/src/semantics/readylog/semantics.cpp index aee0ec44..52e2aa80 100644 --- a/src/semantics/readylog/semantics.cpp +++ b/src/semantics/readylog/semantics.cpp @@ -58,14 +58,12 @@ unique_ptr SemanticsFactory::construct() /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -ReadylogContext &ReadylogSemantics::rl_context() const -{ return dynamic_cast(context()); } +ReadylogContext &Semantics::rl_context() const +{ return dynamic_cast(context()); } + -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// Value Semantics::evaluate(const BindingChain &b, const History &h) { @@ -102,9 +100,6 @@ Value Semantics::evaluate(const BindingChain &b, const History &h) } } -const Expression &Semantics::expression() const -{ return dynamic_cast(model_element()); } - ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -179,7 +174,7 @@ unique_ptr Semantics::trans(const BindingChain &, History &hi } -EC_word gologpp::Semantics::next_readylog_term() +EC_word Semantics::next_readylog_term() { if (!next_readylog_term_.initialized()) next_readylog_term_ = plterm(); @@ -187,7 +182,7 @@ EC_word gologpp::Semantics::next_readylog_term() } -bool Semantics::final(const BindingChain &b, const History &h) +bool Semantics::final(const BindingChain &, const History &h) { EC_word final = ::term(EC_functor("final", 2), next_readylog_term(), @@ -197,9 +192,6 @@ bool Semantics::final(const BindingChain &b, const History &h) return rv; } -const Instruction &Semantics::instruction() const -{ return dynamic_cast(model_element()); } - ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -221,7 +213,6 @@ ReadylogContext &ReadylogSemanticsFactory::context() - } // namespace gologpp diff --git a/src/semantics/readylog/semantics.h b/src/semantics/readylog/semantics.h index 162f5556..c2ded2ed 100644 --- a/src/semantics/readylog/semantics.h +++ b/src/semantics/readylog/semantics.h @@ -44,31 +44,32 @@ class ReadylogSemanticsFactory : public SemanticsFactory { BOOST_PP_SEQ_FOR_EACH(GOLOGPP_DECL_MAKE_SEMANTICS_OVERRIDE, (), GOLOGPP_SEMANTIC_TYPES) }; +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// - -class ReadylogSemantics +template<> +class Semantics : public virtual GeneralSemantics { public: - using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; + virtual EC_word plterm() = 0; ReadylogContext &rl_context() const; - - virtual EC_word plterm() = 0; }; template<> class Semantics : public virtual GeneralSemantics -, public ReadylogSemantics +, public Semantics { public: using GeneralSemantics::GeneralSemantics; - virtual ~Semantics() override = default; + virtual ~Semantics() override = default; virtual Value evaluate(const BindingChain &b, const History &h) override; - virtual const Expression &expression() const override; }; @@ -76,43 +77,78 @@ class Semantics template<> class Semantics : public virtual GeneralSemantics -, public ReadylogSemantics +, public Semantics { public: using GeneralSemantics::GeneralSemantics; - virtual ~Semantics() override = default; + virtual ~Semantics() override = default; virtual unique_ptr trans(const BindingChain &b, History &h) override; virtual bool final(const BindingChain &b, const History &h) override; EC_word next_readylog_term(); - virtual const Instruction &instruction() const override; protected: ManagedTerm next_readylog_term_; }; +template +class Semantics + && is_expression +> > +: public GeneralSemantics +, public Semantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; -template<> -class Semantics -: public virtual GeneralSemantics + virtual EC_word plterm() override; + + ReadylogContext &rl_context() const + { return dynamic_cast(GeneralSemantics::context()); } +}; + + +template +class Semantics + && is_instruction +> > +: public GeneralSemantics +, public Semantics { +public: + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; + + virtual EC_word plterm() override; + + ReadylogContext &rl_context() const + { return dynamic_cast(GeneralSemantics::context()); } }; template -class Semantics -: public Semantics -, public GeneralSemantics +class Semantics + && !is_expression + && !is_instruction +> > +: public GeneralSemantics +, public Semantics { public: using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; + virtual EC_word plterm() override; - virtual const GologT &model_element() const override - { return GeneralSemantics::element(); } + ReadylogContext &rl_context() const + { return dynamic_cast(GeneralSemantics::context()); } }; diff --git a/src/semantics/readylog/value.h b/src/semantics/readylog/value.h index fe707362..93138678 100644 --- a/src/semantics/readylog/value.h +++ b/src/semantics/readylog/value.h @@ -32,14 +32,13 @@ namespace gologpp { template<> class Semantics -: public Semantics -, public GeneralSemantics +: public GeneralSemantics +, public Semantics { public: Semantics(const Value &value, ReadylogContext &context); using GeneralSemantics::evaluate; - using Semantics::expression; virtual ~Semantics() override = default; diff --git a/src/semantics/readylog/variable.h b/src/semantics/readylog/variable.h index cebf62d1..94d8074f 100644 --- a/src/semantics/readylog/variable.h +++ b/src/semantics/readylog/variable.h @@ -33,7 +33,7 @@ namespace gologpp { template<> class Semantics -: public ReadylogSemantics +: public Semantics , public GeneralSemantics { public: @@ -54,7 +54,6 @@ class Semantics bool dead_; EC_atom golog_var_; bool as_golog_var_; - }; From 5baa772819630ce66047839e374153e42a2fc819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 26 Jul 2021 01:17:03 +0200 Subject: [PATCH 07/33] execution: minor infrastructure for native semantics --- src/execution/activity.cpp | 10 ++++++++++ src/execution/activity.h | 7 +++++-- src/execution/platform_backend.h | 1 + src/execution/transition.h | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/execution/activity.cpp b/src/execution/activity.cpp index cc0a3c72..d71a7b2f 100644 --- a/src/execution/activity.cpp +++ b/src/execution/activity.cpp @@ -82,6 +82,16 @@ void Activity::update(Transition::Hook hook) PlatformBackend::Lock backend_lock = exec_context_.backend().lock(); set_state(target_state(hook)); exec_context_.exog_queue_push(shared_from_this()); + update_condition_.notify_all(); +} + +void Activity::wait_for_update() +{ + std::unique_lock update_lock { update_mutex_ }; + State prev_state = state(); + update_condition_.wait(update_lock, [&] { + return state() != prev_state; + }); } diff --git a/src/execution/activity.h b/src/execution/activity.h index 4849e43e..3abf70e4 100644 --- a/src/execution/activity.h +++ b/src/execution/activity.h @@ -23,8 +23,7 @@ #include #include "transition.h" -#include - +#include namespace gologpp { @@ -51,6 +50,8 @@ class Activity void update(Transition::Hook hook); + void wait_for_update(); + const std::string &mapped_name() const; Value mapped_arg_value(const string &name) const; @@ -63,6 +64,8 @@ class Activity private: State state_; AExecutionController &exec_context_; + std::condition_variable update_condition_; + std::mutex update_mutex_; }; diff --git a/src/execution/platform_backend.h b/src/execution/platform_backend.h index 1a319a87..f87fa235 100644 --- a/src/execution/platform_backend.h +++ b/src/execution/platform_backend.h @@ -50,6 +50,7 @@ class PlatformBackend { shared_ptr erase_activity(const Transition &); shared_ptr start_activity(const Transition &); + shared_ptr end_activity(const Transition &); void cancel_activity(const Transition &); Lock lock(); diff --git a/src/execution/transition.h b/src/execution/transition.h index acfab459..f7df85e3 100644 --- a/src/execution/transition.h +++ b/src/execution/transition.h @@ -38,6 +38,7 @@ class Transition using Hook = DurativeCall::Hook; Transition(const shared_ptr &action, vector> &&args, Hook hook); + Transition(const shared_ptr &action, const vector> &args, Hook hook); Transition(const Transition &); virtual const Action &operator * () const override; From 502ec219d97beaf15cc1931c523bdf9eedb2eb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 26 Jul 2021 01:43:06 +0200 Subject: [PATCH 08/33] platform: adapt Taptenc semantics to interface changes --- src/semantics/platform/taptenc/clock_formula.h | 4 +++- src/semantics/platform/taptenc/constraint.h | 4 ++++ src/semantics/platform/taptenc/semantics.cpp | 7 ++++++- src/semantics/platform/taptenc/semantics.h | 11 +++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/semantics/platform/taptenc/clock_formula.h b/src/semantics/platform/taptenc/clock_formula.h index 3583c500..a82920d2 100644 --- a/src/semantics/platform/taptenc/clock_formula.h +++ b/src/semantics/platform/taptenc/clock_formula.h @@ -26,7 +26,9 @@ namespace gologpp { template<> -class Semantics { +class Semantics +: public TaptencExpressionSemantics +{ public: virtual std::unique_ptr compile() = 0; }; diff --git a/src/semantics/platform/taptenc/constraint.h b/src/semantics/platform/taptenc/constraint.h index 3d4ddb29..b96dee5b 100644 --- a/src/semantics/platform/taptenc/constraint.h +++ b/src/semantics/platform/taptenc/constraint.h @@ -49,6 +49,7 @@ class Semantics template<> class Semantics +: public TaptencExpressionSemantics { public: virtual std::vector compile() = 0; @@ -106,6 +107,7 @@ class Semantics> template<> class Semantics> : public GeneralSemantics> +, public TaptencExpressionSemantics { public: Semantics(const platform::TemporalUnaryOperation &elem, AExecutionController &context); @@ -118,6 +120,7 @@ class Semantics> template<> class Semantics> : public GeneralSemantics> +, TaptencExpressionSemantics { public: Semantics(const platform::TemporalBinaryOperation &elem, AExecutionController &context); @@ -149,6 +152,7 @@ class Semantics template<> class Semantics +: public TaptencExpressionSemantics { public: virtual std::unique_ptr compile( diff --git a/src/semantics/platform/taptenc/semantics.cpp b/src/semantics/platform/taptenc/semantics.cpp index e1435c0e..adbe50b9 100644 --- a/src/semantics/platform/taptenc/semantics.cpp +++ b/src/semantics/platform/taptenc/semantics.cpp @@ -51,7 +51,12 @@ unique_ptr SemanticsFactory::construct() PlanTransformation *TaptencSemanticsFactory::make_transformation() { return new TaptencTransformation(); } -} // namespace platform +} + +Value TaptencExpressionSemantics::evaluate(const BindingChain &, const History &) +{ throw Bug("This method shoudln't be called: Expression evaluation is not implemented here for the Taptenc semantics."); } + +// namespace platform } // namespace gologpp diff --git a/src/semantics/platform/taptenc/semantics.h b/src/semantics/platform/taptenc/semantics.h index 752b88c0..072a3bbf 100644 --- a/src/semantics/platform/taptenc/semantics.h +++ b/src/semantics/platform/taptenc/semantics.h @@ -33,6 +33,16 @@ string uppaal_qualified_name(const ElemT &e) } + +class TaptencExpressionSemantics +: public virtual GeneralSemantics +{ +public: + virtual Value evaluate(const BindingChain &, const History &) override; +}; + + + namespace platform { class TaptencSemanticsFactory : public platform::SemanticsFactory { @@ -42,6 +52,7 @@ class TaptencSemanticsFactory : public platform::SemanticsFactory { BOOST_PP_SEQ_FOR_EACH(GOLOGPP_DECL_MAKE_SEMANTICS_OVERRIDE, (), GOLOGPP_PLATFORM_ELEMENTS) }; + } // namespace platform From ebd93ec53d30a1df34bbdba11726c7c9cf6c9aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 26 Jul 2021 02:01:55 +0200 Subject: [PATCH 09/33] semantics: adapt native semantics to new interface Implementations still TODO --- CMakeLists.txt | 7 +-- src/semantics/native/action.cpp | 30 +--------- src/semantics/native/action.h | 39 ------------ src/semantics/native/arithmetic.cpp | 6 +- src/semantics/native/arithmetic.h | 2 +- src/semantics/native/compound_expression.h | 10 ---- src/semantics/native/domain.h | 10 ---- src/semantics/native/execution.cpp | 17 ++++-- src/semantics/native/execution.h | 11 ++-- src/semantics/native/fluent.h | 22 ------- src/semantics/native/formula.cpp | 62 ++++++++++--------- src/semantics/native/formula.h | 1 - src/semantics/native/history.cpp | 2 - src/semantics/native/history.h | 10 +++- src/semantics/native/procedural.cpp | 14 +---- src/semantics/native/procedural.h | 16 ----- src/semantics/native/reference.cpp | 61 +++++++++++++++++-- src/semantics/native/reference.h | 59 +++--------------- src/semantics/native/semantics.cpp | 10 ++-- src/semantics/native/semantics.h | 70 ++++++++++++---------- src/semantics/native/string.h | 22 ------- src/semantics/native/transition.cpp | 24 ++++++++ src/semantics/native/transition.h | 40 +++++++++++++ src/semantics/native/value.h | 5 +- src/semantics/native/variable.h | 12 ---- src/tools/nativegpp-test.cpp | 60 ++++++++++++------- 26 files changed, 278 insertions(+), 344 deletions(-) create mode 100644 src/semantics/native/transition.cpp create mode 100644 src/semantics/native/transition.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a0d21e8a..21a2525d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -409,6 +409,7 @@ if (${BUILD_NATIVE_SEMANTICS}) src/semantics/native/effect_axiom.cpp src/semantics/native/compound_expression.cpp src/semantics/native/list_expression.cpp + src/semantics/native/transition.cpp ) link_directories(${ECLIPSE_LIBRARY_DIRS}) @@ -442,15 +443,11 @@ if (${BUILD_NATIVE_SEMANTICS}) src/semantics/native/history.h src/semantics/native/compound_expression.h src/semantics/native/list_expression.h + src/semantics/native/transition.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/golog++/semantics/native ) - install(FILES - src/semantics/native/boilerplate.pl - DESTINATION ${SEMANTICS_INSTALL_DIR}/native - ) - get_target_property(NATIVEGPP_CXXFLAGS_L nativegolog++ INTERFACE_COMPILE_OPTIONS) set(NATIVEGPP_CXXFLAGS "-I${ECLIPSE_INCLUDE_DIRS}") if (${NATIVEGPP_CXXFLAGS_L}) diff --git a/src/semantics/native/action.cpp b/src/semantics/native/action.cpp index 0caf28a0..c1d8c08a 100644 --- a/src/semantics/native/action.cpp +++ b/src/semantics/native/action.cpp @@ -16,6 +16,7 @@ **************************************************************************/ #include +#include #include "action.h" #include "effect_axiom.h" @@ -29,35 +30,6 @@ namespace gologpp { -template<> -unique_ptr Semantics::trans(const Binding &b, History &h) { - while (!element()->precondition().semantics().evaluate(b, h)) - this->context().drain_exog_queue_blocking(); - - vector> arg_vals; - Binding b1(b); - for (const auto ¶m : element()->params()) { - Value v = element().arg_for_param(param).semantics().evaluate(b, h); - arg_vals.emplace_back(new Value( - param->type(), - v - )); - // TODO: Meh. Dangerous object lifetime here. - b1.bind(param, *arg_vals.back()); - } - - shared_ptr trans_start = std::make_shared( - element()->shared_from_this(), - arg_vals, - Transition::Hook::START - ); - - // TODO: eliminate Transition object here - shared_ptr a = context().backend().start_activity(*trans_start); - h.semantics().append(trans_start); - context().backend().wait_for_end(*a); -} - } // namespace gologpp diff --git a/src/semantics/native/action.h b/src/semantics/native/action.h index 422207b4..51a8eb22 100644 --- a/src/semantics/native/action.h +++ b/src/semantics/native/action.h @@ -30,45 +30,6 @@ namespace gologpp { class Action; -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; -}; - - -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; -}; - - -template<> -class Semantics> -: public Semantics -, public GeneralSemantics> -{ -public: - using GeneralSemantics>::GeneralSemantics; -}; - - -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; -}; - } // namespace gologpp diff --git a/src/semantics/native/arithmetic.cpp b/src/semantics/native/arithmetic.cpp index 9f279a4e..14ec0ccb 100644 --- a/src/semantics/native/arithmetic.cpp +++ b/src/semantics/native/arithmetic.cpp @@ -25,12 +25,12 @@ namespace gologpp { template<> -Value Semantics::evaluate(const Binding &b, const History &h) +Value Semantics::evaluate(const BindingChain &b, const History &h) { switch (element().op()) { case ArithmeticOperation::Operator::POWER: - return element().lhs().semantics().evaluate(h).pow( - element().lhs().semantics().evaluate(h) + return element().lhs().semantics().evaluate(b, h).pow( + element().lhs().semantics().evaluate(b, h) ); } } diff --git a/src/semantics/native/arithmetic.h b/src/semantics/native/arithmetic.h index e33f8479..1714caee 100644 --- a/src/semantics/native/arithmetic.h +++ b/src/semantics/native/arithmetic.h @@ -18,13 +18,13 @@ #ifndef READYLOG_ARITHMETIC_H_ #define READYLOG_ARITHMETIC_H_ +#include #include "semantics.h" namespace gologpp { - } #endif // READYLOG_ARITHMETIC_H_ diff --git a/src/semantics/native/compound_expression.h b/src/semantics/native/compound_expression.h index 34a4b7df..278e37e0 100644 --- a/src/semantics/native/compound_expression.h +++ b/src/semantics/native/compound_expression.h @@ -25,16 +25,6 @@ namespace gologpp { -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual Value evaluate(const AbstractReference &context, const History &h) override; -}; - } diff --git a/src/semantics/native/domain.h b/src/semantics/native/domain.h index c1c6380f..571d5802 100644 --- a/src/semantics/native/domain.h +++ b/src/semantics/native/domain.h @@ -25,16 +25,6 @@ namespace gologpp { -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual Value evaluate(const Binding &b, const History &h) override; -}; - } diff --git a/src/semantics/native/execution.cpp b/src/semantics/native/execution.cpp index 0153f987..f2f4f711 100644 --- a/src/semantics/native/execution.cpp +++ b/src/semantics/native/execution.cpp @@ -45,7 +45,7 @@ void NativeContext::shutdown() NativeContext::NativeContext(unique_ptr &&exec_backend) -: AExecutionContext(std::make_unique(), std::move(exec_backend)) +: AExecutionController(std::move(exec_backend)) { // TODO } @@ -59,18 +59,17 @@ NativeContext &NativeContext::instance() { return *instance_; } -void NativeContext::compile(const Block &block) +void NativeContext::compile(const Fluent &fluent) { } -void NativeContext::compile(const AbstractAction &aa) +void NativeContext::compile(const Action &aa) { - } -void NativeContext::compile(const Fluent &fluent) +void NativeContext::compile(const ExogAction &action) { } @@ -80,11 +79,17 @@ void NativeContext::compile(const Function &function) } +void NativeContext::compile(const ExogFunction &function) +{ +} + + void NativeContext::postcompile() { } -void NativeContext::run(Block &&program) + +void NativeContext::run(const Instruction &program) { } diff --git a/src/semantics/native/execution.h b/src/semantics/native/execution.h index 8cbbf120..441945ab 100644 --- a/src/semantics/native/execution.h +++ b/src/semantics/native/execution.h @@ -20,7 +20,7 @@ #include -#include +#include #include "semantics.h" #include "history.h" @@ -29,7 +29,7 @@ namespace gologpp { -class NativeContext : public AExecutionContext { +class NativeContext : public AExecutionController { public: virtual ~NativeContext() override; static void init(unique_ptr &&backend = nullptr); @@ -37,16 +37,17 @@ class NativeContext : public AExecutionContext { static NativeContext &instance(); virtual void precompile() override {} - virtual void compile(const Block &block) override; - virtual void compile(const AbstractAction &action) override; virtual void compile(const Fluent &fluent) override; + virtual void compile(const Action &action) override; + virtual void compile(const ExogAction &action) override; virtual void compile(const Function &function) override; + virtual void compile(const ExogFunction &function) override; virtual void compile(const Procedure &proc) override; virtual void postcompile() override; shared_ptr wait_for_end(Activity &a); - virtual void run(Block &&program) override; + virtual void run(const Instruction &program) override; private: NativeContext(unique_ptr &&exec_backend); diff --git a/src/semantics/native/fluent.h b/src/semantics/native/fluent.h index 6cb7e6f5..8da9a646 100644 --- a/src/semantics/native/fluent.h +++ b/src/semantics/native/fluent.h @@ -25,28 +25,6 @@ namespace gologpp { -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual ~Semantics() override = default; -}; - - - -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual ~Semantics() override = default; -}; - } // namespace gologpp diff --git a/src/semantics/native/formula.cpp b/src/semantics/native/formula.cpp index 24a93112..ea4ded01 100644 --- a/src/semantics/native/formula.cpp +++ b/src/semantics/native/formula.cpp @@ -24,51 +24,52 @@ namespace gologpp { + template<> -Value Semantics::evaluate(const Binding &b, const History &h) -{ return !element().expression().semantics().evaluate(b, h); } +Value Semantics::evaluate(const BindingChain &b, const History &h) +{ return !element().expression().semantics().evaluate(b, h); } template<> -Value gologpp::Semantics::evaluate(const Binding &b, const History &h) +Value gologpp::Semantics::evaluate(const BindingChain &b, const History &h) { switch(element().op()) { case Comparison::Operator::EQ: return Value( get_type(), - element().lhs().semantics().evaluate(b, h) - == element().lhs().semantics().evaluate(b, h) + element().lhs().semantics().evaluate(b, h) + == element().lhs().semantics().evaluate(b, h) ); case Comparison::Operator::NEQ: return Value( get_type(), - element().lhs().semantics().evaluate(b, h) - != element().lhs().semantics().evaluate(b, h) + element().lhs().semantics().evaluate(b, h) + != element().lhs().semantics().evaluate(b, h) ); case Comparison::Operator::GE: return Value( get_type(), - element().lhs().semantics().evaluate(b, h) - >= element().lhs().semantics().evaluate(b, h) + element().lhs().semantics().evaluate(b, h) + >= element().lhs().semantics().evaluate(b, h) ); case Comparison::Operator::LE: return Value( get_type(), - element().lhs().semantics().evaluate(b, h) - <= element().lhs().semantics().evaluate(b, h) + element().lhs().semantics().evaluate(b, h) + <= element().lhs().semantics().evaluate(b, h) ); case Comparison::Operator::GT: return Value( get_type(), - element().lhs().semantics().evaluate(b, h) - > element().lhs().semantics().evaluate(b, h) + element().lhs().semantics().evaluate(b, h) + > element().lhs().semantics().evaluate(b, h) ); case Comparison::Operator::LT: return Value( get_type(), - element().lhs().semantics().evaluate(b, h) - < element().lhs().semantics().evaluate(b, h) + element().lhs().semantics().evaluate(b, h) + < element().lhs().semantics().evaluate(b, h) ); } } @@ -76,10 +77,10 @@ Value gologpp::Semantics::evaluate(const Binding &b, const History & template<> -Value gologpp::Semantics::evaluate(const Binding &b, const History &h) +Value gologpp::Semantics::evaluate(const BindingChain &b, const History &h) { - bool lhs = static_cast(element().lhs().semantics().evaluate(b, h)); - bool rhs = static_cast(element().rhs().semantics().evaluate(b, h)); + bool lhs = static_cast(element().lhs().semantics().evaluate(b, h)); + bool rhs = static_cast(element().rhs().semantics().evaluate(b, h)); switch (element().op()) { case BooleanOperator::OR: @@ -98,22 +99,27 @@ Value gologpp::Semantics::evaluate(const Binding &b, const His template<> -Value gologpp::Semantics::evaluate(const Binding &b, const History &h) { +Value gologpp::Semantics::evaluate(const BindingChain &b, const History &h) { + const Domain &d = element().variable().type(); switch (element().op()) { case Quantification::Operator::FORALL: - for (const auto &val : element().variable().domain().elements()) { - // TODO: What if domain empty? - Binding b1(b); - b1.bind(element().variable().shared(), *val); - if (!static_cast(element().expression().semantics().evaluate(b1, h))) + // TODO: Statically check that variable has a domain type + for (const auto &val : d.elements()) { + Binding var_bind; + var_bind.bind(element().variable().shared(), unique_ptr(val->copy())); + BindingChain b_local = b; + b_local.push_back(&var_bind); + if (!static_cast(element().expression().semantics().evaluate(b_local, h))) return Value(get_type(), false); } return Value(get_type(), true); case Quantification::Operator::EXISTS: - for (const auto &val : element().variable().domain().elements()) { - Binding b1(b); - b1.bind(element().variable().shared(), *val); - if (static_cast(element().expression().semantics().evaluate(b1, h))) + for (const auto &val : d.elements()) { + Binding var_bind; + var_bind.bind(element().variable().shared(), unique_ptr(val->copy())); + BindingChain b_local = b; + b_local.push_back(&var_bind); + if (static_cast(element().expression().semantics().evaluate(b_local, h))) return Value(get_type(), true); } return Value(get_type(), false); diff --git a/src/semantics/native/formula.h b/src/semantics/native/formula.h index b9fc7a07..1879f800 100644 --- a/src/semantics/native/formula.h +++ b/src/semantics/native/formula.h @@ -26,7 +26,6 @@ namespace gologpp { - } // namespace gologpp diff --git a/src/semantics/native/history.cpp b/src/semantics/native/history.cpp index e67b8b42..9a3deae9 100644 --- a/src/semantics/native/history.cpp +++ b/src/semantics/native/history.cpp @@ -15,8 +15,6 @@ * along with golog++. If not, see . **************************************************************************/ -#include - #include "history.h" #include "action.h" #include "execution.h" diff --git a/src/semantics/native/history.h b/src/semantics/native/history.h index f896df9f..7f14aab8 100644 --- a/src/semantics/native/history.h +++ b/src/semantics/native/history.h @@ -29,12 +29,18 @@ namespace gologpp { template<> class Semantics : public GeneralSemantics { public: - Semantics(History &); + using GeneralSemantics::GeneralSemantics; virtual ~Semantics() override = default; virtual shared_ptr get_last_transition() override; + virtual void append(const Reference &) override; virtual void append(shared_ptr> exog) override; - virtual void append_sensing_result(shared_ptr) override; + virtual void append_sensing_result( + shared_ptr a, + const Expression &lhs, + const Value &sensing_result + ) override; + virtual void append(const Transition &trans) override; virtual bool should_progress() const override; virtual void progress() override; diff --git a/src/semantics/native/procedural.cpp b/src/semantics/native/procedural.cpp index 7f25efaf..696ebe5b 100644 --- a/src/semantics/native/procedural.cpp +++ b/src/semantics/native/procedural.cpp @@ -22,6 +22,8 @@ #include "value.h" #include "action.h" +#include + #include @@ -29,22 +31,12 @@ namespace gologpp { template<> -unique_ptr Semantics::trans(const Binding &b, History &h) +unique_ptr Semantics::trans(const BindingChain &b, History &h) { for (const unique_ptr &instr : element().elements()) instr->semantics().trans(b, h); } -template<> -unique_ptr Semantics::plan(const Binding &b, History &h) -{ - unique_ptr rv; - for (const unique_ptr &instr : element().elements()) { - - } -} - - } diff --git a/src/semantics/native/procedural.h b/src/semantics/native/procedural.h index a592de66..d429cc68 100644 --- a/src/semantics/native/procedural.h +++ b/src/semantics/native/procedural.h @@ -33,22 +33,6 @@ namespace gologpp { -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual unique_ptr trans(const Binding &b, History &h) override; - virtual unique_ptr plan(const Binding &b, History &h) override; - -private: - vector>::const_iterator ip; -}; - - - } // namespace gologpp diff --git a/src/semantics/native/reference.cpp b/src/semantics/native/reference.cpp index 595ca784..464eceaa 100644 --- a/src/semantics/native/reference.cpp +++ b/src/semantics/native/reference.cpp @@ -21,22 +21,71 @@ #include "execution.h" #include "formula.h" #include "action.h" +#include "history.h" -#include +#include +#include +#include namespace gologpp { -unique_ptr Semantics>::trans(const Binding &b, History &h) { +template<> +unique_ptr Semantics>::trans(const BindingChain &b, History &h) +{ + vector> ground_args; + for (const Expression *e : element().args()) + ground_args.emplace_back(unique_ptr(e->semantics().evaluate(b, h).copy())); + + try { + Transition trans_start(element().target(), ground_args, Transition::Hook::START); + trans_start.attach_semantics(context().semantics_factory()); + trans_start.semantics().trans({}, h); + + Transition trans_end(element().target(), ground_args, Transition::Hook::END); + trans_end.attach_semantics(context().semantics_factory()); + trans_end.semantics().trans({}, h); + } catch (Escalate &e) { + e.set_static_cause(&element()); + throw; + } + + return nullptr; } -unique_ptr Semantics>::plan(const Binding &b, History &h) { - Binding merged = element().binding().ground(b); - if (element()->precondition().general_semantics().evaluate(merged, h) != Value(get_type(), true)) - throw NotPossible(); + +template<> +unique_ptr Semantics::trans(const BindingChain &b, History &h) +{ + if (b.size()) + throw Bug("Attempting to execute transition with non-empty binding"); + + shared_ptr a; + switch (element().hook()) { + case Transition::Hook::START: + context().backend().start_activity(element()); + break; + case Transition::Hook::CANCEL: + context().backend().cancel_activity(element()); + break; + case Transition::Hook::END: + context().backend().end_activity(element()); + break; + case Transition::Hook::FINISH: + a = context().backend().end_activity(element()); + if (a->state() != Activity::target_state(element().hook())) + throw Escalate(nullptr, element().shared_from_this()); + break; + case Transition::Hook::FAIL: + throw Unsupported(element().str() + ": " + to_string(element().hook()) + " not supported"); + } + + h.special_semantics().append(element()); + return nullptr; } + } // namespace gologpp diff --git a/src/semantics/native/reference.h b/src/semantics/native/reference.h index 70089797..c86849d4 100644 --- a/src/semantics/native/reference.h +++ b/src/semantics/native/reference.h @@ -25,6 +25,8 @@ #include #include +#include + #include "semantics.h" #include "utilities.h" #include "variable.h" @@ -32,68 +34,21 @@ namespace gologpp { -template class Reference; - -class NativeContext; - -template<> -class Semantics> -: public Semantics -, public GeneralSemantics> -{ -public: - using GeneralSemantics>::GeneralSemantics; - virtual Value evaluate(const Binding &b, const History &h) override; -}; - template<> -class Semantics> -: public GeneralSemantics> -, public Semantics +class Semantics +: public GeneralSemantics { public: - using GeneralSemantics>::GeneralSemantics; - virtual Value evaluate(const Binding &b, const History &h) override; -}; - - + using GeneralSemantics::GeneralSemantics; -template<> -class Semantics> -: public GeneralSemantics> -, public Semantics -{ -public: - using GeneralSemantics>::GeneralSemantics; - unique_ptr trans(const Binding &b, History &h) override; + virtual GeneralSemantics *copy(const Binding &target_element) const override; + virtual const ModelElement &model_element() const override; }; -template<> -class Semantics> -: public GeneralSemantics> -, public Semantics -{ -public: - using GeneralSemantics>::GeneralSemantics; - unique_ptr trans(const Binding &b, History &h) override; - unique_ptr plan(const Binding &b, History &h) override; -}; - - - -template<> -class Semantics>; - -template<> -class Semantics>; - -template<> -class Semantics>; - } // namespace gologpp diff --git a/src/semantics/native/semantics.cpp b/src/semantics/native/semantics.cpp index 434cb7f2..022ddcff 100644 --- a/src/semantics/native/semantics.cpp +++ b/src/semantics/native/semantics.cpp @@ -32,6 +32,10 @@ #include "history.h" #include "compound_expression.h" #include "list_expression.h" +#include "transition.h" + +#include +#include namespace gologpp { @@ -44,12 +48,6 @@ unique_ptr> NativeSemanticsFactory::make_semantic BOOST_PP_SEQ_FOR_EACH(GOLOGPP_DEFINE_MAKE_SEMANTICS_IMPL, (), GOLOGPP_SEMANTIC_TYPES) -unique_ptr Semantics::plan(const Binding &b, History &h) -{ - -} - - } // namespace gologpp diff --git a/src/semantics/native/semantics.h b/src/semantics/native/semantics.h index 3d622a77..d2c64b1e 100644 --- a/src/semantics/native/semantics.h +++ b/src/semantics/native/semantics.h @@ -33,58 +33,62 @@ using enable_if_subclass = std::enable_if < >; -template<> -class Semantics -: public virtual GeneralSemantics -{ +class Escalate { public: - virtual ~Semantics() override = default; -}; + Escalate(const Instruction *static_cause, shared_ptr dynamic_cause); + void set_static_cause(const Instruction *cause); + const Instruction *static_cause() const; + void set_dynamic_cause(shared_ptr cause); + shared_ptr dynamic_cause() const; -template<> -class Semantics -: public GeneralSemantics -, public Semantics -{ -public: - virtual Value evaluate(const Binding &context, const History &h) override; - virtual const Expression &expression() const override; +private: + const Instruction *static_cause_; + shared_ptr dynamic_cause_; }; -template<> -class Semantics -: public GeneralSemantics -, public Semantics + +template +class Semantics>> +: public GeneralSemantics { public: - virtual unique_ptr plan(const Binding &b, History &h); - virtual bool final(const Binding &b, const History &h) override; - virtual const Instruction &instruction() const override; + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; + + virtual unique_ptr trans(const BindingChain &b, History &h) override; + + virtual bool final(const BindingChain &, const History &) override + { throw Bug("This method should not be called"); } }; + template -class Semantics -: public Semantics +class Semantics>> +: public GeneralSemantics { public: - typename std::enable_if < std::is_base_of::value, - Value - >::type evaluate(const Binding &b, const History &h) override; + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; - typename enable_if_subclass< GologT, Instruction, - unique_ptr - >::type trans(const Binding &b, History &h) override; - - const GologT &element() const; + virtual Value evaluate(const BindingChain &b, const History &h) override; }; +template +class Semantics + && !is_instruction +>> +: public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + virtual ~Semantics() override = default; +}; -using EvaluationSemantics = Semantics; -using TransitionSemantics = Semantics; #define GOLOGPP_DECL_MAKE_SEMANTICS_OVERRIDE(_r, _data, GologT) \ virtual unique_ptr> make_semantics(GologT &) override; diff --git a/src/semantics/native/string.h b/src/semantics/native/string.h index 57e085ce..74812026 100644 --- a/src/semantics/native/string.h +++ b/src/semantics/native/string.h @@ -25,28 +25,6 @@ namespace gologpp { -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual Value evaluate(const History &h) override; -}; - - -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual Value evaluate(const History &h) override; -}; - - } #endif // READYLOG_STRING_CONCATENATION_H_ diff --git a/src/semantics/native/transition.cpp b/src/semantics/native/transition.cpp new file mode 100644 index 00000000..5d797a80 --- /dev/null +++ b/src/semantics/native/transition.cpp @@ -0,0 +1,24 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#include "transition.h" + +namespace gologpp { + + + +} diff --git a/src/semantics/native/transition.h b/src/semantics/native/transition.h new file mode 100644 index 00000000..c1ecf66b --- /dev/null +++ b/src/semantics/native/transition.h @@ -0,0 +1,40 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#pragma once + +#include + +namespace gologpp { + + +template<> +class Semantics +: public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + + virtual GeneralSemantics *copy(const Transition &target_element) const override; + virtual unique_ptr trans(const BindingChain &b, History &h) override; + + virtual bool final(const BindingChain &, const History &) override + { throw Bug("This method should not be called"); } +}; + + +} // namespace gologpp diff --git a/src/semantics/native/value.h b/src/semantics/native/value.h index 45e4c4bf..e3a17707 100644 --- a/src/semantics/native/value.h +++ b/src/semantics/native/value.h @@ -29,14 +29,13 @@ namespace gologpp { template<> class Semantics -: public Semantics -, public GeneralSemantics +: public GeneralSemantics { public: using GeneralSemantics::GeneralSemantics; virtual ~Semantics() override = default; - virtual Value evaluate(const Binding &b, const History &h) override; + virtual Value evaluate(const BindingChain &b, const History &h) override; virtual GeneralSemantics *copy(const Value &target_element) const override; }; diff --git a/src/semantics/native/variable.h b/src/semantics/native/variable.h index 48d29bd9..e8b6b72b 100644 --- a/src/semantics/native/variable.h +++ b/src/semantics/native/variable.h @@ -27,18 +27,6 @@ namespace gologpp { -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - virtual Value evaluate(const Binding &b, const History &h) override; -}; - - - } // namespace gologpp diff --git a/src/tools/nativegpp-test.cpp b/src/tools/nativegpp-test.cpp index ae2600dc..c03eb867 100644 --- a/src/tools/nativegpp-test.cpp +++ b/src/tools/nativegpp-test.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -33,36 +34,55 @@ using namespace gologpp; -void test_parser(const string &filename) +int test_file(unique_ptr &&mainproc) { - Instruction *mainproc = parser::parse_file(filename).release(); - - for (shared_ptr g : global_scope().globals()) - std::cout << g->str() << std::endl; - - std::cout << mainproc->str() << std::endl; - - NativeContext::init(); - NativeContext &ctx = NativeContext::instance(); - - ctx.run(Block( - new Scope(global_scope()), - { mainproc } - )); - - NativeContext::shutdown(); + shared_ptr f_postcond = global_scope().lookup_global("postcond"); + unique_ptr> postcond; + if (f_postcond) { + postcond.reset(f_postcond->make_ref({})); + postcond->attach_semantics(NativeContext::instance().semantics_factory()); + } + + mainproc->attach_semantics(NativeContext::instance().semantics_factory()); + + NativeContext::instance().run(*mainproc); + + if (postcond) { + log(LogLevel::INF) << "Testing postcond(): " << flush; + bool success = static_cast( + postcond->semantics().evaluate({}, NativeContext::instance().history()) + ); + + if (success) { + log(LogLevel::INF) << "OK" << flush; + return 0; + } + else { + log(LogLevel::ERR) << "FAIL" << flush; + return 1; + } + } + else + return 0; } - int main(int argc, const char **argv) { string filename = SOURCE_DIR "/examples/blocksworld.gpp"; if (argc > 1) filename = argv[1]; - test_parser(filename); - return 0; + parser::parse_file(filename); + shared_ptr mainproc = global_scope().lookup_global("main"); + if (!mainproc) { + log(LogLevel::ERR) << "No procedure main() in " << filename << flush; + return -2; + } + + int rv = test_file(unique_ptr(mainproc->ref({}))); + + return rv; } From 1c71f8a2a9a90fc4f0c70a335b175f07ada6a3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Wed, 15 Sep 2021 18:41:49 +0200 Subject: [PATCH 10/33] plan: fix max_reward(...) signature not used or implemented currently --- src/execution/plan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/execution/plan.h b/src/execution/plan.h index 3c877bd5..4d0ca129 100644 --- a/src/execution/plan.h +++ b/src/execution/plan.h @@ -73,7 +73,7 @@ class Plan Plan() = default; Plan(Plan &&sub); - Value max_reward(const Binding &binding, const Reference &reward_func); + Value max_reward(const BindingChain &binding, const Reference &reward_func); Plan &append(TimedInstruction &&); Plan &append(Plan &&); From 6883d979083109fbd5c1c696b46bd51e4c13a750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Thu, 6 Oct 2022 19:30:50 +0200 Subject: [PATCH 11/33] move ExecutionController::run() into ReadylogContext it's very readylog-specific and won't necessarily be useful for other semantics impls --- src/execution/controller.cpp | 131 -------------------------- src/execution/controller.h | 18 ---- src/execution/transition.h | 2 + src/model/gologpp.h | 1 - src/semantics/readylog/execution.cpp | 122 +++++++++++++++++++++++- src/semantics/readylog/execution.h | 5 +- src/semantics/readylog/transition.cpp | 2 +- src/semantics/readylog/transition.h | 2 +- 8 files changed, 126 insertions(+), 157 deletions(-) diff --git a/src/execution/controller.cpp b/src/execution/controller.cpp index 337e6a84..5dbc6cf2 100644 --- a/src/execution/controller.cpp +++ b/src/execution/controller.cpp @@ -254,136 +254,5 @@ shared_ptr AExecutionController::switch_state_actio { return switch_state_action_; } -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -ExecutionController::ExecutionController( - unique_ptr &&exec_backend, - unique_ptr &&plan_transformation -) -: AExecutionController(std::move(exec_backend)) -, plan_transformation_(std::move(plan_transformation)) -{ - if (!plan_transformation_) - plan_transformation_.reset(semantics_factory().platform_semantics_factory().make_transformation()); -} - -ExecutionController::~ExecutionController() -{} - - -void ExecutionController::run(const Instruction &program) -{ - try { - history().attach_semantics(semantics_factory()); - global_scope().implement_globals(semantics_factory(), *this); - - plan_transformation_->init(*this); - - while (!program.general_semantics().final({}, history())) { - set_silent(true); - - unique_ptr plan { - program.general_semantics().trans({}, history()) - }; - - if (plan) { - plan = plan_transformation_->transform(std::move(*plan)); - - log(LogLevel::INF) << "<<< Transformed schedule: " << *plan << flush; - - while (!plan->elements().empty()) { - set_silent(true); - - if (terminated) - throw Terminate(); - - if (!exog_empty()) { - drain_exog_queue(); - if (backend().any_component_state_changed_exog()) - plan = plan_transformation_->transform(std::move(*plan)); - } - - unique_ptr empty_plan; - - if (plan->elements().front().earliest_timepoint() > context_time()) { - backend().schedule_timer_event( - plan->elements().front().earliest_timepoint() - ); - } - else { - // Plan elements are expected to not return plans again (nullptr or empty Plan). - empty_plan = plan->elements().front().instruction() - .general_semantics().trans({}, history()) - ; - } - - Clock::time_point timeout = plan->next_timeout(); - - if (empty_plan) { - // Empty plan: successfully executed - if (!empty_plan->elements().empty()) - throw Bug( - "Plan instruction returned a plan: " - + plan->elements().front().instruction().str() - ); - plan->elements().erase(plan->elements().begin()); - } - else { - // Current Plan element not executable - try { - drain_exog_queue_blocking(timeout); - } catch (ExogTimeout &) - { - exog_timer_wakeup(); - log(LogLevel::ERR) << "=== Next-action timeout " << timeout << " exceeded" << flush; - - auto sw_state = dynamic_cast *>( - &plan->elements().front().instruction() - ); - if (sw_state) { - global_scope().lookup_global( - static_cast(dynamic_cast( - sw_state->arg_for_param(sw_state->target()->param_component()) - )) - )->backend().handle_missed_transition(); - } - - drain_exog_queue(); - } - - if (context_time() > plan->elements().front().latest_timepoint() - || backend().any_component_state_changed_exog() - ) { - // First plan element's time window has passed: replan! - log(LogLevel::INF) << "=== Re-transforming..." << flush; - plan->make_start_slack(Clock::seconds(16384)); - plan = plan_transformation_->transform(std::move(*plan)); - log(LogLevel::INF) << "=== New schedule " << *plan << flush; - } - } - - if (history().general_semantics().should_progress()) { - log(LogLevel::DBG) << "=== Progressing history." << flush; - history().general_semantics().progress(); - } - } - } - else { - drain_exog_queue_blocking(nullopt); - } - - if (terminated) - throw Terminate(); - - } - } catch (Terminate &) { - log(LogLevel::DBG) << ">>> Terminated." << flush; - } -} - - - } diff --git a/src/execution/controller.h b/src/execution/controller.h index 9b04a873..ebf8d46a 100644 --- a/src/execution/controller.h +++ b/src/execution/controller.h @@ -122,24 +122,6 @@ class AExecutionController { -class ExecutionController : public AExecutionController { -public: - ExecutionController( - unique_ptr &&exec_backend, - unique_ptr &&plan_transformation - ); - - virtual ~ExecutionController() override; - - virtual void run(const Instruction &program) override; - -private: - unique_ptr plan_transformation_; -}; - - - - } // namespace gologpp #endif diff --git a/src/execution/transition.h b/src/execution/transition.h index f7df85e3..8c23625d 100644 --- a/src/execution/transition.h +++ b/src/execution/transition.h @@ -75,6 +75,8 @@ class GeneralSemantics virtual AExecutionController &context() const override; + shared_ptr activity() const; + private: const Transition *element_; AExecutionController &context_; diff --git a/src/model/gologpp.h b/src/model/gologpp.h index 5eb7260c..920aa64a 100644 --- a/src/model/gologpp.h +++ b/src/model/gologpp.h @@ -151,7 +151,6 @@ template class GeneralSemantics; class SemanticsFactory; class AExecutionController; -class ExecutionController; class PlatformBackend; diff --git a/src/semantics/readylog/execution.cpp b/src/semantics/readylog/execution.cpp index 8af61d31..af99a791 100644 --- a/src/semantics/readylog/execution.cpp +++ b/src/semantics/readylog/execution.cpp @@ -34,6 +34,8 @@ #include #include +#include +#include namespace filesystem = std::experimental::filesystem; @@ -56,12 +58,13 @@ ReadylogContext::ReadylogContext( unique_ptr &&exec_backend, unique_ptr &&transformation ) -: ExecutionController( - std::move(exec_backend), - std::move(transformation) - ) +: AExecutionController(std::move(exec_backend)) , options_(options) +, plan_transformation_(std::move(transformation)) { + if (!plan_transformation_) + plan_transformation_ = std::make_unique(); + Logger::Guard lg(LogLevel::DBG); ec_set_option_ptr(EC_OPTION_ECLIPSEDIR, const_cast(static_cast(ECLIPSE_DIR))); std::cout << "Using eclipse-clp in " << ECLIPSE_DIR << std::endl; @@ -295,5 +298,116 @@ bool ReadylogContext::ec_query(EC_word t) } +void ReadylogContext::run(const Instruction &program) +{ + try { + history().attach_semantics(semantics_factory()); + global_scope().implement_globals(semantics_factory(), *this); + + plan_transformation_->init(*this); + + while (!program.general_semantics().final({}, history())) { + set_silent(true); + + unique_ptr plan { + program.general_semantics().trans({}, history()) + }; + + if (plan) { + plan = plan_transformation_->transform(std::move(*plan)); + + log(LogLevel::INF) << "<<< Transformed schedule: " << *plan << flush; + + while (!plan->elements().empty()) { + set_silent(true); + + if (terminated) + throw Terminate(); + + if (!exog_empty()) { + drain_exog_queue(); + if (backend().any_component_state_changed_exog()) + plan = plan_transformation_->transform(std::move(*plan)); + } + + unique_ptr empty_plan; + + if (plan->elements().front().earliest_timepoint() > context_time()) { + backend().schedule_timer_event( + plan->elements().front().earliest_timepoint() + ); + } + else { + // Plan elements are expected to not return plans again (nullptr or empty Plan). + empty_plan = plan->elements().front().instruction() + .general_semantics().trans({}, history()) + ; + } + + Clock::time_point timeout = plan->next_timeout(); + + if (empty_plan) { + // Empty plan: successfully executed + if (!empty_plan->elements().empty()) + throw Bug( + "Plan instruction returned a plan: " + + plan->elements().front().instruction().str() + ); + plan->elements().erase(plan->elements().begin()); + } + else { + // Current Plan element not executable + try { + drain_exog_queue_blocking(timeout); + } catch (ExogTimeout &) + { + exog_timer_wakeup(); + log(LogLevel::ERR) << "=== Next-action timeout " << timeout << " exceeded" << flush; + + auto sw_state = dynamic_cast *>( + &plan->elements().front().instruction() + ); + if (sw_state) { + global_scope().lookup_global( + static_cast(dynamic_cast( + sw_state->arg_for_param(sw_state->target()->param_component()) + )) + )->backend().handle_missed_transition(); + } + + drain_exog_queue(); + } + + if (context_time() > plan->elements().front().latest_timepoint() + || backend().any_component_state_changed_exog() + ) { + // First plan element's time window has passed: replan! + log(LogLevel::INF) << "=== Re-transforming..." << flush; + plan->make_start_slack(Clock::seconds(16384)); + plan = plan_transformation_->transform(std::move(*plan)); + log(LogLevel::INF) << "=== New schedule " << *plan << flush; + } + } + + if (history().general_semantics().should_progress()) { + log(LogLevel::DBG) << "=== Progressing history." << flush; + history().general_semantics().progress(); + } + } + } + else { + drain_exog_queue_blocking(nullopt); + } + + if (terminated) + throw Terminate(); + + } + } catch (Terminate &) { + log(LogLevel::DBG) << ">>> Terminated." << flush; + } +} + + } // namespace gologpp diff --git a/src/semantics/readylog/execution.h b/src/semantics/readylog/execution.h index f428a3d5..3a3ba6df 100644 --- a/src/semantics/readylog/execution.h +++ b/src/semantics/readylog/execution.h @@ -33,7 +33,7 @@ struct eclipse_opts { bool toplevel = false; }; -class ReadylogContext : public ExecutionController { +class ReadylogContext : public AExecutionController { public: virtual ~ReadylogContext() override; @@ -46,6 +46,8 @@ class ReadylogContext : public ExecutionController { static void shutdown(); static ReadylogContext &instance(); + virtual void run(const Instruction &program) override; + virtual void precompile() override; virtual void compile(const Action &) override; virtual void compile(const ExogAction &) override; @@ -78,6 +80,7 @@ class ReadylogContext : public ExecutionController { int last_rv_; eclipse_opts options_; static unique_ptr instance_; + unique_ptr plan_transformation_; }; diff --git a/src/semantics/readylog/transition.cpp b/src/semantics/readylog/transition.cpp index 37a0ed25..a9474c18 100644 --- a/src/semantics/readylog/transition.cpp +++ b/src/semantics/readylog/transition.cpp @@ -27,7 +27,7 @@ namespace gologpp { -Semantics::Semantics(const Transition &elem, ExecutionController &context) +Semantics::Semantics(const Transition &elem, ReadylogContext &context) : GeneralSemantics(elem, context) {} diff --git a/src/semantics/readylog/transition.h b/src/semantics/readylog/transition.h index 376a6f29..69732073 100644 --- a/src/semantics/readylog/transition.h +++ b/src/semantics/readylog/transition.h @@ -30,7 +30,7 @@ class Semantics , public Semantics { public: - Semantics(const Transition &elem, ExecutionController &context); + Semantics(const Transition &elem, ReadylogContext &context); virtual ~Semantics() override = default; virtual EC_word plterm() override; From a1327230d34c3567771fca678724d556d11ce482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Thu, 6 Oct 2022 20:12:59 +0200 Subject: [PATCH 12/33] move Transition semantics impl to ReadylogSemantics Same as the ExecutionContext, specific to readylog. --- src/execution/transition.cpp | 62 +------------------------- src/execution/transition.h | 2 - src/semantics/readylog/transition.cpp | 64 ++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 65 deletions(-) diff --git a/src/execution/transition.cpp b/src/execution/transition.cpp index abfc9ae5..4fdc35a0 100644 --- a/src/execution/transition.cpp +++ b/src/execution/transition.cpp @@ -75,6 +75,7 @@ string Transition::to_string(const string &pfx) const + GeneralSemantics::GeneralSemantics(const Transition &elem, AExecutionController &context) : element_(&elem) , context_(context) @@ -90,67 +91,6 @@ void GeneralSemantics::update_element(const Transition *new_element) AExecutionController &GeneralSemantics::context() const { return context_; } - -unique_ptr GeneralSemantics::trans(const BindingChain &b, History &history) -{ - BindingChain merged(b); - merged.emplace_back(&element().binding()); - - switch(element().hook()) - { - case Transition::Hook::CANCEL: - if (context().backend().current_state(element()) == Activity::State::RUNNING) - context().backend().cancel_activity(element()); - else - return nullptr; - break; - case Transition::Hook::START: - if ( - context().backend().current_state(element()) != Activity::State::RUNNING - && static_cast( - element().target()->precondition().general_semantics().evaluate( - merged, - history - ) - ) - ) - context().backend().start_activity(element()); - else - return nullptr; - break; - case Transition::Hook::FINISH: - if (context().backend().current_state(element()) == Activity::State::FINAL) { - shared_ptr a = context().backend().erase_activity(element()); - } - else - return nullptr; - break; - case Transition::Hook::FAIL: - if (context().backend().current_state(element()) == Activity::State::FAILED) - context().backend().erase_activity(element()); - else - return nullptr; - break; - case Transition::Hook::END: - if ( - context().backend().current_state(element()) == Activity::State::FAILED - || context().backend().current_state(element()) == Activity::State::FINAL - ) - context().backend().erase_activity(element()); - else - return nullptr; - } - - if (!element()->silent()) { - log(LogLevel::NFY) << "<<< trans: " << element().str() << flush; - context().set_silent(false); - } - - history.general_semantics().append(element()); - - return unique_ptr(new Plan()); -} - const ModelElement &GeneralSemantics::model_element() const { return element(); } diff --git a/src/execution/transition.h b/src/execution/transition.h index 8c23625d..45ebeb4c 100644 --- a/src/execution/transition.h +++ b/src/execution/transition.h @@ -64,8 +64,6 @@ class GeneralSemantics GeneralSemantics(const Transition &elem, AExecutionController &context); GeneralSemantics(const GeneralSemantics &other); - virtual unique_ptr trans(const BindingChain &, History &) override; - const Transition &element() const; virtual const ModelElement &model_element() const override; virtual const Instruction &instruction() const override; diff --git a/src/semantics/readylog/transition.cpp b/src/semantics/readylog/transition.cpp index a9474c18..f9487f1a 100644 --- a/src/semantics/readylog/transition.cpp +++ b/src/semantics/readylog/transition.cpp @@ -22,6 +22,7 @@ #include "utilities.h" #include +#include namespace gologpp { @@ -77,8 +78,67 @@ shared_ptr gologpp::Semantics::transition_from_plterm(EC Semantics *Semantics::copy(const Transition &target_element) const { return new Semantics(target_element, rl_context()); } -unique_ptr Semantics::trans(const BindingChain &b, History &h) -{ return GeneralSemantics::trans(b, h); } + +unique_ptr Semantics::trans(const BindingChain &b, History &history) +{ + BindingChain merged(b); + merged.emplace_back(&element().binding()); + + switch(element().hook()) + { + case Transition::Hook::CANCEL: + if (context().backend().current_state(element()) == Activity::State::RUNNING) + context().backend().cancel_activity(element()); + else + return nullptr; + break; + case Transition::Hook::START: + if ( + context().backend().current_state(element()) != Activity::State::RUNNING + && static_cast( + element().target()->precondition().general_semantics().evaluate( + merged, + history + ) + ) + ) + context().backend().start_activity(element()); + else + return nullptr; + break; + case Transition::Hook::FINISH: + if (context().backend().current_state(element()) == Activity::State::FINAL) { + shared_ptr a = context().backend().erase_activity(element()); + } + else + return nullptr; + break; + case Transition::Hook::FAIL: + if (context().backend().current_state(element()) == Activity::State::FAILED) + context().backend().erase_activity(element()); + else + return nullptr; + break; + case Transition::Hook::END: + if ( + context().backend().current_state(element()) == Activity::State::FAILED + || context().backend().current_state(element()) == Activity::State::FINAL + ) + context().backend().erase_activity(element()); + else + return nullptr; + } + + if (!element()->silent()) { + log(LogLevel::NFY) << "<<< trans: " << element().str() << flush; + context().set_silent(false); + } + + history.general_semantics().append(element()); + + return unique_ptr(new Plan()); +} + const Instruction &Semantics::instruction() const { return GeneralSemantics::instruction(); } From 381f3c921c67fb33bdbd4d35d312585858fde5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Sat, 7 Jan 2023 18:48:24 +0100 Subject: [PATCH 13/33] model: redesign event architecture The Reference< > template gained a new parameter for the argument type. It can be an arbitrary Expression or a Value. There is also a new, specific event type for use with the exog queue, which makes use of this new Reference (i.e. Grounding). This change may cause some minor breakage in downstream code, but it should be straightforward to fix because the change is making compiler errors more specific and adds some additional type safety around the handling of events. --- CMakeLists.txt | 4 +- src/execution/activity.cpp | 37 ++++---- src/execution/activity.h | 29 +++--- src/execution/controller.cpp | 41 ++++---- src/execution/controller.h | 11 +-- src/execution/dummy_backend.cpp | 6 +- src/execution/event.cpp | 61 ++++++++++++ src/execution/event.h | 60 ++++++++++++ src/execution/history.cpp | 4 +- src/execution/history.h | 10 +- src/execution/plan.cpp | 8 +- src/execution/platform_backend.cpp | 16 ++-- src/execution/platform_backend.h | 2 +- src/execution/transition.cpp | 23 +---- src/execution/transition.h | 18 ++-- src/model/domain.h | 1 - src/model/expressions.h | 1 - src/model/gologpp.h | 29 ++++-- src/model/platform/component_backend.cpp | 5 +- src/model/platform/component_backend.h | 1 + src/model/platform/reference.h | 4 +- src/model/procedural.cpp | 1 - src/model/procedural.h | 2 +- src/model/reference.cpp | 61 ++++++++---- src/model/reference.h | 113 +++++++++++++---------- src/model/semantics.h | 1 + src/model/utilities.cpp | 9 -- src/model/utilities.h | 11 ++- src/model/value.h | 2 +- src/model/variable.h | 1 - src/parser/expressions.cpp | 2 +- src/parser/fluent.cpp | 1 - src/parser/fluent.h | 1 - src/parser/platform/reference.cpp | 2 +- src/parser/reference.cpp | 8 +- src/parser/value.cpp | 1 + 36 files changed, 366 insertions(+), 221 deletions(-) create mode 100644 src/execution/event.cpp create mode 100644 src/execution/event.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 21a2525d..08412db3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ endif() include_directories(${Boost_INCLUDE_DIR} src) -add_compile_options(-Wall -Wno-unknown-pragmas) +add_compile_options(-Wall -Wno-unknown-pragmas -fdiagnostics-path-format=inline-events -fdiagnostics-show-path-depths) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -fno-omit-frame-pointer -DDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2") @@ -115,6 +115,7 @@ set(INTERFACE_SRC src/execution/plan.cpp src/execution/platform_backend.cpp src/execution/transformation.cpp + src/execution/event.cpp src/model/platform/component.cpp src/model/platform/constraint.cpp @@ -173,6 +174,7 @@ install(FILES src/execution/plan.h src/execution/platform_backend.h src/execution/transformation.h + src/execution/event.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/golog++/execution ) diff --git a/src/execution/activity.cpp b/src/execution/activity.cpp index d71a7b2f..7749b0ba 100644 --- a/src/execution/activity.cpp +++ b/src/execution/activity.cpp @@ -25,14 +25,15 @@ namespace gologpp { -Activity::Activity(const shared_ptr &action, vector> &&args, AExecutionController &ctx, State state) -: ReferenceBase(action, std::move(args)) +Activity::Activity(const shared_ptr &action, vector> &&args, AExecutionController &ctx, State state) +: action_ref_(action, std::move(args)) , state_(state) , exec_context_(ctx) {} + Activity::Activity(const Transition &trans, AExecutionController &ctx) -: ReferenceBase(trans.target(), copy(trans.args())) +: action_ref_(trans.action(), copy(trans.ref().args())) , state_(State::IDLE) , exec_context_(ctx) { @@ -40,18 +41,6 @@ Activity::Activity(const Transition &trans, AExecutionController &ctx) throw Bug("Activity must be constructed from a START Transition"); } -const Action &Activity::operator *() const -{ return *this->target(); } - -Action &Activity::operator *() -{ return *this->target(); } - -const Action *Activity::operator ->() const -{ return this->target().get(); } - -Action *Activity::operator ->() -{ return this->target().get(); } - void Activity::set_state(Activity::State state) { state_ = state; } @@ -81,7 +70,13 @@ void Activity::update(Transition::Hook hook) { PlatformBackend::Lock backend_lock = exec_context_.backend().lock(); set_state(target_state(hook)); - exec_context_.exog_queue_push(shared_from_this()); + exec_context_.exog_queue_push( + shared_ptr(new Transition( + action(), + vector>(args().begin(), args().end()), + hook + )) + ); update_condition_.notify_all(); } @@ -99,22 +94,22 @@ Value Activity::mapped_arg_value(const string &name) const { return dynamic_cast &>( - target()->mapping().mapped_expr(name).general_semantics() - ).evaluate({ &this->binding() }, exec_context_.history()); + action()->mapping().mapped_expr(name).general_semantics() + ).evaluate({ &this->ref().binding() }, exec_context_.history()); } const std::string &Activity::mapped_name() const -{ return target()->mapping().backend_name(); } +{ return action()->mapping().backend_name(); } string Activity::to_string(const string &pfx) const -{ return pfx + "state(" + ReferenceBase::to_string("") + ") = " + gologpp::to_string(state()); } +{ return pfx + "state(" + ref().to_string("") + ") = " + gologpp::to_string(state()); } void Activity::attach_semantics(SemanticsFactory &implementor) { if (!semantics_) { - binding().attach_semantics(implementor); + ref().binding().attach_semantics(implementor); semantics_ = implementor.make_semantics(*this); for (auto &c : args()) c->attach_semantics(implementor); diff --git a/src/execution/activity.h b/src/execution/activity.h index 3abf70e4..312cfefc 100644 --- a/src/execution/activity.h +++ b/src/execution/activity.h @@ -29,31 +29,32 @@ namespace gologpp { class Activity -: public ReferenceBase -, public Reference -, public Instruction +: public Instruction , public LanguageElement +, public NoScopeOwner , public std::enable_shared_from_this { public: enum State { IDLE, RUNNING, FINAL, CANCELLED, FAILED }; - Activity(const shared_ptr &action, vector> &&args, AExecutionController &, State state = IDLE); - Activity(const Transition &, AExecutionController &); - - virtual const Action &operator * () const override; - virtual Action &operator * () override; - virtual const Action *operator -> () const override; - virtual Action *operator -> () override; + Activity( + const shared_ptr &action, + vector> &&args, + AExecutionController &, State state = IDLE + ); - State state() const; - void set_state(State s); + Activity(const Transition &, AExecutionController &); void update(Transition::Hook hook); - void wait_for_update(); + State state() const; + void set_state(State s); const std::string &mapped_name() const; Value mapped_arg_value(const string &name) const; + shared_ptr action() const; + const vector &args() const; + const Reference &ref() const; + Reference &ref(); virtual string to_string(const string &pfx) const override; @@ -62,6 +63,8 @@ class Activity static State target_state(Transition::Hook); private: + Reference action_ref_; + State state_; AExecutionController &exec_context_; std::condition_variable update_condition_; diff --git a/src/execution/controller.cpp b/src/execution/controller.cpp index 5dbc6cf2..23800f6d 100644 --- a/src/execution/controller.cpp +++ b/src/execution/controller.cpp @@ -27,7 +27,6 @@ #include #include -#include "plan.h" #include "controller.h" #include "history.h" #include "platform_backend.h" @@ -88,16 +87,16 @@ AExecutionController::AExecutionController(unique_ptr &&platfor } -shared_ptr> AExecutionController::exog_queue_pop() +shared_ptr AExecutionController::exog_queue_pop() { std::lock_guard locked{ exog_mutex_ }; - shared_ptr> rv = std::move(exog_queue_.front()); + shared_ptr rv = std::move(exog_queue_.front()); exog_queue_.pop_front(); return rv; } -shared_ptr> AExecutionController::exog_queue_poll(optional timeout) +shared_ptr AExecutionController::exog_queue_poll(optional timeout) { exog_queue_block(timeout); return exog_queue_pop(); @@ -137,7 +136,7 @@ void AExecutionController::terminate() } -void AExecutionController::exog_queue_push(shared_ptr> exog) +void AExecutionController::exog_queue_push(shared_ptr exog) { std::lock_guard { exog_mutex_ }; exog_queue_.push_back(std::move(exog)); @@ -147,7 +146,7 @@ void AExecutionController::exog_queue_push(shared_ptr> } } -void AExecutionController::exog_queue_push_front(shared_ptr > exog) +void AExecutionController::exog_queue_push_front(shared_ptr exog) { std::lock_guard { exog_mutex_ }; exog_queue_.push_front(std::move(exog)); @@ -160,14 +159,13 @@ void AExecutionController::exog_queue_push_front(shared_ptr> { - step_time_action_->make_ref( - { new Value( - get_type(), - Clock::now().time_since_epoch().count()) - } - ) - } ); + exog_queue_push_front(shared_ptr { new ExogEvent { + step_time_action_, + { unique_ptr( new Value ( + get_type(), + Clock::now().time_since_epoch().count() + ) ) } + } } ); std::lock_guard l2 { wait_mutex_ }; } @@ -191,24 +189,23 @@ History &AExecutionController::history() void AExecutionController::drain_exog_queue() { while (!exog_empty()) { - shared_ptr> exog = exog_queue_pop(); + shared_ptr exog = exog_queue_pop(); if (!std::dynamic_pointer_cast>(exog)) { // Nothing to do here for SwitchStateAction: // its effects have already been applied to the component model - if (!(*exog)->silent()) { - log(LogLevel::INF) << ">>> Exogenous event: " << exog << flush; + if (!exog->ref()->silent()) { + log(LogLevel::INF) << ">>> Exogenous event: " << exog->ref() << flush; silent_ = false; } - exog->attach_semantics(semantics_factory()); shared_ptr activity = std::dynamic_pointer_cast(exog); - if (activity && activity->target()->senses()) + if (activity && activity->action()->senses()) history().general_semantics().append_sensing_result( activity, - activity->target()->senses()->lhs(), - activity->target()->senses()->rhs().general_semantics().evaluate( - { &activity->binding() }, + activity->action()->senses()->lhs(), + activity->action()->senses()->rhs().general_semantics().evaluate( + { &activity->ref().binding() }, history() ) ); diff --git a/src/execution/controller.h b/src/execution/controller.h index ebf8d46a..05414f48 100644 --- a/src/execution/controller.h +++ b/src/execution/controller.h @@ -23,7 +23,6 @@ #include "platform_backend.h" #include "history.h" -#include "transformation.h" #include #include @@ -48,7 +47,7 @@ class ExogTimeout { class AExecutionController { public: - typedef std::deque>> ExogQueue; + typedef std::deque> ExogQueue; AExecutionController(unique_ptr &&platform_backend); virtual ~AExecutionController() = default; @@ -67,18 +66,18 @@ class AExecutionController { virtual void run(const Instruction &program) = 0; /// \return Head popped from the exog_queue or nullptr if it is empty. - shared_ptr> exog_queue_pop(); + shared_ptr exog_queue_pop(); /// Block until the exog_queue is non-empty. /// \return Head popped from the exog_queue. - shared_ptr> exog_queue_poll(optional timeout); + shared_ptr exog_queue_poll(optional timeout); /// Block until the exog_queue is non-empty. void exog_queue_block(optional timeout); bool exog_empty(); - void exog_queue_push(shared_ptr> exog); - void exog_queue_push_front(shared_ptr> exog); + void exog_queue_push(shared_ptr exog); + void exog_queue_push_front(shared_ptr exog); /// Update context_time and unblock exog_queue. void exog_timer_wakeup(); diff --git a/src/execution/dummy_backend.cpp b/src/execution/dummy_backend.cpp index 9ca827c1..0e6abd27 100644 --- a/src/execution/dummy_backend.cpp +++ b/src/execution/dummy_backend.cpp @@ -72,13 +72,11 @@ std::function DummyBackend::rnd_exog_generator() break; shared_ptr exog = exogs_[static_cast(rnd_exog_index_(prng_))]; - vector> args; + vector> args; for (shared_ptr p : exog->params()) args.push_back(rnd_value(p->type())); - shared_ptr> event(new Reference(exog, std::move(args))); - event->attach_semantics(exec_context()->semantics_factory()); - + shared_ptr event(new Event(exog, std::move(args))); exec_context()->exog_queue_push(event); } log(LogLevel::INF) << "exog generator TERMINATED" << flush; diff --git a/src/execution/event.cpp b/src/execution/event.cpp new file mode 100644 index 00000000..6c1df5e1 --- /dev/null +++ b/src/execution/event.cpp @@ -0,0 +1,61 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + + +#include "event.h" +#include +#include +#include + +namespace gologpp { + +template +Event::Event(shared_ptr action, vector> &&args) +: ground_action_(action, std::forward>>(args)) +{} + +template +Event::Event(shared_ptr action, std::initializer_list> &&args) +: ground_action_(action, std::vector> { std::forward>>(args) }) +{} + +template +const vector &Event::args() +{ return ground_action_.args(); } + + +template +vector> Event::argscp() const +{ + vector> rv; + for (Value *v : ground_action_.args()) + rv.push_back(unique_ptr(v)); + return rv; +} + + +template +class Event; + +template +class Event; + +template +class Event; + + +} // gologpp diff --git a/src/execution/event.h b/src/execution/event.h new file mode 100644 index 00000000..a90804cc --- /dev/null +++ b/src/execution/event.h @@ -0,0 +1,60 @@ +/************************************************************************* + * This file is part of golog++. + * + * golog++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * golog++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with golog++. If not, see . +**************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace gologpp { + + +class AbstractEvent +{ +public: + virtual const Reference &ref() const = 0; + virtual Reference &ref() = 0; +}; + + +template +class Event +: public AbstractEvent +{ +public: + Event(shared_ptr action, vector> &&args); + Event(shared_ptr action, std::initializer_list> &&args); + Event(shared_ptr action, std::initializer_list &&args); + shared_ptr &action() const; + + const vector &args(); + vector> argscp() const; + virtual const Reference &ref() const override; + virtual Reference &ref() override; + + +protected: + Reference ground_action_; +}; + + +} diff --git a/src/execution/history.cpp b/src/execution/history.cpp index 18872a85..679c5993 100644 --- a/src/execution/history.cpp +++ b/src/execution/history.cpp @@ -26,7 +26,7 @@ GeneralSemantics::GeneralSemantics(History &h, AExecutionController &co , context_(context) {} -GeneralSemantics::~GeneralSemantics() +GeneralSemantics::~GeneralSemantics() {} @@ -54,7 +54,7 @@ AExecutionController &GeneralSemantics::context() const const ModelElement &GeneralSemantics::model_element() const { return history_; } -void GeneralSemantics::append(shared_ptr> a) +void GeneralSemantics::append(shared_ptr a) { append(*a); } diff --git a/src/execution/history.h b/src/execution/history.h index 2272acd2..822de2ac 100644 --- a/src/execution/history.h +++ b/src/execution/history.h @@ -43,13 +43,11 @@ class History : public LanguageElement, public NoScopeOwner { template<> class GeneralSemantics : public virtual GeneralSemantics { public: - GeneralSemantics(History &history, AExecutionController &context); - virtual ~GeneralSemantics() override; + GeneralSemantics(History &history, AExecutionController &context); + virtual ~GeneralSemantics() override; - virtual shared_ptr get_last_transition() = 0; - virtual void append(const Reference &) = 0; - virtual void append(const Transition &) = 0; - virtual void append(shared_ptr>); + virtual void append(const AbstractEvent &) = 0; + virtual void append(shared_ptr); virtual bool should_progress() const = 0; virtual void progress() = 0; diff --git a/src/execution/plan.cpp b/src/execution/plan.cpp index 612938a7..495b2ee4 100644 --- a/src/execution/plan.cpp +++ b/src/execution/plan.cpp @@ -134,7 +134,7 @@ void Plan::sanitize_time_window(iterator back_from_it) auto it = std::find_if(reverse_iterator(back_from_it), elements().rend(), [&] (TimedInstruction &ti) { try { Transition &trans2 = ti.instruction().cast(); - return trans2.hook() == Transition::Hook::START && trans2 == *trans; + return trans2.hook() == Transition::Hook::START && trans2.ref() == trans->ref(); } catch (std::bad_cast &) { return false; } @@ -143,19 +143,19 @@ void Plan::sanitize_time_window(iterator back_from_it) if (it == elements().rend()) { // Not found: use best guess ti.set_earliest(prev_earliest); - ti.set_latest(prev_latest + trans->target()->duration().max); + ti.set_latest(prev_latest + trans->action()->duration().max); } else { // Found: add on top ti.set_earliest( std::max( - it->earliest_timepoint() + trans->target()->duration().min, + it->earliest_timepoint() + trans->action()->duration().min, prev_earliest ) ); ti.set_latest( std::max( - it->latest_timepoint() + trans->target()->duration().max, + it->latest_timepoint() + trans->action()->duration().max, prev_latest ) ); diff --git a/src/execution/platform_backend.cpp b/src/execution/platform_backend.cpp index 57d783e2..3ce9c22b 100644 --- a/src/execution/platform_backend.cpp +++ b/src/execution/platform_backend.cpp @@ -42,7 +42,7 @@ shared_ptr PlatformBackend::start_activity(const Transition &trans) { Lock l(lock()); shared_ptr a = std::make_shared(trans, *exec_ctx_); - auto it = activities_.find(a->hash()); + auto it = activities_.find(a->ref().hash()); if (it != activities_.end()) throw UserError( "Cannot start an action while another one with the same arguments is still running." @@ -51,16 +51,16 @@ shared_ptr PlatformBackend::start_activity(const Transition &trans) a->attach_semantics(exec_context()->semantics_factory()); a->set_state(Activity::target_state(trans.hook())); execute_activity(a); - activities_.insert({a->hash(), a}); + activities_.insert({a->ref().hash(), a}); return a; } void PlatformBackend::cancel_activity(const Transition &trans) { Lock l(lock()); - auto it = activities_.find(trans.hash()); + auto it = activities_.find(trans.ref().hash()); if (it == activities_.end()) - throw Bug("Activity lost: " + trans->str()); + throw Bug("Activity lost: " + trans.ref().str()); else if (it->second->state() != Activity::State::RUNNING) log(LogLevel::ERR) << "Cannot cancel activity " << it->second->str() << flush; else @@ -76,13 +76,13 @@ shared_ptr PlatformBackend::erase_activity(const Transition &trans) { Lock l(lock()); - ActivityMap::iterator it = activities_.find(trans.hash()); + ActivityMap::iterator it = activities_.find(trans.ref().hash()); shared_ptr dur_running; if (it != activities_.end()) dur_running = std::dynamic_pointer_cast(it->second); if (!dur_running) - throw LostTransition(trans->str()); + throw LostTransition(trans.ref().str()); // Either the durative action's state exactly matches the primitive action's hook, // or the hook is END, which may be executed if the durative state is either FINAL, FAILED or CANCELLED @@ -99,7 +99,7 @@ shared_ptr PlatformBackend::erase_activity(const Transition &trans) return dur_running; } else - throw InconsistentTransition(trans->str()); + throw InconsistentTransition(trans.ref().str()); } @@ -110,7 +110,7 @@ void PlatformBackend::set_context(AExecutionController *ctx) } -Activity::State PlatformBackend::current_state(const ReferenceBase &a) +Activity::State PlatformBackend::current_state(const Grounding &a) { Lock l(lock()); diff --git a/src/execution/platform_backend.h b/src/execution/platform_backend.h index f87fa235..d5ec331d 100644 --- a/src/execution/platform_backend.h +++ b/src/execution/platform_backend.h @@ -58,7 +58,7 @@ class PlatformBackend { void set_context(AExecutionController *ctx); AExecutionController *exec_context(); - Activity::State current_state(const ReferenceBase &); + Activity::State current_state(const Grounding &); void terminate(); virtual void schedule_timer_event(Clock::time_point when); diff --git a/src/execution/transition.cpp b/src/execution/transition.cpp index 4fdc35a0..2a862551 100644 --- a/src/execution/transition.cpp +++ b/src/execution/transition.cpp @@ -24,19 +24,14 @@ #include "controller.h" #include "transition.h" -#include "history.h" namespace gologpp { -Transition::Transition(const shared_ptr &action, vector> &&args, Hook hook) -: ReferenceBase(action, std::move(args)) -, hook_(hook) -{} Transition::Transition(const Transition &other) -: ReferenceBase(other) +: Event(other.action(), other.argscp()) , hook_(other.hook()) { if (other.semantics_) { @@ -44,18 +39,6 @@ Transition::Transition(const Transition &other) } } -const Action &Transition::operator *() const -{ return *this->target(); } - -Action &Transition::operator *() -{ return *this->target(); } - -const Action *Transition::operator ->() const -{ return this->target().get(); } - -Action *Transition::operator ->() -{ return this->target().get(); } - Transition::Hook Transition::hook() const { return hook_; } @@ -64,14 +47,14 @@ void Transition::attach_semantics(SemanticsFactory &implementor) { if (!semantics_) { semantics_ = implementor.make_semantics(*this); - binding().attach_semantics(implementor); + ground_action_.attach_semantics(implementor); for (auto &c : args()) c->attach_semantics(implementor); } } string Transition::to_string(const string &pfx) const -{ return pfx + gologpp::to_string(hook()) + "(" + ReferenceBase::to_string(pfx) + ")"; } +{ return pfx + gologpp::to_string(hook()) + "(" + ground_action_.to_string(pfx) + ")"; } diff --git a/src/execution/transition.h b/src/execution/transition.h index 45ebeb4c..64db45d3 100644 --- a/src/execution/transition.h +++ b/src/execution/transition.h @@ -23,28 +23,24 @@ #include #include #include +#include namespace gologpp { class Transition -: public ReferenceBase -, public Reference -, public Instruction +: public Instruction +, public Event +, public NoScopeOwner , public LanguageElement , public std::enable_shared_from_this { public: using Hook = DurativeCall::Hook; - Transition(const shared_ptr &action, vector> &&args, Hook hook); - Transition(const shared_ptr &action, const vector> &args, Hook hook); + using Event::Event; Transition(const Transition &); - - virtual const Action &operator * () const override; - virtual Action &operator * () override; - virtual const Action *operator -> () const override; - virtual Action *operator -> () override; + Transition(shared_ptr action, vector> &&value, Hook hook); Hook hook() const; virtual string to_string(const string &pfx) const override; @@ -73,8 +69,6 @@ class GeneralSemantics virtual AExecutionController &context() const override; - shared_ptr activity() const; - private: const Transition *element_; AExecutionController &context_; diff --git a/src/model/domain.h b/src/model/domain.h index e85c7c95..3b60dc3a 100644 --- a/src/model/domain.h +++ b/src/model/domain.h @@ -21,7 +21,6 @@ #include "gologpp.h" #include "language.h" #include "scope.h" -#include "expressions.h" #include "value.h" #include "error.h" diff --git a/src/model/expressions.h b/src/model/expressions.h index bf2d529e..252c1825 100644 --- a/src/model/expressions.h +++ b/src/model/expressions.h @@ -19,7 +19,6 @@ #define GOLOGPP_EXPRESSIONS_H_ #include "language.h" -#include "utilities.h" #include "gologpp.h" #include "types.h" diff --git a/src/model/gologpp.h b/src/model/gologpp.h index 920aa64a..f5f45d0b 100644 --- a/src/model/gologpp.h +++ b/src/model/gologpp.h @@ -52,9 +52,11 @@ class Logger; class Expression; class Instruction; +class Value; -class Binding; -using BindingChain = vector; +template class ABinding; +using Binding = ABinding; +class BindingChain; class ModelElement; class Plan; @@ -70,8 +72,11 @@ class ExogAction; class BackendMapping; +class AbstractEvent; +template class Event; class Activity; class Transition; +using ExogEvent = Event; class Identifier; @@ -101,7 +106,6 @@ class Fluent; class InitialValue; class Variable; -class Value; class Domain; class ArithmeticOperation; @@ -138,7 +142,10 @@ class Procedure; class ExogFunction; class AbstractReference; -template class Reference; +template class Reference; + +template +using Grounding = Reference; class CompoundExpression; class ListExpression; @@ -154,8 +161,6 @@ class AExecutionController; class PlatformBackend; -using ExogEvent = Reference; - namespace platform { @@ -213,12 +218,17 @@ class SemanticsFactory; (Conditional) \ (During) \ (Reference) \ + (Grounding) \ + (Grounding) \ (Reference) \ + (Grounding) \ (DurativeCall) \ (Reference) \ (ListPop) \ (Transition) \ - (ListPush) + (ListPush) \ + (Event) \ + (Event) #define GOLOGPP_EXPRESSIONS \ (Variable) \ @@ -241,12 +251,15 @@ class SemanticsFactory; (CompoundExpression) \ (ListExpression) + + #define GOLOGPP_OTHER \ (EffectAxiom>) \ (EffectAxiom) \ (EffectAxiom) \ (InitialValue)(Fluent) \ - (Binding) \ + (ABinding) \ + (ABinding) \ (Domain) \ (Function) \ (ExogFunction) \ diff --git a/src/model/platform/component_backend.cpp b/src/model/platform/component_backend.cpp index 3eba1bf5..7f545995 100644 --- a/src/model/platform/component_backend.cpp +++ b/src/model/platform/component_backend.cpp @@ -74,9 +74,8 @@ void ComponentBackend::exog_state_change(const shared_ptr &tgt) log(LogLevel::ERR) << "Component backend \"" << model().name() << "\" breached model by going from state \"" << model().current_state() << "\" to \"" << tgt->name() << "\"" << flush; - shared_ptr exog_state_change = exec_context_->switch_state_action(); - shared_ptr> evt { new gologpp::Reference { - exog_state_change, + shared_ptr> evt { new Event { + exec_context_->switch_state_action(), { new Value(get_type(), model_->name()), new Value(get_type(), model_->current_state()->name()), diff --git a/src/model/platform/component_backend.h b/src/model/platform/component_backend.h index 8ba8a01b..398cfadd 100644 --- a/src/model/platform/component_backend.h +++ b/src/model/platform/component_backend.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace gologpp { diff --git a/src/model/platform/reference.h b/src/model/platform/reference.h index c1110fa9..69ccfe43 100644 --- a/src/model/platform/reference.h +++ b/src/model/platform/reference.h @@ -28,12 +28,12 @@ namespace platform { template<> class Reference -: public ReferenceBase +: public ReferenceBase , public ChildElement , public LanguageElement, VoidType> { public: - using ReferenceBase::ReferenceBase; + using ReferenceBase::ReferenceBase; virtual void attach_semantics(gologpp::SemanticsFactory &f) override; }; diff --git a/src/model/procedural.cpp b/src/model/procedural.cpp index ff8d1a50..6c982f2d 100644 --- a/src/model/procedural.cpp +++ b/src/model/procedural.cpp @@ -19,7 +19,6 @@ #include #include "procedural.h" -#include "formula.h" #include "reference.h" #include "expressions.h" diff --git a/src/model/procedural.h b/src/model/procedural.h index 3e8ffcb2..c51ee15f 100644 --- a/src/model/procedural.h +++ b/src/model/procedural.h @@ -452,7 +452,7 @@ class GeneralSemantics> public: GeneralSemantics(const Reference &elem, AExecutionController &context); - virtual ~GeneralSemantics>() = default; + virtual ~GeneralSemantics() = default; virtual Value evaluate(const BindingChain &, const History &) override; diff --git a/src/model/reference.cpp b/src/model/reference.cpp index a788a29e..32b18ce5 100644 --- a/src/model/reference.cpp +++ b/src/model/reference.cpp @@ -14,36 +14,39 @@ * You should have received a copy of the GNU General Public License * along with golog++. If not, see . **************************************************************************/ - #include "reference.h" +#include "value.h" #include namespace gologpp { - -Binding::Binding(const Binding &other) +template +ABinding::ABinding(const ABinding &other) { for (auto &pair : other.var_bindings_) var_bindings_.emplace(pair.first, dynamic_cast(*pair.second).copy()); if (other.semantics_) set_semantics(unique_ptr>( - other.general_semantics().copy(*this) + other.general_semantics>().copy(*this) ) ); } -Binding::Binding(Binding &&other) +template +ABinding::ABinding(ABinding &&other) : var_bindings_(std::move(other.var_bindings_)) { if (other.semantics_) throw Bug("Cannot move a Binding after semantics have been assigned"); } -void Binding::bind(shared_ptr var, unique_ptr &&expr) +template +void ABinding::bind(shared_ptr var, unique_ptr &&expr) { var_bindings_.insert(std::make_pair(var, std::move(expr))); } -Expression &Binding::get(shared_ptr param) const +template +ExprT &ABinding::get(shared_ptr param) const { auto it = var_bindings_.find(param); if (it == var_bindings_.end()) @@ -51,11 +54,13 @@ Expression &Binding::get(shared_ptr param) const return *it->second; } -const Binding::MapT &Binding::map() const +template +const typename ABinding::MapT &ABinding::map() const { return var_bindings_; } -void Binding::attach_semantics(SemanticsFactory &f) +template +void ABinding::attach_semantics(SemanticsFactory &f) { if (!semantics_) { set_semantics(f.make_semantics(*this)); @@ -65,7 +70,8 @@ void Binding::attach_semantics(SemanticsFactory &f) } -string Binding::to_string(const string &pfx) const +template +string ABinding::to_string(const string &pfx) const { string rv; for (auto &entry : var_bindings_) @@ -75,25 +81,49 @@ string Binding::to_string(const string &pfx) const return rv; } + +template +class ABinding; + +template +class ABinding; + ///////////////////////////////////////////////////////////////////////////////////////////////// /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -GeneralSemantics::GeneralSemantics(const Binding &elem, AExecutionController &context) +template +GeneralSemantics>::GeneralSemantics(const ABinding &elem, AExecutionController &context) : element_(&elem) , context_(context) {} -const Binding &GeneralSemantics::element() const +template +const ABinding &GeneralSemantics>::element() const { return *element_; } -void GeneralSemantics::update_element(const Binding *new_element) +template +void GeneralSemantics>::update_element(const ABinding *new_element) { element_ = new_element; } -AExecutionController &GeneralSemantics::context() const +template +AExecutionController &GeneralSemantics>::context() const { return context_; } +template +const ModelElement &GeneralSemantics>::model_element() const +{ return *element_; } + +template +class GeneralSemantics>; + +template +class GeneralSemantics>; + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// void Reference::attach_semantics(SemanticsFactory &implementor) { @@ -102,9 +132,6 @@ void Reference::attach_semantics(SemanticsFactory &implementor) semantics_ = implementor.make_semantics(*this); } -const ModelElement &GeneralSemantics::model_element() const -{ return *element_; } - } diff --git a/src/model/reference.h b/src/model/reference.h index f27d9042..38be796b 100644 --- a/src/model/reference.h +++ b/src/model/reference.h @@ -15,18 +15,17 @@ * along with golog++. If not, see . **************************************************************************/ -#ifndef GOLOGPP_REFERENCE_H_ -#define GOLOGPP_REFERENCE_H_ +#pragma once #include "abstract_reference.h" #include "language.h" #include "expressions.h" +#include "value.h" #include "utilities.h" #include "gologpp.h" #include "scope.h" #include "error.h" #include "variable.h" -#include "domain.h" #include #include @@ -37,21 +36,26 @@ namespace gologpp { -class Binding : public ModelElement { +template +class ABinding : public ModelElement { public: using MapT = std::unordered_map < shared_ptr, - unique_ptr + unique_ptr >; - Binding(const Binding &); - Binding(Binding &&); - Binding() = default; + ABinding(const ABinding &); + ABinding(ABinding &&); - virtual ~Binding() = default; + template + ABinding(const ABinding &, enable_if::value> * = 0); - void bind(shared_ptr var, unique_ptr &&expr); - virtual Expression &get(shared_ptr param) const; + ABinding() = default; + + virtual ~ABinding() = default; + + void bind(shared_ptr var, unique_ptr &&expr); + virtual ExprT &get(shared_ptr param) const; const MapT &map() const; virtual void attach_semantics(SemanticsFactory &f) override; @@ -65,43 +69,56 @@ class Binding : public ModelElement { /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -template<> -class GeneralSemantics +/// Disambiguate this against the generic GeneralSemantics, which +/// is also a partial specialization but requires this to be false in Cond. +template +bool partially_specialized> = true; + + +template +class GeneralSemantics> : public virtual GeneralSemantics { public: - GeneralSemantics(const Binding &elem, AExecutionController &context); + GeneralSemantics(const ABinding &elem, AExecutionController &context); - virtual ~GeneralSemantics() = default; + virtual ~GeneralSemantics() = default; - const Binding &element() const; - void update_element(const Binding *new_element); + const ABinding &element() const; + void update_element(const ABinding *new_element); virtual AExecutionController &context() const override; virtual const ModelElement &model_element() const override; - virtual GeneralSemantics *copy(const Binding &target_element) const = 0; + virtual GeneralSemantics> *copy(const ABinding &target_element) const = 0; private: - const Binding *element_; + const ABinding *element_; AExecutionController &context_; }; + +class BindingChain : public vector *> { +public: + using vector *>::vector; + BindingChain(std::initializer_list *>); +}; + ///////////////////////////////////////////////////////////////////////////////////////////////// /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -template +template class ReferenceBase : public virtual AbstractReference , public NoScopeOwner { public: - ReferenceBase(const shared_ptr &target, vector> &&args) + ReferenceBase(const shared_ptr &target, vector> &&args) : target_(target) { size_t idx = 0; while (idx < args.size() && idx < this->target()->params().size()) { - unique_ptr arg { std::move(args[idx]) }; + unique_ptr arg { std::move(args[idx]) }; arg->set_parent(this); args_.emplace_back(arg.get()); binding_.bind(this->target()->params()[idx], std::move(arg)); @@ -110,7 +127,7 @@ class ReferenceBase ensure_consistent(); } - ReferenceBase(const shared_ptr &target, Binding &&binding) + ReferenceBase(const shared_ptr &target, ABinding &&binding) : target_(target) , binding_(std::move(binding)) { @@ -119,30 +136,30 @@ class ReferenceBase ensure_consistent(); } - ReferenceBase(const shared_ptr &target, const vector &args) - : ReferenceBase(target, vector>(args.begin(), args.end())) + ReferenceBase(const shared_ptr &target, const vector &args) + : ReferenceBase(target, vector>(args.begin(), args.end())) {} - ReferenceBase(const string &target_name, const vector &args) + ReferenceBase(const string &target_name, const vector &args) : ReferenceBase( global_scope().lookup_global(target_name), args ) {} - ReferenceBase(const string &target_name, const boost::optional> &args) + ReferenceBase(const string &target_name, const boost::optional> &args) : ReferenceBase(target_name, args.get_value_or({})) {} - ReferenceBase(ReferenceBase &&other) + ReferenceBase(ReferenceBase &&other) : args_(std::move(other.args_)) , target_(std::move(other.target_)) , binding_(std::move(other.binding_)) { ensure_consistent(); } - ReferenceBase(const ReferenceBase &other) + ReferenceBase(const ReferenceBase &other) : args_(copy(other.args_)) , target_(other.target_) , binding_(other.binding_) @@ -164,7 +181,7 @@ class ReferenceBase { return this->target().get(); } - bool operator == (const ReferenceBase &other) const + bool operator == (const ReferenceBase &other) const { if (this->target() != other.target()) return false; @@ -175,7 +192,7 @@ class ReferenceBase return true; } - bool operator != (const ReferenceBase &other) const + bool operator != (const ReferenceBase &other) const { return !(*this == other); } const string &name() const @@ -190,13 +207,13 @@ class ReferenceBase virtual bool bound() const override { return !target_.expired(); } - const vector &args() const + const vector &args() const { return args_; } - vector &args() + vector &args() { return args_; } - virtual const Expression &arg_for_param(shared_ptr param) const override + virtual const ArgsT &arg_for_param(shared_ptr param) const override { return binding_.get(param); } virtual bool consistent() const override @@ -243,21 +260,21 @@ class ReferenceBase return rv; } - virtual Binding &binding() + virtual ABinding &binding() { return binding_; } - virtual const Binding &binding() const + virtual const ABinding &binding() const { return binding_; } protected: - vector args_; + vector args_; weak_ptr target_; - Binding binding_; + ABinding binding_; }; -template<> -class Reference +template +class Reference : public virtual AbstractReference { public: @@ -271,22 +288,22 @@ class Reference /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -template +template class Reference -: public ReferenceBase -, public LanguageElement> +: public ReferenceBase +, public LanguageElement> , public TargetT::SignifierT , public virtual std::conditional < std::is_base_of::value, - Reference, + Reference, AbstractReference >::type { public: - using ReferenceBase::ReferenceBase; + using ReferenceBase::ReferenceBase; - Reference(const Reference &other) - : ReferenceBase(other) + Reference(const Reference &other) + : ReferenceBase(other) {} virtual ~Reference() override = default; @@ -514,4 +531,4 @@ struct equal_to *> { } -#endif // GOLOGPP_REFERENCE_H_ + diff --git a/src/model/semantics.h b/src/model/semantics.h index 9fc66156..d6eda1d5 100644 --- a/src/model/semantics.h +++ b/src/model/semantics.h @@ -128,6 +128,7 @@ template class GeneralSemantics && !is_instruction + && !partially_specialized > > : public virtual GeneralSemantics { diff --git a/src/model/utilities.cpp b/src/model/utilities.cpp index 1ac114af..6e715e40 100644 --- a/src/model/utilities.cpp +++ b/src/model/utilities.cpp @@ -16,7 +16,6 @@ **************************************************************************/ #include "utilities.h" -#include "logger.h" #include "value.h" namespace gologpp { @@ -42,14 +41,6 @@ string Identifier::signature_str() const { return name() + "/" + std::to_string(arity()); } -vector> copy(const vector> &v) -{ - vector> rv; - for (const unique_ptr &e : v) - rv.emplace_back(dynamic_cast(*e).copy()); - return rv; -} - vector copy(const vector &v) { diff --git a/src/model/utilities.h b/src/model/utilities.h index 3a57ec38..70848d2f 100644 --- a/src/model/utilities.h +++ b/src/model/utilities.h @@ -72,8 +72,15 @@ struct identifier_equals { }; -vector> copy(const vector> &v); -vector copy(const vector &v); +template +vector copy(const vector &v) +{ + vector rv; + for (const EPtrT &e : v) + rv.emplace_back(e->copy()); + return rv; +} + template diff --git a/src/model/value.h b/src/model/value.h index cfd0a219..a7a017d3 100644 --- a/src/model/value.h +++ b/src/model/value.h @@ -208,7 +208,7 @@ class GeneralSemantics public: GeneralSemantics(const Value &elem, AExecutionController &context); - virtual ~GeneralSemantics() = default; + virtual ~GeneralSemantics() = default; virtual AExecutionController &context() const override; diff --git a/src/model/variable.h b/src/model/variable.h index 1d155e87..5f9aee7c 100644 --- a/src/model/variable.h +++ b/src/model/variable.h @@ -23,7 +23,6 @@ #include "utilities.h" #include "expressions.h" #include "scope.h" -#include "domain.h" #include "semantics.h" #include diff --git a/src/parser/expressions.cpp b/src/parser/expressions.cpp index 32037619..308262c2 100644 --- a/src/parser/expressions.cpp +++ b/src/parser/expressions.cpp @@ -37,13 +37,13 @@ #include #include "types.h" +#include "domain.h" #include "arithmetic.h" #include "formula.h" #include "string_expression.h" #include "symbolic_expression.h" #include "compound_expression.h" #include "list_expression.h" -#include "mixed_member_access.h" #include diff --git a/src/parser/fluent.cpp b/src/parser/fluent.cpp index 04e35aae..60bc6a68 100644 --- a/src/parser/fluent.cpp +++ b/src/parser/fluent.cpp @@ -17,7 +17,6 @@ #include "fluent.h" #include "types.h" -#include "domain.h" #include "variable.h" #include "value.h" diff --git a/src/parser/fluent.h b/src/parser/fluent.h index c9c0f34d..7ee04508 100644 --- a/src/parser/fluent.h +++ b/src/parser/fluent.h @@ -19,7 +19,6 @@ #define GOLOGPP_PARSER_FLUENT_H_ #include "utilities.h" -#include "domain.h" namespace gologpp { namespace parser { diff --git a/src/parser/platform/reference.cpp b/src/parser/platform/reference.cpp index aaa8c5ac..502399e1 100644 --- a/src/parser/platform/reference.cpp +++ b/src/parser/platform/reference.cpp @@ -117,7 +117,7 @@ PlatformRefParser::PlatformRefParser() > ")" ) [ _val = phoenix::bind(&get_platform_global_ref, _r2, _1, _2), - if_(!_val || !phoenix::bind(&ReferenceBase::consistent, *_val)) [ + if_(!_val || !phoenix::bind(&ReferenceBase::consistent, *_val)) [ _pass = false, delete_(_val) ] diff --git a/src/parser/reference.cpp b/src/parser/reference.cpp index 4efab203..3d4f00e8 100644 --- a/src/parser/reference.cpp +++ b/src/parser/reference.cpp @@ -33,11 +33,15 @@ #include #include #include -#include #include #include #include +// Somehow this ends up including deprecated /usr/include/boost/spirit/include/phoenix.hpp +#define BOOST_ALLOW_DEPRECATED_HEADERS +#include + + #include #include #include @@ -89,7 +93,7 @@ ReferenceParser::ReferenceParser() > ")" ) [ _val = phoenix::bind(&get_ref, _r2, _1, _2), - if_(!_val || !phoenix::bind(&ReferenceBase::consistent, *_val)) [ + if_(!_val || !phoenix::bind(&ReferenceBase::consistent, *_val)) [ _pass = false, delete_(_val) ] diff --git a/src/parser/value.cpp b/src/parser/value.cpp index ba6a8ffb..e779545c 100644 --- a/src/parser/value.cpp +++ b/src/parser/value.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include From 5fc42b5dd5793732db2448935453e7202630185f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Thu, 26 Jan 2023 01:09:29 +0100 Subject: [PATCH 14/33] model: clarify copyability of elements & semantics --- src/execution/activity.cpp | 20 ++++--- src/execution/activity.h | 10 +--- src/execution/dummy_backend.cpp | 2 +- src/execution/event.cpp | 42 +++++++++++---- src/execution/event.h | 17 +++++- src/execution/platform_backend.cpp | 7 ++- src/execution/transition.cpp | 19 +++---- src/execution/transition.h | 13 ++++- src/model/domain.cpp | 2 +- src/model/effect_axiom.h | 2 - src/model/gologpp.h | 15 +++--- src/model/model_element.cpp | 2 +- src/model/model_element.h | 8 ++- src/model/platform/component_backend.cpp | 3 +- src/model/platform/switch_state_action.h | 10 ++++ src/model/reference.cpp | 38 +++++++------- src/model/reference.h | 66 +++++++++++++++--------- src/model/semantics.h | 34 +++++++++++- src/model/utilities.cpp | 10 ---- src/model/utilities.h | 4 +- src/model/value.cpp | 7 +-- src/model/value.h | 2 - 22 files changed, 206 insertions(+), 127 deletions(-) diff --git a/src/execution/activity.cpp b/src/execution/activity.cpp index 7749b0ba..cabbc4a3 100644 --- a/src/execution/activity.cpp +++ b/src/execution/activity.cpp @@ -102,19 +102,17 @@ Value Activity::mapped_arg_value(const string &name) const const std::string &Activity::mapped_name() const { return action()->mapping().backend_name(); } -string Activity::to_string(const string &pfx) const -{ return pfx + "state(" + ref().to_string("") + ") = " + gologpp::to_string(state()); } +shared_ptr Activity::action() const +{ return ref().target(); } +const vector &Activity::args() const +{ return ref().args(); } -void Activity::attach_semantics(SemanticsFactory &implementor) -{ - if (!semantics_) { - ref().binding().attach_semantics(implementor); - semantics_ = implementor.make_semantics(*this); - for (auto &c : args()) - c->attach_semantics(implementor); - } -} +const Reference &Activity::ref() const +{ return action_ref_; } + +Reference &Activity::ref() +{ return action_ref_; } string to_string(Activity::State s) diff --git a/src/execution/activity.h b/src/execution/activity.h index 312cfefc..2da72e9a 100644 --- a/src/execution/activity.h +++ b/src/execution/activity.h @@ -28,11 +28,7 @@ namespace gologpp { -class Activity -: public Instruction -, public LanguageElement -, public NoScopeOwner -, public std::enable_shared_from_this { +class Activity { public: enum State { IDLE, RUNNING, FINAL, CANCELLED, FAILED }; @@ -56,10 +52,6 @@ class Activity const Reference &ref() const; Reference &ref(); - virtual string to_string(const string &pfx) const override; - - virtual void attach_semantics(SemanticsFactory &) override; - static State target_state(Transition::Hook); private: diff --git a/src/execution/dummy_backend.cpp b/src/execution/dummy_backend.cpp index 0e6abd27..7f85b06d 100644 --- a/src/execution/dummy_backend.cpp +++ b/src/execution/dummy_backend.cpp @@ -122,7 +122,7 @@ void DummyBackend::preempt_activity(shared_ptr a) { std::lock_guard locked(thread_mtx_); if (activity_threads_.find(a) == activity_threads_.end()) - throw EngineError("No such activity: " + a->str()); + throw EngineError("No such activity: " + a->ref().str()); activity_threads_[a]->cancel(); } diff --git a/src/execution/event.cpp b/src/execution/event.cpp index 6c1df5e1..09b3ab13 100644 --- a/src/execution/event.cpp +++ b/src/execution/event.cpp @@ -20,33 +20,57 @@ #include #include #include +#include namespace gologpp { +string AbstractEvent::to_string(const string &pfx) const +{ return ref().to_string(pfx); } + template Event::Event(shared_ptr action, vector> &&args) -: ground_action_(action, std::forward>>(args)) +: ground_action_(action, std::move(args)) {} template Event::Event(shared_ptr action, std::initializer_list> &&args) -: ground_action_(action, std::vector> { std::forward>>(args) }) +: ground_action_(action, std::vector> { std::move(args) }) {} template -const vector &Event::args() -{ return ground_action_.args(); } +Event::Event(shared_ptr action, std::initializer_list &&args) +: ground_action_(action, std::vector> { args.begin(), args.end() }) +{} +template +Event::Event(Event &&other) +: ground_action_(std::move(other.ground_action_)) +{} template -vector> Event::argscp() const +Event::Event(const Event &other) +: ground_action_(other.ground_action_) { - vector> rv; - for (Value *v : ground_action_.args()) - rv.push_back(unique_ptr(v)); - return rv; + if (other.semantics_) + semantics_.reset(other.template general_semantics>().copy(*this)); } +template +shared_ptr Event::action() const +{ return ground_action_.target(); } + +template +const vector &Event::args() +{ return ground_action_.args(); } + +template +const Reference &Event::ref() const +{ return ground_action_; } + +template +Reference &Event::ref() +{ return ground_action_; } + template class Event; diff --git a/src/execution/event.h b/src/execution/event.h index a90804cc..b1a2afd8 100644 --- a/src/execution/event.h +++ b/src/execution/event.h @@ -29,32 +29,45 @@ namespace gologpp { class AbstractEvent +: public virtual AbstractLanguageElement +, public NoScopeOwner { public: virtual const Reference &ref() const = 0; virtual Reference &ref() = 0; + + virtual string to_string(const string &pfx) const override; }; +template +static constexpr const bool is_copyable> = true; + + template class Event : public AbstractEvent +, public std::enable_shared_from_this> { public: Event(shared_ptr action, vector> &&args); Event(shared_ptr action, std::initializer_list> &&args); Event(shared_ptr action, std::initializer_list &&args); - shared_ptr &action() const; + Event(Event &&other); + explicit Event(const Event &other); + + shared_ptr action() const; const vector &args(); - vector> argscp() const; virtual const Reference &ref() const override; virtual Reference &ref() override; + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(ground_action_) protected: Reference ground_action_; }; + } diff --git a/src/execution/platform_backend.cpp b/src/execution/platform_backend.cpp index 3ce9c22b..edec0c39 100644 --- a/src/execution/platform_backend.cpp +++ b/src/execution/platform_backend.cpp @@ -46,9 +46,8 @@ shared_ptr PlatformBackend::start_activity(const Transition &trans) if (it != activities_.end()) throw UserError( "Cannot start an action while another one with the same arguments is still running." - " Currently: " + it->second->str() + " Currently: " + it->second->ref().str() ); - a->attach_semantics(exec_context()->semantics_factory()); a->set_state(Activity::target_state(trans.hook())); execute_activity(a); activities_.insert({a->ref().hash(), a}); @@ -62,7 +61,7 @@ void PlatformBackend::cancel_activity(const Transition &trans) if (it == activities_.end()) throw Bug("Activity lost: " + trans.ref().str()); else if (it->second->state() != Activity::State::RUNNING) - log(LogLevel::ERR) << "Cannot cancel activity " << it->second->str() << flush; + log(LogLevel::ERR) << "Cannot cancel activity " << it->second->ref().str() << flush; else preempt_activity(std::dynamic_pointer_cast(it->second)); } @@ -118,7 +117,7 @@ Activity::State PlatformBackend::current_state(const Grounding &a) if (it == activities_.end()) return Activity::State::IDLE; else { - return it->second->cast().state(); + return it->second->state(); } } diff --git a/src/execution/transition.cpp b/src/execution/transition.cpp index 2a862551..9c02ad18 100644 --- a/src/execution/transition.cpp +++ b/src/execution/transition.cpp @@ -21,7 +21,6 @@ #include #include - #include "controller.h" #include "transition.h" @@ -29,15 +28,15 @@ namespace gologpp { - Transition::Transition(const Transition &other) -: Event(other.action(), other.argscp()) +: Event(other) , hook_(other.hook()) -{ - if (other.semantics_) { - semantics_.reset(other.general_semantics().copy(*this)); - } -} +{} + +Transition::Transition(shared_ptr action, vector > &&value, Hook hook) +: Event(action, std::move(value)) +, hook_(hook) +{} Transition::Hook Transition::hook() const { return hook_; } @@ -78,8 +77,6 @@ const ModelElement &GeneralSemantics::model_element() const { return element(); } const Instruction &GeneralSemantics::instruction() const -{ return element(); } - - +{ return static_cast(element()); } } // namespace gologpp diff --git a/src/execution/transition.h b/src/execution/transition.h index 64db45d3..43e0dddf 100644 --- a/src/execution/transition.h +++ b/src/execution/transition.h @@ -31,9 +31,7 @@ namespace gologpp { class Transition : public Instruction , public Event -, public NoScopeOwner , public LanguageElement -, public std::enable_shared_from_this { public: using Hook = DurativeCall::Hook; @@ -77,6 +75,17 @@ class GeneralSemantics +class ExogEvent +: public Event +, public LanguageElement +, public Instruction +{ +public: + using Event::Event; +}; + + + } #endif // GOLOGPP_TRANSITION_H_ diff --git a/src/model/domain.cpp b/src/model/domain.cpp index bf2d9239..e1a8045d 100644 --- a/src/model/domain.cpp +++ b/src/model/domain.cpp @@ -180,7 +180,7 @@ void Domain::add_elements(const Domain &other) for (const unique_ptr &e : other.elements()) { if (!(element_type() >= *e)) throw TypeError(*e, element_type()); - elements_.emplace(e->copy()); + elements_.emplace(new Value(*e)); } } diff --git a/src/model/effect_axiom.h b/src/model/effect_axiom.h index a9130127..a1fed6f9 100644 --- a/src/model/effect_axiom.h +++ b/src/model/effect_axiom.h @@ -20,10 +20,8 @@ #include "utilities.h" #include "action.h" -#include "reference.h" #include "language.h" #include "expressions.h" -#include "fluent.h" #include "procedural.h" #include diff --git a/src/model/gologpp.h b/src/model/gologpp.h index f5f45d0b..2e0825fe 100644 --- a/src/model/gologpp.h +++ b/src/model/gologpp.h @@ -54,8 +54,7 @@ class Expression; class Instruction; class Value; -template class ABinding; -using Binding = ABinding; +template class Binding; class BindingChain; class ModelElement; @@ -76,7 +75,7 @@ class AbstractEvent; template class Event; class Activity; class Transition; -using ExogEvent = Event; +class ExogEvent; class Identifier; @@ -154,6 +153,7 @@ class History; template class Semantics; template class GeneralSemantics; +template class CopyableSemantics; class SemanticsFactory; @@ -176,6 +176,7 @@ class Clock; class State; class SwitchStateAction; +class SwitchStateEvent; class ClockFormula; class ClockBound; @@ -228,7 +229,8 @@ class SemanticsFactory; (Transition) \ (ListPush) \ (Event) \ - (Event) + (Event) \ + (Event) #define GOLOGPP_EXPRESSIONS \ (Variable) \ @@ -258,14 +260,13 @@ class SemanticsFactory; (EffectAxiom) \ (EffectAxiom) \ (InitialValue)(Fluent) \ - (ABinding) \ - (ABinding) \ + (Binding) \ + (Binding) \ (Domain) \ (Function) \ (ExogFunction) \ (Procedure) \ (Action) \ - (Activity) \ (ExogAction) \ (Scope) \ (History) diff --git a/src/model/model_element.cpp b/src/model/model_element.cpp index 8b6b7c1b..0ac6f827 100644 --- a/src/model/model_element.cpp +++ b/src/model/model_element.cpp @@ -25,7 +25,7 @@ namespace gologpp { string ModelElement::str() const { return to_string(""); } -void ModelElement::set_semantics(std::unique_ptr> &&impl) +void ModelElement::set_semantics(unique_ptr> &&impl) { semantics_ = std::move(impl); } diff --git a/src/model/model_element.h b/src/model/model_element.h index 1e4d6c4a..0d0d0b1d 100644 --- a/src/model/model_element.h +++ b/src/model/model_element.h @@ -26,6 +26,10 @@ namespace gologpp { +template +static constexpr const bool is_copyable = false; + + class ModelElement { public: using SignifierT = ModelElement; @@ -52,7 +56,7 @@ class ModelElement { Semantics &semantics() const { return dynamic_cast &>(*semantics_); } - void set_semantics(std::unique_ptr> &&impl); + void set_semantics(unique_ptr> &&impl); virtual void attach_semantics(SemanticsFactory &) = 0; virtual string to_string(const string &pfx) const = 0; @@ -67,7 +71,7 @@ class ModelElement { { return dynamic_cast(*this); } protected: - std::unique_ptr> semantics_; + unique_ptr> semantics_; }; diff --git a/src/model/platform/component_backend.cpp b/src/model/platform/component_backend.cpp index 7f545995..3003429c 100644 --- a/src/model/platform/component_backend.cpp +++ b/src/model/platform/component_backend.cpp @@ -20,6 +20,7 @@ #include #include "component_backend.h" +#include "switch_state_action.h" #include @@ -74,7 +75,7 @@ void ComponentBackend::exog_state_change(const shared_ptr &tgt) log(LogLevel::ERR) << "Component backend \"" << model().name() << "\" breached model by going from state \"" << model().current_state() << "\" to \"" << tgt->name() << "\"" << flush; - shared_ptr> evt { new Event { + shared_ptr evt { new SwitchStateEvent { exec_context_->switch_state_action(), { new Value(get_type(), model_->name()), diff --git a/src/model/platform/switch_state_action.h b/src/model/platform/switch_state_action.h index 82d5ff7a..decdbc31 100644 --- a/src/model/platform/switch_state_action.h +++ b/src/model/platform/switch_state_action.h @@ -18,6 +18,7 @@ #pragma once #include +#include namespace gologpp { namespace platform { @@ -45,6 +46,15 @@ class SwitchStateAction }; +class SwitchStateEvent +: public Instruction +, public Event +, public LanguageElement +{ + using Event::Event; +}; + + } // namespace platform ///////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/model/reference.cpp b/src/model/reference.cpp index 32b18ce5..3cdb0bc9 100644 --- a/src/model/reference.cpp +++ b/src/model/reference.cpp @@ -22,19 +22,19 @@ namespace gologpp { -template -ABinding::ABinding(const ABinding &other) +template<> +Binding::Binding(const Binding &other) { for (auto &pair : other.var_bindings_) - var_bindings_.emplace(pair.first, dynamic_cast(*pair.second).copy()); + var_bindings_.emplace(pair.first, new Value(*pair.second)); if (other.semantics_) set_semantics(unique_ptr>( - other.general_semantics>().copy(*this) + other.general_semantics>().copy(*this) ) ); } template -ABinding::ABinding(ABinding &&other) +Binding::Binding(Binding &&other) : var_bindings_(std::move(other.var_bindings_)) { if (other.semantics_) @@ -42,11 +42,11 @@ ABinding::ABinding(ABinding &&other) } template -void ABinding::bind(shared_ptr var, unique_ptr &&expr) +void Binding::bind(shared_ptr var, unique_ptr &&expr) { var_bindings_.insert(std::make_pair(var, std::move(expr))); } template -ExprT &ABinding::get(shared_ptr param) const +ExprT &Binding::get(shared_ptr param) const { auto it = var_bindings_.find(param); if (it == var_bindings_.end()) @@ -55,12 +55,12 @@ ExprT &ABinding::get(shared_ptr param) const } template -const typename ABinding::MapT &ABinding::map() const +const typename Binding::MapT &Binding::map() const { return var_bindings_; } template -void ABinding::attach_semantics(SemanticsFactory &f) +void Binding::attach_semantics(SemanticsFactory &f) { if (!semantics_) { set_semantics(f.make_semantics(*this)); @@ -71,7 +71,7 @@ void ABinding::attach_semantics(SemanticsFactory &f) template -string ABinding::to_string(const string &pfx) const +string Binding::to_string(const string &pfx) const { string rv; for (auto &entry : var_bindings_) @@ -83,43 +83,43 @@ string ABinding::to_string(const string &pfx) const template -class ABinding; +class Binding; template -class ABinding; +class Binding; ///////////////////////////////////////////////////////////////////////////////////////////////// /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// template -GeneralSemantics>::GeneralSemantics(const ABinding &elem, AExecutionController &context) +GeneralSemantics>::GeneralSemantics(const Binding &elem, AExecutionController &context) : element_(&elem) , context_(context) {} template -const ABinding &GeneralSemantics>::element() const +const Binding &GeneralSemantics>::element() const { return *element_; } template -void GeneralSemantics>::update_element(const ABinding *new_element) +void GeneralSemantics>::update_element(const Binding *new_element) { element_ = new_element; } template -AExecutionController &GeneralSemantics>::context() const +AExecutionController &GeneralSemantics>::context() const { return context_; } template -const ModelElement &GeneralSemantics>::model_element() const +const ModelElement &GeneralSemantics>::model_element() const { return *element_; } template -class GeneralSemantics>; +class GeneralSemantics>; template -class GeneralSemantics>; +class GeneralSemantics>; ///////////////////////////////////////////////////////////////////////////////////////////////// /***********************************************************************************************/ diff --git a/src/model/reference.h b/src/model/reference.h index 38be796b..550eebc7 100644 --- a/src/model/reference.h +++ b/src/model/reference.h @@ -36,26 +36,34 @@ namespace gologpp { -template class ABinding : public ModelElement { +public: + void bind(shared_ptr var, unique_ptr &&value); + virtual Expression &get(shared_ptr param) const = 0; +}; + + +template +class Binding : public ABinding { public: using MapT = std::unordered_map < shared_ptr, unique_ptr >; - ABinding(const ABinding &); - ABinding(ABinding &&); + Binding(const Binding &); + Binding(Binding &&); + // Allow cross-conversion between Binding and Binding template - ABinding(const ABinding &, enable_if::value> * = 0); + Binding(const Binding &, enable_if::value> * = 0); - ABinding() = default; + Binding() = default; - virtual ~ABinding() = default; + virtual ~Binding() = default; void bind(shared_ptr var, unique_ptr &&expr); - virtual ExprT &get(shared_ptr param) const; + virtual ExprT &get(shared_ptr param) const override; const MapT &map() const; virtual void attach_semantics(SemanticsFactory &f) override; @@ -70,37 +78,36 @@ class ABinding : public ModelElement { ///////////////////////////////////////////////////////////////////////////////////////////////// /// Disambiguate this against the generic GeneralSemantics, which -/// is also a partial specialization but requires this to be false in Cond. +/// is also a partial specialization but is disabled if this is true. template -bool partially_specialized> = true; +bool partially_specialized>> = true; template -class GeneralSemantics> +class GeneralSemantics> : public virtual GeneralSemantics { public: - GeneralSemantics(const ABinding &elem, AExecutionController &context); + GeneralSemantics(const Binding &elem, AExecutionController &context); virtual ~GeneralSemantics() = default; - const ABinding &element() const; - void update_element(const ABinding *new_element); + const Binding &element() const; + void update_element(const Binding *new_element); virtual AExecutionController &context() const override; virtual const ModelElement &model_element() const override; - virtual GeneralSemantics> *copy(const ABinding &target_element) const = 0; + virtual GeneralSemantics> *copy(const Binding &target_element) const = 0; private: - const ABinding *element_; + const Binding *element_; AExecutionController &context_; }; -class BindingChain : public vector *> { +class BindingChain : public vector { public: - using vector *>::vector; - BindingChain(std::initializer_list *>); + using vector::vector; }; ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -120,14 +127,14 @@ class ReferenceBase while (idx < args.size() && idx < this->target()->params().size()) { unique_ptr arg { std::move(args[idx]) }; arg->set_parent(this); - args_.emplace_back(arg.get()); binding_.bind(this->target()->params()[idx], std::move(arg)); + args_.emplace_back(&binding_.get(this->target()->params()[idx])); ++idx; } ensure_consistent(); } - ReferenceBase(const shared_ptr &target, ABinding &&binding) + ReferenceBase(const shared_ptr &target, Binding &&binding) : target_(target) , binding_(std::move(binding)) { @@ -148,6 +155,7 @@ class ReferenceBase ) {} + ReferenceBase(const string &target_name, const boost::optional> &args) : ReferenceBase(target_name, args.get_value_or({})) {} @@ -260,16 +268,16 @@ class ReferenceBase return rv; } - virtual ABinding &binding() + virtual Binding &binding() { return binding_; } - virtual const ABinding &binding() const + virtual const Binding &binding() const { return binding_; } protected: vector args_; weak_ptr target_; - ABinding binding_; + Binding binding_; }; @@ -288,6 +296,9 @@ class Reference /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// +template +static constexpr const bool is_copyable> = true; + template class Reference : public ReferenceBase @@ -302,9 +313,14 @@ class Reference public: using ReferenceBase::ReferenceBase; - Reference(const Reference &other) + explicit Reference(const Reference &other) : ReferenceBase(other) - {} + { + if (other.semantics_) + this->semantics_.reset( + other.template general_semantics>().copy(*this) + ); + } virtual ~Reference() override = default; diff --git a/src/model/semantics.h b/src/model/semantics.h index d6eda1d5..1cd76d97 100644 --- a/src/model/semantics.h +++ b/src/model/semantics.h @@ -36,7 +36,7 @@ namespace gologpp { * Use it as a condition in the enable_if that gives Cond to prevent the ambiguous partial specialization * errors that would otherwise occur. */ -template +template static constexpr bool partially_specialized = false; template @@ -50,9 +50,29 @@ static constexpr bool is_expression = std::is_base_of::value /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// + +template +class CopyableSemantics +{ +public: + virtual GeneralSemantics *copy(const GologT &target_element) const = 0; +}; + + +template +class NonCopyableSemantics +{}; + + + template class GeneralSemantics>> : public virtual GeneralSemantics +, public std::conditional< + is_copyable, + CopyableSemantics, + NonCopyableSemantics + >::type { public: GeneralSemantics(const GologT &elem, AExecutionController &context) @@ -90,6 +110,11 @@ class GeneralSemantics>> template class GeneralSemantics>> : public virtual GeneralSemantics +, public std::conditional< + is_copyable, + CopyableSemantics, + NonCopyableSemantics + >::type { public: GeneralSemantics(const GologT &elem, AExecutionController &context) @@ -128,9 +153,14 @@ template class GeneralSemantics && !is_instruction - && !partially_specialized + && !partially_specialized> > > : public virtual GeneralSemantics +, public std::conditional< + is_copyable, + CopyableSemantics, + NonCopyableSemantics + >::type { public: GeneralSemantics(const GologT &elem, AExecutionController &context) diff --git a/src/model/utilities.cpp b/src/model/utilities.cpp index 6e715e40..281b881e 100644 --- a/src/model/utilities.cpp +++ b/src/model/utilities.cpp @@ -16,7 +16,6 @@ **************************************************************************/ #include "utilities.h" -#include "value.h" namespace gologpp { @@ -42,15 +41,6 @@ string Identifier::signature_str() const -vector copy(const vector &v) -{ - vector rv; - for (const Expression *e : v) - rv.emplace_back(dynamic_cast(*e).copy()); - return rv; -} - - #ifdef DEBUG_PARSER const string indent(""); #else diff --git a/src/model/utilities.h b/src/model/utilities.h index 70848d2f..31deb991 100644 --- a/src/model/utilities.h +++ b/src/model/utilities.h @@ -77,7 +77,9 @@ vector copy(const vector &v) { vector rv; for (const EPtrT &e : v) - rv.emplace_back(e->copy()); + rv.emplace_back( + new typename std::remove_pointer::type(*e) + ); return rv; } diff --git a/src/model/value.cpp b/src/model/value.cpp index d683c6a5..d29917f4 100644 --- a/src/model/value.cpp +++ b/src/model/value.cpp @@ -25,11 +25,11 @@ namespace gologpp { unique_ptr::unique_ptr(const unique_ptr &c) -: std::unique_ptr(c->copy()) +: std::unique_ptr(new Value(*c)) {} gologpp::unique_ptr::unique_ptr(const Value &v) -: std::unique_ptr(v.copy()) +: std::unique_ptr(new Value(v)) {} unique_ptr &unique_ptr::operator = (const unique_ptr &c) @@ -248,9 +248,6 @@ size_t Value::hash() const string Value::to_string(const string &pfx) const { return boost::apply_visitor(to_string_visitor { pfx, !(get_type() >= *this) }, representation_); } -Value *Value::copy() const -{ return new Value(*this); } - bool Value::operator == (const Expression &e) const { diff --git a/src/model/value.h b/src/model/value.h index a7a017d3..2b75b32a 100644 --- a/src/model/value.h +++ b/src/model/value.h @@ -157,8 +157,6 @@ class Value Value operator % (const Value &) const; Value pow(const Value &) const; - virtual Value *copy() const; - virtual void attach_semantics(SemanticsFactory &f) override; static Value undefined(); From 860a7a85aa6b1c94e2bbb20603a9d9558e11243b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Tue, 31 Jan 2023 17:58:30 +0100 Subject: [PATCH 15/33] model: fix Reference inheritance --- src/model/action.cpp | 8 +++++--- src/model/gologpp.h | 7 ++++--- src/model/model_element.h | 2 +- src/model/platform/reference.h | 1 - src/model/platform/switch_state_action.h | 7 +++++-- src/model/reference.h | 12 +++++++++++- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/model/action.cpp b/src/model/action.cpp index a95c7c00..8e861d5c 100644 --- a/src/model/action.cpp +++ b/src/model/action.cpp @@ -17,11 +17,11 @@ #include "mapping.h" #include "action.h" -#include "fluent.h" #include "reference.h" #include "effect_axiom.h" -#include "execution/controller.h" #include "error.h" +#include + #include namespace gologpp { @@ -222,7 +222,9 @@ void ExogAction::define( set_mapping(mapping.value()); } -void ExogAction::set_mapping(BackendMapping *m) { + +void ExogAction::set_mapping(BackendMapping *m) +{ string missing; const BackendMapping::ArgMapping &arg_mapping = m->arg_mapping(); diff --git a/src/model/gologpp.h b/src/model/gologpp.h index 2e0825fe..65bf059f 100644 --- a/src/model/gologpp.h +++ b/src/model/gologpp.h @@ -46,6 +46,7 @@ using std::nullopt; template using enable_if = typename std::enable_if::type; + using string = std::string; class Logger; @@ -77,6 +78,7 @@ class Activity; class Transition; class ExogEvent; + class Identifier; class Global; @@ -227,10 +229,9 @@ class SemanticsFactory; (Reference) \ (ListPop) \ (Transition) \ + (ExogEvent) \ (ListPush) \ - (Event) \ - (Event) \ - (Event) + (platform::SwitchStateEvent) #define GOLOGPP_EXPRESSIONS \ (Variable) \ diff --git a/src/model/model_element.h b/src/model/model_element.h index 0d0d0b1d..52413334 100644 --- a/src/model/model_element.h +++ b/src/model/model_element.h @@ -25,11 +25,11 @@ namespace gologpp { - template static constexpr const bool is_copyable = false; + class ModelElement { public: using SignifierT = ModelElement; diff --git a/src/model/platform/reference.h b/src/model/platform/reference.h index 69ccfe43..96dd24cf 100644 --- a/src/model/platform/reference.h +++ b/src/model/platform/reference.h @@ -29,7 +29,6 @@ namespace platform { template<> class Reference : public ReferenceBase -, public ChildElement , public LanguageElement, VoidType> { public: diff --git a/src/model/platform/switch_state_action.h b/src/model/platform/switch_state_action.h index decdbc31..ded7582f 100644 --- a/src/model/platform/switch_state_action.h +++ b/src/model/platform/switch_state_action.h @@ -47,11 +47,14 @@ class SwitchStateAction class SwitchStateEvent -: public Instruction -, public Event +: public Event , public LanguageElement +, public Instruction { +public: using Event::Event; + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(ground_action_) }; diff --git a/src/model/reference.h b/src/model/reference.h index 550eebc7..62313ce9 100644 --- a/src/model/reference.h +++ b/src/model/reference.h @@ -118,6 +118,7 @@ template class ReferenceBase : public virtual AbstractReference , public NoScopeOwner +, public TargetT::SignifierT { public: ReferenceBase(const shared_ptr &target, vector> &&args) @@ -303,7 +304,6 @@ template class Reference : public ReferenceBase , public LanguageElement> -, public TargetT::SignifierT , public virtual std::conditional < std::is_base_of::value, Reference, @@ -348,6 +348,16 @@ class Reference }; + +/*template +static constexpr bool partially_specialized>> = true; + +template +class GeneralSemantics> +: public GeneralSemantics +{ +};*/ + ///////////////////////////////////////////////////////////////////////////////////////////////// /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// From 658820379bc0d7f72697e3c6060ea65b1f5c5471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Tue, 31 Jan 2023 20:53:10 +0100 Subject: [PATCH 16/33] execution: fix copying & instantiation of semantics --- src/execution/activity.cpp | 18 +++++++++--------- src/execution/activity.h | 8 ++++---- src/execution/controller.cpp | 1 + src/execution/dummy_backend.cpp | 2 +- src/execution/event.cpp | 6 ++---- src/execution/event.h | 6 ------ src/execution/platform_backend.cpp | 1 + src/execution/platform_backend.h | 1 - src/execution/transition.cpp | 27 +++++++++++++++------------ src/execution/transition.h | 16 ++++++++++++---- 10 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/execution/activity.cpp b/src/execution/activity.cpp index cabbc4a3..8883bb73 100644 --- a/src/execution/activity.cpp +++ b/src/execution/activity.cpp @@ -71,11 +71,7 @@ void Activity::update(Transition::Hook hook) PlatformBackend::Lock backend_lock = exec_context_.backend().lock(); set_state(target_state(hook)); exec_context_.exog_queue_push( - shared_ptr(new Transition( - action(), - vector>(args().begin(), args().end()), - hook - )) + shared_ptr(new Transition(action(), args(), hook)) ); update_condition_.notify_all(); } @@ -89,7 +85,6 @@ void Activity::wait_for_update() }); } - Value Activity::mapped_arg_value(const string &name) const { return @@ -98,15 +93,20 @@ Value Activity::mapped_arg_value(const string &name) const ).evaluate({ &this->ref().binding() }, exec_context_.history()); } - const std::string &Activity::mapped_name() const { return action()->mapping().backend_name(); } shared_ptr Activity::action() const { return ref().target(); } -const vector &Activity::args() const -{ return ref().args(); } + +vector> Activity::args() const +{ + vector> rv; + for (const Value *arg : ref().args()) + rv.emplace_back(new Value(*arg)); + return rv; +} const Reference &Activity::ref() const { return action_ref_; } diff --git a/src/execution/activity.h b/src/execution/activity.h index 2da72e9a..edf52c71 100644 --- a/src/execution/activity.h +++ b/src/execution/activity.h @@ -48,14 +48,14 @@ class Activity { const std::string &mapped_name() const; Value mapped_arg_value(const string &name) const; shared_ptr action() const; - const vector &args() const; - const Reference &ref() const; - Reference &ref(); + vector> args() const; + const Grounding &ref() const; + Grounding &ref(); static State target_state(Transition::Hook); private: - Reference action_ref_; + Grounding action_ref_; State state_; AExecutionController &exec_context_; diff --git a/src/execution/controller.cpp b/src/execution/controller.cpp index 23800f6d..4a50afe9 100644 --- a/src/execution/controller.cpp +++ b/src/execution/controller.cpp @@ -92,6 +92,7 @@ shared_ptr AExecutionController::exog_queue_pop() std::lock_guard locked{ exog_mutex_ }; shared_ptr rv = std::move(exog_queue_.front()); exog_queue_.pop_front(); + rv->attach_semantics(semantics_factory()); return rv; } diff --git a/src/execution/dummy_backend.cpp b/src/execution/dummy_backend.cpp index 7f85b06d..daa728e6 100644 --- a/src/execution/dummy_backend.cpp +++ b/src/execution/dummy_backend.cpp @@ -76,7 +76,7 @@ std::function DummyBackend::rnd_exog_generator() for (shared_ptr p : exog->params()) args.push_back(rnd_value(p->type())); - shared_ptr event(new Event(exog, std::move(args))); + shared_ptr event(new ExogEvent(exog, std::move(args))); exec_context()->exog_queue_push(event); } log(LogLevel::INF) << "exog generator TERMINATED" << flush; diff --git a/src/execution/event.cpp b/src/execution/event.cpp index 09b3ab13..fd329a09 100644 --- a/src/execution/event.cpp +++ b/src/execution/event.cpp @@ -24,6 +24,7 @@ namespace gologpp { + string AbstractEvent::to_string(const string &pfx) const { return ref().to_string(pfx); } @@ -50,10 +51,7 @@ Event::Event(Event &&other) template Event::Event(const Event &other) : ground_action_(other.ground_action_) -{ - if (other.semantics_) - semantics_.reset(other.template general_semantics>().copy(*this)); -} +{} template shared_ptr Event::action() const diff --git a/src/execution/event.h b/src/execution/event.h index b1a2afd8..6f1c5c66 100644 --- a/src/execution/event.h +++ b/src/execution/event.h @@ -40,10 +40,6 @@ class AbstractEvent }; -template -static constexpr const bool is_copyable> = true; - - template class Event : public AbstractEvent @@ -62,8 +58,6 @@ class Event virtual const Reference &ref() const override; virtual Reference &ref() override; - DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(ground_action_) - protected: Reference ground_action_; }; diff --git a/src/execution/platform_backend.cpp b/src/execution/platform_backend.cpp index edec0c39..98c834d9 100644 --- a/src/execution/platform_backend.cpp +++ b/src/execution/platform_backend.cpp @@ -18,6 +18,7 @@ #include "platform_backend.h" #include "controller.h" #include "activity.h" +#include "transition.h" #include #include diff --git a/src/execution/platform_backend.h b/src/execution/platform_backend.h index d5ec331d..80820980 100644 --- a/src/execution/platform_backend.h +++ b/src/execution/platform_backend.h @@ -22,7 +22,6 @@ #include #include -#include "transition.h" #include "activity.h" #include "clock.h" diff --git a/src/execution/transition.cpp b/src/execution/transition.cpp index 9c02ad18..8a89e64f 100644 --- a/src/execution/transition.cpp +++ b/src/execution/transition.cpp @@ -31,7 +31,10 @@ namespace gologpp { Transition::Transition(const Transition &other) : Event(other) , hook_(other.hook()) -{} +{ + if (other.semantics_) + semantics_.reset(other.general_semantics().copy(*this)); +} Transition::Transition(shared_ptr action, vector > &&value, Hook hook) : Event(action, std::move(value)) @@ -41,17 +44,6 @@ Transition::Transition(shared_ptr action, vector > &&v Transition::Hook Transition::hook() const { return hook_; } - -void Transition::attach_semantics(SemanticsFactory &implementor) -{ - if (!semantics_) { - semantics_ = implementor.make_semantics(*this); - ground_action_.attach_semantics(implementor); - for (auto &c : args()) - c->attach_semantics(implementor); - } -} - string Transition::to_string(const string &pfx) const { return pfx + gologpp::to_string(hook()) + "(" + ground_action_.to_string(pfx) + ")"; } @@ -79,4 +71,15 @@ const ModelElement &GeneralSemantics::model_element() const const Instruction &GeneralSemantics::instruction() const { return static_cast(element()); } + + +ExogEvent::ExogEvent(const ExogEvent &other) +: Event(other) +{ + if (other.semantics_) + semantics_.reset(other.general_semantics().copy(*this)); +} + + + } // namespace gologpp diff --git a/src/execution/transition.h b/src/execution/transition.h index 43e0dddf..97dd08a4 100644 --- a/src/execution/transition.h +++ b/src/execution/transition.h @@ -15,8 +15,7 @@ * along with golog++. If not, see . **************************************************************************/ -#ifndef GOLOGPP_TRANSITION_H_ -#define GOLOGPP_TRANSITION_H_ +#pragma once #include #include @@ -28,6 +27,9 @@ namespace gologpp { +template<> +inline constexpr const bool is_copyable = true; + class Transition : public Instruction , public Event @@ -42,7 +44,8 @@ class Transition Hook hook() const; virtual string to_string(const string &pfx) const override; - virtual void attach_semantics(SemanticsFactory &) override; + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(ground_action_) private: Hook hook_; @@ -75,6 +78,9 @@ class GeneralSemantics +template<> +inline constexpr const bool is_copyable = true; + class ExogEvent : public Event , public LanguageElement @@ -82,10 +88,12 @@ class ExogEvent { public: using Event::Event; + ExogEvent(const ExogEvent &other); + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(ground_action_) }; } -#endif // GOLOGPP_TRANSITION_H_ From 34520720c23c1604863e6e7d511d94c10ac47056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Tue, 31 Jan 2023 20:54:02 +0100 Subject: [PATCH 17/33] parser: silence boost::phoenix deprecated header warnings --- src/parser/expressions.cpp | 4 ++++ src/parser/reference.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/parser/expressions.cpp b/src/parser/expressions.cpp index 308262c2..4ae9a627 100644 --- a/src/parser/expressions.cpp +++ b/src/parser/expressions.cpp @@ -24,6 +24,10 @@ #include #include #include + +// This ends up including deprecated /usr/include/boost/spirit/include/phoenix.hpp, +// So we're silencing the warning until boost is fixed. +#define BOOST_ALLOW_DEPRECATED_HEADERS #include #include diff --git a/src/parser/reference.cpp b/src/parser/reference.cpp index 3d4f00e8..39a189c5 100644 --- a/src/parser/reference.cpp +++ b/src/parser/reference.cpp @@ -37,7 +37,8 @@ #include #include -// Somehow this ends up including deprecated /usr/include/boost/spirit/include/phoenix.hpp +// This ends up including deprecated /usr/include/boost/spirit/include/phoenix.hpp, +// So we're silencing the warning until boost is fixed. #define BOOST_ALLOW_DEPRECATED_HEADERS #include From f86e6d3f2e6122f569137813253c1fd29796574d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Tue, 31 Jan 2023 20:55:13 +0100 Subject: [PATCH 18/33] readylog: adapt to changed Reference interface --- CMakeLists.txt | 5 +- src/semantics/readylog/action.cpp | 3 +- src/semantics/readylog/effect_axiom.h | 6 +- src/semantics/readylog/execution.cpp | 7 +++ src/semantics/readylog/execution.h | 1 + src/semantics/readylog/fluent.cpp | 3 +- src/semantics/readylog/history.cpp | 5 +- src/semantics/readylog/history.h | 5 +- src/semantics/readylog/reference.cpp | 21 ++++--- src/semantics/readylog/reference.h | 81 +++++++++++++++++++++------ src/semantics/readylog/semantics.h | 6 +- src/semantics/readylog/transition.cpp | 40 ++++++------- src/semantics/readylog/transition.h | 18 ++++-- src/semantics/readylog/utilities.cpp | 4 +- src/semantics/readylog/utilities.h | 2 +- 15 files changed, 135 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08412db3..0a35c02f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,8 @@ set(SEMANTICS_INSTALL_DIR ${CMAKE_INSTALL_DATAROOTDIR}/golog++/semantics) set(GOLOGPP_VERSION 0.1.0) - +file(GLOB_RECURSE GOLOGPP_HEADERS "src/*.h") +add_custom_target(headers SOURCES ${GOLOGPP_HEADERS}) ###################################################################################### # The golog++ language metamodel: libgolog++.so @@ -318,7 +319,6 @@ if (${BUILD_READYLOG_SEMANTICS}) src/semantics/readylog/compound_expression.cpp src/semantics/readylog/list_expression.cpp src/semantics/readylog/transition.cpp - src/semantics/readylog/activity.cpp src/semantics/readylog/plan.cpp ) @@ -353,7 +353,6 @@ if (${BUILD_READYLOG_SEMANTICS}) src/semantics/readylog/compound_expression.h src/semantics/readylog/list_expression.h src/semantics/readylog/transition.h - src/semantics/readylog/activity.h src/semantics/readylog/plan.h src/semantics/readylog/wrap_eclipseclass.h diff --git a/src/semantics/readylog/action.cpp b/src/semantics/readylog/action.cpp index ca6aeb6f..244599b4 100644 --- a/src/semantics/readylog/action.cpp +++ b/src/semantics/readylog/action.cpp @@ -15,11 +15,10 @@ * along with golog++. If not, see . **************************************************************************/ -#include "value.h" #include "action.h" #include "effect_axiom.h" -#include "scope.h" #include "variable.h" +#include "domain.h" #include "wrap_eclipseclass.h" diff --git a/src/semantics/readylog/effect_axiom.h b/src/semantics/readylog/effect_axiom.h index ab52396d..4a2e134c 100644 --- a/src/semantics/readylog/effect_axiom.h +++ b/src/semantics/readylog/effect_axiom.h @@ -24,10 +24,6 @@ #include #include -#include "reference.h" -#include "scope.h" -#include "execution.h" - #include "wrap_eclipseclass.h" @@ -35,7 +31,7 @@ namespace gologpp { template -bool partially_specialized> = true; +bool partially_specialized>> = true; template class Semantics, void> diff --git a/src/semantics/readylog/execution.cpp b/src/semantics/readylog/execution.cpp index af99a791..24da8645 100644 --- a/src/semantics/readylog/execution.cpp +++ b/src/semantics/readylog/execution.cpp @@ -26,6 +26,7 @@ #include "utilities.h" #include "history.h" #include "transition.h" +#include "event.h" #include #include @@ -410,4 +411,10 @@ void ReadylogContext::run(const Instruction &program) +template<> +EC_word Semantics::plterm() +{ return element().ref().semantics().plterm(); } + + + } // namespace gologpp diff --git a/src/semantics/readylog/execution.h b/src/semantics/readylog/execution.h index 3a3ba6df..71d35fba 100644 --- a/src/semantics/readylog/execution.h +++ b/src/semantics/readylog/execution.h @@ -21,6 +21,7 @@ #include #include +#include #include "wrap_eclipseclass.h" namespace gologpp { diff --git a/src/semantics/readylog/fluent.cpp b/src/semantics/readylog/fluent.cpp index 9a4015a4..6974ce05 100644 --- a/src/semantics/readylog/fluent.cpp +++ b/src/semantics/readylog/fluent.cpp @@ -17,11 +17,10 @@ #include "fluent.h" #include "execution.h" -#include "scope.h" #include "utilities.h" -#include "value.h" #include "semantics.h" #include "variable.h" +#include "domain.h" #include diff --git a/src/semantics/readylog/history.cpp b/src/semantics/readylog/history.cpp index 52f7bd9d..37584dcb 100644 --- a/src/semantics/readylog/history.cpp +++ b/src/semantics/readylog/history.cpp @@ -63,10 +63,7 @@ shared_ptr Semantics::get_last_transition() } -void Semantics::append(const Transition &trans) -{ extend_history(::list(trans.semantics().plterm(), plterm())); } - -void Semantics::append(const Reference &trans) +void Semantics::append(const AbstractEvent &trans) { extend_history(::list(trans.semantics().plterm(), plterm())); } diff --git a/src/semantics/readylog/history.h b/src/semantics/readylog/history.h index 46a9b627..5b9a959b 100644 --- a/src/semantics/readylog/history.h +++ b/src/semantics/readylog/history.h @@ -36,9 +36,8 @@ class Semantics Semantics(History &, ReadylogContext &context); virtual ~Semantics() override = default; - virtual shared_ptr get_last_transition() override; - virtual void append(const Transition &exog) override; - virtual void append(const Reference &exog) override; + virtual shared_ptr get_last_transition(); + virtual void append(const AbstractEvent &exog) override; virtual bool should_progress() const override; virtual void progress() override; diff --git a/src/semantics/readylog/reference.cpp b/src/semantics/readylog/reference.cpp index dc9f7c3a..c38ea5e6 100644 --- a/src/semantics/readylog/reference.cpp +++ b/src/semantics/readylog/reference.cpp @@ -24,12 +24,11 @@ namespace gologpp { EC_word reference_term(const Reference &ref) { return EC_atom(ref.name().c_str()); } -template<> + EC_word Semantics>::plterm() { return element().target()->special_semantics().plterm(); } - template<> EC_word Semantics>::plterm() { @@ -41,14 +40,14 @@ EC_word Semantics>::plterm() } - template<> EC_word Semantics>::plterm() { return reference_term(element()); } -EC_word Semantics::plterm() +template +EC_word Semantics>::plterm() { if (this->element().map().empty()) return EC_atom("true"); @@ -67,8 +66,16 @@ EC_word Semantics::plterm() } } -Semantics *Semantics::copy(const Binding &target_element) const -{ return new Semantics(target_element, rl_context()); } +template +Semantics> *Semantics>::copy(const Binding &target_element) const +{ return new Semantics>(target_element, rl_context()); } + + +template +class Semantics>; + +template +class Semantics>; @@ -76,7 +83,7 @@ EC_word pl_binding_chain(const BindingChain &bc) { EC_word rv = EC_atom("true"); for (auto &b : bc) - rv = ::term(EC_functor(",", 2), rv, b->semantics().plterm()); + rv = ::term(EC_functor(",", 2), rv, b->semantics().plterm()); return rv; } diff --git a/src/semantics/readylog/reference.h b/src/semantics/readylog/reference.h index dc99d3ea..5846fe7a 100644 --- a/src/semantics/readylog/reference.h +++ b/src/semantics/readylog/reference.h @@ -30,7 +30,6 @@ #include "semantics.h" #include "utilities.h" #include "variable.h" -#include "value.h" #include "wrap_eclipseclass.h" @@ -41,22 +40,27 @@ namespace gologpp { EC_word pl_binding_chain(const BindingChain &b); -template<> -class Semantics -: public GeneralSemantics +/// Disambiguate this against the generic Semantics, which +/// is also a partial specialization but requires this to be false in Cond. +template +bool partially_specialized>> = true; + +template +class Semantics> +: public GeneralSemantics> , public Semantics { public: - using GeneralSemantics::GeneralSemantics; + using GeneralSemantics>::GeneralSemantics; virtual EC_word plterm() override; - virtual Semantics *copy(const Binding &target_element) const override; + virtual Semantics> *copy(const Binding &target_element) const override; }; -template -EC_word reference_term(const ReferenceBase &ref) +template +EC_word reference_term(const ReferenceBase &ref) { if (ref.arity() > 0) return ::term(EC_functor(ref.mangled_name().c_str(), ref.arity()), @@ -71,18 +75,17 @@ EC_word reference_term(const Reference &ref); -/// Disambiguate this against the generic Semantics, which +/*/// Disambiguate this against the generic Semantics, which /// is also a partial specialization but requires this to be false in Cond. -template -bool partially_specialized> = true; +template +bool partially_specialized>> = true;*/ -template -class Semantics> -: public GeneralSemantics> -, public Semantics::ElementType> +template +class ReferenceSemantics +: public GeneralSemantics> { public: - using GeneralSemantics>::GeneralSemantics; + using GeneralSemantics>::GeneralSemantics; bool args_need_eval() { for (auto &expr : this->element().args()) @@ -130,12 +133,58 @@ class Semantics> return ::term(EC_functor("and", 1), list); } +}; + + + +template +bool partially_specialized>> = true; + + +template +class Semantics> +: public ReferenceSemantics +, public Semantics +{ +public: + using ReferenceSemantics::ReferenceSemantics; + + Semantics> *copy(const Reference &target) const override + { return new Semantics>(target, this->context()); } virtual EC_word plterm() override { return reference_term(this->element()); } }; + +template +class Semantics> +: public ReferenceSemantics +, public Semantics +{ +public: + using ReferenceSemantics::ReferenceSemantics; + + virtual EC_word plterm() override + { return reference_term(this->element()); } +}; + + + +template<> +class Semantics> +: public Semantics +, public GeneralSemantics> +{ +public: + using GeneralSemantics>::GeneralSemantics; + + virtual EC_word plterm() override; +}; + + + template<> class Semantics> : public GeneralSemantics> diff --git a/src/semantics/readylog/semantics.h b/src/semantics/readylog/semantics.h index c2ded2ed..98501ab2 100644 --- a/src/semantics/readylog/semantics.h +++ b/src/semantics/readylog/semantics.h @@ -95,7 +95,7 @@ class Semantics template class Semantics + !partially_specialized> && is_expression > > : public GeneralSemantics @@ -114,7 +114,7 @@ class Semantics class Semantics + !partially_specialized> && is_instruction > > : public GeneralSemantics @@ -134,7 +134,7 @@ class Semantics class Semantics + !partially_specialized> && !is_expression && !is_instruction > > diff --git a/src/semantics/readylog/transition.cpp b/src/semantics/readylog/transition.cpp index f9487f1a..fd3cf176 100644 --- a/src/semantics/readylog/transition.cpp +++ b/src/semantics/readylog/transition.cpp @@ -15,7 +15,6 @@ * along with golog++. If not, see . **************************************************************************/ -#include "value.h" #include "transition.h" #include "execution.h" #include "reference.h" @@ -28,15 +27,10 @@ namespace gologpp { -Semantics::Semantics(const Transition &elem, ReadylogContext &context) -: GeneralSemantics(elem, context) -{} - - EC_word Semantics::plterm() { return ::term(EC_functor(to_string(element().hook()).c_str(), 1), - reference_term(element()) + reference_term(element().ref()) ); } @@ -50,7 +44,7 @@ static const ::std::unordered_map<::std::string, Transition::Hook> name2state { }; -shared_ptr gologpp::Semantics::transition_from_plterm(EC_word t) +shared_ptr Semantics::transition_from_plterm(EC_word t) { string headname = functor_name(t); @@ -65,7 +59,7 @@ shared_ptr gologpp::Semantics::transition_from_plterm(EC t.arg(1, t); headname = functor_name(t); - vector> args = plterm_args(t); + vector> args = plterm_args(t); shared_ptr action = global_scope().lookup_global(Name::demangle(headname)); shared_ptr rv { new Transition { action, std::move(args), state_it->second} }; @@ -82,21 +76,21 @@ Semantics *Semantics::copy(const Transition &target_elem unique_ptr Semantics::trans(const BindingChain &b, History &history) { BindingChain merged(b); - merged.emplace_back(&element().binding()); + merged.emplace_back(&element().ref().binding()); switch(element().hook()) { case Transition::Hook::CANCEL: - if (context().backend().current_state(element()) == Activity::State::RUNNING) + if (context().backend().current_state(element().ref()) == Activity::State::RUNNING) context().backend().cancel_activity(element()); else return nullptr; break; case Transition::Hook::START: if ( - context().backend().current_state(element()) != Activity::State::RUNNING + context().backend().current_state(element().ref()) != Activity::State::RUNNING && static_cast( - element().target()->precondition().general_semantics().evaluate( + element().action()->precondition().general_semantics().evaluate( merged, history ) @@ -107,29 +101,29 @@ unique_ptr Semantics::trans(const BindingChain &b, History &hi return nullptr; break; case Transition::Hook::FINISH: - if (context().backend().current_state(element()) == Activity::State::FINAL) { + if (context().backend().current_state(element().ref()) == Activity::State::FINAL) { shared_ptr a = context().backend().erase_activity(element()); } else return nullptr; break; case Transition::Hook::FAIL: - if (context().backend().current_state(element()) == Activity::State::FAILED) + if (context().backend().current_state(element().ref()) == Activity::State::FAILED) context().backend().erase_activity(element()); else return nullptr; break; case Transition::Hook::END: if ( - context().backend().current_state(element()) == Activity::State::FAILED - || context().backend().current_state(element()) == Activity::State::FINAL + context().backend().current_state(element().ref()) == Activity::State::FAILED + || context().backend().current_state(element().ref()) == Activity::State::FINAL ) context().backend().erase_activity(element()); else return nullptr; } - if (!element()->silent()) { + if (!element().action()->silent()) { log(LogLevel::NFY) << "<<< trans: " << element().str() << flush; context().set_silent(false); } @@ -140,9 +134,15 @@ unique_ptr Semantics::trans(const BindingChain &b, History &hi } -const Instruction &Semantics::instruction() const -{ return GeneralSemantics::instruction(); } +EC_word Semantics::plterm() +{ return element().ref().semantics().plterm(); } + +unique_ptr Semantics::trans(const BindingChain &, History &) +{ throw Bug("trans(...) should not be called on an ExogEvent"); } + +Semantics *Semantics::copy(const ExogEvent &target_element) const +{ return new Semantics(target_element, rl_context()); } diff --git a/src/semantics/readylog/transition.h b/src/semantics/readylog/transition.h index 69732073..8d676c67 100644 --- a/src/semantics/readylog/transition.h +++ b/src/semantics/readylog/transition.h @@ -30,19 +30,29 @@ class Semantics , public Semantics { public: - Semantics(const Transition &elem, ReadylogContext &context); + using GeneralSemantics::GeneralSemantics; virtual ~Semantics() override = default; virtual EC_word plterm() override; virtual unique_ptr trans(const BindingChain &b, History &h) override; - virtual const Instruction &instruction() const override; - virtual Semantics *copy(const Transition &target_element) const override; - static shared_ptr transition_from_plterm(EC_word); }; +template<> +class Semantics +: public GeneralSemantics +, public Semantics +{ +public: + using GeneralSemantics::GeneralSemantics; + + virtual EC_word plterm() override; + virtual unique_ptr trans(const BindingChain &b, History &h) override; + virtual Semantics *copy(const ExogEvent &target_element) const override; +}; + } // namespace gologpp diff --git a/src/semantics/readylog/utilities.cpp b/src/semantics/readylog/utilities.cpp index a9687d68..4c3771e2 100644 --- a/src/semantics/readylog/utilities.cpp +++ b/src/semantics/readylog/utilities.cpp @@ -146,9 +146,9 @@ string functor_name(EC_word term) { } -vector> plterm_args(EC_word head) { +vector> plterm_args(EC_word head) { EC_word term; - vector> rv; + vector> rv; for (int j = 1; j <= head.arity(); j++) { head.arg(j,term); diff --git a/src/semantics/readylog/utilities.h b/src/semantics/readylog/utilities.h index 772136be..6b94f5c2 100644 --- a/src/semantics/readylog/utilities.h +++ b/src/semantics/readylog/utilities.h @@ -117,7 +117,7 @@ EC_word copy_term(EC_word t); string functor_name(EC_word t); -vector> plterm_args(EC_word t); +vector> plterm_args(EC_word t); class ManagedTerm { From 0ba67a893545e2b1398ffd24a2b1e5c36f5afd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Tue, 31 Jan 2023 20:55:39 +0100 Subject: [PATCH 19/33] cmake: remove gcc-specific compiler flags Want to stay compat with clang. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a35c02f..1daf5b03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ endif() include_directories(${Boost_INCLUDE_DIR} src) -add_compile_options(-Wall -Wno-unknown-pragmas -fdiagnostics-path-format=inline-events -fdiagnostics-show-path-depths) +add_compile_options(-Wall -Wno-unknown-pragmas) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -fno-omit-frame-pointer -DDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2") From 77ca4f2bf540637965a4a8cdcbc9df076b9145c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Thu, 9 Feb 2023 18:41:11 +0100 Subject: [PATCH 20/33] fix reference ExprT inheritance --- src/model/platform/reference.h | 1 + src/model/reference.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/model/platform/reference.h b/src/model/platform/reference.h index 96dd24cf..69ccfe43 100644 --- a/src/model/platform/reference.h +++ b/src/model/platform/reference.h @@ -29,6 +29,7 @@ namespace platform { template<> class Reference : public ReferenceBase +, public ChildElement , public LanguageElement, VoidType> { public: diff --git a/src/model/reference.h b/src/model/reference.h index 62313ce9..ded6b548 100644 --- a/src/model/reference.h +++ b/src/model/reference.h @@ -118,7 +118,6 @@ template class ReferenceBase : public virtual AbstractReference , public NoScopeOwner -, public TargetT::SignifierT { public: ReferenceBase(const shared_ptr &target, vector> &&args) @@ -304,6 +303,7 @@ template class Reference : public ReferenceBase , public LanguageElement> +, public TargetT::SignifierT , public virtual std::conditional < std::is_base_of::value, Reference, From b7bfeab3df784efbadcea67610e5bbdd8f0b62ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Thu, 9 Feb 2023 18:41:50 +0100 Subject: [PATCH 21/33] taptenc: Adapt to new Refernce interface --- src/semantics/platform/taptenc/transformation.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/semantics/platform/taptenc/transformation.cpp b/src/semantics/platform/taptenc/transformation.cpp index ac453eb4..eacef677 100644 --- a/src/semantics/platform/taptenc/transformation.cpp +++ b/src/semantics/platform/taptenc/transformation.cpp @@ -138,7 +138,7 @@ vector TaptencTransformation::plan_gpp_to_taptenc(Plan &&p) for (auto &ti : p.elements()) { if (ti.instruction().is_a()) { Transition &trans = ti.instruction().cast(); - std::string actstr = gologpp::to_string(trans.hook()) + "G" + trans->name(); + std::string actstr = gologpp::to_string(trans.hook()) + "G" + trans.ref().name(); std::vector argstr; for (auto &arg : trans.args()) @@ -155,7 +155,7 @@ vector TaptencTransformation::plan_gpp_to_taptenc(Plan &&p) boost::numeric_cast(earliest_shifted), boost::numeric_cast(latest_shifted) ), - taptenc::Bounds(trans->duration().min.count(), trans->duration().max.count()) + taptenc::Bounds(trans.ref()->duration().min.count(), trans.ref()->duration().max.count()) } ); } else { @@ -190,14 +190,14 @@ unique_ptr TaptencTransformation::plan_taptenc_to_gpp(taptenc::timed_trace std::string TaptencTransformation::store_arg(Value &v) { - auto it = arg_to_sym_.find(unique_ptr(v.copy())); + auto it = arg_to_sym_.find(unique_ptr(new Value(v))); if (it != arg_to_sym_.end()) return it->second; else { size_t count = arg_to_sym_.size(); std::string rv = "arg" + std::to_string(count); - arg_to_sym_.insert({ unique_ptr(v.copy()), rv }); - sym_to_arg_.insert({ rv, unique_ptr(v.copy()) }); + arg_to_sym_.insert({ unique_ptr(new Value(v)), rv }); + sym_to_arg_.insert({ rv, unique_ptr(new Value(v)) }); return rv; } } @@ -208,7 +208,7 @@ Value *TaptencTransformation::retrieve_arg(std::string taptenc_symbolic_arg) auto it = sym_to_arg_.find(taptenc_symbolic_arg); if (it == sym_to_arg_.end()) throw Bug("Cannot retrieve argument from storage: " + taptenc_symbolic_arg); - return it->second->copy(); + return new Value(*it->second); } @@ -236,7 +236,7 @@ TimedInstruction TaptencTransformation::parse_domain_action( string act_name = tt_action.substr(hook_sep + 1, brace_opn - (hook_sep + 1)); string argstr = tt_action.substr(brace_opn + 1, brace_cls - (brace_opn + 1)); - vector> args; + vector> args; while (argstr.size()) { auto arg_sep = argstr.find(taptenc::constants::VAR_SEP); args.emplace_back(retrieve_arg(argstr.substr(0, arg_sep))); From 9ed9d8a24ba1f267eca404b02ac196944bbcbef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Fri, 10 Mar 2023 19:33:29 +0100 Subject: [PATCH 22/33] rename list_expression.* -> list.* Preparation for moving list operations out of procedural.* --- CMakeLists.txt | 16 ++++++++-------- src/model/{list_expression.cpp => list.cpp} | 2 +- src/model/{list_expression.h => list.h} | 0 src/parser/{list_expression.cpp => list.cpp} | 4 ++-- src/parser/{list_expression.h => list.h} | 0 .../native/{list_expression.cpp => list.cpp} | 11 ++++++++++- .../list_expression.h => native/list.h} | 2 +- .../readylog/{list_expression.cpp => list.cpp} | 2 +- .../list_expression.h => readylog/list.h} | 2 +- 9 files changed, 24 insertions(+), 15 deletions(-) rename src/model/{list_expression.cpp => list.cpp} (98%) rename src/model/{list_expression.h => list.h} (100%) rename src/parser/{list_expression.cpp => list.cpp} (97%) rename src/parser/{list_expression.h => list.h} (100%) rename src/semantics/native/{list_expression.cpp => list.cpp} (72%) rename src/semantics/{readylog/list_expression.h => native/list.h} (96%) rename src/semantics/readylog/{list_expression.cpp => list.cpp} (97%) rename src/semantics/{native/list_expression.h => readylog/list.h} (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1daf5b03..d3f43e52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,7 @@ set(INTERFACE_SRC src/model/language.cpp src/model/types.cpp src/model/compound_expression.cpp - src/model/list_expression.cpp + src/model/list.cpp src/model/semantics.cpp src/model/logger.cpp src/model/name.cpp @@ -158,7 +158,7 @@ install(FILES src/model/mapping.h src/model/types.h src/model/compound_expression.h - src/model/list_expression.h + src/model/list.h src/model/logger.h src/model/name.h @@ -231,7 +231,7 @@ if (${BUILD_PARSER}) src/parser/compound_expression.cpp src/parser/mixed_member_access.cpp src/parser/mapping.cpp - src/parser/list_expression.cpp + src/parser/list.cpp src/parser/value.cpp src/parser/platform/clock_formula.cpp @@ -268,7 +268,7 @@ if (${BUILD_PARSER}) src/parser/compound_expression.h src/parser/mixed_member_access.h src/parser/mapping.h - src/parser/list_expression.h + src/parser/list.h src/parser/value.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/golog++/parser ) @@ -317,7 +317,7 @@ if (${BUILD_READYLOG_SEMANTICS}) src/semantics/readylog/reference.cpp src/semantics/readylog/effect_axiom.cpp src/semantics/readylog/compound_expression.cpp - src/semantics/readylog/list_expression.cpp + src/semantics/readylog/list.cpp src/semantics/readylog/transition.cpp src/semantics/readylog/plan.cpp ) @@ -351,7 +351,7 @@ if (${BUILD_READYLOG_SEMANTICS}) src/semantics/readylog/string.h src/semantics/readylog/history.h src/semantics/readylog/compound_expression.h - src/semantics/readylog/list_expression.h + src/semantics/readylog/list.h src/semantics/readylog/transition.h src/semantics/readylog/plan.h src/semantics/readylog/wrap_eclipseclass.h @@ -409,7 +409,7 @@ if (${BUILD_NATIVE_SEMANTICS}) src/semantics/native/reference.cpp src/semantics/native/effect_axiom.cpp src/semantics/native/compound_expression.cpp - src/semantics/native/list_expression.cpp + src/semantics/native/list.cpp src/semantics/native/transition.cpp ) @@ -443,7 +443,7 @@ if (${BUILD_NATIVE_SEMANTICS}) src/semantics/native/string.h src/semantics/native/history.h src/semantics/native/compound_expression.h - src/semantics/native/list_expression.h + src/semantics/native/list.h src/semantics/native/transition.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/golog++/semantics/native diff --git a/src/model/list_expression.cpp b/src/model/list.cpp similarity index 98% rename from src/model/list_expression.cpp rename to src/model/list.cpp index 77b565d7..ff62017a 100644 --- a/src/model/list_expression.cpp +++ b/src/model/list.cpp @@ -15,7 +15,7 @@ * along with golog++. If not, see . **************************************************************************/ -#include "list_expression.h" +#include "list.h" #include "semantics.h" namespace gologpp { diff --git a/src/model/list_expression.h b/src/model/list.h similarity index 100% rename from src/model/list_expression.h rename to src/model/list.h diff --git a/src/parser/list_expression.cpp b/src/parser/list.cpp similarity index 97% rename from src/parser/list_expression.cpp rename to src/parser/list.cpp index d346dbfa..75cf2b55 100644 --- a/src/parser/list_expression.cpp +++ b/src/parser/list.cpp @@ -16,7 +16,7 @@ **************************************************************************/ #include "types.h" -#include "list_expression.h" +#include "list.h" #include "variable.h" #include "value.h" #include "reference.h" @@ -24,7 +24,7 @@ #include "expressions.h" #include -#include +#include #include #include diff --git a/src/parser/list_expression.h b/src/parser/list.h similarity index 100% rename from src/parser/list_expression.h rename to src/parser/list.h diff --git a/src/semantics/native/list_expression.cpp b/src/semantics/native/list.cpp similarity index 72% rename from src/semantics/native/list_expression.cpp rename to src/semantics/native/list.cpp index 9e67e948..08060a9f 100644 --- a/src/semantics/native/list_expression.cpp +++ b/src/semantics/native/list.cpp @@ -15,10 +15,19 @@ * along with golog++. If not, see . **************************************************************************/ -#include "list_expression.h" +#include "list.h" +#include namespace gologpp { +template<> +Value Semantics::evaluate(const BindingChain &b, const History &h) +{ + ListType::Representation rv; + for (const unique_ptr &expr : element().entries()) + rv.emplace_back(expr->semantics().evaluate(b, h)); + return Value(element().type(), rv); +} } // namespace gologpp diff --git a/src/semantics/readylog/list_expression.h b/src/semantics/native/list.h similarity index 96% rename from src/semantics/readylog/list_expression.h rename to src/semantics/native/list.h index 7011c973..2c5a6321 100644 --- a/src/semantics/readylog/list_expression.h +++ b/src/semantics/native/list.h @@ -20,7 +20,7 @@ #include "semantics.h" -#include +#include namespace gologpp { diff --git a/src/semantics/readylog/list_expression.cpp b/src/semantics/readylog/list.cpp similarity index 97% rename from src/semantics/readylog/list_expression.cpp rename to src/semantics/readylog/list.cpp index 74448dc2..cacd6967 100644 --- a/src/semantics/readylog/list_expression.cpp +++ b/src/semantics/readylog/list.cpp @@ -15,7 +15,7 @@ * along with golog++. If not, see . **************************************************************************/ -#include "list_expression.h" +#include "list.h" namespace gologpp { diff --git a/src/semantics/native/list_expression.h b/src/semantics/readylog/list.h similarity index 96% rename from src/semantics/native/list_expression.h rename to src/semantics/readylog/list.h index 7011c973..2c5a6321 100644 --- a/src/semantics/native/list_expression.h +++ b/src/semantics/readylog/list.h @@ -20,7 +20,7 @@ #include "semantics.h" -#include +#include namespace gologpp { From 9fe71f0cb2cdd87ef4cf09c602896c298c573894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Fri, 10 Mar 2023 20:37:02 +0100 Subject: [PATCH 23/33] move list-related code into list.* --- src/model/list.cpp | 105 +++++++++++++++++++++++ src/model/list.h | 104 ++++++++++++++++++++++- src/model/procedural.cpp | 106 ------------------------ src/model/procedural.h | 104 ----------------------- src/model/types.cpp | 2 +- src/parser/action.cpp | 1 + src/parser/arithmetic.cpp | 2 +- src/parser/assignment.cpp | 1 + src/parser/effect_axiom.cpp | 2 + src/parser/expressions.cpp | 2 +- src/parser/list.cpp | 1 + src/parser/list.h | 1 + src/parser/mixed_member_access.cpp | 3 +- src/parser/statements.h | 1 + src/semantics/readylog/effect_axiom.cpp | 1 + src/semantics/readylog/history.cpp | 4 + src/semantics/readylog/history.h | 3 +- src/semantics/readylog/list.cpp | 77 +++++++++++++++++ src/semantics/readylog/list.h | 12 +++ src/semantics/readylog/procedural.cpp | 77 +---------------- src/semantics/readylog/procedural.h | 14 ---- src/semantics/readylog/semantics.cpp | 2 +- src/semantics/readylog/semantics.h | 1 + 23 files changed, 319 insertions(+), 307 deletions(-) diff --git a/src/model/list.cpp b/src/model/list.cpp index ff62017a..fd314ec6 100644 --- a/src/model/list.cpp +++ b/src/model/list.cpp @@ -100,5 +100,110 @@ bool ListExpression::operator <= (const Type &t) const return t >= *this; } +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +ListAccess::ListAccess(Expression *subject, Expression *index) +: subject_(subject) +, index_(index) +{ + subject_->set_parent(this); + index_->set_parent(this); +} + +const Expression &ListAccess::subject() const +{ return *subject_; } + +const Expression &ListAccess::index() const +{ return *index_; } + + +const Type &ListAccess::type() const +{ + return dynamic_cast( + subject_->type() + ).element_type(); +} + +string ListAccess::to_string(const string &pfx) const +{ return subject_->to_string(pfx) + '[' + index_->str() + ']'; } + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +ListLength::ListLength(Expression *subject) +: subject_(subject) +{ subject_->set_parent(this); } + +const Expression &ListLength::subject() const +{ return *subject_; } + +string ListLength::to_string(const string &pfx) const +{ return "length(" + subject_->to_string(pfx) + ')'; } + + + +string to_string(ListOpEnd which_end) +{ + switch (which_end) { + case FRONT: + return "front"; + case BACK: + return "back"; + } + throw Bug(string("Unhandled ") + typeid(which_end).name()); +} + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +ListPop::ListPop(Expression *list, ListOpEnd which_end) +: list_(list) +, which_end_(which_end) +{ list_->set_parent(this); } + +const Expression &ListPop::list() const +{ return *list_; } + +ListOpEnd ListPop::which_end() const +{ return which_end_; } + +string ListPop::to_string(const string &pfx) const +{ return pfx + "pop_" + gologpp::to_string(which_end_) + '(' + list_->str() + ')'; } + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +ListPush::ListPush(Expression *list, ListOpEnd which_end, Expression *what) +: list_(list) +, which_end_(which_end) +{ + list_->set_parent(this); + + what->ensure_type( + dynamic_cast( + list_->type() + ).element_type() + ); + what_.reset(what); + what_->set_parent(this); +} + +const Expression &ListPush::list() const +{ return *list_; } + +ListOpEnd ListPush::which_end() const +{ return which_end_; } + +const Expression &ListPush::what() const +{ return *what_; } + +string ListPush::to_string(const string &pfx) const +{ return pfx + "push_" + gologpp::to_string(which_end_) + '(' + list_->str() + ')'; } + } // namespace gologpp diff --git a/src/model/list.h b/src/model/list.h index a7e28536..3cc0875a 100644 --- a/src/model/list.h +++ b/src/model/list.h @@ -18,11 +18,12 @@ #ifndef GOLOGPP_LIST_EXPRESSION_H_ #define GOLOGPP_LIST_EXPRESSION_H_ -#include "language.h" #include "gologpp.h" +#include "language.h" #include "expressions.h" #include "scope.h" #include "types.h" +#include "semantics.h" #include @@ -52,6 +53,107 @@ class ListExpression vector> entries_; }; +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +class ListAccess +: public Expression +, public NoScopeOwner +, public LanguageElement +{ +public: + ListAccess(Expression *subject, Expression *index); + const Expression &subject() const; + const Expression &index() const; + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*subject_, *index_) + + virtual const Type &type() const override; + + string to_string(const string &pfx) const override; + +private: + SafeExprOwner subject_; + SafeExprOwner index_; +}; + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +class ListLength +: public Expression +, public NoScopeOwner +, public LanguageElement +{ +public: + ListLength(Expression *subject); + const Expression &subject() const; + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*subject_) + + string to_string(const string &pfx) const override; + +private: + SafeExprOwner subject_; +}; + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +enum ListOpEnd { + FRONT, BACK +}; + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +class ListPop +: public Instruction +, public NoScopeOwner +, public LanguageElement +{ +public: + ListPop(Expression *list, ListOpEnd which_end); + const Expression &list() const; + ListOpEnd which_end() const; + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*list_) + + string to_string(const string &pfx) const override; + +private: + SafeExprOwner list_; + ListOpEnd which_end_; +}; + +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +class ListPush +: public Instruction +, public NoScopeOwner +, public LanguageElement +{ +public: + ListPush(Expression *list, ListOpEnd which_end, Expression *what); + const Expression &list() const; + ListOpEnd which_end() const; + const Expression &what() const; + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*list_, *what_) + + string to_string(const string &pfx) const override; + +private: + SafeExprOwner list_; + ListOpEnd which_end_; + unique_ptr what_; +}; } // namespace gologpp diff --git a/src/model/procedural.cpp b/src/model/procedural.cpp index 6c982f2d..fc59a553 100644 --- a/src/model/procedural.cpp +++ b/src/model/procedural.cpp @@ -597,111 +597,6 @@ string FieldAccess::to_string(const string &pfx) const /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -ListAccess::ListAccess(Expression *subject, Expression *index) -: subject_(subject) -, index_(index) -{ - subject_->set_parent(this); - index_->set_parent(this); -} - -const Expression &ListAccess::subject() const -{ return *subject_; } - -const Expression &ListAccess::index() const -{ return *index_; } - - -const Type &ListAccess::type() const -{ - return dynamic_cast( - subject_->type() - ).element_type(); -} - -string ListAccess::to_string(const string &pfx) const -{ return subject_->to_string(pfx) + '[' + index_->str() + ']'; } - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -ListLength::ListLength(Expression *subject) -: subject_(subject) -{ subject_->set_parent(this); } - -const Expression &ListLength::subject() const -{ return *subject_; } - -string ListLength::to_string(const string &pfx) const -{ return "length(" + subject_->to_string(pfx) + ')'; } - - - -string to_string(ListOpEnd which_end) -{ - switch (which_end) { - case FRONT: - return "front"; - case BACK: - return "back"; - } - throw Bug(string("Unhandled ") + typeid(which_end).name()); -} - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -ListPop::ListPop(Expression *list, ListOpEnd which_end) -: list_(list) -, which_end_(which_end) -{ list_->set_parent(this); } - -const Expression &ListPop::list() const -{ return *list_; } - -ListOpEnd ListPop::which_end() const -{ return which_end_; } - -string ListPop::to_string(const string &pfx) const -{ return pfx + "pop_" + gologpp::to_string(which_end_) + '(' + list_->str() + ')'; } - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -ListPush::ListPush(Expression *list, ListOpEnd which_end, Expression *what) -: list_(list) -, which_end_(which_end) -{ - list_->set_parent(this); - - what->ensure_type( - dynamic_cast( - list_->type() - ).element_type() - ); - what_.reset(what); - what_->set_parent(this); -} - -const Expression &ListPush::list() const -{ return *list_; } - -ListOpEnd ListPush::which_end() const -{ return which_end_; } - -const Expression &ListPush::what() const -{ return *what_; } - -string ListPush::to_string(const string &pfx) const -{ return pfx + "push_" + gologpp::to_string(which_end_) + '(' + list_->str() + ')'; } - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - During::During( Reference *action_call, Instruction *parallel_block, @@ -752,7 +647,6 @@ string During::to_string(const string &pfx) const - } // namespace gologpp diff --git a/src/model/procedural.h b/src/model/procedural.h index c51ee15f..5a581b1d 100644 --- a/src/model/procedural.h +++ b/src/model/procedural.h @@ -35,8 +35,6 @@ #include "scope.h" #include "action.h" #include "reference.h" -#include "fluent.h" -#include "mapping.h" namespace gologpp { @@ -528,108 +526,6 @@ class FieldAccess /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -class ListAccess -: public Expression -, public NoScopeOwner -, public LanguageElement -{ -public: - ListAccess(Expression *subject, Expression *index); - const Expression &subject() const; - const Expression &index() const; - - DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*subject_, *index_) - - virtual const Type &type() const override; - - string to_string(const string &pfx) const override; - -private: - SafeExprOwner subject_; - SafeExprOwner index_; -}; - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -class ListLength -: public Expression -, public NoScopeOwner -, public LanguageElement -{ -public: - ListLength(Expression *subject); - const Expression &subject() const; - - DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*subject_) - - string to_string(const string &pfx) const override; - -private: - SafeExprOwner subject_; -}; - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -enum ListOpEnd { - FRONT, BACK -}; - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -class ListPop -: public Instruction -, public NoScopeOwner -, public LanguageElement -{ -public: - ListPop(Expression *list, ListOpEnd which_end); - const Expression &list() const; - ListOpEnd which_end() const; - - DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*list_) - - string to_string(const string &pfx) const override; - -private: - SafeExprOwner list_; - ListOpEnd which_end_; -}; - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - -class ListPush -: public Instruction -, public NoScopeOwner -, public LanguageElement -{ -public: - ListPush(Expression *list, ListOpEnd which_end, Expression *what); - const Expression &list() const; - ListOpEnd which_end() const; - const Expression &what() const; - - DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*list_, *what_) - - string to_string(const string &pfx) const override; - -private: - SafeExprOwner list_; - ListOpEnd which_end_; - unique_ptr what_; -}; - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - class During : public Instruction , public NoScopeOwner diff --git a/src/model/types.cpp b/src/model/types.cpp index 1fed7404..40a396ac 100644 --- a/src/model/types.cpp +++ b/src/model/types.cpp @@ -18,7 +18,7 @@ #include "types.h" #include "scope.h" #include "domain.h" -#include "list_expression.h" +#include "list.h" #include "logger.h" namespace gologpp { diff --git a/src/parser/action.cpp b/src/parser/action.cpp index 66ea99a7..32d43423 100644 --- a/src/parser/action.cpp +++ b/src/parser/action.cpp @@ -40,6 +40,7 @@ #include #include +#include #include diff --git a/src/parser/arithmetic.cpp b/src/parser/arithmetic.cpp index a7de3a68..4270cf8f 100644 --- a/src/parser/arithmetic.cpp +++ b/src/parser/arithmetic.cpp @@ -18,7 +18,7 @@ #include "arithmetic.h" #include "variable.h" #include "value.h" -#include "list_expression.h" +#include "list.h" #include "mixed_member_access.h" #include "expressions.h" #include "reference.h" diff --git a/src/parser/assignment.cpp b/src/parser/assignment.cpp index 986217f1..987b002d 100644 --- a/src/parser/assignment.cpp +++ b/src/parser/assignment.cpp @@ -21,6 +21,7 @@ #include "types.h" #include "expressions.h" #include "mixed_member_access.h" +#include "list.h" #include #include diff --git a/src/parser/effect_axiom.cpp b/src/parser/effect_axiom.cpp index 7d61b587..1d6165fd 100644 --- a/src/parser/effect_axiom.cpp +++ b/src/parser/effect_axiom.cpp @@ -34,6 +34,8 @@ #include #include +#include +#include #include "reference.h" #include "mixed_member_access.h" diff --git a/src/parser/expressions.cpp b/src/parser/expressions.cpp index 4ae9a627..5e9333db 100644 --- a/src/parser/expressions.cpp +++ b/src/parser/expressions.cpp @@ -47,7 +47,7 @@ #include "string_expression.h" #include "symbolic_expression.h" #include "compound_expression.h" -#include "list_expression.h" +#include "list.h" #include diff --git a/src/parser/list.cpp b/src/parser/list.cpp index 75cf2b55..a4415cbc 100644 --- a/src/parser/list.cpp +++ b/src/parser/list.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/parser/list.h b/src/parser/list.h index 68c096ba..40137582 100644 --- a/src/parser/list.h +++ b/src/parser/list.h @@ -19,6 +19,7 @@ #define GOLOGPP_PARSER_LIST_EXPRESSION_H_ #include "utilities.h" +#include namespace gologpp { namespace parser { diff --git a/src/parser/mixed_member_access.cpp b/src/parser/mixed_member_access.cpp index 5a866a27..9b52990d 100644 --- a/src/parser/mixed_member_access.cpp +++ b/src/parser/mixed_member_access.cpp @@ -19,7 +19,7 @@ #include "types.h" #include "compound_expression.h" #include "expressions.h" -#include "list_expression.h" +#include "list.h" #include #include @@ -37,6 +37,7 @@ #include #include +#include #include diff --git a/src/parser/statements.h b/src/parser/statements.h index 603b3285..d1e8ab46 100644 --- a/src/parser/statements.h +++ b/src/parser/statements.h @@ -23,6 +23,7 @@ #include "assignment.h" #include "formula.h" #include "arithmetic.h" +#include "list.h" namespace gologpp { diff --git a/src/semantics/readylog/effect_axiom.cpp b/src/semantics/readylog/effect_axiom.cpp index da0e3cd8..941d1c82 100644 --- a/src/semantics/readylog/effect_axiom.cpp +++ b/src/semantics/readylog/effect_axiom.cpp @@ -18,6 +18,7 @@ #include "effect_axiom.h" #include "procedural.h" #include "action.h" +#include "list.h" diff --git a/src/semantics/readylog/history.cpp b/src/semantics/readylog/history.cpp index 37584dcb..c448b4c2 100644 --- a/src/semantics/readylog/history.cpp +++ b/src/semantics/readylog/history.cpp @@ -66,6 +66,9 @@ shared_ptr Semantics::get_last_transition() void Semantics::append(const AbstractEvent &trans) { extend_history(::list(trans.semantics().plterm(), plterm())); } +void Semantics::append(shared_ptr e) +{ append(*e); } + void Semantics::append_sensing_result( shared_ptr, @@ -124,5 +127,6 @@ void Semantics::progress() + } // namespace gologpp diff --git a/src/semantics/readylog/history.h b/src/semantics/readylog/history.h index 5b9a959b..0a532ac1 100644 --- a/src/semantics/readylog/history.h +++ b/src/semantics/readylog/history.h @@ -37,7 +37,8 @@ class Semantics virtual ~Semantics() override = default; virtual shared_ptr get_last_transition(); - virtual void append(const AbstractEvent &exog) override; + virtual void append(const AbstractEvent &e) override; + virtual void append(shared_ptr e) override; virtual bool should_progress() const override; virtual void progress() override; diff --git a/src/semantics/readylog/list.cpp b/src/semantics/readylog/list.cpp index cacd6967..6e20a89b 100644 --- a/src/semantics/readylog/list.cpp +++ b/src/semantics/readylog/list.cpp @@ -37,4 +37,81 @@ EC_word Semantics::plterm() } + +EC_word Semantics::pl_index() +{ return element().index().semantics().plterm(); } + + +EC_word Semantics::plterm() +{ + return ::term(EC_functor("gpp_list_access", 2), + element().subject().semantics().plterm(), + pl_index() + ); +} + + + +template<> +EC_word Semantics::plterm() +{ + string fn; + switch(element().which_end()) { + case ListOpEnd::BACK: + fn = "gpp_list_pop_back"; + break; + case ListOpEnd::FRONT: + fn = "gpp_list_pop_front"; + } + + if (fn.empty()) + throw Bug("Invalid ListOpEnd Enum value: " + std::to_string(element().which_end())); + + return ::term(EC_functor("set", 2), + element().list().semantics().plterm(), + ::term(EC_functor(fn.c_str(), 1), + element().list().semantics().plterm() + ) + ); + +} + + + +template<> +EC_word Semantics::plterm() +{ + string fn; + switch(element().which_end()) { + case ListOpEnd::BACK: + fn = "gpp_list_push_back"; + break; + case ListOpEnd::FRONT: + fn = "gpp_list_push_front"; + } + + if (fn.empty()) + throw Bug("Invalid ListOpEnd Enum value: " + std::to_string(element().which_end())); + + return ::term(EC_functor("set", 2), + element().list().semantics().plterm(), + ::term(EC_functor(fn.c_str(), 2), + element().list().semantics().plterm(), + element().what().semantics().plterm() + ) + ); +} + + + +template<> +EC_word Semantics::plterm() +{ + return ::term(EC_functor("gpp_list_length", 1), + element().subject().semantics().plterm() + ); +} + + + } // namespace gologpp diff --git a/src/semantics/readylog/list.h b/src/semantics/readylog/list.h index 2c5a6321..749554ed 100644 --- a/src/semantics/readylog/list.h +++ b/src/semantics/readylog/list.h @@ -25,6 +25,18 @@ namespace gologpp { +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + + virtual EC_word plterm() override; + EC_word pl_index(); +}; + } diff --git a/src/semantics/readylog/procedural.cpp b/src/semantics/readylog/procedural.cpp index 310c46cb..1be25464 100644 --- a/src/semantics/readylog/procedural.cpp +++ b/src/semantics/readylog/procedural.cpp @@ -23,6 +23,7 @@ #include "action.h" #include "history.h" #include "plan.h" +#include "list.h" #include @@ -429,82 +430,6 @@ EC_word Semantics::field_assign(const Expression &value) -EC_word Semantics::pl_index() -{ return element().index().semantics().plterm(); } - - -EC_word Semantics::plterm() -{ - return ::term(EC_functor("gpp_list_access", 2), - element().subject().semantics().plterm(), - pl_index() - ); -} - - - -template<> -EC_word Semantics::plterm() -{ - string fn; - switch(element().which_end()) { - case ListOpEnd::BACK: - fn = "gpp_list_pop_back"; - break; - case ListOpEnd::FRONT: - fn = "gpp_list_pop_front"; - } - - if (fn.empty()) - throw Bug("Invalid ListOpEnd Enum value: " + std::to_string(element().which_end())); - - return ::term(EC_functor("set", 2), - element().list().semantics().plterm(), - ::term(EC_functor(fn.c_str(), 1), - element().list().semantics().plterm() - ) - ); - -} - - - -template<> -EC_word Semantics::plterm() -{ - string fn; - switch(element().which_end()) { - case ListOpEnd::BACK: - fn = "gpp_list_push_back"; - break; - case ListOpEnd::FRONT: - fn = "gpp_list_push_front"; - } - - if (fn.empty()) - throw Bug("Invalid ListOpEnd Enum value: " + std::to_string(element().which_end())); - - return ::term(EC_functor("set", 2), - element().list().semantics().plterm(), - ::term(EC_functor(fn.c_str(), 2), - element().list().semantics().plterm(), - element().what().semantics().plterm() - ) - ); -} - - - -template<> -EC_word Semantics::plterm() -{ - return ::term(EC_functor("gpp_list_length", 1), - element().subject().semantics().plterm() - ); -} - - - template<> EC_word Semantics::plterm() { diff --git a/src/semantics/readylog/procedural.h b/src/semantics/readylog/procedural.h index 89ee0ceb..006c183c 100644 --- a/src/semantics/readylog/procedural.h +++ b/src/semantics/readylog/procedural.h @@ -132,20 +132,6 @@ class Semantics -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - - virtual EC_word plterm() override; - EC_word pl_index(); -}; - - - } // namespace gologpp diff --git a/src/semantics/readylog/semantics.cpp b/src/semantics/readylog/semantics.cpp index 52e2aa80..44d87467 100644 --- a/src/semantics/readylog/semantics.cpp +++ b/src/semantics/readylog/semantics.cpp @@ -31,7 +31,7 @@ #include "string.h" #include "history.h" #include "compound_expression.h" -#include "list_expression.h" +#include "list.h" #include "activity.h" #include "transition.h" #include "execution.h" diff --git a/src/semantics/readylog/semantics.h b/src/semantics/readylog/semantics.h index 98501ab2..4b7869cc 100644 --- a/src/semantics/readylog/semantics.h +++ b/src/semantics/readylog/semantics.h @@ -83,6 +83,7 @@ class Semantics using GeneralSemantics::GeneralSemantics; virtual ~Semantics() override = default; + virtual unique_ptr trans(const BindingChain &b, History &h) override; virtual bool final(const BindingChain &b, const History &h) override; From c2a3483597d105ec73c478ea737c33bbd473d247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Sat, 11 Mar 2023 17:17:42 +0100 Subject: [PATCH 24/33] rename compound_expression.* -> compound.* --- CMakeLists.txt | 16 ++++++++-------- .../{compound_expression.cpp => compound.cpp} | 2 +- src/model/{compound_expression.h => compound.h} | 4 +++- .../{compound_expression.cpp => compound.cpp} | 4 ++-- src/parser/{compound_expression.h => compound.h} | 0 src/parser/expressions.cpp | 2 +- src/parser/mixed_member_access.cpp | 2 +- .../{compound_expression.cpp => compound.cpp} | 2 +- .../{compound_expression.h => compound.h} | 2 +- src/semantics/readylog/semantics.cpp | 2 +- 10 files changed, 19 insertions(+), 17 deletions(-) rename src/model/{compound_expression.cpp => compound.cpp} (98%) rename src/model/{compound_expression.h => compound.h} (94%) rename src/parser/{compound_expression.cpp => compound.cpp} (97%) rename src/parser/{compound_expression.h => compound.h} (100%) rename src/semantics/readylog/{compound_expression.cpp => compound.cpp} (97%) rename src/semantics/readylog/{compound_expression.h => compound.h} (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3f43e52..1df392fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ set(INTERFACE_SRC src/model/mapping.cpp src/model/language.cpp src/model/types.cpp - src/model/compound_expression.cpp + src/model/compound.cpp src/model/list.cpp src/model/semantics.cpp src/model/logger.cpp @@ -157,7 +157,7 @@ install(FILES src/model/string.h src/model/mapping.h src/model/types.h - src/model/compound_expression.h + src/model/compound.h src/model/list.h src/model/logger.h src/model/name.h @@ -228,7 +228,7 @@ if (${BUILD_PARSER}) src/parser/symbolic_expression.cpp src/parser/string_expression.cpp src/parser/domain.cpp - src/parser/compound_expression.cpp + src/parser/compound.cpp src/parser/mixed_member_access.cpp src/parser/mapping.cpp src/parser/list.cpp @@ -265,7 +265,7 @@ if (${BUILD_PARSER}) src/parser/expressions.h src/parser/symbolic_expression.h src/parser/domain.h - src/parser/compound_expression.h + src/parser/compound.h src/parser/mixed_member_access.h src/parser/mapping.h src/parser/list.h @@ -316,7 +316,7 @@ if (${BUILD_READYLOG_SEMANTICS}) src/semantics/readylog/history.cpp src/semantics/readylog/reference.cpp src/semantics/readylog/effect_axiom.cpp - src/semantics/readylog/compound_expression.cpp + src/semantics/readylog/compound.cpp src/semantics/readylog/list.cpp src/semantics/readylog/transition.cpp src/semantics/readylog/plan.cpp @@ -350,7 +350,7 @@ if (${BUILD_READYLOG_SEMANTICS}) src/semantics/readylog/reference.h src/semantics/readylog/string.h src/semantics/readylog/history.h - src/semantics/readylog/compound_expression.h + src/semantics/readylog/compound.h src/semantics/readylog/list.h src/semantics/readylog/transition.h src/semantics/readylog/plan.h @@ -408,7 +408,7 @@ if (${BUILD_NATIVE_SEMANTICS}) src/semantics/native/history.cpp src/semantics/native/reference.cpp src/semantics/native/effect_axiom.cpp - src/semantics/native/compound_expression.cpp + src/semantics/native/compound.cpp src/semantics/native/list.cpp src/semantics/native/transition.cpp ) @@ -442,7 +442,7 @@ if (${BUILD_NATIVE_SEMANTICS}) src/semantics/native/reference.h src/semantics/native/string.h src/semantics/native/history.h - src/semantics/native/compound_expression.h + src/semantics/native/compound.h src/semantics/native/list.h src/semantics/native/transition.h diff --git a/src/model/compound_expression.cpp b/src/model/compound.cpp similarity index 98% rename from src/model/compound_expression.cpp rename to src/model/compound.cpp index 569b716f..c1338478 100644 --- a/src/model/compound_expression.cpp +++ b/src/model/compound.cpp @@ -15,7 +15,7 @@ * along with golog++. If not, see . **************************************************************************/ -#include "compound_expression.h" +#include "compound.h" #include "semantics.h" #include diff --git a/src/model/compound_expression.h b/src/model/compound.h similarity index 94% rename from src/model/compound_expression.h rename to src/model/compound.h index a7f64159..03873e15 100644 --- a/src/model/compound_expression.h +++ b/src/model/compound.h @@ -35,6 +35,8 @@ class CompoundExpression , public NoScopeOwner { public: + using EntryMap = std::unordered_map>; + CompoundExpression(const Type &type, const vector> &entries); const Expression &entry(const string &key) const; @@ -44,7 +46,7 @@ class CompoundExpression const CompoundType &compound_type() const; private: - std::unordered_map> entries_; + EntryMap entries_; }; diff --git a/src/parser/compound_expression.cpp b/src/parser/compound.cpp similarity index 97% rename from src/parser/compound_expression.cpp rename to src/parser/compound.cpp index 5edd71ec..cbbeca93 100644 --- a/src/parser/compound_expression.cpp +++ b/src/parser/compound.cpp @@ -15,7 +15,7 @@ * along with golog++. If not, see . **************************************************************************/ -#include "compound_expression.h" +#include "compound.h" #include "mixed_member_access.h" #include "value.h" #include "variable.h" @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include diff --git a/src/parser/compound_expression.h b/src/parser/compound.h similarity index 100% rename from src/parser/compound_expression.h rename to src/parser/compound.h diff --git a/src/parser/expressions.cpp b/src/parser/expressions.cpp index 5e9333db..566012c0 100644 --- a/src/parser/expressions.cpp +++ b/src/parser/expressions.cpp @@ -46,7 +46,7 @@ #include "formula.h" #include "string_expression.h" #include "symbolic_expression.h" -#include "compound_expression.h" +#include "compound.h" #include "list.h" #include diff --git a/src/parser/mixed_member_access.cpp b/src/parser/mixed_member_access.cpp index 9b52990d..106f05f7 100644 --- a/src/parser/mixed_member_access.cpp +++ b/src/parser/mixed_member_access.cpp @@ -17,7 +17,7 @@ #include "mixed_member_access.h" #include "types.h" -#include "compound_expression.h" +#include "compound.h" #include "expressions.h" #include "list.h" diff --git a/src/semantics/readylog/compound_expression.cpp b/src/semantics/readylog/compound.cpp similarity index 97% rename from src/semantics/readylog/compound_expression.cpp rename to src/semantics/readylog/compound.cpp index 69ac54c6..2d42e3d8 100644 --- a/src/semantics/readylog/compound_expression.cpp +++ b/src/semantics/readylog/compound.cpp @@ -15,7 +15,7 @@ * along with golog++. If not, see . **************************************************************************/ -#include "compound_expression.h" +#include "compound.h" namespace gologpp { diff --git a/src/semantics/readylog/compound_expression.h b/src/semantics/readylog/compound.h similarity index 96% rename from src/semantics/readylog/compound_expression.h rename to src/semantics/readylog/compound.h index a5261d4e..c99cf680 100644 --- a/src/semantics/readylog/compound_expression.h +++ b/src/semantics/readylog/compound.h @@ -20,7 +20,7 @@ #include "semantics.h" -#include +#include namespace gologpp { diff --git a/src/semantics/readylog/semantics.cpp b/src/semantics/readylog/semantics.cpp index 44d87467..4425c3dd 100644 --- a/src/semantics/readylog/semantics.cpp +++ b/src/semantics/readylog/semantics.cpp @@ -30,7 +30,7 @@ #include "domain.h" #include "string.h" #include "history.h" -#include "compound_expression.h" +#include "compound.h" #include "list.h" #include "activity.h" #include "transition.h" From abb5d9dc2c83a43fdf3dac7237122b4080c30564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Sat, 11 Mar 2023 18:15:09 +0100 Subject: [PATCH 25/33] move FieldAccess stuff into compound.* --- src/model/compound.cpp | 28 +++++++++++ src/model/compound.h | 26 ++++++++++ src/model/procedural.cpp | 27 ----------- src/model/procedural.h | 25 ---------- src/parser/action.cpp | 1 + src/parser/assignment.cpp | 7 +-- src/parser/assignment.h | 1 + src/parser/effect_axiom.cpp | 1 + src/parser/mixed_member_access.cpp | 2 +- src/parser/statements.h | 2 + src/semantics/readylog/compound.cpp | 63 +++++++++++++++++++++++++ src/semantics/readylog/compound.h | 19 ++++++++ src/semantics/readylog/effect_axiom.cpp | 1 + src/semantics/readylog/procedural.cpp | 62 +----------------------- src/semantics/readylog/procedural.h | 18 ------- 15 files changed, 148 insertions(+), 135 deletions(-) diff --git a/src/model/compound.cpp b/src/model/compound.cpp index c1338478..75f10063 100644 --- a/src/model/compound.cpp +++ b/src/model/compound.cpp @@ -98,5 +98,33 @@ const CompoundType &CompoundExpression::compound_type() const ); } +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +FieldAccess::FieldAccess(Expression *subject, const string &field_name) +: subject_(subject) +, field_name_(field_name) +{ + subject_->set_parent(this); +} + +const Expression &FieldAccess::subject() const +{ return *subject_; } + +const string &FieldAccess::field_name() const +{ return field_name_; } + +const Type &FieldAccess::type() const +{ + return dynamic_cast( + subject_->type() + ).field_type(field_name_); +} + +string FieldAccess::to_string(const string &pfx) const +{ return pfx + subject().str() + "." + field_name(); } + + } diff --git a/src/model/compound.h b/src/model/compound.h index 03873e15..ea323573 100644 --- a/src/model/compound.h +++ b/src/model/compound.h @@ -23,6 +23,7 @@ #include "expressions.h" #include "scope.h" #include "types.h" +#include "semantics.h" #include @@ -49,6 +50,31 @@ class CompoundExpression EntryMap entries_; }; +///////////////////////////////////////////////////////////////////////////////////////////////// +/***********************************************************************************************/ +///////////////////////////////////////////////////////////////////////////////////////////////// + +class FieldAccess +: public Expression +, public NoScopeOwner +, public LanguageElement +{ +public: + FieldAccess(Expression *subject, const string &field_name); + const Expression &subject() const; + const string &field_name() const; + + DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*subject_) + + virtual const Type &type() const override; + + string to_string(const string &pfx) const override; + +private: + SafeExprOwner subject_; + const string field_name_; +}; + } // namespace gologpp diff --git a/src/model/procedural.cpp b/src/model/procedural.cpp index fc59a553..7440f81d 100644 --- a/src/model/procedural.cpp +++ b/src/model/procedural.cpp @@ -570,33 +570,6 @@ string to_string(DurativeCall::Hook h) /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -FieldAccess::FieldAccess(Expression *subject, const string &field_name) -: subject_(subject) -, field_name_(field_name) -{ - subject_->set_parent(this); -} - -const Expression &FieldAccess::subject() const -{ return *subject_; } - -const string &FieldAccess::field_name() const -{ return field_name_; } - -const Type &FieldAccess::type() const -{ - return dynamic_cast( - subject_->type() - ).field_type(field_name_); -} - -string FieldAccess::to_string(const string &pfx) const -{ return pfx + subject().str() + "." + field_name(); } - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - During::During( Reference *action_call, Instruction *parallel_block, diff --git a/src/model/procedural.h b/src/model/procedural.h index 5a581b1d..0f2c68f3 100644 --- a/src/model/procedural.h +++ b/src/model/procedural.h @@ -501,31 +501,6 @@ string to_string(DurativeCall::Hook); /***********************************************************************************************/ ///////////////////////////////////////////////////////////////////////////////////////////////// -class FieldAccess -: public Expression -, public NoScopeOwner -, public LanguageElement -{ -public: - FieldAccess(Expression *subject, const string &field_name); - const Expression &subject() const; - const string &field_name() const; - - DEFINE_ATTACH_SEMANTICS_WITH_MEMBERS(*subject_) - - virtual const Type &type() const override; - - string to_string(const string &pfx) const override; - -private: - SafeExprOwner subject_; - const string field_name_; -}; - -///////////////////////////////////////////////////////////////////////////////////////////////// -/***********************************************************************************************/ -///////////////////////////////////////////////////////////////////////////////////////////////// - class During : public Instruction , public NoScopeOwner diff --git a/src/parser/action.cpp b/src/parser/action.cpp index 32d43423..88e38dee 100644 --- a/src/parser/action.cpp +++ b/src/parser/action.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include diff --git a/src/parser/assignment.cpp b/src/parser/assignment.cpp index 987b002d..94650e9a 100644 --- a/src/parser/assignment.cpp +++ b/src/parser/assignment.cpp @@ -16,12 +16,13 @@ **************************************************************************/ #include "assignment.h" -#include "arithmetic.h" -#include "formula.h" #include "types.h" #include "expressions.h" #include "mixed_member_access.h" -#include "list.h" + +#include +#include +#include #include #include diff --git a/src/parser/assignment.h b/src/parser/assignment.h index 0bca6b97..127c42dd 100644 --- a/src/parser/assignment.h +++ b/src/parser/assignment.h @@ -19,6 +19,7 @@ #define GOLOGPP_PARSER_ASSIGNMENT_H_ #include +#include #include #include "utilities.h" diff --git a/src/parser/effect_axiom.cpp b/src/parser/effect_axiom.cpp index 1d6165fd..6dced24c 100644 --- a/src/parser/effect_axiom.cpp +++ b/src/parser/effect_axiom.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include "reference.h" #include "mixed_member_access.h" diff --git a/src/parser/mixed_member_access.cpp b/src/parser/mixed_member_access.cpp index 106f05f7..34dfc8f0 100644 --- a/src/parser/mixed_member_access.cpp +++ b/src/parser/mixed_member_access.cpp @@ -38,7 +38,7 @@ #include #include -#include +#include namespace gologpp { diff --git a/src/parser/statements.h b/src/parser/statements.h index d1e8ab46..1f437598 100644 --- a/src/parser/statements.h +++ b/src/parser/statements.h @@ -25,6 +25,8 @@ #include "arithmetic.h" #include "list.h" +#include + namespace gologpp { namespace parser { diff --git a/src/semantics/readylog/compound.cpp b/src/semantics/readylog/compound.cpp index 2d42e3d8..8ed19deb 100644 --- a/src/semantics/readylog/compound.cpp +++ b/src/semantics/readylog/compound.cpp @@ -16,6 +16,8 @@ **************************************************************************/ #include "compound.h" +#include "list.h" +#include "reference.h" namespace gologpp { @@ -38,4 +40,65 @@ EC_word Semantics::plterm() } +/** + * Transform nested field- and list accesses into a pair of the innermost subject (must be a + * list- or compound-valued fluent) and a sequence of list indices and field names. Only one of either + * @a fa or @a la may be set, depending on whether the outermost expression is a list access or a field access. + * + * @param fa The rightmost field access or nullptr + * @param la The rightmost list access or nullptr + * @return A reference to the fluent (either list- or compound-valued), and an eclipse list + * with a mixture of list indices and field names that sequentially index (deeply) into the + * returned fluent. + */ +std::pair *, EC_word> traverse_mixed_field_access(const FieldAccess *fa, const ListAccess *la) { + const Expression *sub; + EC_word field_list = ::nil(); + + do { + if (fa) { + field_list = ::list(fa->special_semantics().pl_field_name(), field_list); + sub = &fa->subject(); + } + else if (la) { + field_list = ::list(la->special_semantics().pl_index(), field_list); + sub = &la->subject(); + } + else + throw Bug("Invalid FieldAccess statement: " + fa->str()); + + fa = dynamic_cast(sub); + la = dynamic_cast(sub); + } while (sub->is_a() || sub->is_a()); + + return { dynamic_cast *>(sub), std::move(field_list) }; +}; + + + +EC_word Semantics::plterm() +{ + return ::term(EC_functor("gpp_field_value", 2), + pl_field_name(), + element().subject().semantics().plterm() + ); +} + + +EC_atom Semantics::pl_field_name() +{ return EC_atom(("#" + element().field_name()).c_str()); } + + +EC_word Semantics::field_assign(const Expression &value) +{ + return ::term(EC_functor("gpp_field_assign", 3), + pl_field_name(), + value.semantics().plterm(), + element().subject().semantics().plterm() + ); +} + + + + } // namespace gologpp diff --git a/src/semantics/readylog/compound.h b/src/semantics/readylog/compound.h index c99cf680..6a3a8fb6 100644 --- a/src/semantics/readylog/compound.h +++ b/src/semantics/readylog/compound.h @@ -25,6 +25,25 @@ namespace gologpp { +std::pair *, EC_word> +traverse_mixed_field_access(const FieldAccess *fa, const ListAccess *la); + + +template<> +class Semantics +: public Semantics +, public GeneralSemantics +{ +public: + using GeneralSemantics::GeneralSemantics; + + virtual EC_word plterm() override; + EC_word field_assign(const Expression &value); + EC_atom pl_field_name(); +}; + + + } #endif // READYLOG_COMPOUND_EXPRESSION_H_ diff --git a/src/semantics/readylog/effect_axiom.cpp b/src/semantics/readylog/effect_axiom.cpp index 941d1c82..eda47433 100644 --- a/src/semantics/readylog/effect_axiom.cpp +++ b/src/semantics/readylog/effect_axiom.cpp @@ -19,6 +19,7 @@ #include "procedural.h" #include "action.h" #include "list.h" +#include "compound.h" diff --git a/src/semantics/readylog/procedural.cpp b/src/semantics/readylog/procedural.cpp index 1be25464..f8f67c05 100644 --- a/src/semantics/readylog/procedural.cpp +++ b/src/semantics/readylog/procedural.cpp @@ -24,6 +24,7 @@ #include "history.h" #include "plan.h" #include "list.h" +#include "compound.h" #include @@ -184,9 +185,6 @@ EC_word Semantics::definition() - - - template<> EC_word Semantics::plterm() { @@ -252,40 +250,6 @@ EC_word Semantics>>::plterm() } -/** - * Transform nested field- and list accesses into a pair of the innermost subject (must be a - * list- or compound-valued fluent) and a sequence of list indices and field names. Only one of either - * @a fa or @a la may be set, depending on whether the outermost expression is a list access or a field access. - * - * @param fa The rightmost field access or nullptr - * @param la The rightmost list access or nullptr - * @return A reference to the fluent (either list- or compound-valued), and an eclipse list - * with a mixture of list indices and field names that sequentially index (deeply) into the - * returned fluent. - */ -std::pair *, EC_word> traverse_mixed_field_access(const FieldAccess *fa, const ListAccess *la) { - const Expression *sub; - EC_word field_list = ::nil(); - - do { - if (fa) { - field_list = ::list(fa->special_semantics().pl_field_name(), field_list); - sub = &fa->subject(); - } - else if (la) { - field_list = ::list(la->special_semantics().pl_index(), field_list); - sub = &la->subject(); - } - else - throw Bug("Invalid FieldAccess statement: " + fa->str()); - - fa = dynamic_cast(sub); - la = dynamic_cast(sub); - } while (sub->is_a() || sub->is_a()); - - return { dynamic_cast *>(sub), std::move(field_list) }; -}; - template<> @@ -406,30 +370,6 @@ EC_word Semantics::plterm() -EC_word Semantics::plterm() -{ - return ::term(EC_functor("gpp_field_value", 2), - pl_field_name(), - element().subject().semantics().plterm() - ); -} - - -EC_atom Semantics::pl_field_name() -{ return EC_atom(("#" + element().field_name()).c_str()); } - - -EC_word Semantics::field_assign(const Expression &value) -{ - return ::term(EC_functor("gpp_field_assign", 3), - pl_field_name(), - value.semantics().plterm(), - element().subject().semantics().plterm() - ); -} - - - template<> EC_word Semantics::plterm() { diff --git a/src/semantics/readylog/procedural.h b/src/semantics/readylog/procedural.h index 006c183c..aec2473e 100644 --- a/src/semantics/readylog/procedural.h +++ b/src/semantics/readylog/procedural.h @@ -113,24 +113,6 @@ class Semantics }; -std::pair *, EC_word> -traverse_mixed_field_access(const FieldAccess *fa, const ListAccess *la); - - -template<> -class Semantics -: public Semantics -, public GeneralSemantics -{ -public: - using GeneralSemantics::GeneralSemantics; - - virtual EC_word plterm() override; - EC_word field_assign(const Expression &value); - EC_atom pl_field_name(); -}; - - } // namespace gologpp From 0c12478a87a2adcd68c7a72228ce9a346a3f0d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 00:16:09 +0200 Subject: [PATCH 26/33] readylog: cleanup PL code search logic --- .gitmodules | 4 +- CMakeLists.txt | 10 ++- src/model/utilities.h | 10 ++- src/semantics/readylog/execution.cpp | 81 ++++++++++--------- src/semantics/readylog/execution.h | 10 ++- .../readylog/{interpreter => readylog_ecl} | 0 src/tests/gologpp-test.cpp | 9 ++- 7 files changed, 76 insertions(+), 48 deletions(-) rename src/semantics/readylog/{interpreter => readylog_ecl} (100%) diff --git a/.gitmodules b/.gitmodules index 2ba5fa68..d5b641a9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "external/taptenc"] path = external/taptenc url = git@github.com:TarikViehmann/taptenc.git -[submodule "src/semantics/readylog/interpreter"] - path = src/semantics/readylog/interpreter +[submodule "src/semantics/readylog/readylog_ecl"] + path = src/semantics/readylog/readylog_ecl url = https://github.com/MASKOR/readylog.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 1df392fb..fb27e3a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,14 +359,22 @@ if (${BUILD_READYLOG_SEMANTICS}) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/golog++/semantics/readylog ) + file( + COPY src/semantics/readylog/boilerplate.pl + DESTINATION "${CMAKE_BINARY_DIR}/semantics/readylog" + ) install(FILES src/semantics/readylog/boilerplate.pl DESTINATION ${SEMANTICS_INSTALL_DIR}/readylog ) if (INSTALL_READYLOG_INTERPRETER) + file( + COPY src/semantics/readylog/readylog_ecl + DESTINATION "${CMAKE_BINARY_DIR}/semantics/readylog" + ) install( - DIRECTORY src/semantics/readylog/interpreter + DIRECTORY src/semantics/readylog/readylog_ecl DESTINATION ${SEMANTICS_INSTALL_DIR}/readylog ) endif() diff --git a/src/model/utilities.h b/src/model/utilities.h index 31deb991..fd32ab72 100644 --- a/src/model/utilities.h +++ b/src/model/utilities.h @@ -195,12 +195,20 @@ string to_string(const T *o, const string &pfx) template typename std::enable_if < - ! std::is_pointer::is_pointer, + ! std::is_pointer::is_pointer && std::is_base_of::value, string >::type to_string(const T &o, const string &pfx) { return o.to_string(pfx); } +template +typename std::enable_if < + ! std::is_pointer::value && !std::is_base_of::value, + string +>::type +to_string(const T &o, const string &pfx) +{ return pfx + std::string(o); } + template diff --git a/src/semantics/readylog/execution.cpp b/src/semantics/readylog/execution.cpp index 24da8645..5d3f5447 100644 --- a/src/semantics/readylog/execution.cpp +++ b/src/semantics/readylog/execution.cpp @@ -16,7 +16,7 @@ **************************************************************************/ #include "wrap_eclipseclass.h" -#include +#include #include "value.h" #include "execution.h" @@ -38,10 +38,12 @@ #include #include -namespace filesystem = std::experimental::filesystem; +#include + namespace gologpp { +namespace filesystem = std::filesystem; unique_ptr ReadylogContext::instance_; @@ -57,12 +59,17 @@ void ReadylogContext::shutdown() ReadylogContext::ReadylogContext( const eclipse_opts &options, unique_ptr &&exec_backend, - unique_ptr &&transformation + unique_ptr &&transformation, + const std::initializer_list &add_search_paths ) : AExecutionController(std::move(exec_backend)) , options_(options) , plan_transformation_(std::move(transformation)) +, search_paths_(add_search_paths.begin(), add_search_paths.end()) { + search_paths_.emplace_back(path(SEMANTICS_INSTALL_DIR) / "readylog"); + search_paths_.emplace_back(path(SOURCE_DIR) / "src" / "semantics" / "readylog"); + if (!plan_transformation_) plan_transformation_ = std::make_unique(); @@ -123,12 +130,17 @@ ReadylogContext::ReadylogContext( ReadylogContext::~ReadylogContext() {} -void ReadylogContext::init(const eclipse_opts &options, unique_ptr &&backend, unique_ptr &&transformation) -{ +void ReadylogContext::init( + const eclipse_opts &options, + unique_ptr &&backend, + unique_ptr &&transformation, + const std::initializer_list &add_search_paths +) { instance_ = unique_ptr(new ReadylogContext( options, std::move(backend), - std::move(transformation) + std::move(transformation), + add_search_paths ) ); } @@ -190,44 +202,35 @@ void ReadylogContext::compile_term(const EC_word &term) } std::string ReadylogContext::find_readylog() { - const char *readylog_pl = std::getenv("READYLOG_PL"); - std::string readylog_path_env = ""; - if (readylog_pl) { - readylog_path_env = std::string(readylog_pl) + ":"; - } - readylog_path_env += (std::string(SEMANTICS_INSTALL_DIR) + "/readylog/interpreter"); - std::size_t last = 0; - std::size_t next; - while (true) { - next = readylog_path_env.find(':', last); - std::string next_path = readylog_path_env.substr(last, next - last); - if (next_path != "") { - filesystem::path readylog_path(next_path); - readylog_path /= "preprocessor.pl"; - if (filesystem::exists(readylog_path)) - return std::string(readylog_path); - } - if (next == std::string::npos) { - throw std::runtime_error("Could not find ReadyLog in \"" + readylog_path_env - + "\" please set READYLOG_PL to the ReadyLog path!"); - } - last = next + 1; + using path = filesystem::path; + + vector paths; + + const char *readylog_env = std::getenv("READYLOG_PL"); + if (readylog_env) + paths.push_back(path(readylog_env) / "preprocessor.pl"); + + for (path p : search_paths_) + paths.emplace_back(p / "readylog_ecl" / "interpreter" / "preprocessor.pl"); + + for (path p : paths) { + if (filesystem::exists(p)) + return string(p); } + throw std::runtime_error("Could not find ReadyLog in \"" + concat_list(paths, ", ") + + "\" please set READYLOG_PL to the ReadyLog path!"); } std::string ReadylogContext::find_boilerplate() { - filesystem::path boilerplate_src_path{SOURCE_DIR}; - boilerplate_src_path /= "src/semantics/readylog/boilerplate.pl"; - if (filesystem::exists(boilerplate_src_path)) { - return boilerplate_src_path.string(); - } - filesystem::path boilerplate_install_path{SEMANTICS_INSTALL_DIR}; - boilerplate_install_path /= "readylog/boilerplate.pl"; - if (filesystem::exists(boilerplate_install_path)) { - return boilerplate_install_path.string(); + using path = filesystem::path; + + for (path p : search_paths_) { + p /= "boilerplate.pl"; + if (filesystem::exists(p)) + return p; } - throw std::runtime_error("Could not find readylog boilerplate in " + boilerplate_src_path.string() - + " or " + boilerplate_install_path.string()); + + throw std::runtime_error("Could not find readylog boilerplate.pl in " + concat_list(search_paths_, ", ")); } diff --git a/src/semantics/readylog/execution.h b/src/semantics/readylog/execution.h index 71d35fba..e2960d1e 100644 --- a/src/semantics/readylog/execution.h +++ b/src/semantics/readylog/execution.h @@ -19,6 +19,7 @@ #define READYLOG_EXECUTION_H_ #include +#include #include #include @@ -41,7 +42,8 @@ class ReadylogContext : public AExecutionController { static void init( const eclipse_opts &options = {false, false, false}, unique_ptr &&backend = nullptr, - unique_ptr &&transformation = nullptr + unique_ptr &&transformation = nullptr, + const std::initializer_list &add_search_paths = {} ); static void shutdown(); @@ -69,9 +71,12 @@ class ReadylogContext : public AExecutionController { ReadylogContext( const eclipse_opts &options, unique_ptr &&exec_backend, - unique_ptr &&transformation + unique_ptr &&transformation, + const std::initializer_list &add_search_paths = {} ); + using path = std::filesystem::path; + void compile_term(const EC_word &term); std::string find_readylog(); std::string find_boilerplate(); @@ -82,6 +87,7 @@ class ReadylogContext : public AExecutionController { eclipse_opts options_; static unique_ptr instance_; unique_ptr plan_transformation_; + vector search_paths_; }; diff --git a/src/semantics/readylog/interpreter b/src/semantics/readylog/readylog_ecl similarity index 100% rename from src/semantics/readylog/interpreter rename to src/semantics/readylog/readylog_ecl diff --git a/src/tests/gologpp-test.cpp b/src/tests/gologpp-test.cpp index b32eef99..16e26211 100644 --- a/src/tests/gologpp-test.cpp +++ b/src/tests/gologpp-test.cpp @@ -37,8 +37,6 @@ - - using namespace gologpp; namespace po = boost::program_options; @@ -111,12 +109,17 @@ int main(int argc, char **argv) { return -2; } + std::filesystem::path arg0_path { argv[0] }; + eclipse_opts options; options.trace = !vm["trace"].empty() || !vm["guitrace"].empty(); options.toplevel = false; options.guitrace = !vm["guitrace"].empty(); - ReadylogContext::init(options); + ReadylogContext::init( + options, nullptr, nullptr, + { arg0_path.parent_path() / "semantics" / "readylog"} + ); int rv = test_file(unique_ptr(mainproc->ref({}))); From 6a1cfb22207cb987cb72706adf3329c7ddb7e7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 00:59:24 +0200 Subject: [PATCH 27/33] workflow: enable gpp tests --- .github/workflows/cmake.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 8b08f3be..3a977e0c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -2,10 +2,10 @@ name: CMake on: workflow_dispatch: - #push: - # branches: [ "master" ] - #pull_request: - # branches: [ "master" ] + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) @@ -43,8 +43,8 @@ jobs: cmake -B ${{github.workspace}}/build \ -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ -DBUILD_READYLOG_SEMANTICS=TRUE \ - -DBUILD_PARSER=FALSE \ - -DBUILD_TESTING=FALSE \ + -DBUILD_PARSER=TRUE \ + -DBUILD_TESTING=TRUE \ - name: Build # Build your program with the given configuration From 3735bfea3129b97c5ea67616c3803c575acd40a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 19:25:51 +0200 Subject: [PATCH 28/33] cmake: fix minor warning --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb27e3a6..77701a3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,8 @@ # along with golog++. If not, see . ########################################################################### -project(golog++) cmake_minimum_required(VERSION 3.0) +project(golog++) include(CMakeDependentOption) include(GNUInstallDirs) From a83886ba6d2e1dfc98e40595fcf633ac317703d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 19:26:07 +0200 Subject: [PATCH 29/33] gologpp-test: add eclipse libdir to RPATH --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77701a3f..da57e0f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -553,6 +553,7 @@ set(GPP_TESTS if (BUILD_PARSER AND BUILD_READYLOG_SEMANTICS) include(CTest) + enable_testing() add_executable(gologpp-test src/tests/gologpp-test.cpp) if (USE_LIBASAN) @@ -561,6 +562,7 @@ if (BUILD_PARSER AND BUILD_READYLOG_SEMANTICS) set(TEST_LIBS ${TEST_LIBS} boost_filesystem boost_program_options parsegolog++ readylog++) target_link_libraries(gologpp-test ${TEST_LIBS}) + set_target_properties(gologpp-test PROPERTIES BUILD_RPATH ${ECLIPSE_LIBRARY_DIRS}) if (BUILD_TAPTENC_SEMANTICS) target_link_libraries(gologpp-test taptenc-golog++) From ada75057a1223eb3feaf265c6de2310f6e5c6eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 19:38:54 +0200 Subject: [PATCH 30/33] workflows/cmake: test verbosely --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 3a977e0c..fff485a1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -54,5 +54,5 @@ jobs: working-directory: ${{github.workspace}}/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} + run: ctest -C ${{env.BUILD_TYPE}} -VV From 729b85b84114f1472d6c9e6419c82b9312f2f1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 19:56:49 +0200 Subject: [PATCH 31/33] workflows/cmake: explicitly update submodules --- .github/workflows/cmake.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index fff485a1..1f2672f0 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -26,6 +26,9 @@ jobs: - name: install-deps run: sudo apt install libboost-all-dev wget + + - name: update submodules + run: git submodule update --force --init --checkout - name: install eclipse-clp run: | From 7b88556ce7ad26b6d9b703b61698b64976d74c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 20:01:15 +0200 Subject: [PATCH 32/33] use HTTPS for taptenc submodule --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index d5b641a9..0236b55a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "external/taptenc"] path = external/taptenc - url = git@github.com:TarikViehmann/taptenc.git + url = https://github.com/TarikViehmann/taptenc.git [submodule "src/semantics/readylog/readylog_ecl"] path = src/semantics/readylog/readylog_ecl url = https://github.com/MASKOR/readylog.git From cafa9f18352d07911c3dc10d0230035aeb6560b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Mon, 27 Mar 2023 20:53:37 +0200 Subject: [PATCH 33/33] workflows/cmake: set 10m timeout on tests --- .github/workflows/cmake.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 1f2672f0..fc81a5ce 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -58,4 +58,5 @@ jobs: # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} -VV + timeout-minutes: 10