Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions inkcpp/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace ink::runtime::internal
public:
fixed_restorable_array(const T& initial, const T &nullValue) : basic_restorable_array<T>(_buffer, SIZE * 2, nullValue)
{
clear(initial);
basic_restorable_array<T>::clear(initial);
Copy link
Owner Author

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.

}

private:
Expand All @@ -177,4 +177,4 @@ namespace ink::runtime::internal
private:
T* _buffer;
};
}
}
6 changes: 3 additions & 3 deletions inkcpp/functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner Author

Choose a reason for hiding this comment

The 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);
}
Expand Down Expand Up @@ -93,4 +93,4 @@ namespace ink::runtime::internal
}
}
#endif
}
}
12 changes: 6 additions & 6 deletions inkcpp/include/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typename can only be for going into something (like foo<int>::bar), in this case it can only be a type, so it's forbidden to write it.

{
// todo - type assert?

Expand All @@ -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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler doesn't know that return_type in traits is a type, so we need the typename qualifier.

{
// Just evalulate
functor(pop_arg<Is>(stack)...);
Expand All @@ -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
Expand Down Expand Up @@ -140,4 +140,4 @@ namespace ink::runtime::internal
D invocableDelegate;
};
#endif
}
}
3 changes: 2 additions & 1 deletion inkcpp/include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ namespace ink::runtime
public:
// No public interface yet
virtual void dummy() = 0;
virtual ~globals_interface() = default;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A virtual class should have a virtual deconstruct.

};
}
}
2 changes: 1 addition & 1 deletion inkcpp/include/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ namespace ink::runtime::internal

template<> struct gen_seq<0> : seq<> {};
template<> struct gen_seq<1> : seq<0> {};
}
}
43 changes: 39 additions & 4 deletions inkcpp/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Copy link
Owner Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
{
Expand Down Expand Up @@ -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");
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler is smart and therefor a static_assert(false always fails, even when it isn't instantiated, but when you put a template inside, it's need an instantiation to fail.

}

template<>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -554,4 +589,4 @@ namespace ink

}
}
}
}
8 changes: 4 additions & 4 deletions inkcpp/runner_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't declare template specializations in a class, only outside.

2 changes: 1 addition & 1 deletion inkcpp_cl/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The declaration of test wants a std::string so we give it :)

if (!success)
return false;
}
Expand Down
27 changes: 24 additions & 3 deletions inkcpp_compiler/binary_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@
#include <map>
#include <fstream>

#ifndef WIN32
#include <cstring>
#endif

namespace ink::compiler::internal
{
using std::vector;
using std::map;
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
{
Expand Down Expand Up @@ -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<char*>(path_cstr), ".", &_context);
const char* token = ink::compiler::internal::strtok_s(
const_cast<char*>(path_cstr), ".", &_context);
while (token != nullptr)
{
// Number
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -339,4 +360,4 @@ namespace ink::compiler::internal
write_container_hash_map(out, name, child.second);
}
}
}
}
13 changes: 12 additions & 1 deletion inkcpp_compiler/binary_stream.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#include "binary_stream.h"

#include <cstring>

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)
Expand Down Expand Up @@ -124,4 +135,4 @@ namespace ink
}
}
}
}
}
12 changes: 3 additions & 9 deletions inkcpp_compiler/binary_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -71,6 +63,8 @@ namespace ink
// Write head
byte_t* _ptr = nullptr;
};
template<>
size_t binary_stream::write(const std::string& value);
}
}
}
}
2 changes: 1 addition & 1 deletion inkcpp_compiler/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ namespace ink
};

static_assert(sizeof(CommandStrings) / sizeof(const char*) == (int)Command::NUM_COMMANDS, "CommandStrings list much match Command enumeration");
}
}
4 changes: 2 additions & 2 deletions inkcpp_compiler/include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "config.h"
#ifdef INK_EXPOSE_JSON
#include "json.hpp"
#include "../json.hpp"
Copy link
Owner Author

Choose a reason for hiding this comment

The 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 #include "header", the json.hpp is one directory about compiler.h.

#endif
#include "compilation_results.h"
#include <iostream>
Expand Down Expand Up @@ -31,4 +31,4 @@ namespace ink
// stream -> file
void run(std::istream& in, const char* filenameOut, compilation_results* results = nullptr);
}
}
}
6 changes: 5 additions & 1 deletion inkcpp_compiler/reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ namespace ink::compiler::internal
_list = list;

// Make sure our buffer is empty
#ifdef WIN32
_Tidy();
#endif
Copy link
Owner Author

Choose a reason for hiding this comment

The 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)
Expand All @@ -82,7 +84,9 @@ namespace ink::compiler::internal

// Clear our state
_list = nullptr;
#ifdef WIN32
_Tidy();
#endif

// Should we throw?
if (_throw)
Expand All @@ -94,4 +98,4 @@ namespace ink::compiler::internal
// Return success
return 0;
}
}
}
2 changes: 1 addition & 1 deletion shared/private/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write external to only declare it and not define it.

#endif
}
Loading