-
-
Notifications
You must be signed in to change notification settings - Fork 21
Platform #6
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
Platform #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,13 +11,13 @@ | |
| namespace ink::runtime::internal | ||
| { | ||
| template<typename T> | ||
| static T function_base::pop(basic_eval_stack* stack) | ||
| T function_base::pop(basic_eval_stack* stack) | ||
| { | ||
| return stack->pop().get<T>(); | ||
| } | ||
|
|
||
| template<typename T> | ||
| static void function_base::push(basic_eval_stack* stack, const T& value) | ||
| void function_base::push(basic_eval_stack* stack, const T& value) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static qualifier for function definition outside of class is forbidden (also is not part of the signature so ...). |
||
| { | ||
| stack->push(value); | ||
| } | ||
|
|
@@ -93,4 +93,4 @@ namespace ink::runtime::internal | |
| } | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,7 @@ namespace ink::runtime::internal | |
|
|
||
| // pops an argument from the stack using the function-type | ||
| template<int index> | ||
| typename arg_type<index> pop_arg(basic_eval_stack* stack) | ||
| arg_type<index> pop_arg(basic_eval_stack* stack) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| // todo - type assert? | ||
|
|
||
|
|
@@ -74,7 +74,7 @@ namespace ink::runtime::internal | |
| static_assert(sizeof...(Is) == traits::arity); | ||
|
|
||
| // void functions | ||
| if constexpr (is_same<void, traits::return_type>::value) | ||
| if constexpr (is_same<void, typename traits::return_type>::value) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler doesn't know that |
||
| { | ||
| // Just evalulate | ||
| functor(pop_arg<Is>(stack)...); | ||
|
|
@@ -83,18 +83,18 @@ namespace ink::runtime::internal | |
| // TODO -- Should be a special "void" value | ||
| push(stack, 0); | ||
| } | ||
| else if constexpr (is_string<traits::return_type>::value) | ||
| else if constexpr (is_string<typename traits::return_type>::value) | ||
| { | ||
| // SPECIAL: The result of the functor is a string type | ||
| // in order to store it in the inkcpp interpreter we | ||
| // need to store it in our allocated string table | ||
| auto string_result = functor(pop_arg<Is>(stack)...); | ||
|
|
||
| // Get string length | ||
| size_t len = string_handler<traits::return_type>::length(string_result); | ||
| size_t len = string_handler<typename traits::return_type>::length(string_result); | ||
|
|
||
| // Get source and allocate buffer | ||
| const char* src = string_handler<traits::return_type>::src(string_result); | ||
| const char* src = string_handler<typename traits::return_type>::src(string_result); | ||
| char* buffer = allocate(strings, len + 1); | ||
|
|
||
| // Copy | ||
|
|
@@ -140,4 +140,4 @@ namespace ink::runtime::internal | |
| D invocableDelegate; | ||
| }; | ||
| #endif | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,5 +13,6 @@ namespace ink::runtime | |
| public: | ||
| // No public interface yet | ||
| virtual void dummy() = 0; | ||
| virtual ~globals_interface() = default; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A virtual class should have a virtual deconstruct. |
||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,47 @@ | |
| #include <iomanip> | ||
| #endif | ||
|
|
||
| #include <cstdio> | ||
| #include <errno.h> | ||
| #include <type_traits> | ||
|
|
||
| namespace ink | ||
| { | ||
| namespace runtime | ||
| { | ||
| namespace internal | ||
| { | ||
| template<typename T> | ||
| int toStr(char * buffer, size_t size, T value) { | ||
| static_assert(!std::is_same<T,T>::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 | ||
| } | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be written with other platform dependencies in a separate file.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually have a task to get rid of as many dependencies as I can so I'll decide where all these should go later :) |
||
| basic_stream::basic_stream(data* buffer, size_t len) | ||
| : _data(buffer), _max(len), _size(0), _save(~0) | ||
| { | ||
|
|
@@ -79,7 +114,7 @@ namespace ink | |
| template<typename OUT> | ||
| inline void write_char(OUT& output, char c) | ||
| { | ||
| static_assert(false, "Invalid output type"); | ||
| static_assert(! std::is_same<OUT,OUT>::value, "Invalid output type"); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler is smart and therefor a |
||
| } | ||
|
|
||
| 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 | |
|
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,9 +108,6 @@ namespace ink::runtime::internal | |
| template<typename T> | ||
| 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 | ||
| } | ||
| } | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't declare template specializations in a class, only outside. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The declaration of |
||
| if (!success) | ||
| return false; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
|
|
||
| #include "config.h" | ||
| #ifdef INK_EXPOSE_JSON | ||
| #include "json.hpp" | ||
| #include "../json.hpp" | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Linux the compiler is quite precise when you use a relative path |
||
| #endif | ||
| #include "compilation_results.h" | ||
| #include <iostream> | ||
|
|
@@ -31,4 +31,4 @@ namespace ink | |
| // stream -> file | ||
| void run(std::istream& in, const char* filenameOut, compilation_results* results = nullptr); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,9 @@ namespace ink::compiler::internal | |
| _list = list; | ||
|
|
||
| // Make sure our buffer is empty | ||
| #ifdef WIN32 | ||
| _Tidy(); | ||
| #endif | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tidy is a MS VCS thing, so no support for Linux. |
||
| } | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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[]; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Write external to only declare it and not define it. |
||
| #endif | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call function from base explicit to avoid compiler misunderstandings.