Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/heckerpowered #7

Merged
merged 12 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: Vertex
name: Mamba
path: |
build/macosx/arm64/release/Jvav
build/windows/x64/release/Jvav.exe
4 changes: 2 additions & 2 deletions src/Mamba/Code Analysis/Diagnostic.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "Diagnostic.h"

#include "MambaCore.h"

namespace Mamba
{
Diagnostic::Diagnostic(const DiagnosticSeverity Severity,
const TextLocation Location,
Diagnostic::Diagnostic(const DiagnosticSeverity Severity, const TextLocation Location,
const std::shared_ptr<const String> Message) noexcept :
Severity(Severity), Location(Location), Message(Message)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mamba/Code Analysis/Diagnostic.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "MambaCore.h"

#include "TextLocation.h"
#include <memory>

Expand All @@ -16,8 +17,7 @@ namespace Mamba
class Diagnostic final
{
public:
[[nodiscard]] Diagnostic(const DiagnosticSeverity Severity,
const TextLocation Location,
[[nodiscard]] Diagnostic(const DiagnosticSeverity Severity, const TextLocation Location,
const std::shared_ptr<const String> Message) noexcept;

const DiagnosticSeverity Severity;
Expand Down
7 changes: 3 additions & 4 deletions src/Mamba/Code Analysis/DiagnosticBag.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once

#include "MambaCore.h"
#include "SyntaxKind.h"
#include "TextLocation.h"

#include <memory>
#include <vector>

#include "SyntaxKind.h"
#include "TextLocation.h"

namespace Mamba
{
class DiagnosticBag : public std::vector<std::shared_ptr<const class Diagnostic>>
Expand Down
2 changes: 2 additions & 0 deletions src/Mamba/Code Analysis/Syntax/ExpressionSyntax.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ExpressionSyntax.h"

#include "SyntaxTree.h"

namespace Mamba
{
ExpressionSyntax::ExpressionSyntax(const std::shared_ptr<const class SyntaxTree> SyntaxTree) noexcept :
Expand Down
7 changes: 4 additions & 3 deletions src/Mamba/Code Analysis/Syntax/Lexer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Lexer.h"

#include "DiagnosticBag.h"
#include "MambaCore.h"
#include "Literal.h"
#include "SourceText.h"
#include "SyntaxFacts.h"
#include "SyntaxKind.h"
Expand All @@ -16,11 +17,11 @@
namespace Mamba
{
Lexer::Lexer(const std::shared_ptr<const class SyntaxTree> SyntaxTree) :
SyntaxTree(SyntaxTree), Text(SyntaxTree->Text), Start(), Position(), Kind(SyntaxKind::BadToken)
SyntaxTree(SyntaxTree), Text(SyntaxTree->Text), Position(), Start(), Kind(SyntaxKind::BadToken)
{
}

std::shared_ptr<const class SyntaxToken> Lexer::Lex() noexcept
std::shared_ptr<const SyntaxToken> Lexer::Lex() noexcept
{
const auto TokenStart = Position;

Expand Down
5 changes: 2 additions & 3 deletions src/Mamba/Code Analysis/Syntax/Lexer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "DiagnosticBag.h"
#include "Literal.h"
#include "MambaCore.h"
#include "SourceText.h"
#include "SyntaxKind.h"
Expand All @@ -20,7 +19,7 @@ namespace Mamba
std::size_t Start;

SyntaxKind Kind;
NullableSharedPtr<Literal> Value;
NullableSharedPtr<struct Literal> Value;

public:
DiagnosticBag Diagnostics;
Expand Down Expand Up @@ -84,7 +83,7 @@ namespace Mamba

// Report an invalid number diagnostic with the specified base and literal
template<std::size_t Base>
void ReportInvalidNumber(const TextSpan& Span, const StringView& Literal)
void ReportInvalidNumber(const TextSpan Span, const StringView Literal)

requires(Base == 2 || Base == 8 || Base == 10 || Base == 16)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mamba/Code Analysis/Syntax/Literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Mamba
Literal::Literal() noexcept {}

Literal::Literal(const std::shared_ptr<String> String) noexcept :
StringValue(String), Value(StringView(*String)), Type(LiteralType::String)
Value(StringView(*String)), Type(LiteralType::String), StringValue(String)
{
}

Expand Down
6 changes: 4 additions & 2 deletions src/Mamba/Code Analysis/Syntax/Literal.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#include "MambaCore.h"

#include <cstdint>
#include <memory>
#include <optional>

namespace Mamba
{
Expand Down Expand Up @@ -43,7 +45,7 @@ namespace Mamba
LiteralValue(const LiteralValue&) = default;
LiteralValue(LiteralValue&&) = default;

friend class Literal;
friend struct Literal;
};

enum class LiteralType
Expand Down Expand Up @@ -74,7 +76,7 @@ namespace Mamba
LiteralValue Value;
LiteralType Type;

std::optional<std::shared_ptr<const String>> StringValue;
::std::optional<std::shared_ptr<const String>> StringValue;

[[nodiscard]] Literal() noexcept;
[[nodiscard]] Literal(const std::shared_ptr<String> String) noexcept;
Expand Down
11 changes: 6 additions & 5 deletions src/Mamba/Code Analysis/Syntax/LiteralExpressionSyntax.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "LiteralExpressionSyntax.h"

#include "Literal.h"
#include "SyntaxToken.h"
#include "SyntaxTree.h"

namespace Mamba
{
LiteralExpressionSyntax::LiteralExpressionSyntax(
const std::shared_ptr<const class SyntaxTree> SyntaxTree,
const std::shared_ptr<const class SyntaxToken> LiteralToken) noexcept :
LiteralExpressionSyntax::LiteralExpressionSyntax(const std::shared_ptr<const class SyntaxTree> SyntaxTree,
const std::shared_ptr<const SyntaxToken> LiteralToken) noexcept :
Super(SyntaxTree), LiteralToken(LiteralToken), Value(LiteralToken->Value)
{
}

LiteralExpressionSyntax::LiteralExpressionSyntax(const std::shared_ptr<const class SyntaxTree> SyntaxTree,
const std::shared_ptr<const class SyntaxToken> LiteralToken,
const std::shared_ptr<const class Literal> Value) noexcept :
const std::shared_ptr<const SyntaxToken> LiteralToken,
const std::shared_ptr<const Literal> Value) noexcept :
Super(SyntaxTree), LiteralToken(LiteralToken), Value(Value)
{
}
Expand Down
7 changes: 5 additions & 2 deletions src/Mamba/Code Analysis/Syntax/LiteralExpressionSyntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ namespace Mamba

[[nodiscard]] LiteralExpressionSyntax(const std::shared_ptr<const class SyntaxTree> SyntaxTree,
const std::shared_ptr<const class SyntaxToken> LiteralToken,
const std::shared_ptr<const class Literal> Value) noexcept;
// msvc bug, struct keyword is required here, class is not allowed
// https://eel.is/c++draft/dcl.dcl#dcl.type.elab-7
// https://zh.cppreference.com/w/cpp/language/elaborated_type_specifier
const std::shared_ptr<const struct Literal> Value) noexcept;

virtual SyntaxKind Kind() const noexcept override;
virtual std::vector<std::shared_ptr<const class SyntaxNode>> Children() const noexcept override;

const std::shared_ptr<const class SyntaxToken> LiteralToken;
const std::shared_ptr<const class Literal> Value;
const std::shared_ptr<const struct Literal> Value;
};
} // namespace Mamba
30 changes: 19 additions & 11 deletions src/Mamba/Code Analysis/Syntax/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
#include "Parser.h"

#include <memory>

#include "AssignmentExpressionSyntax.h"
#include "BinaryExpressionSyntax.h"
#include "BlockStatementSyntax.h"
#include "BreakStatementSyntax.h"
#include "CallExpressionSyntax.h"
#include "CompilationUnitSyntax.h"
#include "ContinueStatementSyntax.h"
#include "DoWhileStatementSyntax.h"
#include "ElseClauseSyntax.h"
#include "ExpressionStatementSyntax.h"
#include "ExpressionSyntax.h"
#include "ForStatementSyntax.h"
#include "FunctionDeclarationSyntax.h"
#include "GlobalStatementSyntax.h"
#include "IfStatementSyntax.h"
#include "Lexer.h"
#include "Literal.h"
#include "LiteralExpressionSyntax.h"
#include "MambaCore.h"
#include "NameExpressionSyntax.h"
#include "ParameterSyntax.h"
#include "ParenthesizedExpressionSyntax.h"
#include "ReturnStatementSyntax.h"
#include "StatementSyntax.h"
#include "SyntaxFacts.h"
#include "SyntaxKind.h"
#include "SyntaxNode.h"
#include "SyntaxToken.h"
#include "SyntaxTree.h"
#include "TypeClauseSyntax.h"
#include "UnaryExpressionSyntax.h"
#include "VariableDeclarationSyntax.h"

#include "MambaCore.h"
#include "WhileStatementSyntax.h"

#include <memory>

namespace Mamba
{
Parser::Parser(const std::shared_ptr<const class SyntaxTree> SyntaxTree) noexcept :
Expand Down Expand Up @@ -234,8 +241,8 @@ namespace Mamba
}

const auto CloseBraceToken = MatchToken(SyntaxKind::CloseBraceToken);
return std::make_shared<BlockStatementSyntax>(SyntaxTree, OpenBraceToken, std::move(Statements),
CloseBraceToken);
return std::make_shared<const BlockStatementSyntax>(SyntaxTree, OpenBraceToken, std::move(Statements),
CloseBraceToken);
}

std::shared_ptr<const StatementSyntax> Parser::ParseVariableDeclaration() noexcept
Expand Down Expand Up @@ -354,7 +361,7 @@ namespace Mamba
std::shared_ptr<const ExpressionStatementSyntax> Parser::ParseExpressionStatement() noexcept
{
const auto Expression = ParseExpression();
return std::make_shared<ExpressionStatementSyntax>(SyntaxTree, Expression);
return std::make_shared<const ExpressionStatementSyntax>(SyntaxTree, Expression);
}

std::shared_ptr<const ExpressionSyntax> Parser::ParseExpression() noexcept
Expand Down Expand Up @@ -451,26 +458,27 @@ namespace Mamba
const auto Left = MatchToken(SyntaxKind::OpenParenthesisToken);
const auto Expression = ParseExpression();
const auto Right = MatchToken(SyntaxKind::CloseParenthesisToken);
return std::make_shared<ParenthesizedExpressionSyntax>(SyntaxTree, Left, Expression, Right);
return std::make_shared<const ParenthesizedExpressionSyntax>(SyntaxTree, Left, Expression, Right);
}

std::shared_ptr<const class ExpressionSyntax> Parser::ParseBooleanLiteral() noexcept
{
const auto IsTrue = Current()->Kind() == SyntaxKind::TrueKeyword;
const auto KeywordToken = MatchToken(IsTrue ? SyntaxKind::TrueKeyword : SyntaxKind::FalseKeyword);
return std::make_shared<LiteralExpressionSyntax>(SyntaxTree, KeywordToken, std::make_shared<Literal>(IsTrue));
return std::make_shared<const LiteralExpressionSyntax>(SyntaxTree, KeywordToken,
std::make_shared<const Literal>(IsTrue));
}

std::shared_ptr<const class ExpressionSyntax> Parser::ParseNumericLiteral() noexcept
{
const auto NumberToken = MatchToken(SyntaxKind::NumberToken);
return std::make_shared<LiteralExpressionSyntax>(SyntaxTree, NumberToken);
return std::make_shared<const LiteralExpressionSyntax>(SyntaxTree, NumberToken);
}

std::shared_ptr<const class ExpressionSyntax> Parser::ParseStringLiteral() noexcept
{
const auto StringToken = MatchToken(SyntaxKind::StringToken);
return std::make_shared<LiteralExpressionSyntax>(SyntaxTree, StringToken);
return std::make_shared<const LiteralExpressionSyntax>(SyntaxTree, StringToken);
}

std::shared_ptr<const class ExpressionSyntax> Parser::ParseNameOrCallExpression() noexcept
Expand Down
17 changes: 3 additions & 14 deletions src/Mamba/Code Analysis/Syntax/Parser.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
#pragma once

#include "BlockStatementSyntax.h"
#include "CompilationUnitSyntax.h"
#include <memory>
#include <vector>

#include "DiagnosticBag.h"
#include "ElseClauseSyntax.h"
#include "ExpressionStatementSyntax.h"
#include "ExpressionSyntax.h"
#include "FunctionDeclarationSyntax.h"
#include "MambaCore.h"
#include "MemberSyntax.h"
#include "ParameterSyntax.h"
#include "SeperatedSyntaxList.h"
#include "StatementSyntax.h"
#include "SyntaxKind.h"
#include "SyntaxToken.h"
#include "TypeClauseSyntax.h"
#include <memory>

namespace Mamba
{
Expand Down
4 changes: 4 additions & 0 deletions src/Mamba/Code Analysis/Syntax/SeperatedSyntaxList.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ namespace Mamba
[[nodiscard]] constexpr Container<T> SkipSeperators(Container<T>&& NodesAndSeparators) const noexcept
{
auto Result = Container<T>(NodesAndSeparators.size() / 2);
#if __cpp_size_t_suffix == 202011L
for (auto Index = 0uz; Index < NodesAndSeparators.size() / 2; ++Index)
#else
for (auto Index = std::size_t(); Index < NodesAndSeparators.size() / 2; ++Index)
#endif
{
Result[Index] = std::move(NodesAndSeparators[Index * 2]);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Mamba/Code Analysis/Syntax/SyntaxFacts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,9 @@ namespace Mamba
return TEXT("AssignmentExpression");
case SyntaxKind::CallExpression:
return TEXT("CallExpression");
deafult:
default:
return TEXT("Unknown");
}

// GCC & MSVC reports that control reaches end of non-void function [-Wreturn-type]
std::unreachable();
}

bool SyntaxFacts::IsKeyword(const SyntaxKind Kind) noexcept
Expand Down
7 changes: 5 additions & 2 deletions src/Mamba/Code Analysis/Syntax/SyntaxNode.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SyntaxNode.h"
#include "SyntaxNode.h"

#include "Literal.h"
#include "MambaCore.h"
#include "SourceText.h"
#include "SyntaxFacts.h"
Expand All @@ -16,6 +17,8 @@ namespace Mamba
{
}

SyntaxNode::~SyntaxNode() noexcept {}

const std::shared_ptr<const class SyntaxNode> SyntaxNode::Parent() const noexcept
{
return SyntaxTree->GetParent(shared_from_this());
Expand Down Expand Up @@ -185,7 +188,7 @@ namespace Mamba

const auto LastChild = Node->Children().size() == 0 ? nullptr : Node->Children().back();

for (const auto Child : Node->Children())
for (auto&& Child : Node->Children())
{
PrettyPrint(Stream, Child, Indent, Child == LastChild);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Mamba/Code Analysis/Syntax/SyntaxNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Mamba
[[nodiscard]] SyntaxNode(const std::shared_ptr<const class SyntaxTree> SyntaxTree) noexcept;

public:
virtual ~SyntaxNode() noexcept;

const std::shared_ptr<const class SyntaxTree> SyntaxTree;

[[nodiscard]] const NullableSharedPtr<const class SyntaxNode> Parent() const noexcept;
Expand Down
8 changes: 3 additions & 5 deletions src/Mamba/Code Analysis/Syntax/SyntaxToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

namespace Mamba
{
SyntaxToken::SyntaxToken(const std::shared_ptr<const class SyntaxTree> SyntaxTree,
const SyntaxKind Kind,
const std::size_t Position,
const std::shared_ptr<const String> Text,
SyntaxToken::SyntaxToken(const std::shared_ptr<const class SyntaxTree> SyntaxTree, const SyntaxKind Kind,
const std::size_t Position, const std::shared_ptr<const String> Text,
const NullableSharedPtr<Literal> Value) noexcept :
Super(SyntaxTree), KindValue(Kind), Position(Position), Text(Text), Value(Value)
Super(SyntaxTree), Position(Position), Text(Text), Value(Value), KindValue(Kind)
{
}

Expand Down
Loading