From ad0f8f9d9b6b9d5080db818af7cb7fc0cd4f616f Mon Sep 17 00:00:00 2001 From: Ian Wright Date: Tue, 28 Apr 2020 15:51:54 +0100 Subject: [PATCH 1/3] fix build path for vscode task --- .vscode/tasks.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9f777b5..75110f1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,9 +7,10 @@ "label": "build", "type": "shell", "command": "cd build; make", - "problemMatcher": [ - "$gcc" - ], + "problemMatcher": { + "base": "$gcc", + "fileLocation": ["relative", "../"] + }, "group": { "kind": "build", "isDefault": true From 8bbc8964f329e89500cc98c28510a5cfc31e3529 Mon Sep 17 00:00:00 2001 From: Ian Wright Date: Tue, 28 Apr 2020 16:34:35 +0100 Subject: [PATCH 2/3] pull out tuple binding --- src/Datalog.h | 37 ++++++++++++++++------------ src/tuple_binding.h | 45 ++++++++++++++++++++++++++++++++++ src/{Variable.h => variable.h} | 0 tests/variable_test.cpp | 2 +- 4 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 src/tuple_binding.h rename src/{Variable.h => variable.h} (100%) diff --git a/src/Datalog.h b/src/Datalog.h index c537100..0ae6981 100644 --- a/src/Datalog.h +++ b/src/Datalog.h @@ -12,46 +12,51 @@ #include #include "tuple_hash.h" -#include "Variable.h" +#include "variable.h" +#include "tuple_binding.h" namespace datalog { using namespace std; +/** + * @brief create a new variable + * + * @tparam T + * @return Variable* + */ template Variable *var() { return new Variable(); } +/** + * @brief get the value of a variable + * + * @tparam T + * @param t + * @return T + */ template T val(Variable *t) { return t->value(); } +/** + * @brief delete a variable + * + * @tparam T + * @param v + */ template void deleteVar(Variable *v) { delete v; } -template -void unbind(Variable *t) -{ - t->unbind(); -} - -template -void unbind(const T &t) {} - -template -void unbind(const tuple &tuple) -{ - apply([](auto &&... args) { ((unbind(args), ...)); }, tuple); -} - template bool bind(const T &a, const T &b) { diff --git a/src/tuple_binding.h b/src/tuple_binding.h new file mode 100644 index 0000000..072d5c5 --- /dev/null +++ b/src/tuple_binding.h @@ -0,0 +1,45 @@ +#ifndef TUPLES_H +#define TUPLES_H + +#include "variable.h" + +namespace datalog { + +/** + * @brief unbind a variable + * + * @tparam T + * @param t + */ +template +void unbind(Variable *t) +{ + t->unbind(); +} + +/** + * @brief unbind no-operation for types that are not variables + * + * @tparam T + * @param t + */ +template +void unbind(const T &t) { + // If t is not a Variable then perform no-op +} + +/** + * @brief apply unbind to a tuple of variables and values + * + * @tparam Ts + * @param tuple + */ +template +void unbind(const tuple &tuple) +{ + apply([](auto &&... args) { ((unbind(args), ...)); }, tuple); +} + +} + +#endif // TUPLES_H \ No newline at end of file diff --git a/src/Variable.h b/src/variable.h similarity index 100% rename from src/Variable.h rename to src/variable.h diff --git a/tests/variable_test.cpp b/tests/variable_test.cpp index d5de203..3cdae51 100644 --- a/tests/variable_test.cpp +++ b/tests/variable_test.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "Variable.h" +#include "variable.h" using namespace datalog; From 2c733cdd0ea8d99a6ad54995076600a265145d4b Mon Sep 17 00:00:00 2001 From: Ian Wright Date: Wed, 29 Apr 2020 13:08:31 +0100 Subject: [PATCH 3/3] embryo test for tuple binding --- src/CMakeLists.txt | 6 ++++++ src/Datalog.h | 4 ++++ src/tuple_binding.h | 4 +++- tests/run_tests.sh | 3 ++- tests/tuple_binding_test.cpp | 21 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/tuple_binding_test.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e12911c..3bbdeb5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,3 +35,9 @@ add_executable(variable_test ../tests/variable_test.cpp) target_include_directories(variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(variable_test tests_main) target_compile_definitions(variable_test PUBLIC UNIX) + +# tuple_binding_test target +add_executable(tuple_binding_test ../tests/tuple_binding_test.cpp) +target_include_directories(tuple_binding_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(tuple_binding_test tests_main) +target_compile_definitions(tuple_binding_test PUBLIC UNIX) diff --git a/src/Datalog.h b/src/Datalog.h index 0ae6981..cdb279b 100644 --- a/src/Datalog.h +++ b/src/Datalog.h @@ -20,6 +20,8 @@ namespace datalog using namespace std; +// High-level API functions + /** * @brief create a new variable * @@ -57,6 +59,8 @@ void deleteVar(Variable *v) delete v; } +// TODO: all functions below here to be refactored into separate files + template bool bind(const T &a, const T &b) { diff --git a/src/tuple_binding.h b/src/tuple_binding.h index 072d5c5..6a23add 100644 --- a/src/tuple_binding.h +++ b/src/tuple_binding.h @@ -5,6 +5,8 @@ namespace datalog { +// TODO: reify the concept of a tuple of values and pointers to Variables + /** * @brief unbind a variable * @@ -18,7 +20,7 @@ void unbind(Variable *t) } /** - * @brief unbind no-operation for types that are not variables + * @brief unbind no-operation for types that are not variables (i.e. values) * * @tparam T * @param t diff --git a/tests/run_tests.sh b/tests/run_tests.sh index d5b72c4..2aead19 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1,4 +1,5 @@ #!/bin/bash set -e ../build/types_test -../build/variable_test \ No newline at end of file +../build/variable_test +../build/tuple_binding_test \ No newline at end of file diff --git a/tests/tuple_binding_test.cpp b/tests/tuple_binding_test.cpp new file mode 100644 index 0000000..5a76daa --- /dev/null +++ b/tests/tuple_binding_test.cpp @@ -0,0 +1,21 @@ +#include "catch.hpp" +#include "Datalog.h" + +using namespace datalog; +using namespace std; + +bool unbindTest() +{ + auto v = var(); + v->bind(3); + tuple t{v, 3}; + v->unbind(); + bool returnVal = !get<0>(t)->isBound(); + deleteVar(v); + return returnVal; +} + +TEST_CASE("tuple binding test", "[tuple-binding]") +{ + REQUIRE(unbindTest()); +}