Skip to content

Commit 7352c44

Browse files
committed
precommit hook
1 parent 76a6663 commit 7352c44

File tree

78 files changed

+363
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+363
-361
lines changed

.clang-format-ignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/runtime/frozen/importlib.h
2+
src/runtime/frozen/importlib_external.h

.github/workflows/premerge.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616

17+
- uses: actions/setup-python@v3
18+
19+
- uses: pre-commit/action@v3.0.1
20+
1721
- name: Install LLVM
1822
run: |
1923
wget https://apt.llvm.org/llvm.sh

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: 'v20.1.8'
4+
hooks:
5+
- id: clang-format

src/ast/AST.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ namespace ast {
1414
AST_NODE_TYPES
1515
#undef __AST_NODE_TYPE
1616

17-
#define __AST_NODE_TYPE(NodeType) \
18-
Value *NodeType::codegen(CodeGenerator *generator) const \
19-
{ \
20-
return generator->visit(this); \
21-
}
17+
#define __AST_NODE_TYPE(NodeType) \
18+
Value *NodeType::codegen(CodeGenerator *generator) const { return generator->visit(this); }
2219
AST_NODE_TYPES
2320
#undef __AST_NODE_TYPE
2421

@@ -34,11 +31,8 @@ void NodeVisitor::dispatch(ASTNode *node)
3431
#undef __AST_NODE_TYPE
3532
}
3633

37-
#define __AST_NODE_TYPE(NodeType) \
38-
void NodeVisitor::dispatch(NodeType *node) \
39-
{ \
40-
visit(node); \
41-
}
34+
#define __AST_NODE_TYPE(NodeType) \
35+
void NodeVisitor::dispatch(NodeType *node) { visit(node); }
4236
AST_NODE_TYPES
4337
#undef __AST_NODE_TYPE
4438

src/ast/optimizers/Optimizers_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "ConstantFolding.hpp"
22
#include "ast/AST.hpp"
3+
#include "executable/Program.hpp"
34
#include "parser/Parser.hpp"
45
#include "runtime/Value.hpp"
56
#include "utilities.hpp"
6-
#include "executable/Program.hpp"
77

88
#include "gtest/gtest.h"
99

@@ -502,7 +502,7 @@ TEST(Optimizer, ConstantFoldIntegerAddition)
502502
expected_ast->emplace(
503503
std::make_shared<Assign>(std::vector<std::shared_ptr<ASTNode>>{ std::make_shared<Name>(
504504
"a", ContextType::STORE, SourceLocation{}) },
505-
std::make_shared<Constant>(BigIntType{2}, SourceLocation{}),
505+
std::make_shared<Constant>(BigIntType{ 2 }, SourceLocation{}),
506506
"",
507507
SourceLocation{}));
508508

src/executable/Program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include "executable/bytecode/codegen/BytecodeGenerator.hpp"
33
#include "executable/llvm/LLVMGenerator.hpp"
44
#include "executable/mlir/Dialect/Python/MLIRGenerator.hpp"
5-
#include "utilities.hpp"
65
#include "mlir/compile.hpp"
6+
#include "utilities.hpp"
77

88

99
Program::Program(std::string &&filename, std::vector<std::string> &&argv)
@@ -34,4 +34,4 @@ std::shared_ptr<Program> compile(std::shared_ptr<ast::Module> node,
3434
}
3535
ASSERT_NOT_REACHED();
3636
}
37-
}
37+
}// namespace compiler

src/executable/bytecode/Bytecode.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Bytecode::Bytecode(size_t register_count,
1717
InstructionVector instructions,
1818
std::shared_ptr<Program> program)
1919
: Function(register_count,
20-
locals_count,
21-
stack_size,
22-
function_name,
23-
FunctionExecutionBackend::BYTECODE,
24-
std::move(program)),
20+
locals_count,
21+
stack_size,
22+
function_name,
23+
FunctionExecutionBackend::BYTECODE,
24+
std::move(program)),
2525
m_instructions(std::move(instructions))
2626
{}
2727

@@ -78,8 +78,12 @@ std::unique_ptr<Bytecode> Bytecode::deserialize(std::span<const uint8_t> &buffer
7878
instructions.push_back(std::move(instruction));
7979
}
8080

81-
return std::make_unique<Bytecode>(
82-
register_count, locals_count, stack_size, function_name, std::move(instructions), std::move(program));
81+
return std::make_unique<Bytecode>(register_count,
82+
locals_count,
83+
stack_size,
84+
function_name,
85+
std::move(instructions),
86+
std::move(program));
8387
}
8488

