Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 #487

Merged
merged 9 commits into from
Nov 14, 2024
Next Next commit
Update CMAKE_CXX_STANDARD to 20 from 17
Signed-off-by: yamacir-kit <httperror@404-notfound.jp>
yamacir-kit committed Nov 13, 2024
commit d8bf58c84316927dbdbf041a77ba7d30168e344e
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "-Og -gdwarf-4") # NOTE: The `-gdwarf-4` option is set
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -DNDEBUG ${${PROJECT_NAME}_RELEASE_PLUS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-4")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.262_amd64.deb
sudo apt install build/meevax_0.5.263_amd64.deb
```

or
@@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.262.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.263.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.262_amd64.deb`
| `package` | Generate debian package `meevax_0.5.263_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.262
0.5.263
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16.3) # Ubuntu 20.04 LTS default

project(example VERSION 0.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

find_package(Meevax REQUIRED) # NOTE: case-insensitive

1 change: 1 addition & 0 deletions include/meevax/bit/bit_cast.hpp
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ inline namespace bit
std::is_trivially_copyable<To>,
std::is_trivially_copyable<From>,
std::is_trivially_constructible<To>>>>
[[deprecated]]
auto bit_cast(From const& from) noexcept
{
To to;
10 changes: 5 additions & 5 deletions include/meevax/memory/nan_boxing_pointer.hpp
Original file line number Diff line number Diff line change
@@ -17,13 +17,13 @@
#ifndef INCLUDED_MEEVAX_MEMORY_NAN_BOXING_POINTER_HPP
#define INCLUDED_MEEVAX_MEMORY_NAN_BOXING_POINTER_HPP

#include <bit>
#include <cstddef>
#include <cmath>
#include <iomanip>
#include <ostream>
#include <typeinfo>

#include <meevax/bit/bit_cast.hpp>
#include <meevax/type_traits/integer.hpp>

namespace meevax
@@ -76,12 +76,12 @@ inline namespace memory

#define DEFINE(TYPE, ...) \
explicit nan_boxing_pointer(TYPE const& value __VA_ARGS__) noexcept \
: data { reinterpret_cast<pointer>(signature_##TYPE | bit_cast<uint8n_t<sizeof(TYPE)>>(value)) } \
: data { reinterpret_cast<pointer>(signature_##TYPE | std::bit_cast<uint8n_t<sizeof(TYPE)>>(value)) } \
{} \
\
auto reset(TYPE const& value __VA_ARGS__) noexcept -> void \
{ \
data = reinterpret_cast<pointer>(signature_##TYPE | bit_cast<uint8n_t<sizeof(TYPE)>>(value)); \
data = reinterpret_cast<pointer>(signature_##TYPE | std::bit_cast<uint8n_t<sizeof(TYPE)>>(value)); \
}

DEFINE(double, )
@@ -127,11 +127,11 @@ inline namespace memory
{
if constexpr (std::is_same_v<std::decay_t<U>, double>)
{
return bit_cast<double>(data);
return std::bit_cast<double>(data);
}
else
{
return bit_cast<std::decay_t<U>>(static_cast<uint8n_t<sizeof(std::decay_t<U>)>>(payload()));
return std::bit_cast<std::decay_t<U>>(static_cast<uint8n_t<sizeof(std::decay_t<U>)>>(payload()));
}
}

36 changes: 34 additions & 2 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
@@ -664,7 +664,23 @@ inline namespace kernel

library.define<procedure>("append!", [](let & xs)
{
return std::accumulate(xs.begin(), xs.end(), unit, [](let & x, let const& y) { return append(x, y); });
auto append = [](auto append, let & x, let & xs) -> auto &
{
if (xs.is<null>())
{
return x;
}
else if (x.is<null>())
{
return x = append(append, car(xs), cdr(xs));
}
else
{
return meevax::append(x, append(append, car(xs), cdr(xs)));
}
};

return not xs.is<pair>() ? xs : append(append, car(xs), cdr(xs));
});

library.define<procedure>("append-reverse", [](let const& xs)
@@ -694,7 +710,23 @@ inline namespace kernel

library.define<procedure>("concatenate!", [](let & xs)
{
return std::accumulate(car(xs).begin(), car(xs).end(), unit, [](let & x, let const& y) { return append(x, y); });
auto concatenate = [](auto concatenate, let & x, let & xs) -> auto &
{
if (xs.is<null>())
{
return x;
}
else if (x.is<null>())
{
return x = concatenate(concatenate, car(xs), cdr(xs));
}
else
{
return meevax::append(x, concatenate(concatenate, car(xs), cdr(xs)));
}
};

return not xs.is<pair>() ? xs : concatenate(concatenate, caar(xs), cdar(xs));
});

library.define<procedure>("list-copy", [](let const& xs)
6 changes: 0 additions & 6 deletions src/kernel/character.cpp
Original file line number Diff line number Diff line change
@@ -79,11 +79,5 @@ inline namespace kernel
return os << cyan(static_cast<std::string>(datum));
}
}

static_assert(std::is_pod_v<character>);

static_assert(std::is_standard_layout_v<character>);

static_assert(std::is_trivial_v<character>);
} // namespace kernel
} // namespace meevax
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ auto main(int const argc, char const* const* const argv) -> int
{
try
{
std::cout << u8"\u03bb> " << e.evaluate(standard_input_port().read()) << std::endl;
std::cout << "> " << e.evaluate(standard_input_port().read()) << std::endl;
}
catch (error const& error)
{