Skip to content

Commit bbc3783

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 bbc3783

39 files changed

+429
-535
lines changed

.github/workflows/macos.yml

Lines changed: 2 additions & 2 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

.github/workflows/pr-test.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: pr-test
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
pull_request:
8+
branches:
9+
- trunk
10+
11+
env:
12+
CTEST_OUTPUT_ON_FAILURE: 1
13+
14+
jobs:
15+
build:
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os:
20+
- windows-2022
21+
- ubuntu-24.04
22+
- macos-14 # arm64
23+
- macos-13
24+
compiler:
25+
- llvm
26+
- gcc
27+
include:
28+
- os: "windows-2022"
29+
compiler: "msvc"
30+
31+
runs-on: ${{ matrix.os }}
32+
steps:
33+
- uses: actions/checkout@v3
34+
with:
35+
submodules: recursive
36+
37+
- uses: actions/cache@v3
38+
with:
39+
path: "build/vcpkg_installed/**/*"
40+
key: ${{ matrix.os }}-vcpkg_installed
41+
42+
- name: Set up C++20
43+
uses: aminya/setup-cpp@v1
44+
with:
45+
compiler: gcc-13
46+
cmake: true
47+
ninja: true
48+
49+
- name: install dependencies
50+
if: ${{ contains(matrix.os, 'macos') }}
51+
run: |
52+
brew install autoconf autoconf-archive automake coreutils libtool ninja
53+
54+
- name: cmake configure
55+
run: |
56+
cmake --preset linux-ninja-Debug
57+
58+
- name: cmake build
59+
run: |
60+
cmake --build --preset linux-ninja-Debug
61+
62+
- name: test
63+
working-directory: build
64+
run: |
65+
ctest -VV

.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

0 commit comments

Comments
 (0)