8589
PyResult<Value> Bytecode::call(VirtualMachine &vm, Interpreter &interpreter) const
@@ -124,7 +128,7 @@ py::PyResult<py::Value> Bytecode::eval_loop(VirtualMachine &vm, Interpreter &int
124128

125129
const auto end_instruction_it = end();
126130
for (; vm.instruction_pointer() != end_instruction_it;
127-
vm.set_instruction_pointer(std::next(vm.instruction_pointer()))) {
131+
vm.set_instruction_pointer(std::next(vm.instruction_pointer()))) {
128132
ASSERT((*vm.instruction_pointer()).get());
129133
const auto &current_ip = vm.instruction_pointer();
130134
const auto &instruction = *current_ip;

src/executable/bytecode/Bytecode.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class Bytecode : public Function
3131

3232
std::vector<uint8_t> serialize() const override;
3333

34-
static std::unique_ptr<Bytecode> deserialize(std::span<const uint8_t> &buffer, std::shared_ptr<Program> program);
34+
static std::unique_ptr<Bytecode> deserialize(std::span<const uint8_t> &buffer,
35+
std::shared_ptr<Program> program);
3536

3637
py::PyResult<py::Value> call(VirtualMachine &, Interpreter &) const override;
3738
py::PyResult<py::Value> call_without_setup(VirtualMachine &, Interpreter &) const override;

src/executable/bytecode/codegen/BytecodeGenerator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#include "executable/bytecode/instructions/Instructions.hpp"
3535
#include "executable/bytecode/instructions/Jump.hpp"
3636
#include "executable/bytecode/instructions/JumpForward.hpp"
37+
#include "executable/bytecode/instructions/JumpIfExceptionMatch.hpp"
3738
#include "executable/bytecode/instructions/JumpIfFalse.hpp"
3839
#include "executable/bytecode/instructions/JumpIfFalseOrPop.hpp"
39-
#include "executable/bytecode/instructions/JumpIfExceptionMatch.hpp"
4040
#include "executable/bytecode/instructions/JumpIfNotExceptionMatch.hpp"
4141
#include "executable/bytecode/instructions/JumpIfTrue.hpp"
4242
#include "executable/bytecode/instructions/JumpIfTrueOrPop.hpp"
@@ -277,7 +277,7 @@ void BytecodeGenerator::store_name(const std::string &name, BytecodeValue *src)
277277
ASSERT(visibility->second->type == VariablesResolver::Scope::Type::CLASS);
278278
return *it;
279279
} else if (auto it = visibility->second->symbol_map.get_visible_symbol(name);
280-
it.has_value()) {
280+
it.has_value()) {
281281
return *it;
282282
} else {
283283
TODO();
@@ -396,7 +396,7 @@ void BytecodeGenerator::delete_var(const std::string &name)
396396
ASSERT(visibility->second->type == VariablesResolver::Scope::Type::CLASS);
397397
return *it;
398398
} else if (auto it = visibility->second->symbol_map.get_visible_symbol(name);
399-
it.has_value()) {
399+
it.has_value()) {
400400
return *it;
401401
} else {
402402
TODO();
@@ -699,7 +699,7 @@ Value *BytecodeGenerator::generate_function(const FunctionType *node)
699699
idx++;
700700
}
701701
for (size_t idx = node->args()->argument_names().size();
702-
const auto &arg_name : node->args()->kw_only_argument_names()) {
702+
const auto &arg_name : node->args()->kw_only_argument_names()) {
703703
varnames.push_back(arg_name);
704704
ASSERT(symbol_map.get_visible_symbol(arg_name).has_value());
705705
if (std::find(cellvars.begin(), cellvars.end(), arg_name) != cellvars.end()) {
@@ -950,7 +950,7 @@ Value *BytecodeGenerator::visit(const Lambda *node)
950950
idx++;
951951
}
952952
for (size_t idx = node->args()->argument_names().size();
953-
const auto &arg_name : node->args()->kw_only_argument_names()) {
953+
const auto &arg_name : node->args()->kw_only_argument_names()) {
954954
varnames.push_back(arg_name);
955955
ASSERT(symbol_map.get_visible_symbol(arg_name).has_value());
956956
if (std::find(cellvars.begin(), cellvars.end(), arg_name) != cellvars.end()) {

src/executable/bytecode/codegen/VariablesResolver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ using namespace ast;
99

1010
namespace {
1111
bool captured_by_closure(VariablesResolver::Visibility v)
12-
{ return v == VariablesResolver::Visibility::CELL || v == VariablesResolver::Visibility::FREE; }
12+
{
13+
return v == VariablesResolver::Visibility::CELL || v == VariablesResolver::Visibility::FREE;
14+
}
1315
}// namespace
1416

1517

0 commit comments

Comments
 (0)