Skip to content

Commit

Permalink
update clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrk24 committed Sep 26, 2024
1 parent e1f495a commit f9c5cce
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 104 deletions.
12 changes: 11 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ ForEachMacros: # It doesn't particularly matter if these are ForEachMacros or If
- testcase
- testgroup
IndentWidth: 4
InsertTrailingCommas: Wrapped
InsertBraces: true
InsertNewlineAtEOF: true
InsertTrailingCommas: Wrapped
IntegerLiteralSeparator:
Binary: 4
Decimal: 3
# So that it doesn't insert it into the wrong place in __cpp numbers in compat.hh
DecimalMinDigits: 7
Hex: 4
HexMinDigits: 6
LineEnding: LF
MaxEmptyLinesToKeep: 2
RemoveParentheses: ReturnStatement
SpaceAfterTemplateKeyword: false
WhitespaceSensitiveMacros:
- STRING_NAME
Expand Down
2 changes: 1 addition & 1 deletion src/compat.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef float small_float;
// constinit, constexpr, or just const, depending on where lambdas are allowed
#define CONSTINIT_LAMBDA constinit const
#elif defined(__cpp_constexpr)
#if __cpp_constexpr >= 201603
#if __cpp_constexpr >= 201603L
// constinit, constexpr, or just const, depending on where lambdas are allowed
#define CONSTINIT_LAMBDA constexpr
#endif
Expand Down
8 changes: 5 additions & 3 deletions src/int24.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ struct int24_t {
constexpr int24_t operator<<(int24_t rhs) const noexcept { return int24_t{ this->value << rhs.value }; }
};

constexpr int24_t INT24_MIN{ -0x800000 };
constexpr int24_t INT24_MAX{ 0x7fffff };
constexpr int24_t INT24_MIN{ -0x80'0000 };
constexpr int24_t INT24_MAX{ 0x7f'ffff };

#define INT24_C(x) \
int24_t { INT32_C(x) }
int24_t { \
INT32_C(x) \
}
2 changes: 1 addition & 1 deletion src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void print_unichar(int24_t c, std::ostream& os) {
0,
};
os << buffer;
} else if (c.value <= 0x1fffff) {
} else if (c.value <= 0x1f'ffff) {
char buffer[] = {
static_cast<char>(0xf0 | (c.value >> 18)),
static_cast<char>(0x80 | ((c.value >> 12) & 0x3f)),
Expand Down
4 changes: 1 addition & 3 deletions src/program.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public:
return m_code[idx];
}

constexpr size_t side_length() const noexcept {
return m_side_length;
}
constexpr size_t side_length() const noexcept { return m_side_length; }
private:
std::vector<int24_t> m_code;
size_t m_side_length;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/clock.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public:

static inline time_point now() noexcept {
// Unix time (ms) for 2000-03-15T01:23:45.680Z
return time_point(duration(953083425680));
return time_point(duration(953'083'425'680));
}
};

Expand All @@ -32,7 +32,7 @@ public:

static inline time_point now() noexcept {
// One time unit before midnight, rounded up
rep x = static_cast<rep>(ceil(86'400'000'000'000.0 * 0x7fffff / 0x800000));
rep x = static_cast<rep>(ceil(86'400'000'000'000.0 * 0x7f'ffff / 0x80'0000));
return time_point(duration(x));
}
};
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/ip_movement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
namespace {
using std::pair;

// Thank you clang-format very cool
#define TEST_ITEM(dir, prog) \
{ \
#dir, { direction::dir, program(prog) } \
#dir, { \
direction::dir, program(prog) \
} \
}

// Each test program consists of every digit 0-9 exactly once, in the order they are hit if the IP is traveling in the
Expand All @@ -28,7 +29,9 @@ std::initializer_list<pair<const char*, pair<direction, program>>> test_programs

#define LR_PAIR(left, left_branch, right, right_branch) \
{ #right "_left", { direction::right, right_branch, true, direction::left } }, { \
#left "_right", { direction::left, left_branch, false, direction::right } \
#left "_right", { \
direction::left, left_branch, false, direction::right \
} \
}

// Each item is a 4-tuple of starting direction, instruction, should go left, ending direction.
Expand All @@ -45,7 +48,9 @@ std::initializer_list<pair<const char*, std::tuple<direction, int24_t, bool, dir
{ "southeast_to_" #se, { direction::southeast, mirror, direction::se } }, \
{ "southwest_to_" #sw, { direction::southwest, mirror, direction::sw } }, \
{ "west_to_" #w, { direction::west, mirror, direction::w } }, { \
"northwest_to_" #nw, { direction::northwest, mirror, direction::nw } \
"northwest_to_" #nw, { \
direction::northwest, mirror, direction::nw \
} \
}

// Tuple: before, mirror, after
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/overflow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ testgroup (overflow) {
test_assert(result.first && result.second == INT24_MIN);
}
, testcase (mul_very_overflow) {
int24_t huge_enough = INT24_C(0x400000);
int24_t huge_enough = INT24_C(0x40'0000);
auto result = huge_enough.multiply_with_overflow(huge_enough);
test_assert(result.first && result.second == INT24_C(0));
}
, testcase (mul_unsigned) {
int24_t first = INT24_C(0x700000);
int24_t first = INT24_C(0x70'0000);
int24_t second = INT24_C(2);
auto result = first.multiply_with_overflow(second);
test_assert(!result.first && result.second == INT24_C(0xe00000));
test_assert(!result.first && result.second == INT24_C(0xe0'0000));
}
, testcase (add_not_overflow) {
int24_t n = INT24_C(0x700000);
int24_t n = INT24_C(0x70'0000);
auto result = n.add_with_overflow(n);
test_assert(!result.first && result.second == INT24_C(0xe00000));
test_assert(!result.first && result.second == INT24_C(0xe0'0000));
result = result.second.add_with_overflow(result.second);
test_assert(!result.first && result.second == INT24_C(-0x400000));
test_assert(!result.first && result.second == INT24_C(-0x40'0000));
}
, testcase (add_overflow) {
auto result = INT24_MIN.add_with_overflow(INT24_MIN);
Expand Down
98 changes: 16 additions & 82 deletions wasm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@eslint/js": "^8.57.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"clang-format": "^1.8.0",
"@wasm-fmt/clang-format": ">19.1.0",
"engine-check": "[email protected]:bbrk24/engine-check.git#6b7fa214f0d5c20508cdad796bd52db4fdcf182f",
"eslint": "^8.57.0",
"eslint-plugin-civet": "0.0.4",
Expand Down

0 comments on commit f9c5cce

Please sign in to comment.