From 09e164c02120f05c9364d5d9a8faad2ec0026425 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Wed, 16 Oct 2024 12:52:32 +0200 Subject: Dangling changes --- modules/core/c++/templates.hpp | 6 +++++ modules/lang/c++/c_common.hpp | 49 +++++++++++++++++++++++++++++++++++++ modules/lang/c++/c_language.hpp | 7 +++++- modules/lang/c++/c_transfer.hpp | 39 +++++++++++++++++++++++++++++ modules/lang/c++/c_types.hpp | 4 +++ modules/lang/examples/SConscript | 4 +-- modules/lang/examples/c_example.cpp | 17 +++++++++++++ 7 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 modules/lang/examples/c_example.cpp diff --git a/modules/core/c++/templates.hpp b/modules/core/c++/templates.hpp index 9f629da..fc9d368 100644 --- a/modules/core/c++/templates.hpp +++ b/modules/core/c++/templates.hpp @@ -13,6 +13,9 @@ struct tmpl_group { static constexpr string_literal name = "tmpl_group"; }; +/** + * Concats two tmpl_group into one + */ template struct tmpl_concat; @@ -21,6 +24,9 @@ struct tmpl_concat, tmpl_group> { using type = tmpl_group; }; +/** + * Returns the position of the parameter type in the parameter pack + */ template struct parameter_pack_index; template struct parameter_pack_index { diff --git a/modules/lang/c++/c_common.hpp b/modules/lang/c++/c_common.hpp index 6999126..968c4c0 100644 --- a/modules/lang/c++/c_common.hpp +++ b/modules/lang/c++/c_common.hpp @@ -4,4 +4,53 @@ namespace saw { namespace lang { struct RemoteC {}; } + +namespace lang_c { +struct config { + std::string prefix; +}; + +struct transfer_binding_state { + struct info { + std::string type; + }; + + std::map hashes; + + struct transpiled_element { + uint32_t crc32; + std::string header; + std::string source; + }; + + std::vector tp_elements; + + error_or find_id_by_crc32(uint32_t hash){ + for(uint64_t iter = 0; iter < tp_elements.size(); ++iter){ + if(tp_elements.at(iter).crc32 == hash){ + return iter; + } + } + + return make_error(); + } + + error_or add_tp_element(uint32_t hash){ + uint64_t id{}; + + try { + language_binding_state::transpiled_element ele; + + ele.crc32 = hash; + + id = tp_elements.size(); + tp_elements.emplace_back(std::move(ele)); + }catch(const std::exception&){ + return make_error(); + } + + return id; + } +}; +} } diff --git a/modules/lang/c++/c_language.hpp b/modules/lang/c++/c_language.hpp index c4b1d48..db3c97e 100644 --- a/modules/lang/c++/c_language.hpp +++ b/modules/lang/c++/c_language.hpp @@ -1,7 +1,7 @@ #pragma once -#include "c_transfer.hpp" #include "c_helper.hpp" +#include "c_transfer.hpp" #include "c_rpc.hpp" namespace saw { @@ -12,6 +12,11 @@ public: std::string prefix; }; public: + error_or generate_transfer(const config& cfg){ + + return make_error(); + } + error_or generate_rpc(const config& cfg){ return make_error(); } diff --git a/modules/lang/c++/c_transfer.hpp b/modules/lang/c++/c_transfer.hpp index 5de204c..953f732 100644 --- a/modules/lang/c++/c_transfer.hpp +++ b/modules/lang/c++/c_transfer.hpp @@ -4,4 +4,43 @@ #include "c_types.hpp" namespace saw { +namespace impl { +template +struct c_transfer_generater; + +template +struct c_transfer_generater { +public: + static error_or apply (const lang_c::config& cfg, lang_c::transfer_binding_state& state){ + + return make_error(); + } +}; + +template +struct c_transfer_generater, Enc> { +private: + // Not used currently + using ReducedTmplGroup = typename tmpl_reduce>::type; +private: + template + static error_or apply_ele(const lang_c::config& cfg, lang_c::transfer_binding_state& state){ + if constexpr ( i < sizeof...(TransTypes)){ + { + using pType = typename parameter_pack_type::type; + auto eov = c_transfer_generater::apply(cfg,state); + if(eov.is_error()){ + return eov; + } + } + return apply_ele(cfg,state); + } + return make_void(); + } +public: + static error_or apply(const lang_c::config& cfg, lang_c::transfer_binding_state& state){ + return apply_ele<0u>(cfg, state); + } +}; +} } diff --git a/modules/lang/c++/c_types.hpp b/modules/lang/c++/c_types.hpp index ff3f5a8..16829f4 100644 --- a/modules/lang/c++/c_types.hpp +++ b/modules/lang/c++/c_types.hpp @@ -18,6 +18,10 @@ struct c_is_primitive> { static constexpr bool value = true; }; +/** + * Returns the string of the name and type of the primitive in C + * The name value provides information on how that element should be named. + */ template struct c_primitive_string { static_assert(always_false, "Not supported"); diff --git a/modules/lang/examples/SConscript b/modules/lang/examples/SConscript index 99561e7..684d410 100644 --- a/modules/lang/examples/SConscript +++ b/modules/lang/examples/SConscript @@ -19,10 +19,10 @@ env.sources += examples_env.sources; env.headers += examples_env.headers; objects_static = [] -examples_env.cli_mod = examples_env.Program('#bin/cli_mod_example', ['cli_mod.cpp', env.library_static]); +examples_env.c_example = examples_env.Program('#bin/c_example', ['c_example.cpp', env.library_static]); # Set Alias -env.examples = [examples_env.cli_mod]; +env.examples = [examples_env.c_example]; env.Alias('examples', env.examples); if env["build_examples"]: diff --git a/modules/lang/examples/c_example.cpp b/modules/lang/examples/c_example.cpp new file mode 100644 index 0000000..f15db93 --- /dev/null +++ b/modules/lang/examples/c_example.cpp @@ -0,0 +1,17 @@ +#include + +saw::error_or real_main(int argc, char** argv){ + using namespace saw; + return make_void(); +} + +int main(int argc, char** argv){ + auto eov = real_main(argc, argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + std::cerr<<"Error: "<