From c77d0fd87bcde42d9d9d760680cb51f75b697253 Mon Sep 17 00:00:00 2001 From: heckerpowered <72550834+heckerpowered@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:53:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update LLVM * Update concat information * Remove website * Remove website * Remove website * Move all parameters to a line * Update dependencies * Add '-j$nproc' to build command * Add comments to the preprocessor * Add comments * Add comment --- CMakeLists.txt | 3 +- Mamba/src/Code Analysis/DiagnosticBag.cpp | 1 + Mamba/src/Code Analysis/DiagnosticBag.h | 83 +++++++++++++++++++++++ Mamba/src/Code Analysis/Syntax/Parser.cpp | 11 +-- Mamba/src/Mamba.h | 16 ++++- Mamba/src/main.cpp | 2 + README.md | 4 +- Website/CMakeLists.txt | 30 -------- Website/README.md | 0 Website/src/main.cpp | 31 --------- Website/xmake.lua | 7 -- fast_io | 2 +- llvm-project | 2 +- xmake.lua | 2 +- 14 files changed, 108 insertions(+), 86 deletions(-) delete mode 100644 Website/CMakeLists.txt delete mode 100644 Website/README.md delete mode 100644 Website/src/main.cpp delete mode 100644 Website/xmake.lua diff --git a/CMakeLists.txt b/CMakeLists.txt index fe9e155..9b23a1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,5 +2,4 @@ cmake_minimum_required(VERSION 3.22) project(jvav) -add_subdirectory(mamba) -add_subdirectory(website) \ No newline at end of file +add_subdirectory(mamba) \ No newline at end of file diff --git a/Mamba/src/Code Analysis/DiagnosticBag.cpp b/Mamba/src/Code Analysis/DiagnosticBag.cpp index b6176b7..94fef59 100644 --- a/Mamba/src/Code Analysis/DiagnosticBag.cpp +++ b/Mamba/src/Code Analysis/DiagnosticBag.cpp @@ -182,6 +182,7 @@ namespace Mamba ReportUnreachableCode(static_cast(Node)->Location()); return; default: + ReportUnreachableCode(static_cast(Node)->Location()); break; } } diff --git a/Mamba/src/Code Analysis/DiagnosticBag.h b/Mamba/src/Code Analysis/DiagnosticBag.h index 6b27e87..ba28bb0 100644 --- a/Mamba/src/Code Analysis/DiagnosticBag.h +++ b/Mamba/src/Code Analysis/DiagnosticBag.h @@ -36,31 +36,114 @@ namespace Mamba } public: + /** + * Report a invalid character. + * e.g. "Invalid character 'x'." + */ void ReportInvalidCharacter(TextLocation Location, Char Character) noexcept; + + /** + * Report a string literal is unterminated. + * e.g. "Unterminated string literal." + */ void ReportUnterminatedString(TextLocation Location) noexcept; + /** + * Report a invalid decimal literal. + * e.g. "Invalid decimal literal 'x'." + */ void ReportInvalidDecimal(TextLocation Location, StringView Literal) noexcept; + + /** + * Report a invalid hexadecimal literal. + * e.g. "Invalid hexadecimal literal 'x'." + */ void ReportInvalidHexadecimal(TextLocation Location, StringView Literal) noexcept; + + /** + * Report a invalid binary literal. + * e.g. "Invalid binary literal 'x'." + */ void ReportInvalidBinary(TextLocation Location, StringView Literal) noexcept; + + /** + * Report a invalid octal literal. + * e.g. "Invalid octal literal 'x'." + */ void ReportInvalidOctal(TextLocation Location, StringView Literal) noexcept; + /** + * Report a unexpected token, specialize information based on expected type. + * e.g. "Unexpected Token 'x', Expected: 'y'" + * e.g. "There should be an identifier." (When expected identifier token) + */ void ReportUnexpectedToken(TextLocation Location, SyntaxKind Kind, SyntaxKind ExpectedKind) noexcept; + /** + * Report that the value of the expression is discarded, usually found in expression statements. + * e.g. "the expression value is discarded" + */ void ReportDiscardExpressionValue(TextLocation Location) noexcept; + + /** + * Report error that a variable is already declared when declare a variable. + * e.g. "Variable 'x' is already declared at here: :" + */ void ReportVariableAlreadyDeclared(TextLocation Location, StringView Name) noexcept; + + /** + * Report the code in the specified location is unreachable. + * e.g. "Unreachable code." + */ void ReportUnreachableCode(TextLocation Location) noexcept; + + /** + * Report the code is unreachable, the location to be reported is depends on the node. + * When the node is a block statement, report the first statement, if there's no statements + * in the block statement, this function do nothing. For all other situations, report the whole + * expression or statement. + */ void ReportUnreachableCode(const SyntaxNode* Node) noexcept; + /** + * Report error for undeclared identifier is used. + * e.g. "Undeclared identifier 'x'" + */ void ReportUndeclaredIdentifier(TextLocation Location, StringView Name) noexcept; + + /** + * Report error for ambiguous identifier, cannot select the best candidate in the overload set. + */ void ReportAmbiguousIdentifier(TextLocation Location, StringView Name) noexcept; + /** + * Report error for unexpected type, expected type and actual type. + * e.g. "Expected type 'int', but got type 'float'." + */ void ReportTypeMismatch(TextLocation Location, const TypeSymbol& ExpectedType, const TypeSymbol& ActualType) noexcept; + /** + * Report error unary expression, which the operator is not defined for the given type. + * e.g. "Undefined unary operator '-' for type 'string'." + */ void ReportUndefinedUnaryOperator(TextLocation Location, const SyntaxToken* OperatorToken, const TypeSymbol& OperandType) noexcept; + + /** + * Report error binary expression, which the operator is not defined for the given types. + * e.g. "Undefined binary operator '+' for types 'int' and 'float'." + */ void ReportUndefinedBinaryOperator(TextLocation Location, const TypeSymbol& LeftType, const SyntaxToken* OperatorToken, const TypeSymbol& RightType) noexcept; + /** + * Report error for trying to assign to an immutable variable. + * e.g. "Cannot assign to variable 'x' because it is immutable." + */ void ReportVariableImmutable(TextLocation Location, StringView Name) noexcept; + /** + * Report error for function call with wrong argument count, expected count and actual count, + * e.g. "Expected 2 arguments, but got 3." + */ void ReportArgumentCountMismatch(TextLocation Location, std::size_t ExpectedCount, std::size_t ActualCount) noexcept; }; diff --git a/Mamba/src/Code Analysis/Syntax/Parser.cpp b/Mamba/src/Code Analysis/Syntax/Parser.cpp index 78c71be..63dfbb5 100644 --- a/Mamba/src/Code Analysis/Syntax/Parser.cpp +++ b/Mamba/src/Code Analysis/Syntax/Parser.cpp @@ -124,16 +124,7 @@ FunctionDeclarationSyntax* Parser::ParseFunctionDeclaration() noexcept auto Type = ParseOptionalTypeClause(); auto Body = ParseBlockStatement(); - return new FunctionDeclarationSyntax( - SyntaxTree, - FunctionKeyword, - IdentifierToken, - OpenParenthesisToken, - std::move(Parameters), - CloseParenthesisToken, - Type, - Body - ); + return new FunctionDeclarationSyntax(SyntaxTree, FunctionKeyword, IdentifierToken, OpenParenthesisToken, std::move(Parameters), CloseParenthesisToken, Type, Body); } SeperatedSyntaxList Parser::ParseParameterList() noexcept diff --git a/Mamba/src/Mamba.h b/Mamba/src/Mamba.h index a0a7808..eefc00d 100644 --- a/Mamba/src/Mamba.h +++ b/Mamba/src/Mamba.h @@ -6,10 +6,22 @@ namespace Mamba { + /** + * Initializes Mamba, the two arguments are the same as the ones passed to main() in a C++ program. + * The function initializes singal handlers, parses the command line arguments to options and + * source files, then compile files, if any. The first command line argument is skipped. + */ std::int32_t InitMamba(int ArgumentCount, [[maybe_unused]] char* Arguments[]) noexcept; - // just for fun + /** + * Just for fun, or it may do something clean when the program crashed or exited. + */ constexpr void MambaOut() noexcept {} - constexpr std::string_view MambaVersion = "Mamba 版本 1.0.0"; + /** + * The version number of Mamba in the format Major.Minor.Version. Major is increased by 1 when there's + * a major rewrite of the project, Minor is increased by 1 when there's significant updates of the project, + * and Build is only increased when there are only minor changes to the project (such as bug fixes). + */ + constexpr std::string_view MambaVersion = "1.0.0"; } // namespace Mamba \ No newline at end of file diff --git a/Mamba/src/main.cpp b/Mamba/src/main.cpp index 9fe7c2f..6a082de 100644 --- a/Mamba/src/main.cpp +++ b/Mamba/src/main.cpp @@ -2,6 +2,8 @@ using namespace Mamba; +// The unit test needs Mamba, the entry point of Mamba causes +// the multiple definition of main function. #if !defined(MAMBA_TEST) int main(int argc, char* argv[]) diff --git a/README.md b/README.md index df0c7f9..ea95c27 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,11 @@ git clone https://github.com/heckerpowered/Jvav.git #### Developing with CMake +Recommend use *ninja* + ``` cmake -B build -cmake --build build -j +cmake --build build -j$nproc ln -s build/compile_commands.json compile_commands.json ``` diff --git a/Website/CMakeLists.txt b/Website/CMakeLists.txt deleted file mode 100644 index 14537e2..0000000 --- a/Website/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -project(website) - -set(CMAKE_CXX_STANDARD 26) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -set(BOOST_INCLUDE_LIBRARIES asio) -set(BOOST_ENABLE_CMAKE ON) - -include(FetchContent) - -FetchContent_Declare( - fast_io - URL https://github.com/Adttil/fast_io/archive/refs/heads/master.zip - DOWNLOAD_EXTRACT_TIMESTAMP TRUE -) -FetchContent_Declare( - boost - GIT_REPOSITORY https://github.com/boostorg/boost.git -) - -FetchContent_MakeAvailable(FASTIO) -FetchContent_MakeAvailable(boost) - -file(GLOB_RECURSE srcs "src/**.cpp") - -add_executable(website ${srcs}) -target_link_libraries(website PRIVATE FAST_IO Boost::asio) \ No newline at end of file diff --git a/Website/README.md b/Website/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/Website/src/main.cpp b/Website/src/main.cpp deleted file mode 100644 index f325d99..0000000 --- a/Website/src/main.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -int main() -try -{ - fast_io::net_service service; - std::vector sockets; - - for (auto i : std::views::iota(0, 65535)) - { - try - { - fast_io::native_socket_file socket(fast_io::tcp_listen(i)); - } - catch (fast_io::error error) - { - fast_io::io::perrln("Failed to listen on port ", i, ", ", error); - } - } - - while (true) - { - fast_io::io::scan(""); - } -} -catch (fast_io::error error) -{ - fast_io::io::perrln(error); -} \ No newline at end of file diff --git a/Website/xmake.lua b/Website/xmake.lua deleted file mode 100644 index 9bfe66a..0000000 --- a/Website/xmake.lua +++ /dev/null @@ -1,7 +0,0 @@ -add_requires("boost", "fast_io") - -target("website") - set_kind("binary") - add_files("src/**.cpp") - add_packages("boost", "fast_io") - set_languages("c++latest") \ No newline at end of file diff --git a/fast_io b/fast_io index 788cb98..2f72d99 160000 --- a/fast_io +++ b/fast_io @@ -1 +1 @@ -Subproject commit 788cb9810f0ca881d15fe594b0dd1144901d14d8 +Subproject commit 2f72d99683203f62e2f4ef78e5dab6b83dbdaceb diff --git a/llvm-project b/llvm-project index 00ca207..34c4f6f 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 00ca2071e08f3a82171e564618981906a15e8dca +Subproject commit 34c4f6f9375ba8193327f2706d05b90e363a33d1 diff --git a/xmake.lua b/xmake.lua index ffa91f9..003f8d6 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1 +1 @@ -includes("mamba", "website") \ No newline at end of file +includes("mamba") \ No newline at end of file