From 0f1575170d60d18698111a36887b34c914386564 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 4 Oct 2024 18:49:31 -0400 Subject: [PATCH] Upgrade JSON BinPack to `0c8caafaa27f74c7124cba5663f2083b79a3ef7d` (#172) Signed-off-by: Juan Cruz Viotti --- DEPENDENCIES | 2 +- cmake/FindJSONBinPack.cmake | 1 - vendor/jsonbinpack/CMakeLists.txt | 14 +-- vendor/jsonbinpack/src/cli/CMakeLists.txt | 24 ----- .../src/cli/command_canonicalize.cc | 33 ------- vendor/jsonbinpack/src/cli/command_compile.cc | 32 ------- vendor/jsonbinpack/src/cli/command_decode.cc | 46 --------- vendor/jsonbinpack/src/cli/command_encode.cc | 40 -------- vendor/jsonbinpack/src/cli/command_help.cc | 38 -------- vendor/jsonbinpack/src/cli/command_version.cc | 10 -- vendor/jsonbinpack/src/cli/commands.h | 22 ----- vendor/jsonbinpack/src/cli/defaults.h | 10 -- vendor/jsonbinpack/src/cli/main.cc | 94 ------------------- vendor/jsonbinpack/src/cli/version.h.in | 10 -- vendor/jsonbinpack/src/numeric/CMakeLists.txt | 3 +- .../include/sourcemeta/jsonbinpack/numeric.h | 24 +---- .../jsonbinpack/numeric_integral.h} | 28 ++++-- .../sourcemeta/jsonbinpack/numeric_real.h} | 8 +- .../sourcemeta/jsonbinpack/numeric_zigzag.h} | 8 +- vendor/jsonbinpack/src/runtime/CMakeLists.txt | 6 +- .../sourcemeta/jsonbinpack/runtime_decoder.h | 28 +++--- .../jsonbinpack/runtime_decoder_basic.h | 3 +- .../sourcemeta/jsonbinpack/runtime_encoder.h | 4 +- .../jsonbinpack/runtime_encoder_basic.h | 3 +- .../sourcemeta/jsonbinpack/runtime_plan.h | 3 +- .../noa/cmake/noa/compiler/options.cmake | 16 +++- .../vendor/noa/cmake/noa/library.cmake | 7 +- 27 files changed, 87 insertions(+), 430 deletions(-) delete mode 100644 vendor/jsonbinpack/src/cli/CMakeLists.txt delete mode 100644 vendor/jsonbinpack/src/cli/command_canonicalize.cc delete mode 100644 vendor/jsonbinpack/src/cli/command_compile.cc delete mode 100644 vendor/jsonbinpack/src/cli/command_decode.cc delete mode 100644 vendor/jsonbinpack/src/cli/command_encode.cc delete mode 100644 vendor/jsonbinpack/src/cli/command_help.cc delete mode 100644 vendor/jsonbinpack/src/cli/command_version.cc delete mode 100644 vendor/jsonbinpack/src/cli/commands.h delete mode 100644 vendor/jsonbinpack/src/cli/defaults.h delete mode 100644 vendor/jsonbinpack/src/cli/main.cc delete mode 100644 vendor/jsonbinpack/src/cli/version.h.in rename vendor/jsonbinpack/src/{runtime/include/sourcemeta/jsonbinpack/runtime_numeric.h => numeric/include/sourcemeta/jsonbinpack/numeric_integral.h} (84%) rename vendor/jsonbinpack/src/{runtime/include/sourcemeta/jsonbinpack/runtime_encoder_real.h => numeric/include/sourcemeta/jsonbinpack/numeric_real.h} (91%) rename vendor/jsonbinpack/src/{runtime/include/sourcemeta/jsonbinpack/runtime_zigzag.h => numeric/include/sourcemeta/jsonbinpack/numeric_zigzag.h} (81%) diff --git a/DEPENDENCIES b/DEPENDENCIES index ac5804c..69d3884 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -3,4 +3,4 @@ noa https://github.com/sourcemeta/noa 517e88aef5981b88ac6bb8caff15d17dffcb4320 jsontoolkit https://github.com/sourcemeta/jsontoolkit b5c8f63fbc4b4b7a9cd4bdd71774d89db6ee2a99 hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc alterschema https://github.com/sourcemeta/alterschema 358df64771979da64e043a416cf340d83a5382ca -jsonbinpack https://github.com/sourcemeta/jsonbinpack 43d53dd32c432333deb1aea147095ed8707b5f11 +jsonbinpack https://github.com/sourcemeta/jsonbinpack 0c8caafaa27f74c7124cba5663f2083b79a3ef7d diff --git a/cmake/FindJSONBinPack.cmake b/cmake/FindJSONBinPack.cmake index cc2b0f6..671718e 100644 --- a/cmake/FindJSONBinPack.cmake +++ b/cmake/FindJSONBinPack.cmake @@ -1,6 +1,5 @@ if(NOT JSONBinPack_FOUND) set(JSONBINPACK_INSTALL OFF CACHE BOOL "disable installation") - set(JSONBINPACK_CLI OFF CACHE BOOL "disable the JSON BinPack CLI module") set(JSONBINPACK_RUNTIME OFF CACHE BOOL "disable the JSON BinPack runtime module") add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/jsonbinpack") set(JSONBinPack_FOUND ON) diff --git a/vendor/jsonbinpack/CMakeLists.txt b/vendor/jsonbinpack/CMakeLists.txt index 389f082..b1e6bd8 100644 --- a/vendor/jsonbinpack/CMakeLists.txt +++ b/vendor/jsonbinpack/CMakeLists.txt @@ -9,7 +9,6 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(vendor/noa/cmake/noa.cmake) # Options -option(JSONBINPACK_CLI "Build the JSON BinPack CLI" ON) option(JSONBINPACK_NUMERIC "Build the JSON BinPack numeric library" ON) option(JSONBINPACK_RUNTIME "Build the JSON BinPack runtime" ON) option(JSONBINPACK_COMPILER "Build the JSON BinPack compiler" ON) @@ -56,11 +55,6 @@ if(JSONBINPACK_COMPILER) add_subdirectory(src/compiler) endif() -# CLI -if(JSONBINPACK_CLI) - add_subdirectory(src/cli) -endif() - if(JSONBINPACK_ADDRESS_SANITIZER) noa_sanitizer(TYPE address) elseif(JSONBINPACK_UNDEFINED_SANITIZER) @@ -89,6 +83,10 @@ if(JSONBINPACK_TESTS) find_package(GoogleTest REQUIRED) enable_testing() + if(JSONBINPACK_NUMERIC) + add_subdirectory(test/numeric) + endif() + if(JSONBINPACK_RUNTIME) add_subdirectory(test/runtime) endif() @@ -97,10 +95,6 @@ if(JSONBINPACK_TESTS) add_subdirectory(test/compiler) endif() - if(JSONBINPACK_CLI) - add_subdirectory(test/cli) - endif() - add_subdirectory(test/e2e) if(PROJECT_IS_TOP_LEVEL) diff --git a/vendor/jsonbinpack/src/cli/CMakeLists.txt b/vendor/jsonbinpack/src/cli/CMakeLists.txt deleted file mode 100644 index 994bf73..0000000 --- a/vendor/jsonbinpack/src/cli/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -configure_file(version.h.in version.h @ONLY) -add_executable(sourcemeta_jsonbinpack_cli main.cc commands.h - command_help.cc command_version.cc - command_canonicalize.cc command_compile.cc - command_encode.cc command_decode.cc - defaults.h version.h.in) - -noa_add_default_options(PRIVATE sourcemeta_jsonbinpack_cli) - -target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::compiler) -target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::runtime) -target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsontoolkit::json) -target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsontoolkit::jsonschema) - -# To find the generated version file -target_include_directories(sourcemeta_jsonbinpack_cli PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") -# Set a friendly name for the binary -set_target_properties(sourcemeta_jsonbinpack_cli PROPERTIES - OUTPUT_NAME jsonbinpack - FOLDER "JSON BinPack/CLI") - -install(TARGETS sourcemeta_jsonbinpack_cli - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - COMPONENT sourcemeta_jsonbinpack) diff --git a/vendor/jsonbinpack/src/cli/command_canonicalize.cc b/vendor/jsonbinpack/src/cli/command_canonicalize.cc deleted file mode 100644 index e5cbb4f..0000000 --- a/vendor/jsonbinpack/src/cli/command_canonicalize.cc +++ /dev/null @@ -1,33 +0,0 @@ -#include "commands.h" -#include "defaults.h" - -#include -#include -#include - -#include // EXIT_SUCCESS -#include // std::filesystem -#include // std::cin, std::cout, std::endl; - -static auto canonicalize_from_json(sourcemeta::jsontoolkit::JSON &schema) - -> int { - sourcemeta::jsonbinpack::canonicalize( - schema, sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - sourcemeta::jsonbinpack::DEFAULT_METASCHEMA); - sourcemeta::jsontoolkit::prettify(schema, std::cout); - std::cout << std::endl; - return EXIT_SUCCESS; -} - -auto sourcemeta::jsonbinpack::cli::canonicalize( - const std::filesystem::path &schema_path) -> int { - auto schema = sourcemeta::jsontoolkit::from_file(schema_path); - return canonicalize_from_json(schema); -} - -auto sourcemeta::jsonbinpack::cli::canonicalize() -> int { - sourcemeta::jsontoolkit::JSON schema = - sourcemeta::jsontoolkit::parse(std::cin); - return canonicalize_from_json(schema); -} diff --git a/vendor/jsonbinpack/src/cli/command_compile.cc b/vendor/jsonbinpack/src/cli/command_compile.cc deleted file mode 100644 index 2ade3ce..0000000 --- a/vendor/jsonbinpack/src/cli/command_compile.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include "commands.h" -#include "defaults.h" - -#include -#include -#include - -#include // EXIT_SUCCESS -#include // std::filesystem -#include // std::cin, std::cout, std::endl - -static auto compile_from_json(sourcemeta::jsontoolkit::JSON &schema) -> int { - sourcemeta::jsonbinpack::compile( - schema, sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - sourcemeta::jsonbinpack::DEFAULT_METASCHEMA); - sourcemeta::jsontoolkit::prettify(schema, std::cout); - std::cout << std::endl; - return EXIT_SUCCESS; -} - -auto sourcemeta::jsonbinpack::cli::compile( - const std::filesystem::path &schema_path) -> int { - auto schema = sourcemeta::jsontoolkit::from_file(schema_path); - return compile_from_json(schema); -} - -auto sourcemeta::jsonbinpack::cli::compile() -> int { - sourcemeta::jsontoolkit::JSON schema = - sourcemeta::jsontoolkit::parse(std::cin); - return compile_from_json(schema); -} diff --git a/vendor/jsonbinpack/src/cli/command_decode.cc b/vendor/jsonbinpack/src/cli/command_decode.cc deleted file mode 100644 index 219d5e4..0000000 --- a/vendor/jsonbinpack/src/cli/command_decode.cc +++ /dev/null @@ -1,46 +0,0 @@ -#include "commands.h" -#include "defaults.h" - -#include -#include - -#include -#include - -#include // EXIT_SUCCESS -#include // std::filesystem -#include // std::ifstream -#include // std::ios_base, std::ios::binary -#include // std::cin, std::cout -#include // std::basic_istream - -template -static auto decode_from_stream(sourcemeta::jsontoolkit::JSON &schema, - std::basic_istream &stream) - -> int { - sourcemeta::jsonbinpack::compile( - schema, sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - sourcemeta::jsonbinpack::DEFAULT_METASCHEMA); - const sourcemeta::jsonbinpack::Plan plan{ - sourcemeta::jsonbinpack::parse(schema)}; - sourcemeta::jsonbinpack::Decoder decoder{stream}; - const sourcemeta::jsontoolkit::JSON result = decoder.decode(plan); - sourcemeta::jsontoolkit::stringify(result, std::cout); - return EXIT_SUCCESS; -} - -auto sourcemeta::jsonbinpack::cli::decode( - const std::filesystem::path &schema_path, - const std::filesystem::path &data_path) -> int { - std::ifstream data_stream{data_path, std::ios::binary}; - data_stream.exceptions(std::ios_base::badbit); - auto schema = sourcemeta::jsontoolkit::from_file(schema_path); - return decode_from_stream(schema, data_stream); -} - -auto sourcemeta::jsonbinpack::cli::decode( - const std::filesystem::path &schema_path) -> int { - auto schema = sourcemeta::jsontoolkit::from_file(schema_path); - return decode_from_stream(schema, std::cin); -} diff --git a/vendor/jsonbinpack/src/cli/command_encode.cc b/vendor/jsonbinpack/src/cli/command_encode.cc deleted file mode 100644 index b90222d..0000000 --- a/vendor/jsonbinpack/src/cli/command_encode.cc +++ /dev/null @@ -1,40 +0,0 @@ -#include "commands.h" -#include "defaults.h" - -#include -#include - -#include -#include - -#include // EXIT_SUCCESS -#include // std::filesystem -#include // std::cin, std::cout - -static auto encode_from_json(sourcemeta::jsontoolkit::JSON &schema, - const sourcemeta::jsontoolkit::JSON &instance) - -> int { - sourcemeta::jsonbinpack::compile( - schema, sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - sourcemeta::jsonbinpack::DEFAULT_METASCHEMA); - const sourcemeta::jsonbinpack::Plan plan{ - sourcemeta::jsonbinpack::parse(schema)}; - sourcemeta::jsonbinpack::Encoder encoder{std::cout}; - encoder.encode(instance, plan); - return EXIT_SUCCESS; -} - -auto sourcemeta::jsonbinpack::cli::encode( - const std::filesystem::path &schema_path, - const std::filesystem::path &instance_path) -> int { - auto schema = sourcemeta::jsontoolkit::from_file(schema_path); - return encode_from_json(schema, - sourcemeta::jsontoolkit::from_file(instance_path)); -} - -auto sourcemeta::jsonbinpack::cli::encode( - const std::filesystem::path &schema_path) -> int { - auto schema = sourcemeta::jsontoolkit::from_file(schema_path); - return encode_from_json(schema, sourcemeta::jsontoolkit::parse(std::cin)); -} diff --git a/vendor/jsonbinpack/src/cli/command_help.cc b/vendor/jsonbinpack/src/cli/command_help.cc deleted file mode 100644 index 0983221..0000000 --- a/vendor/jsonbinpack/src/cli/command_help.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include "commands.h" - -#include // EXIT_SUCCESS -#include // std::cerr - -static const char *USAGE_DETAILS = R"EOF( - version Print version information and quit. - - help Print this help information and quit. - - canonicalize [schema.json] Canonicalize a given JSON Schema definition - and print the result to stdout. If a path to - a schema is not provided, the schema will - be read from standard input. - - compile [schema.json] Compile a given JSON Schema definition - into an encoding schema and print the result to - stdout. If a path to a schema is not provided, - the schema will be read from standard input. - - encode [data.json] Encode a given JSON instance based on the given - encoding schema (or JSON Schema) and print the - results to stdout. If a path to the instance is - not provided, the instance will be read from - standard input. - - decode [data.bin] Decode a given bit-string based on the given - encoding schema (or JSON Schema) and print the - results to stdout. If a path to the bit-string - is not provided, it will be read from standard - input. -)EOF"; - -auto sourcemeta::jsonbinpack::cli::help(const std::string &program) -> int { - std::clog << "Usage: " << program << " [arguments...]\n"; - std::clog << USAGE_DETAILS; - return EXIT_SUCCESS; -} diff --git a/vendor/jsonbinpack/src/cli/command_version.cc b/vendor/jsonbinpack/src/cli/command_version.cc deleted file mode 100644 index 3990e6c..0000000 --- a/vendor/jsonbinpack/src/cli/command_version.cc +++ /dev/null @@ -1,10 +0,0 @@ -#include "commands.h" -#include "version.h" - -#include // EXIT_SUCCESS -#include // std::cout - -auto sourcemeta::jsonbinpack::cli::version() -> int { - std::cout << sourcemeta::jsonbinpack::VERSION << "\n"; - return EXIT_SUCCESS; -} diff --git a/vendor/jsonbinpack/src/cli/commands.h b/vendor/jsonbinpack/src/cli/commands.h deleted file mode 100644 index 2b41a6d..0000000 --- a/vendor/jsonbinpack/src/cli/commands.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SOURCEMETA_JSONBINPACK_CLI_COMMANDS_H_ -#define SOURCEMETA_JSONBINPACK_CLI_COMMANDS_H_ - -#include // std::filesystem -#include // std::string - -namespace sourcemeta::jsonbinpack::cli { -auto help(const std::string &program) -> int; -auto version() -> int; -auto canonicalize(const std::filesystem::path &schema_path) -> int; -auto canonicalize() -> int; -auto compile(const std::filesystem::path &schema_path) -> int; -auto compile() -> int; -auto encode(const std::filesystem::path &schema_path, - const std::filesystem::path &instance_path) -> int; -auto encode(const std::filesystem::path &schema_path) -> int; -auto decode(const std::filesystem::path &schema_path, - const std::filesystem::path &data_path) -> int; -auto decode(const std::filesystem::path &schema_path) -> int; -} // namespace sourcemeta::jsonbinpack::cli - -#endif diff --git a/vendor/jsonbinpack/src/cli/defaults.h b/vendor/jsonbinpack/src/cli/defaults.h deleted file mode 100644 index 76a906f..0000000 --- a/vendor/jsonbinpack/src/cli/defaults.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SOURCEMETA_JSONBINPACK_CLI_DEFAULTS_H_ -#define SOURCEMETA_JSONBINPACK_CLI_DEFAULTS_H_ - -namespace sourcemeta::jsonbinpack { -// TODO: Rename to dialect -const char *const DEFAULT_METASCHEMA = - "https://json-schema.org/draft/2020-12/schema"; -} // namespace sourcemeta::jsonbinpack - -#endif diff --git a/vendor/jsonbinpack/src/cli/main.cc b/vendor/jsonbinpack/src/cli/main.cc deleted file mode 100644 index 7349cc8..0000000 --- a/vendor/jsonbinpack/src/cli/main.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "commands.h" - -#include // std::min -#include // EXIT_FAILURE -#include // std::exception -#include // std::cerr -#include // std::ostringstream -#include // std::runtime_error -#include // std::vector - -static auto assert_arguments(const std::string &command, - const std::vector &arguments, - const std::vector::size_type count) - -> void { - if (arguments.size() >= count) { - return; - } - - std::ostringstream error{}; - error << "Command '" << command << "' requires " << count - << " arguments, but you passed " << arguments.size() << "."; - throw std::runtime_error(error.str()); -} - -static auto cli_main(const std::string &program, const std::string &command, - const std::vector &arguments) -> int { - if (command.empty()) { - sourcemeta::jsonbinpack::cli::help(program); - return EXIT_FAILURE; - } - - if (command == "help") { - return sourcemeta::jsonbinpack::cli::help(program); - } - - if (command == "version") { - return sourcemeta::jsonbinpack::cli::version(); - } - - if (command == "canonicalize") { - if (arguments.empty()) { - return sourcemeta::jsonbinpack::cli::canonicalize(); - } - - assert_arguments(command, arguments, 1); - return sourcemeta::jsonbinpack::cli::canonicalize(arguments.at(0)); - } - - if (command == "compile") { - if (arguments.empty()) { - return sourcemeta::jsonbinpack::cli::compile(); - } - - assert_arguments(command, arguments, 1); - return sourcemeta::jsonbinpack::cli::compile(arguments.at(0)); - } - - if (command == "encode") { - if (arguments.size() == 1) { - return sourcemeta::jsonbinpack::cli::encode(arguments.at(0)); - } - - assert_arguments(command, arguments, 2); - return sourcemeta::jsonbinpack::cli::encode(arguments.at(0), - arguments.at(1)); - } - - if (command == "decode") { - if (arguments.size() == 1) { - return sourcemeta::jsonbinpack::cli::decode(arguments.at(0)); - } - - assert_arguments(command, arguments, 2); - return sourcemeta::jsonbinpack::cli::decode(arguments.at(0), - arguments.at(1)); - } - - std::cerr << "Unknown command: " << command << "\n"; - return EXIT_FAILURE; -} - -auto main(int argc, char *argv[]) -> int { - const std::string program{argv[0]}; - const std::string command{argc > 1 ? argv[1] : ""}; - const std::vector arguments{argv + std::min(2, argc), - argv + argc}; - - try { - return cli_main(program, command, arguments); - } catch (const std::exception &error) { - std::cerr << "Error: " << error.what() << "\n"; - return EXIT_FAILURE; - } -} diff --git a/vendor/jsonbinpack/src/cli/version.h.in b/vendor/jsonbinpack/src/cli/version.h.in deleted file mode 100644 index 3cc1e7b..0000000 --- a/vendor/jsonbinpack/src/cli/version.h.in +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SOURCEMETA_JSONBINPACK_CLI_VERSION_H_ -#define SOURCEMETA_JSONBINPACK_CLI_VERSION_H_ - -namespace sourcemeta { - namespace jsonbinpack { - const char * const VERSION = "@CMAKE_PROJECT_VERSION@"; - } -} - -#endif diff --git a/vendor/jsonbinpack/src/numeric/CMakeLists.txt b/vendor/jsonbinpack/src/numeric/CMakeLists.txt index 7e34924..d5f4174 100644 --- a/vendor/jsonbinpack/src/numeric/CMakeLists.txt +++ b/vendor/jsonbinpack/src/numeric/CMakeLists.txt @@ -1,5 +1,6 @@ noa_library(NAMESPACE sourcemeta PROJECT jsonbinpack NAME numeric - FOLDER "JSON BinPack/Numeric") + FOLDER "JSON BinPack/Numeric" + PRIVATE_HEADERS integral.h real.h zigzag.h) if(JSONBINPACK_INSTALL) noa_library_install(NAMESPACE sourcemeta PROJECT jsonbinpack NAME numeric) diff --git a/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric.h b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric.h index 833c713..4b9801c 100644 --- a/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric.h +++ b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric.h @@ -1,9 +1,6 @@ #ifndef SOURCEMETA_JSONBINPACK_NUMERIC_H_ #define SOURCEMETA_JSONBINPACK_NUMERIC_H_ -#include // std::uint8_t, std::int64_t -#include // std::numeric_limits - /// @defgroup numeric Numeric /// @brief A comprehensive numeric library for JSON BinPack /// @@ -13,23 +10,8 @@ /// #include /// ``` -namespace sourcemeta::jsonbinpack { - -/// @ingroup numeric -template constexpr auto is_byte(const T value) noexcept -> bool { - return value <= std::numeric_limits::max(); -} - -/// @ingroup numeric -constexpr auto count_multiples(const std::int64_t minimum, - const std::int64_t maximum, - const std::int64_t multiplier) -> std::uint64_t { - assert(minimum <= maximum); - assert(multiplier > 0); - return static_cast((maximum / multiplier) - - ((minimum - 1) / multiplier)); -} - -} // namespace sourcemeta::jsonbinpack +#include +#include +#include #endif diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_numeric.h b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_integral.h similarity index 84% rename from vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_numeric.h rename to vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_integral.h index 0adcbcf..a29b93d 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_numeric.h +++ b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_integral.h @@ -1,27 +1,39 @@ -#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_NUMERIC_H_ -#define SOURCEMETA_JSONBINPACK_RUNTIME_NUMERIC_H_ +#ifndef SOURCEMETA_JSONBINPACK_NUMERIC_INTEGRAL_H_ +#define SOURCEMETA_JSONBINPACK_NUMERIC_INTEGRAL_H_ #include // assert #include // std::abs #include // std::uint8_t, std::int64_t, std::uint64_t #include // std::numeric_limits -// TODO: Move to src/numeric - namespace sourcemeta::jsonbinpack { -template constexpr auto uint_max = (2 << (T - 1)) - 1; - +/// @ingroup numeric template constexpr auto is_byte(const T value) noexcept -> bool { return value <= std::numeric_limits::max(); } +/// @ingroup numeric +constexpr auto count_multiples(const std::int64_t minimum, + const std::int64_t maximum, + const std::int64_t multiplier) -> std::uint64_t { + assert(minimum <= maximum); + assert(multiplier > 0); + return static_cast((maximum / multiplier) - + ((minimum - 1) / multiplier)); +} + +/// @ingroup numeric +template constexpr auto uint_max = (2 << (T - 1)) - 1; + +/// @ingroup numeric template constexpr auto is_within(const T value, const std::int64_t lower, const std::int64_t higher) noexcept -> bool { return value >= lower && value <= higher; } +/// @ingroup numeric template constexpr auto is_within(const T value, const std::uint64_t lower, const std::uint64_t higher) noexcept -> bool { @@ -33,6 +45,7 @@ constexpr auto is_within(const T value, const std::uint64_t lower, } } +/// @ingroup numeric constexpr auto abs(const std::int64_t value) noexcept -> std::uint64_t { if (value < 0) { return static_cast(value * -1); @@ -41,6 +54,7 @@ constexpr auto abs(const std::int64_t value) noexcept -> std::uint64_t { } } +/// @ingroup numeric constexpr auto divide_ceil(const std::int64_t dividend, const std::uint64_t divisor) noexcept -> std::int64_t { @@ -68,6 +82,7 @@ constexpr auto divide_ceil(const std::int64_t dividend, } } +/// @ingroup numeric constexpr auto divide_floor(const std::int64_t dividend, const std::uint64_t divisor) noexcept -> std::int64_t { @@ -88,6 +103,7 @@ constexpr auto divide_floor(const std::int64_t dividend, } } +/// @ingroup numeric constexpr auto closest_smallest_exponent(const std::uint64_t value, const std::uint8_t base, const std::uint8_t exponent_start, diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder_real.h b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_real.h similarity index 91% rename from vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder_real.h rename to vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_real.h index 37788a5..fe52879 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder_real.h +++ b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_real.h @@ -1,12 +1,10 @@ -#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_REAL_H_ -#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_REAL_H_ +#ifndef SOURCEMETA_JSONBINPACK_NUMERIC_REAL_H_ +#define SOURCEMETA_JSONBINPACK_NUMERIC_REAL_H_ #include // assert #include // std::modf, std::floor, std::isfinite #include // std::floating_point, std::integral -// TODO: Move to src/numeric - namespace sourcemeta::jsonbinpack { // IEEE764 floating-point encoding is not precise. Some real numbers @@ -14,6 +12,7 @@ namespace sourcemeta::jsonbinpack { // used. Here, we abuse those imprecision characteristics for // space-efficiency by performing rounding on a very, very low // threshold. +/// @ingroup numeric template constexpr auto correct_ieee764(const Real value) -> Real { assert(std::isfinite(value)); @@ -29,6 +28,7 @@ constexpr auto correct_ieee764(const Real value) -> Real { } } +/// @ingroup numeric template constexpr auto real_digits(Real value, std::uint64_t *point_position) -> Integer { diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_zigzag.h b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_zigzag.h similarity index 81% rename from vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_zigzag.h rename to vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_zigzag.h index 27052f2..37d0748 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_zigzag.h +++ b/vendor/jsonbinpack/src/numeric/include/sourcemeta/jsonbinpack/numeric_zigzag.h @@ -1,13 +1,12 @@ -#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ZIGZAG_H_ -#define SOURCEMETA_JSONBINPACK_RUNTIME_ZIGZAG_H_ +#ifndef SOURCEMETA_JSONBINPACK_NUMERIC_ZIGZAG_H_ +#define SOURCEMETA_JSONBINPACK_NUMERIC_ZIGZAG_H_ #include // std::abs #include // std::uint64_t, std::int64_t -// TODO: Move to src/numeric - namespace sourcemeta::jsonbinpack { +/// @ingroup numeric constexpr auto zigzag_encode(const std::int64_t value) noexcept -> std::uint64_t { if (value >= 0) { @@ -17,6 +16,7 @@ constexpr auto zigzag_encode(const std::int64_t value) noexcept return (static_cast(std::abs(value)) * 2) - 1; } +/// @ingroup numeric constexpr auto zigzag_decode(const std::uint64_t value) noexcept -> std::int64_t { if (value % 2 == 0) { diff --git a/vendor/jsonbinpack/src/runtime/CMakeLists.txt b/vendor/jsonbinpack/src/runtime/CMakeLists.txt index f45673a..a62fc05 100644 --- a/vendor/jsonbinpack/src/runtime/CMakeLists.txt +++ b/vendor/jsonbinpack/src/runtime/CMakeLists.txt @@ -2,9 +2,9 @@ noa_library(NAMESPACE sourcemeta PROJECT jsonbinpack NAME runtime FOLDER "JSON BinPack/Runtime" PRIVATE_HEADERS decoder.h decoder_basic.h - encoder.h encoder_basic.h encoder_context.h encoder_real.h + encoder.h encoder_basic.h encoder_context.h plan.h plan_wrap.h parser.h - zigzag.h varint.h numeric.h + varint.h SOURCES runtime_parser.cc runtime_parser_v1.h) if(JSONBINPACK_INSTALL) @@ -13,3 +13,5 @@ endif() target_link_libraries(sourcemeta_jsonbinpack_runtime PUBLIC sourcemeta::jsontoolkit::json) +target_link_libraries(sourcemeta_jsonbinpack_runtime PUBLIC + sourcemeta::jsonbinpack::numeric) diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder.h b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder.h index 8d01b6a..7118841 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder.h +++ b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder.h @@ -1,8 +1,9 @@ #ifndef SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_H_ #define SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_H_ +#include + #include -#include #include #include @@ -209,9 +210,9 @@ class Decoder : private BasicDecoder { if (is_shared) { const std::uint64_t position{this->position()}; const std::uint64_t current{this->rewind(this->get_varint(), position)}; - sourcemeta::jsontoolkit::JSON string{this->get_string_utf8(length)}; + const sourcemeta::jsontoolkit::JSON value{this->get_string_utf8(length)}; this->seek(current); - return string; + return value; } else { return UTF8_STRING_NO_LENGTH({length}); } @@ -229,9 +230,10 @@ class Decoder : private BasicDecoder { if (is_shared) { const std::uint64_t position{this->position()}; const std::uint64_t current{this->rewind(this->get_varint(), position)}; - sourcemeta::jsontoolkit::JSON string = UTF8_STRING_NO_LENGTH({length}); + const sourcemeta::jsontoolkit::JSON value{ + UTF8_STRING_NO_LENGTH({length})}; this->seek(current); - return string; + return value; } else { return UTF8_STRING_NO_LENGTH({length}); } @@ -251,9 +253,10 @@ class Decoder : private BasicDecoder { if (is_shared) { const std::uint64_t position{this->position()}; const std::uint64_t current{this->rewind(this->get_varint(), position)}; - sourcemeta::jsontoolkit::JSON string = UTF8_STRING_NO_LENGTH({length}); + const sourcemeta::jsontoolkit::JSON value{ + UTF8_STRING_NO_LENGTH({length})}; this->seek(current); - return string; + return value; } else { return UTF8_STRING_NO_LENGTH({length}); } @@ -289,10 +292,10 @@ class Decoder : private BasicDecoder { if (prefix == 0) { const std::uint64_t position{this->position()}; const std::uint64_t current{this->rewind(this->get_varint(), position)}; - sourcemeta::jsontoolkit::JSON string = - PREFIX_VARINT_LENGTH_STRING_SHARED(options); + const sourcemeta::jsontoolkit::JSON value{ + PREFIX_VARINT_LENGTH_STRING_SHARED(options)}; this->seek(current); - return string; + return value; } else { return sourcemeta::jsontoolkit::JSON{this->get_string_utf8(prefix - 1)}; } @@ -438,9 +441,10 @@ class Decoder : private BasicDecoder { const std::uint64_t position{this->position()}; const std::uint64_t current{ this->rewind(this->get_varint(), position)}; - sourcemeta::jsontoolkit::JSON string{this->get_string_utf8(length)}; + const sourcemeta::jsontoolkit::JSON value{ + this->get_string_utf8(length)}; this->seek(current); - return string; + return value; }; case TYPE_STRING: return subtype == 0 ? this->FLOOR_VARINT_PREFIX_UTF8_STRING_SHARED( diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder_basic.h b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder_basic.h index 3b7af0a..74914d0 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder_basic.h +++ b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder_basic.h @@ -2,8 +2,9 @@ #define SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_BASIC_H_ #ifndef DOXYGEN +#include + #include -#include #include // assert #include // std::ceil diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder.h b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder.h index bee9ca0..1dd8aa7 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder.h +++ b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder.h @@ -1,9 +1,9 @@ #ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_H_ #define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_H_ +#include + #include -#include -#include #include #include diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder_basic.h b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder_basic.h index 3261b6f..636ac4b 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder_basic.h +++ b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder_basic.h @@ -2,9 +2,10 @@ #define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_BASIC_H_ #ifndef DOXYGEN +#include + #include #include -#include #include // std::find_if #include // assert diff --git a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_plan.h b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_plan.h index ef4e34a..c2ef0b5 100644 --- a/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_plan.h +++ b/vendor/jsonbinpack/src/runtime/include/sourcemeta/jsonbinpack/runtime_plan.h @@ -1,7 +1,8 @@ #ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODING_H_ #define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODING_H_ -#include +#include + #include #include // std::int64_t, std::uint64_t diff --git a/vendor/jsonbinpack/vendor/noa/cmake/noa/compiler/options.cmake b/vendor/jsonbinpack/vendor/noa/cmake/noa/compiler/options.cmake index c859781..b1fc6e5 100644 --- a/vendor/jsonbinpack/vendor/noa/cmake/noa/compiler/options.cmake +++ b/vendor/jsonbinpack/vendor/noa/cmake/noa/compiler/options.cmake @@ -40,6 +40,8 @@ function(noa_add_default_options visibility target) -Wnon-virtual-dtor -Woverloaded-virtual -Winvalid-offsetof + -funroll-loops + -fstrict-aliasing # Assume that signed arithmetic overflow of addition, subtraction and # multiplication wraps around using twos-complement representation @@ -68,6 +70,18 @@ function(noa_add_default_options visibility target) -Wc++11-extensions -Wcomma -Wno-exit-time-destructors - -Wrange-loop-analysis) + -Wrange-loop-analysis + + # Enable loop vectorization for performance reasons + -fvectorize + # Enable vectorization of straight-line code for performance + -fslp-vectorize) + elseif(NOA_COMPILER_GCC) + target_compile_options("${target}" ${visibility} + # Newer versions of GCC (i.e. 14) seem to print a lot of false-positives here + -Wno-dangling-reference + + # Disables runtime type information + -fno-rtti) endif() endfunction() diff --git a/vendor/jsonbinpack/vendor/noa/cmake/noa/library.cmake b/vendor/jsonbinpack/vendor/noa/cmake/noa/library.cmake index 56e152b..05d5774 100644 --- a/vendor/jsonbinpack/vendor/noa/cmake/noa/library.cmake +++ b/vendor/jsonbinpack/vendor/noa/cmake/noa/library.cmake @@ -22,13 +22,14 @@ function(noa_library) if(NOA_LIBRARY_SOURCES) set(ABSOLUTE_PRIVATE_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/${NOA_LIBRARY_NAME}_export.h") - foreach(private_header IN LISTS NOA_LIBRARY_PRIVATE_HEADERS) - list(APPEND ABSOLUTE_PRIVATE_HEADERS "${INCLUDE_PREFIX}/${NOA_LIBRARY_NAME}_${private_header}") - endforeach() else() set(ABSOLUTE_PRIVATE_HEADERS) endif() + foreach(private_header IN LISTS NOA_LIBRARY_PRIVATE_HEADERS) + list(APPEND ABSOLUTE_PRIVATE_HEADERS "${INCLUDE_PREFIX}/${NOA_LIBRARY_NAME}_${private_header}") + endforeach() + if(NOA_LIBRARY_NAMESPACE) set(TARGET_NAME "${NOA_LIBRARY_NAMESPACE}_${NOA_LIBRARY_PROJECT}_${NOA_LIBRARY_NAME}") set(ALIAS_NAME "${NOA_LIBRARY_NAMESPACE}::${NOA_LIBRARY_PROJECT}::${NOA_LIBRARY_NAME}")