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
450 changes: 222 additions & 228 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions inkcpp/include/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ class callback final : public callback_base
static_cast<int>(type), static_cast<int>(new_val.type)
);
if constexpr (traits::arity == 2) {
// inkAssert(!old_val.has_value() || old_val.value().type == type,
// "Missmatch type for variable observers old value: expected optional<%i> got
// optional<%i>", static_cast<int>(type), static_cast<int>(old_val.value().type));
if (old_val.has_value() && old_val.value().type != type) {
inkFail(
"Missmatch type for variable observers old value: expected optional<%i> got "
"optional<%i>",
static_cast<int>(type), static_cast<int>(old_val.value().type)
);
}
}
};
if constexpr (traits::arity > 0) {
Expand Down
4 changes: 2 additions & 2 deletions inkcpp/include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class globals_interface
* @return nullopt if variable won't exist or type won't match
*/
template<typename T>
optional<T> get(const char* name) const
optional<T> get(const char* /*name*/) const
{
static_assert(internal::always_false<T>::value, "Requested Type is not supported");
}
Expand All @@ -41,7 +41,7 @@ class globals_interface
* @retval true on success
*/
template<typename T>
bool set(const char* name, const T& val)
bool set(const char* /*name*/, const T& /*val*/)
{
static_assert(internal::always_false<T>::value, "Requested Type is not supported");
return false;
Expand Down
7 changes: 7 additions & 0 deletions inkcpp/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ struct value {

/// @}

#ifdef __GNUCC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wtautological-compare"
#endif
/** Get value to corresponding type
* @tparam Ty #Type label of type to get
* @attention behavior if undefined if Ty != value.type
Expand All @@ -138,6 +142,9 @@ struct value {
{
static_assert(Ty != Ty, "No value getter for the selected type");
}
#ifdef __GNUCC__
# pragma GCC diagnostic pop
#endif
};

/** access a @ref ink::runtime::value::Type::Bool value */
Expand Down
7 changes: 5 additions & 2 deletions inkcpp/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class operation
static constexpr bool enabled = false;

template<typename T>
operation(const T& t)
operation(const T& /*t*/)
{
}

Expand All @@ -69,7 +69,10 @@ class operation
* @param stack were the result(s) get pushed
* @param vs array of values, first one = first argument etc
*/
void operator()(basic_eval_stack& stack, value* vs) { inkFail("operation not implemented!"); }
void operator()(basic_eval_stack& /*stack*/, value* /*vs*/)
{
inkFail("operation not implemented!");
}
};
} // namespace ink::runtime::internal

Expand Down
2 changes: 1 addition & 1 deletion inkcpp/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void basic_stream::append(const value* in, unsigned int length)
}

template<typename T>
inline void write_char(T& output, char c)
inline void write_char(T& /*output*/, char /*c*/)
{
static_assert(always_false<T>::value, "Invalid output type");
}
Expand Down
8 changes: 3 additions & 5 deletions inkcpp/string_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ namespace casting
const char* get() const { return _str; }

private:
const value& _val;
const char* _str;
char _data[512]; // TODO define central
const char* _str;
char _data[512]; // TODO define central
};

