diff --git a/inkcpp/array.h b/inkcpp/array.h index 8ce2e240..acd4a3f2 100644 --- a/inkcpp/array.h +++ b/inkcpp/array.h @@ -151,7 +151,7 @@ namespace ink::runtime::internal public: fixed_restorable_array(const T& initial, const T &nullValue) : basic_restorable_array(_buffer, SIZE * 2, nullValue) { - clear(initial); + basic_restorable_array::clear(initial); } private: @@ -177,4 +177,4 @@ namespace ink::runtime::internal private: T* _buffer; }; -} \ No newline at end of file +} diff --git a/inkcpp/functional.cpp b/inkcpp/functional.cpp index b16f38a3..573bfa20 100644 --- a/inkcpp/functional.cpp +++ b/inkcpp/functional.cpp @@ -11,13 +11,13 @@ namespace ink::runtime::internal { template - static T function_base::pop(basic_eval_stack* stack) + T function_base::pop(basic_eval_stack* stack) { return stack->pop().get(); } template - static void function_base::push(basic_eval_stack* stack, const T& value) + void function_base::push(basic_eval_stack* stack, const T& value) { stack->push(value); } @@ -93,4 +93,4 @@ namespace ink::runtime::internal } } #endif -} \ No newline at end of file +} diff --git a/inkcpp/include/functional.h b/inkcpp/include/functional.h index 5d9b41ab..81cdc9cb 100644 --- a/inkcpp/include/functional.h +++ b/inkcpp/include/functional.h @@ -59,7 +59,7 @@ namespace ink::runtime::internal // pops an argument from the stack using the function-type template - typename arg_type pop_arg(basic_eval_stack* stack) + arg_type pop_arg(basic_eval_stack* stack) { // todo - type assert? @@ -74,7 +74,7 @@ namespace ink::runtime::internal static_assert(sizeof...(Is) == traits::arity); // void functions - if constexpr (is_same::value) + if constexpr (is_same::value) { // Just evalulate functor(pop_arg(stack)...); @@ -83,7 +83,7 @@ namespace ink::runtime::internal // TODO -- Should be a special "void" value push(stack, 0); } - else if constexpr (is_string::value) + else if constexpr (is_string::value) { // SPECIAL: The result of the functor is a string type // in order to store it in the inkcpp interpreter we @@ -91,10 +91,10 @@ namespace ink::runtime::internal auto string_result = functor(pop_arg(stack)...); // Get string length - size_t len = string_handler::length(string_result); + size_t len = string_handler::length(string_result); // Get source and allocate buffer - const char* src = string_handler::src(string_result); + const char* src = string_handler::src(string_result); char* buffer = allocate(strings, len + 1); // Copy @@ -140,4 +140,4 @@ namespace ink::runtime::internal D invocableDelegate; }; #endif -} \ No newline at end of file +} diff --git a/inkcpp/include/globals.h b/inkcpp/include/globals.h index 10edd7b5..8262eb53 100644 --- a/inkcpp/include/globals.h +++ b/inkcpp/include/globals.h @@ -13,5 +13,6 @@ namespace ink::runtime public: // No public interface yet virtual void dummy() = 0; + virtual ~globals_interface() = default; }; -} \ No newline at end of file +} diff --git a/inkcpp/include/traits.h b/inkcpp/include/traits.h index 7657d5e8..5e3104fa 100644 --- a/inkcpp/include/traits.h +++ b/inkcpp/include/traits.h @@ -168,4 +168,4 @@ namespace ink::runtime::internal template<> struct gen_seq<0> : seq<> {}; template<> struct gen_seq<1> : seq<0> {}; -} \ No newline at end of file +} diff --git a/inkcpp/output.cpp b/inkcpp/output.cpp index f2be47cb..bdfce373 100644 --- a/inkcpp/output.cpp +++ b/inkcpp/output.cpp @@ -5,12 +5,47 @@ #include #endif +#include +#include +#include + namespace ink { namespace runtime { namespace internal { + template + int toStr(char * buffer, size_t size, T value) { + static_assert(!std::is_same::value, "Type not supported for conversion!"); + return EINVAL; + } + + // error behavior from: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/itoa-s-itow-s?view=msvc-160 + template<> + int toStr(char * buffer, size_t size, int value) { +#ifdef WIN32 + return _itoa_s(value, buffer, size, 10); +#else + if ( buffer == nullptr || size < 1 ){ return EINVAL; } + int res = snprintf(buffer, size, "%d", value); + if (res > 0 && res < size) { return 0; } + return EINVAL; +#endif + } + + // error behavior from: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/gcvt-s?view=msvc-160 + template<> + int toStr(char * buffer, size_t size, float value) { +#ifdef WIN32 + return _gcvt_s(buffer, size, value, 11); +#else + if ( buffer == nullptr || size < 1 ) { return EINVAL; } + int res = snprintf(buffer, size, "%f.10", value); + if (res > 0 && res < size) { return 0; } + return EINVAL; +#endif + } basic_stream::basic_stream(data* buffer, size_t len) : _data(buffer), _max(len), _size(0), _save(~0) { @@ -79,7 +114,7 @@ namespace ink template inline void write_char(OUT& output, char c) { - static_assert(false, "Invalid output type"); + static_assert(! std::is_same::value, "Invalid output type"); } template<> @@ -415,13 +450,13 @@ namespace ink { case data_type::int32: // Convert to string and advance - _itoa_s(_data[i].integer_value, ptr, end - ptr, 10); + toStr(ptr, end - ptr, _data[i].integer_value); while (*ptr != 0) ptr++; break; case data_type::float32: // Convert to string and advance - _gcvt_s(ptr, end - ptr, (double)_data[i].float_value, 11); + toStr(ptr, end - ptr, _data[i].float_value); while (*ptr != 0) ptr++; break; @@ -554,4 +589,4 @@ namespace ink } } -} \ No newline at end of file +} diff --git a/inkcpp/runner_impl.h b/inkcpp/runner_impl.h index e1ab909c..c56eb280 100644 --- a/inkcpp/runner_impl.h +++ b/inkcpp/runner_impl.h @@ -108,9 +108,6 @@ namespace ink::runtime::internal template inline T read(); - template<> - inline const char* read(); - choice& add_choice(); void clear_choices(); @@ -168,7 +165,10 @@ namespace ink::runtime::internal bool _saved = false; }; + template<> + inline const char* runner_impl::read(); + #ifdef INK_ENABLE_STL std::ostream& operator<<(std::ostream&, runner_impl&); #endif -} \ No newline at end of file +} diff --git a/inkcpp_cl/test.cpp b/inkcpp_cl/test.cpp index 7cea8422..4dcf8f69 100644 --- a/inkcpp_cl/test.cpp +++ b/inkcpp_cl/test.cpp @@ -173,7 +173,7 @@ bool test_directory(const std::string& directory) { if (p.path().extension() == ".ink") { - bool success = test(p.path().u8string()); + bool success = test(p.path().string()); if (!success) return false; } diff --git a/inkcpp_compiler/binary_emitter.cpp b/inkcpp_compiler/binary_emitter.cpp index d65881c1..e15c7397 100644 --- a/inkcpp_compiler/binary_emitter.cpp +++ b/inkcpp_compiler/binary_emitter.cpp @@ -4,6 +4,10 @@ #include #include +#ifndef WIN32 +#include +#endif + namespace ink::compiler::internal { using std::vector; @@ -11,6 +15,22 @@ namespace ink::compiler::internal using std::string; using std::tuple; + char* strtok_s(char * s, const char * sep, char** context) { +#ifdef WIN32 + return strtok_s(s, sep, context); +#else + if ( + context == nullptr || + sep == nullptr || + s == nullptr && *context == nullptr ) + { + errno = EINVAL; + return nullptr; + } + return strtok_r(s, sep, context); +#endif + } + // holds information about a container struct container_data { @@ -243,7 +263,8 @@ namespace ink::compiler::internal // We need to parse the path offset_t noop_offset = ~0; char* _context = nullptr; - const char* token = strtok_s(const_cast(path_cstr), ".", &_context); + const char* token = ink::compiler::internal::strtok_s( + const_cast(path_cstr), ".", &_context); while (token != nullptr) { // Number @@ -275,7 +296,7 @@ namespace ink::compiler::internal firstParent = false; // Get the next token - token = strtok_s(nullptr, ".", &_context); + token = ink::compiler::internal::strtok_s(nullptr, ".", &_context); } if (noop_offset != ~0) @@ -339,4 +360,4 @@ namespace ink::compiler::internal write_container_hash_map(out, name, child.second); } } -} \ No newline at end of file +} diff --git a/inkcpp_compiler/binary_stream.cpp b/inkcpp_compiler/binary_stream.cpp index a19e1c30..83466da6 100644 --- a/inkcpp_compiler/binary_stream.cpp +++ b/inkcpp_compiler/binary_stream.cpp @@ -1,11 +1,22 @@ #include "binary_stream.h" +#include + namespace ink { namespace compiler { namespace internal { + template<> + size_t binary_stream::write(const std::string& value) + { + constexpr byte_t ZERO = 0; + size_t len = write((const byte_t*)value.c_str(), value.length()); + len += write(&ZERO, 1); + return len; + } + binary_stream::binary_stream() : _currentSlab(nullptr) , _ptr(nullptr) @@ -124,4 +135,4 @@ namespace ink } } } -} \ No newline at end of file +} diff --git a/inkcpp_compiler/binary_stream.h b/inkcpp_compiler/binary_stream.h index 27a2ab5b..6d4efe25 100644 --- a/inkcpp_compiler/binary_stream.h +++ b/inkcpp_compiler/binary_stream.h @@ -26,14 +26,6 @@ namespace ink } // Write a string plus a null terminator - template<> - size_t write(const std::string& value) - { - const byte_t ZERO = 0; - size_t len = write((const byte_t*)value.c_str(), value.length()); - len += write(&ZERO, 1); - return len; - } // Writes data to the end of the stream size_t write(const byte_t* data, size_t len); @@ -71,6 +63,8 @@ namespace ink // Write head byte_t* _ptr = nullptr; }; + template<> + size_t binary_stream::write(const std::string& value); } } -} \ No newline at end of file +} diff --git a/inkcpp_compiler/command.cpp b/inkcpp_compiler/command.cpp index 0648276b..26406028 100644 --- a/inkcpp_compiler/command.cpp +++ b/inkcpp_compiler/command.cpp @@ -66,4 +66,4 @@ namespace ink }; static_assert(sizeof(CommandStrings) / sizeof(const char*) == (int)Command::NUM_COMMANDS, "CommandStrings list much match Command enumeration"); -} \ No newline at end of file +} diff --git a/inkcpp_compiler/include/compiler.h b/inkcpp_compiler/include/compiler.h index cf19be19..2e22410c 100644 --- a/inkcpp_compiler/include/compiler.h +++ b/inkcpp_compiler/include/compiler.h @@ -2,7 +2,7 @@ #include "config.h" #ifdef INK_EXPOSE_JSON -#include "json.hpp" +#include "../json.hpp" #endif #include "compilation_results.h" #include @@ -31,4 +31,4 @@ namespace ink // stream -> file void run(std::istream& in, const char* filenameOut, compilation_results* results = nullptr); } -} \ No newline at end of file +} diff --git a/inkcpp_compiler/reporter.cpp b/inkcpp_compiler/reporter.cpp index e4f92116..b3b7b553 100644 --- a/inkcpp_compiler/reporter.cpp +++ b/inkcpp_compiler/reporter.cpp @@ -62,7 +62,9 @@ namespace ink::compiler::internal _list = list; // Make sure our buffer is empty +#ifdef WIN32 _Tidy(); +#endif } void error_strbuf::throw_on_sync(bool t) @@ -82,7 +84,9 @@ namespace ink::compiler::internal // Clear our state _list = nullptr; +#ifdef WIN32 _Tidy(); +#endif // Should we throw? if (_throw) @@ -94,4 +98,4 @@ namespace ink::compiler::internal // Return success return 0; } -} \ No newline at end of file +} diff --git a/shared/private/command.h b/shared/private/command.h index 0c904f88..a164be23 100644 --- a/shared/private/command.h +++ b/shared/private/command.h @@ -126,6 +126,6 @@ namespace ink constexpr unsigned int CommandSize = sizeof(Command) + sizeof(CommandFlag) + sizeof(PayloadType); #ifdef INK_COMPILER - const char* CommandStrings[]; + extern const char* CommandStrings[]; #endif } diff --git a/shared/public/system.h b/shared/public/system.h index 9ef63b06..7b01dad7 100644 --- a/shared/public/system.h +++ b/shared/public/system.h @@ -10,6 +10,7 @@ #endif #ifdef INK_ENABLE_STL #include +#include #endif #undef assert @@ -103,7 +104,7 @@ namespace ink #endif #ifdef INK_ENABLE_STL - using ink_exception = std::exception; + using ink_exception = std::runtime_error; #else // Non-STL exception class class ink_exception @@ -134,4 +135,4 @@ namespace ink #define inkZeroMemory ink::zero_memory #define inkAssert ink::assert #define inkFail(text) ink::assert(text) -#endif \ No newline at end of file +#endif