Skip to content

Commit ed216e5

Browse files
committed
chore: Refactor file layout
Step towards a header only release Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent afa5627 commit ed216e5

38 files changed

Lines changed: 365 additions & 536 deletions

.github/workflows/macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
runs-on: ${{ matrix.os }}
2626
steps:
2727
- name: Set up C++20
28-
uses: aminya/setup-cpp@v0.44.0
28+
uses: aminya/setup-cpp@v1
2929
with:
30-
compiler: gcc
30+
compiler: gcc-13
3131
cmake: true
3232
ninja: true
3333

@@ -42,7 +42,7 @@ jobs:
4242

4343
- name: install dependencies
4444
run: |
45-
brew install autoconf autoconf-archive automake coreutils libtool ninja
45+
brew install pkg-config autoconf autoconf-archive automake coreutils libtool cmake ninja
4646
4747
- name: configure
4848
run: |

.github/workflows/ubuntu.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
strategy:
2020
matrix:
2121
include:
22-
- os: "ubuntu-22.04"
2322
- os: "ubuntu-24.04"
2423
fail-fast: false
2524

CMakeLists.txt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
cmake_minimum_required(VERSION 3.14...3.22)
1+
cmake_minimum_required(VERSION 3.5...3.16)
22

3-
project(component-model LANGUAGES CXX)
3+
project(cmcpp)
44

5-
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
6-
message(FATAL_ERROR
7-
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
8-
)
9-
endif()
5+
set(CMAKE_CXX_STANDARD 20)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
find_package(Boost)
9+
10+
add_library(cmcpp STATIC
11+
src/context.cpp
12+
src/util.cpp
13+
)
1014

11-
enable_testing()
15+
target_include_directories(cmcpp
16+
INTERFACE include
17+
PRIVATE ${Boost_INCLUDE_DIR}
18+
)
1219

13-
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
20+
target_link_libraries(cmcpp
21+
)
1422

15-
add_subdirectory(src)
16-
add_subdirectory(test)
23+
include_directories(
24+
include
25+
)
26+
27+
if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
28+
add_subdirectory(test)
29+
endif()

CMakePresets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"name": "Debug",
2626
"installDir": "${sourceDir}/build/stage/Debug",
2727
"cacheVariables": {
28-
"CMAKE_BUILD_TYPE": "Debug"
28+
"CMAKE_BUILD_TYPE": "Debug",
29+
"BUILD_TESTING": "ON"
2930
},
3031
"hidden": true
3132
},

include/cmcpp.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef CMCPP_HPP
2+
#define CMCPP_HPP
3+
4+
#include <cmcpp/integer.hpp>
5+
#include <cmcpp/float.hpp>
6+
#include <cmcpp/string.hpp>
7+
#include <cmcpp/flags.hpp>
8+
#include <cmcpp/list.hpp>
9+
#include <cmcpp/tuple.hpp>
10+
#include <cmcpp/variant.hpp>
11+
#include <cmcpp/lower.hpp>
12+
#include <cmcpp/lift.hpp>
13+
14+
#endif // CMCPP_HPP

src/flags.hpp renamed to include/cmcpp/flags.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,23 @@ namespace cmcpp
5858
flags::store(cx, v, ptr);
5959
}
6060

61+
template <Flags T>
62+
inline WasmValVector lower_flat(CallContext &cx, const T &v)
63+
{
64+
return flags::lower_flat(cx, v);
65+
}
66+
6167
template <Flags T>
6268
inline T load(const CallContext &cx, uint32_t ptr)
6369
{
6470
return flags::load<T>(cx, ptr);
6571
}
72+
73+
template <Flags T>
74+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi)
75+
{
76+
return flags::lift_flat<T>(cx, vi);
77+
}
78+
6679
}
6780
#endif

src/float.hpp renamed to include/cmcpp/float.hpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,33 @@ namespace cmcpp
1111

