Skip to content

Commit 5dc7e51

Browse files
committed
feat: Add tuple and record support
Signed-off-by Gordon Smith <GordonJSmith@gmail.com>
1 parent c59bcc1 commit 5dc7e51

20 files changed

Lines changed: 787 additions & 143 deletions

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,3 @@ TODO
7777
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=GordonSmith/component-model-cpp&type=Date" />
7878
</picture>
7979
</a>
80-

src/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ project(component-model-cpp)
33
set(CMAKE_CXX_STANDARD 20)
44
set(CMAKE_CXX_STANDARD_REQUIRED ON)
55

6+
find_package(Boost)
7+
68
set(SRC
79
boolean.cpp
810
boolean.hpp
@@ -31,10 +33,6 @@ add_library(${PROJECT_NAME} STATIC
3133
${SRC}
3234
)
3335

34-
# target_include_directories(${PROJECT_NAME}
35-
# ...
36-
# )
37-
3836
target_link_libraries(${PROJECT_NAME}
3937
)
4038

@@ -47,4 +45,5 @@ target_compile_options(${PROJECT_NAME} PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>
4745
target_include_directories(
4846
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
4947
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
48+
${Boost_INCLUDE_DIR}
5049
)

src/lift.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "string.hpp"
88
#include "list.hpp"
99
#include "flags.hpp"
10-
#include "record.hpp"
10+
#include "tuple.hpp"
1111
#include "variant.hpp"
1212
#include "util.hpp"
1313

@@ -62,13 +62,21 @@ namespace cmcpp
6262
return flags::lift_flat<T>(cx, vi);
6363
}
6464

65-
template <Record T>
65+
template <Tuple T>
6666
T lift_flat(const CallContext &cx, const CoreValueIter &vi)
6767
{
68-
auto x = record::lift_flat_record<T>(cx, vi);
68+
auto x = tuple::lift_flat_tuple<T>(cx, vi);
6969
return x;
7070
}
7171

72+
template <Record T>
73+
T lift_flat(const CallContext &cx, const CoreValueIter &vi)
74+
{
75+
using TupleType = decltype(boost::pfr::structure_to_tuple(std::declval<typename ValTrait<T>::inner_type>()));
76+
TupleType x = tuple::lift_flat_tuple<TupleType>(cx, vi);
77+
return to_struct<T>(x);
78+
}
79+
7280
template <Variant T>
7381
T lift_flat(const CallContext &cx, const CoreValueIter &vi)
7482
{

src/lower.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "string.hpp"
88
#include "list.hpp"
99
#include "flags.hpp"
10-
#include "record.hpp"
10+
#include "tuple.hpp"
1111
#include "util.hpp"
1212

1313
#include <tuple>
@@ -66,17 +66,25 @@ namespace cmcpp
6666
return flags::lower_flat(cx, v);
6767
}
6868

69+
template <Tuple T>
70+
inline WasmValVector lower_flat(CallContext &cx, const T &v)
71+
{
72+
return tuple::lower_flat_tuple(cx, v);
73+
}
74+
6975
template <Record T>
7076
inline WasmValVector lower_flat(CallContext &cx, const T &v)
7177
{
72-
return record::lower_flat_record(cx, v);
78+
auto x = boost::pfr::structure_to_tuple(v);
79+
return tuple::lower_flat_tuple(cx, x);
7380
}
7481

7582
template <Variant T>
7683
inline WasmValVector lower_flat(CallContext &cx, const T &v)
7784
{
7885
return variant::lower_flat_variant(cx, v);
7986
}
87+
8088
}
8189

8290
#endif

src/record.cpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)