diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56de7dd2..67cb5fdd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -176,19 +176,16 @@ jobs: if: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master' }} steps: - uses: actions/checkout@v3 - - name: install clang - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 15 - name: Fetch master branch run: | git fetch origin master --depth 1 - name: Check clang-format run: | diff=$(git clang-format-15 --style file -q --diff origin/master) - echo $diff + # echo $diff if [ "$diff" != "" ]; then + echo run git clang-format --style file master + echo or upstream/master depending on your setup exit 1 fi diff --git a/inkcpp/array.h b/inkcpp/array.h index 332b8c61..a72b2a6b 100644 --- a/inkcpp/array.h +++ b/inkcpp/array.h @@ -29,7 +29,7 @@ class managed_array : public snapshot_interface const T& operator[](size_t i) const { return data()[i]; } - T& operator[](size_t i) { return data()[i]; } + T& operator[](size_t i) { return data()[i]; } const T* data() const { @@ -49,23 +49,23 @@ class managed_array : public snapshot_interface } } - const T* begin() const { return data(); } + const T* begin() const { return data(); } - T* begin() { return data(); } + T* begin() { return data(); } - const T* end() const { return data() + _size; } + const T* end() const { return data() + _size; } - T* end() { return data() + _size; } + T* end() { return data() + _size; } - const T& back() const { return end()[-1]; } + const T& back() const { return end()[-1]; } - T& back() { return end()[-1]; } + T& back() { return end()[-1]; } const size_t size() const { return _size; } const size_t capacity() const { return _capacity; } - T& push() + T& push() { if constexpr (dynamic) { if (_size == _capacity) { @@ -92,7 +92,7 @@ class managed_array : public snapshot_interface _size = size; } - void extend(size_t capacity = 0); + void extend(size_t capacity = 0); size_t snap(unsigned char* data, const snapper& snapper) const { @@ -148,20 +148,20 @@ class managed_restorable_array : public managed_arraysize(); } + void save() { _last_size = this->size(); } - void forgett() { _last_size = 0; } + void forgett() { _last_size = 0; } - bool has_changed() const { return base::size() != _last_size; } + bool has_changed() const { return base::size() != _last_size; } size_t snap(unsigned char* data, const snapshot_interface::snapper& snapper) const { - unsigned char* ptr = data; - bool should_write = data != nullptr; - ptr += base::snap(ptr, snapper); - ptr = base::snap_write(ptr, _last_size, should_write); + unsigned char* ptr = data; + bool should_write = data != nullptr; + ptr += base::snap(ptr, snapper); + ptr = base::snap_write(ptr, _last_size, should_write); return ptr - data; } @@ -217,28 +217,28 @@ class basic_restorable_array : public snapshot_interface } // == Non-Copyable == - basic_restorable_array(const basic_restorable_array&) = delete; - basic_restorable_array& operator=(const basic_restorable_array&) = delete; + basic_restorable_array(const basic_restorable_array&) = delete; + basic_restorable_array& operator=(const basic_restorable_array&) = delete; // set value by index - void set(size_t index, const T& value); + void set(size_t index, const T& value); // get value by index - const T& get(size_t index) const; + const T& get(size_t index) const; // size of the array - inline size_t capacity() const { return _capacity; } + inline size_t capacity() const { return _capacity; } // only const indexing is supported due to save/restore system - inline const T& operator[](size_t index) const { return get(index); } + inline const T& operator[](size_t index) const { return get(index); } // == Save/Restore == - void save(); - void restore(); - void forget(); + void save(); + void restore(); + void forget(); // Resets all values and clears any save points - void clear(const T& value); + void clear(const T& value); // snapshot interface virtual size_t snap(unsigned char* data, const snapper&) const; @@ -247,7 +247,7 @@ class basic_restorable_array : public snapshot_interface protected: inline T* buffer() { return _array; } - void set_new_buffer(T* buffer, size_t capacity) + void set_new_buffer(T* buffer, size_t capacity) { _array = buffer; _temp = buffer + capacity / 2; @@ -263,17 +263,17 @@ class basic_restorable_array : public snapshot_interface void clear_temp(); private: - bool _saved; + bool _saved; // real values live here - T* _array; + T* _array; // we store values here when we're in save mode // they're copied on a call to forget() - T* _temp; + T* _temp; // size of both _array and _temp - size_t _capacity; + size_t _capacity; // null const T _null; diff --git a/inkcpp/runner_impl.cpp b/inkcpp/runner_impl.cpp index ef036745..d25fe36b 100644 --- a/inkcpp/runner_impl.cpp +++ b/inkcpp/runner_impl.cpp @@ -408,7 +408,7 @@ std::string runner_impl::getline() advance_line(); // Read line into std::string result += _output.get(); - fill = _output.last_char() == ' '; + fill = _output.last_char() == ' '; } while (_ptr != nullptr && _output.last_char() != '\n'); // TODO: fallback choice = no choice @@ -531,13 +531,13 @@ void runner_impl::choose(size_t index) restore(); // restore to stack state when choice was maked _globals->turn(); // Get the choice - const auto& c = has_choices() ? _choices[index] : _fallback_choice.value(); + const auto& c = has_choices() ? _choices[index] : _fallback_choice.value(); // Get its thread - thread_t choiceThread = c._thread; + thread_t choiceThread = c._thread; // Figure out where our previous pointer was for that thread - ip_t prev = nullptr; + ip_t prev = nullptr; if (choiceThread == ~0) { prev = _done; } else { @@ -592,30 +592,30 @@ snapshot* runner_impl::create_snapshot() const size_t runner_impl::snap(unsigned char* data, snapper& snapper) const { - unsigned char* ptr = data; - bool should_write = data != nullptr; - snapper.current_runner_tags = _tags[0].ptr(); - std::uintptr_t offset = _ptr != nullptr ? _ptr - _story->instructions() : 0; - ptr = snap_write(ptr, offset, should_write); - offset = _backup - _story->instructions(); - ptr = snap_write(ptr, offset, should_write); - offset = _done - _story->instructions(); - ptr = snap_write(ptr, offset, should_write); - ptr = snap_write(ptr, _rng.get_state(), should_write); - ptr = snap_write(ptr, _evaluation_mode, should_write); - ptr = snap_write(ptr, _string_mode, should_write); - ptr = snap_write(ptr, _saved_evaluation_mode, should_write); - ptr = snap_write(ptr, _saved, should_write); - ptr = snap_write(ptr, _is_falling, should_write); - ptr += _output.snap(data ? ptr : nullptr, snapper); - ptr += _stack.snap(data ? ptr : nullptr, snapper); - ptr += _ref_stack.snap(data ? ptr : nullptr, snapper); - ptr += _eval.snap(data ? ptr : nullptr, snapper); - ptr = snap_write(ptr, _choice_tags_begin, should_write); - ptr += _tags.snap(data ? ptr : nullptr, snapper); - ptr += _container.snap(data ? ptr : nullptr, snapper); - ptr += _threads.snap(data ? ptr : nullptr, snapper); - ptr = snap_write(ptr, _fallback_choice.has_value(), should_write); + unsigned char* ptr = data; + bool should_write = data != nullptr; + snapper.current_runner_tags = _tags[0].ptr(); + std::uintptr_t offset = _ptr != nullptr ? _ptr - _story->instructions() : 0; + ptr = snap_write(ptr, offset, should_write); + offset = _backup - _story->instructions(); + ptr = snap_write(ptr, offset, should_write); + offset = _done - _story->instructions(); + ptr = snap_write(ptr, offset, should_write); + ptr = snap_write(ptr, _rng.get_state(), should_write); + ptr = snap_write(ptr, _evaluation_mode, should_write); + ptr = snap_write(ptr, _string_mode, should_write); + ptr = snap_write(ptr, _saved_evaluation_mode, should_write); + ptr = snap_write(ptr, _saved, should_write); + ptr = snap_write(ptr, _is_falling, should_write); + ptr += _output.snap(data ? ptr : nullptr, snapper); + ptr += _stack.snap(data ? ptr : nullptr, snapper); + ptr += _ref_stack.snap(data ? ptr : nullptr, snapper); + ptr += _eval.snap(data ? ptr : nullptr, snapper); + ptr = snap_write(ptr, _choice_tags_begin, should_write); + ptr += _tags.snap(data ? ptr : nullptr, snapper); + ptr += _container.snap(data ? ptr : nullptr, snapper); + ptr += _threads.snap(data ? ptr : nullptr, snapper); + ptr = snap_write(ptr, _fallback_choice.has_value(), should_write); if (_fallback_choice) { ptr += _fallback_choice.value().snap(data ? ptr : nullptr, snapper); } @@ -1011,7 +1011,7 @@ void runner_impl::step() bool is_redef = flag & CommandFlag::ASSIGNMENT_IS_REDEFINE; // Get the top value and put it into the variable - value v = _eval.pop(); + value v = _eval.pop(); set_var(variableName, v, is_redef); } break; @@ -1019,11 +1019,11 @@ void runner_impl::step() hash_t variableName = read(); // Check if it's a redefinition (not yet used, seems important for pointers later?) - bool is_redef = flag & CommandFlag::ASSIGNMENT_IS_REDEFINE; + bool is_redef = flag & CommandFlag::ASSIGNMENT_IS_REDEFINE; // If not, we're setting a global (temporary variables are explicitely defined as such, // where globals are defined using SET_VARIABLE). - value val = _eval.pop(); + value val = _eval.pop(); if (is_redef) { set_var(variableName, val, is_redef); } else { @@ -1037,12 +1037,12 @@ void runner_impl::step() hash_t functionName = read(); // Interpret flag as argument count - int numArguments = ( int ) flag; + int numArguments = ( int ) flag; // find and execute. will automatically push a valid if applicable - bool success = _functions.call( - functionName, &_eval, numArguments, _globals->strings(), _globals->lists() - ); + bool success = _functions.call( + functionName, &_eval, numArguments, _globals->strings(), _globals->lists() + ); // If we failed, notify a potential fallback function if (! success) { @@ -1388,7 +1388,7 @@ void runner_impl::restore() // Not doing this anymore. There can be lingering stack entries from function returns // inkAssert(_eval.is_empty(), "Can not save interpreter state while eval stack is not empty"); - _saved = false; + _saved = false; } void runner_impl::forget() diff --git a/inkcpp_cl/inkcpp_cl.cpp b/inkcpp_cl/inkcpp_cl.cpp index cf4164b2..3a42cb5e 100644 --- a/inkcpp_cl/inkcpp_cl.cpp +++ b/inkcpp_cl/inkcpp_cl.cpp @@ -41,8 +41,8 @@ int main(int argc, const char** argv) for (int i = 1; i < argc - 1; i++) { std::string option = argv[i]; if (option == "-o") { - outputFilename = argv[i + 1]; - i += 1; + outputFilename = argv[i + 1]; + i += 1; } else if (option == "-p") { playMode = true; if (i + 1 < argc - 1 && argv[i + 1][0] != '-') { @@ -143,7 +143,7 @@ int main(int argc, const char** argv) std::unique_ptr myInk{story::from_file(outputFilename.c_str())}; // Start runner - runner thread; + runner thread; if (snapshotFile.size()) { auto snap_ptr = snapshot::from_file(snapshotFile.c_str()); thread = myInk->new_runner_from_snapshot(*snap_ptr);