Skip to content

Commit

Permalink
[swallow]: update clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
muqiuhan committed Apr 24, 2024
1 parent 6c5492f commit 0f0f910
Show file tree
Hide file tree
Showing 20 changed files with 331 additions and 335 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ ContinuationIndentWidth: 2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: true
PadOperators: true
AlignConsecutiveMacros:
Expand Down
4 changes: 2 additions & 2 deletions compiler/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ namespace swallow::compiler::type
Manager typeManager;
Environment typeEnvironment;

auto intType = Type::Ptr(new Base("Int"));
auto binopType =
auto intType = Type::Ptr(new Base("Int"));
auto binopType =
Type::Ptr(new Arrow(intType, Type::Ptr(new type::Arrow(intType, intType))));

typeEnvironment.Bind("+", binopType);
Expand Down
28 changes: 18 additions & 10 deletions compiler/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,37 @@

namespace swallow::compiler::ast
{

/** The base class of expressions */
class AST
{

public:
using Ptr = std::unique_ptr<AST>;

/** The location of the current expression in the source file.
* (generated by Bison, passed in parser.y) */
const yy::location Location;
type::Type::Ptr NodeType;

using Ptr = std::unique_ptr<AST>;
type::Type::Ptr NodeType;

explicit AST(const yy::location Location) : Location(Location) {}

virtual ~AST() = default;

/** This function calls TypeCheck,
* stores the result in NodeType and returns NodeType */
auto CommonTypeCheck(
type::Manager &typeManager, const type::Environment &typeEnvironment) noexcept
-> type::Type::Ptr;
type::Manager &typeManager,
const type::Environment &typeEnvironment) noexcept -> type::Type::Ptr;

void CommonResolve(const type::Manager &typeManager) noexcept;
void CommonResolve(const type::Manager &typeManager) noexcept;

virtual void Resolve(const type::Manager &typeManager) noexcept = 0;

virtual auto TypeCheck(
type::Manager &typeManager, const type::Environment &typeEnvironment) const noexcept
-> utils::Result<type::Type::Ptr, utils::Void> = 0;
virtual auto
TypeCheck(type::Manager &typeManager, const type::Environment &typeEnvironment)
const noexcept -> utils::Result<type::Type::Ptr, utils::Void> = 0;

virtual void Dump(uint8_t indent, std::ostream &to) const noexcept = 0;

Expand Down Expand Up @@ -322,8 +330,8 @@ namespace swallow::compiler::ast
const AST::Ptr Body;
std::vector<gmachine::instruction::Instruction::Ptr> Instructions;

std::vector<type::Type::Ptr> ParamTypes;
type::Type::Ptr ReturnType;
std::vector<type::Type::Ptr> ParamTypes;
type::Type::Ptr ReturnType;

Fn(
const yy::location Location,
Expand Down
4 changes: 2 additions & 2 deletions compiler/ast/g-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace swallow::compiler::ast
into.push_back(Instruction::Ptr(
machineEnvironment->HasVariable(ID)
? dynamic_cast<Instruction *>(
new instruction::Push(machineEnvironment->GetOffset(ID).value()))
new instruction::Push(machineEnvironment->GetOffset(ID).value()))

: dynamic_cast<Instruction *>(new instruction::PushGlobal(ID))));
}
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace swallow::compiler::ast
constructorPattern->Params.rend(),
[&](const auto &param) {
newEnvironment = Environment::Ptr(new Variable(param, newEnvironment));
});
});

branchInstructions.push_back(Instruction::Ptr(new instruction::Split()));
branch->Expr->Compile(newEnvironment, branchInstructions);
Expand Down
Loading

0 comments on commit 0f0f910

Please sign in to comment.