Skip to content

Commit

Permalink
format with new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
JBenda committed Dec 15, 2023
1 parent 13dfe68 commit e6ba67e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 77 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions inkcpp/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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) {
Expand All @@ -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
{
Expand Down Expand Up @@ -148,20 +148,20 @@ class managed_restorable_array : public managed_array<T, dynamic, initialCapacit
{
}

void restore() { base::resize(_last_size); }
void restore() { base::resize(_last_size); }

void save() { _last_size = this->size(); }
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;
}

Expand Down Expand Up @@ -217,28 +217,28 @@ class basic_restorable_array : public snapshot_interface
}

// == Non-Copyable ==
basic_restorable_array(const basic_restorable_array<T>&) = delete;
basic_restorable_array<T>& operator=(const basic_restorable_array<T>&) = delete;
basic_restorable_array(const basic_restorable_array<T>&) = delete;
basic_restorable_array<T>& operator=(const basic_restorable_array<T>&) = 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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
72 changes: 36 additions & 36 deletions inkcpp/runner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1011,19 +1011,19 @@ 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<Scope::LOCAL>(variableName, v, is_redef);
} break;

case Command::SET_VARIABLE: {
hash_t variableName = read<hash_t>();

// 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 {
Expand All @@ -1037,12 +1037,12 @@ void runner_impl::step()
hash_t functionName = read<hash_t>();

// 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) {
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions inkcpp_cl/inkcpp_cl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] != '-') {
Expand Down Expand Up @@ -143,7 +143,7 @@ int main(int argc, const char** argv)
std::unique_ptr<story> 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);
Expand Down

0 comments on commit e6ba67e

Please sign in to comment.