1212
namespace float_
1313
{
14-
int32_t encode_float_as_i32(float32_t f);
15-
int64_t encode_float_as_i64(float64_t f);
16-
float32_t decode_i32_as_float(int32_t i);
17-
float64_t decode_i64_as_float(int64_t i);
18-
float32_t core_f32_reinterpret_i32(int32_t i);
14+
inline int32_t encode_float_as_i32(float32_t f)
15+
16+
{
17+
return *reinterpret_cast<int32_t *>(&f);
18+
}
19+
20+
inline int64_t encode_float_as_i64(float64_t f)
21+
{
22+
return *reinterpret_cast<int64_t *>(&f);
23+
}
24+
25+
inline float32_t decode_i32_as_float(int32_t i)
26+
{
27+
return *reinterpret_cast<float32_t *>(&i);
28+
}
29+
30+
inline float64_t decode_i64_as_float(int64_t i)
31+
{
32+
return *reinterpret_cast<float64_t *>(&i);
33+
}
34+
35+
inline float32_t core_f32_reinterpret_i32(int32_t i)
36+
{
37+
float f;
38+
std::memcpy(&f, &i, sizeof f);
39+
return f;
40+
}
1941

2042
template <Float T>
2143
T canonicalize_nan(T f)
@@ -78,11 +100,24 @@ namespace cmcpp
78100
float_::store<T>(cx, v, ptr);
79101
}
80102

103+
template <Float T>
104+
inline WasmValVector lower_flat(CallContext &cx, const T &v)
105+
{
106+
return {float_::lower_flat<T>(v)};
107+
}
108+
81109
template <Float T>
82110
inline T load(const CallContext &cx, uint32_t ptr)
83111
{
84112
return float_::load<T>(cx, ptr);
85113
}
114+
115+
template <Float T>
116+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi)
117+
{
118+
using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0]>::type;
119+
return float_::canonicalize_nan<T>(std::get<WasmValType>(vi.next(ValTrait<T>::flat_types[0])));
120+
}
86121
}
87122

88123
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ namespace cmcpp
7373
integer::store<T>(cx, v, ptr);
7474
}
7575

76+
template <SignedInteger T>
77+
inline WasmValVector lower_flat(CallContext &cx, const T &v)
78+
{
79+
using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0]>::type;
80+
return integer::lower_flat_signed(v, ValTrait<WasmValType>::size * 8);
81+
}
82+
7683
template <Boolean T>
7784
inline T load(const CallContext &cx, uint32_t ptr)
7885
{
@@ -90,6 +97,18 @@ namespace cmcpp
9097
{
9198
return integer::load<T>(cx, ptr);
9299
}
100+
101+
template <UnsignedInteger T>
102+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi)
103+
{
104+
return integer::lift_flat_unsigned<T>(vi, ValTrait<T>::size * 8, 8);
105+
}
106+
107+
template <SignedInteger T>
108+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi)
109+
{
110+
return integer::lift_flat_signed<T>(vi, ValTrait<T>::size * 8, 8);
111+
}
93112
}
94113

95114
#endif

include/cmcpp/lift.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef CMCPP_LIFT_HPP
2+
#define CMCPP_LIFT_HPP
3+
4+
#include "context.hpp"
5+
#include "util.hpp"
6+
7+
namespace cmcpp
8+
{
9+
template <Boolean T>
10+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi)
11+
{
12+
return convert_int_to_bool(vi.next<int32_t>());
13+
}
14+
15+
template <Char T>
16+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi)
17+
{
18+
return convert_i32_to_char(cx, vi.next<int32_t>());
19+
}
20+
21+
template <UnsignedInteger T>
22+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
23+
24+
template <SignedInteger T>
25+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
26+
27+
template <Float T>
28+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
29+
30+
template <String T>
31+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
32+
33+
template <List T>
34+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
35+
36+
template <Flags T>
37+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
38+
39+
template <Tuple T>
40+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
41+
42+
template <Record T>
43+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
44+
45+
template <Variant T>
46+
inline T lift_flat(const CallContext &cx, const CoreValueIter &vi);
47+
48+
}
49+
50+
#endif

0 commit comments

Comments
 (0)