// constructor for string_cast class
string_cast::string_cast(const value& val)
: _val{val}
, _str{nullptr}
: _str{nullptr}
{
if (val.type() == value_type::string) {
// reference string if value is already a string
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/string_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ink::runtime::internal
class string_table final : public snapshot_interface
{
public:
virtual ~string_table();
~string_table();

// Create a dynamic string of a particular length
char* create(size_t length);
Expand Down
41 changes: 28 additions & 13 deletions inkcpp/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,27 @@ class value : public snapshot_interface
bool set(const ink::runtime::value& val);
ink::runtime::value to_interface_value(list_table&) const;

#ifdef __GNUCC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wtautological-compare"
#endif
/// get value of the type (if possible)
template<value_type ty>
typename ret<ty>::type get() const
{
static_assert(ty != ty, "No getter for this type defined!");
}

#ifdef __GNUCC__
# pragma GCC diagnostic pop
#endif

/// check if value evaluates to true
bool truthy(const list_table& lists) const;

/// set value of type (if possible)
template<value_type ty, typename... Args>
constexpr value& set(Args... args)
constexpr value& set(Args...)
{
static_assert(sizeof...(Args) != sizeof...(Args), "No setter for this type defined!");
return *this;
Expand Down Expand Up @@ -192,30 +200,37 @@ class value : public snapshot_interface
}

/// actual storage
struct value_jump {
uint32_t jump;
uint32_t thread_id;
};

struct value_frame {
uint32_t addr;
bool eval; // was eval mode active in frame above
};

struct value_pointer {
hash_t name;
int ci;
};

union {

bool bool_value;
int32_t int32_value;
string_type string_value;
uint32_t uint32_value;
float float_value;

struct {
uint32_t jump;
uint32_t thread_id;
} jump;
value_jump jump;

list_table::list list_value;
list_flag list_flag_value;

struct {
uint32_t addr;
bool eval; // was eval mode active in frame above
} frame_value;
value_frame frame_value;

struct {
hash_t name;
int ci;
} pointer;
value_pointer pointer;
};

static constexpr size_t max_value_size = sizeof_largest_type<
Expand Down
8 changes: 3 additions & 5 deletions inkcpp_c/tests/Globals.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#include <inkcpp.h>

Expand All @@ -12,7 +10,7 @@ HInkStory* story = NULL;
HInkGlobals* store = NULL;
HInkRunner* thread = NULL;

void setup()
void setup(void)
{
if (! story) {
story = ink_story_from_file(INK_TEST_RESOURCE_DIR "GlobalStory.bin");
Expand All @@ -27,7 +25,7 @@ void setup()
thread = ink_story_new_runner(story, store);
}

int main()
int main(void)
{
//====== Just reading Globals =====
setup();
Expand Down Expand Up @@ -57,7 +55,7 @@ int main()
val.int32_v = 30;
assert(ink_globals_set(store, "age", val));

// set value of 'friendl_name_of_player'
// set value of 'friendly_name_of_player'
val.type = ValueTypeString;
val.string_v = "Freddy";
assert(ink_globals_set(store, "friendly_name_of_player", val));
Expand Down
4 changes: 1 addition & 3 deletions inkcpp_c/tests/Observer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#include <inkcpp.h>

Expand All @@ -21,7 +19,7 @@ void observer(InkValue new_value, InkValue old_value)
}
}

int main()
int main(void)
{
HInkStory* story = ink_story_from_file(INK_TEST_RESOURCE_DIR "ObserverStory.bin");
HInkGlobals* store = ink_story_new_globals(story);
Expand Down
6 changes: 2 additions & 4 deletions inkcpp_c/tests/Snapshot.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#include <inkcpp.h>

Expand All @@ -22,7 +20,7 @@ void check_end(HInkRunner* runner)
assert(strcmp(ink_choice_text(ink_runner_get_choice(RUNNER, IDX)), STR) == 0)
#define CHECK_NEXT_LINE(RUNNER, STR) assert(strcmp(ink_runner_get_line(RUNNER), STR) == 0)

int main()
int main(void)
{
{
HInkStory* story = ink_story_from_file(INK_TEST_RESOURCE_DIR "SimpleStoryFlow.bin");
Expand All @@ -41,7 +39,7 @@ int main()
++cnt;
}

// snapshot befroe choose, context (last output lines) can not bet optained at loading
// snapshot before choose, context (last output lines) can not bet obtained at loading
HInkSnapshot* snap2 = ink_runner_create_snapshot(runner);

check_end(runner);
Expand Down
3 changes: 1 addition & 2 deletions inkcpp_c/tests/Tags.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <string.h>
#include <stdio.h>
#include <stdbool.h>

#include <inkcpp.h>

#undef NDEBUG
#include <assert.h>

int main()
int main(void)
{
HInkStory* story = ink_story_from_file(INK_TEST_RESOURCE_DIR "TagsStory.bin");
HInkGlobals* store = ink_story_new_globals(story);
Expand Down
16 changes: 8 additions & 8 deletions inkcpp_test/Observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ SCENARIO("Observer", "[observer][globals][runtime]")
CHECK_FALSE(o_i.has_value());
} else {
CHECK(i == 5);
CHECK(o_i.has_value());
CHECK(o_i.value() == 1);
}
REQUIRE(o_i.has_value());
CHECK(o_i.value() == 1);
}
};
int var2_cnt = 0;
auto var2 = [&var2_cnt](value v, ink::optional<value> o_v) {
Expand All @@ -167,11 +167,11 @@ SCENARIO("Observer", "[observer][globals][runtime]")
CHECK_FALSE(o_v.has_value());
} else {
CHECK(str == "test");
CHECK(o_v.has_value());
CHECK(o_v.value().type == value::Type::String);
std::string str2(o_v.value().get<value::Type::String>());
CHECK(str2 == "hello");
}
REQUIRE(o_v.has_value());
CHECK(o_v.value().type == value::Type::String);
std::string str2(o_v.value().get<value::Type::String>());
CHECK(str2 == "hello");
}
};

globals->observe("var1", var1);
Expand Down
23 changes: 23 additions & 0 deletions proofing/diff_py-codecs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/diff.py b/diff.py
index 115bf2c..320607d 100644
--- a/diff.py
+++ b/diff.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

import sys
-import codecs
from difflib import unified_diff

if len(sys.argv) != 3:
@@ -9,8 +8,8 @@ if len(sys.argv) != 3:

_, a, b = sys.argv

-a_lines = codecs.open(a, encoding='utf-8-sig').read().splitlines()
-b_lines = codecs.open(b, encoding='utf-8-sig').read().splitlines()
+a_lines = open(a, encoding="utf-8-sig").read().splitlines()
+b_lines = open(b, encoding="utf-8-sig").read().splitlines()


out_lines = list(unified_diff(a_lines, b_lines, fromfile=a, tofile=b, lineterm=""))
Loading