Skip to content
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
7 changes: 4 additions & 3 deletions .github/launch-lizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

i = lizard.analyze(files)

print(f"""Lizard report
print(f"""### Lizard report
---

Listing only functions with cyclomatic complexity >= 15 or NLOC >= 100 or parameters >= 10.
Expand All @@ -22,8 +22,9 @@

if func.cyclomatic_complexity >= 15 or func.nloc >= 100 or param_count >= 10:
data.append([
f"{filename} | {func.start_line}:{func.end_line} | `{func.name}` | {param_count} | {func.nloc}", func.cyclomatic_complexity
f"{filename} | {func.start_line}:{func.end_line} | `{func.name}` | {param_count} | {func.nloc}",
func.cyclomatic_complexity
])

for line in sorted(data, key=lambda e: e[1], reverse=True):
print(f"| {line[0]} | {line[1]} |")
print(f"| {line[0]} | {line[1]} |")
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ jobs:
artifact: "windows-msvc-22"
}
- {
os: macos-latest, name: "MacOS Clang 14",
artifact: "macos-clang-14",
compiler: clang, compiler_version: 14, sanitizers: "On"
os: macos-latest, name: "MacOS Clang 15",
artifact: "macos-clang-15",
compiler: clang, compiler_version: 15, sanitizers: "On"
}

steps:
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
- { os: ubuntu-latest, name: "Ubuntu Clang 15", artifact: "ubuntu-clang-15" }
- { os: ubuntu-latest, name: "Ubuntu GCC 13", artifact: "ubuntu-gcc-13" }
- { os: windows-latest, name: "Windows VS 2022", artifact: "windows-msvc-22", }
- { os: macos-latest, name: "MacOS Clang 14", artifact: "macos-clang-14", }
- { os: macos-latest, name: "MacOS Clang 15", artifact: "macos-clang-15", }

steps:
- uses: actions/checkout@v4
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/lizard.yml

This file was deleted.

10 changes: 8 additions & 2 deletions .github/workflows/setup-compilers/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ runs:
shell: bash
run: |
if [[ '${{ startsWith(inputs.os_name, 'macos') }}' == 'true' ]]; then
echo "cc=${{ inputs.compiler }}" >> $GITHUB_OUTPUT
echo "cxx=${{ inputs.compiler }}++" >> $GITHUB_OUTPUT
echo "cc=/usr/local/opt/llvm@${{ inputs.compiler_version }}/bin/${{ inputs.compiler }}" >> $GITHUB_OUTPUT
echo "cxx=/usr/local/opt/llvm@${{ inputs.compiler_version }}/bin/${{ inputs.compiler }}++" >> $GITHUB_OUTPUT
elif [[ '${{ inputs.compiler }}' == 'clang' ]]; then
echo "cc=clang-${{ inputs.compiler_version }}" >> $GITHUB_OUTPUT
echo "cxx=clang++-${{ inputs.compiler_version }}" >> $GITHUB_OUTPUT
Expand All @@ -51,6 +51,12 @@ runs:
libc++-${{ inputs.compiler_version }}-dev libc++abi-${{ inputs.compiler_version }}-dev \
clang-tools-${{ inputs.compiler_version }}

- name: Update LLVM compilers
if: startsWith(inputs.os_name, 'macos')
shell: bash
run: |
brew install llvm@${{ inputs.compiler_version }}

- name: Setup Windows environment
uses: ilammy/msvc-dev-cmd@v1
if: startsWith(inputs.os_name, 'windows')
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Static analysis

on:
pull_request:

jobs:
static_analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.9'

- run: |
sudo apt install -yq cppcheck
pip install lizard

- name: Create lizard report
id: lizard
shell: bash
run: |
content=$(python .github/launch-lizard.py)
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
# echo "report=$content" >> $GITHUB_OUTPUT
echo ::set-output name=report::$content

- name: Run cppcheck
id: cppcheck
shell: bash
run: |
cppcheck --platform=unix64 --template="{file}:{line}: {severity}: {message}" \
--output-file=cppcheck.txt -j $(nproc) \
-I include src
cat cppcheck.txt | sort > cppcheck_sorted.txt
echo "report=$(cat cppcheck_sorted.txt)" >> $GITHUB_OUTPUT

- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Static analysis report

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Static analysis report
${{ steps.lizard.outputs.report }}
---
### CppCheck report
```
${{ steps.cppcheck.outputs.report }}
```
edit-mode: replace
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- added the padding/instruction/argumentation values when displaying instructions in the bytecode reader
- `$repr` macro to get a string representation of a given node
- added boost-ext/ut to write unit tests in C++
- basic ArkScript code formatter, available through the CLI: `arkscript -f|--format`
- comments are now tracked in the AST and attached to the nearest node below them

### Changed
- instructions are on 4 bytes: 1 byte for the instruction, 1 byte of padding, 2 bytes for an immediate argument
Expand Down
20 changes: 8 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ target_include_directories(ArkReactor
target_link_libraries(ArkReactor PUBLIC termcolor)

if (UNIX OR LINUX)
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
target_link_libraries(ArkReactor PUBLIC stdc++fs)
endif()

find_package(Threads)
target_link_libraries(ArkReactor PRIVATE ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
Expand Down Expand Up @@ -180,10 +176,15 @@ endif()

# TODO: consider using ctest
if (ARK_TESTS)
file(GLOB_RECURSE UT_SOURCES ${ark_SOURCE_DIR}/tests/unittests/*.cpp)
file(GLOB_RECURSE UT_SOURCES
${ark_SOURCE_DIR}/tests/unittests/*.cpp
${ark_SOURCE_DIR}/lib/fmt/src/format.cc
${ark_SOURCE_DIR}/src/arkscript/Formatter.cpp
${ark_SOURCE_DIR}/src/arkscript/JsonCompiler.cpp)
add_executable(unittests ${UT_SOURCES})

add_subdirectory(${ark_SOURCE_DIR}/lib/ut)
target_include_directories(unittests PUBLIC ${ark_SOURCE_DIR}/include)
target_link_libraries(unittests PUBLIC ArkReactor termcolor ut)

add_compile_definitions(BOOST_UT_DISABLE_MODULE)
Expand All @@ -194,11 +195,8 @@ endif()
if (ARK_BUILD_EXE)
# additional files needed for the exe (repl, command line and stuff)
file(GLOB_RECURSE EXE_SOURCES
${ark_SOURCE_DIR}/src/arkscript/REPL/Utils.cpp
${ark_SOURCE_DIR}/src/arkscript/REPL/Repl.cpp
${ark_SOURCE_DIR}/lib/fmt/src/format.cc
${ark_SOURCE_DIR}/src/arkscript/main.cpp)

${ark_SOURCE_DIR}/src/arkscript/*.cpp
${ark_SOURCE_DIR}/lib/fmt/src/format.cc)
add_executable(arkscript ${EXE_SOURCES})

if (MSVC)
Expand All @@ -213,9 +211,7 @@ if (ARK_BUILD_EXE)
add_subdirectory("${ark_SOURCE_DIR}/lib/replxx" EXCLUDE_FROM_ALL)
add_subdirectory("${ark_SOURCE_DIR}/lib/clipp" EXCLUDE_FROM_ALL)

target_include_directories(arkscript PUBLIC "${ark_SOURCE_DIR}/src/arkscript/")
target_link_libraries(arkscript PUBLIC ArkReactor replxx clipp termcolor)

target_compile_features(arkscript PRIVATE cxx_std_20)

enable_lto(arkscript)
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,35 @@ SYNOPSIS
arkscript --dev-info
arkscript -e <expression>
arkscript -c <file> [-d]
arkscript <file> [-d] [-L <lib_dir>]
arkscript -f <file> [--dry-run]
arkscript --ast <file> [-d] [-L <lib_dir>]
arkscript -bcr <file> -on
arkscript -bcr <file> -a [-s <start> <end>]
arkscript -bcr <file> -st [-s <start> <end>]
arkscript -bcr <file> -vt [-s <start> <end>]
arkscript -bcr <file> [-cs] [-p <page>] [-s <start> <end>]
arkscript <file> [-d] [-L <lib_dir>]

OPTIONS
-h, --help Display this message
-v, --version Display ArkScript version and exit
--dev-info Display development information and exit
-e, --eval Evaluate ArkScript expression

-c, --compile Compile the given program to bytecode, but do not run
-d, --debug... Increase debug level (default: 0)

-L, --lib Set the location of the ArkScript standard library. Paths can be
delimited by ';'

-f, --format Format the given source file in place
--dry-run Do not modify the file, only print out the changes

--ast Compile the given program and output its AST as JSON to stdout
-d, --debug... Increase debug level (default: 0)
-L, --lib Set the location of the ArkScript standard library. Paths can be
delimited by ';'

-bcr, --bytecode-reader Launch the bytecode reader
-on, --only-names Display only the bytecode segments names and sizes
-a, --all Display all the bytecode segments (default)
Expand All @@ -208,8 +223,9 @@ OPTIONS
-cs, --code Display only the code segments
-p, --page Set the bytecode reader code segment to display
-s, --slice Select a slice of instructions in the bytecode
-L, --lib Set the location of the ArkScript standard library. Paths can be
delimited by ';'

VERSION
4.0.0-86587c14

LICENSE
Mozilla Public License 2.0
Expand Down
17 changes: 12 additions & 5 deletions include/Ark/Compiler/AST/BaseParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <exception>
#include <stdexcept>
#include <utility>
#include <vector>
#include <initializer_list>

#include <Ark/Platform.hpp>
Expand All @@ -15,8 +16,8 @@ namespace Ark::internal
{
struct FilePosition
{
std::size_t row;
std::size_t col;
std::size_t row = 0;
std::size_t col = 0;
};

class ARK_API BaseParser
Expand All @@ -25,17 +26,22 @@ namespace Ark::internal
BaseParser() = default;

private:
std::string m_filename;
std::string m_str;
std::vector<std::pair<std::string::iterator, std::size_t>> m_it_to_row;
std::string::iterator m_it, m_next_it;
utf8_char_t m_sym;
FilePosition m_filepos;

void registerNewLine(std::string::iterator it, std::size_t row);

/*
getting next character and changing the values of count/row/col/sym
*/
void next();

protected:
std::string m_filename;

void initParser(const std::string& filename, const std::string& code);

FilePosition getCursor();
Expand Down Expand Up @@ -69,8 +75,9 @@ namespace Ark::internal
bool space(std::string* s = nullptr);
bool inlineSpace(std::string* s = nullptr);
bool endOfLine(std::string* s = nullptr);
bool comment();
bool newlineOrComment();
bool comment(std::string* s = nullptr);
bool spaceComment(std::string* s = nullptr);
bool newlineOrComment(std::string* s = nullptr);
bool prefix(char c);
bool suffix(char c);
bool number(std::string* s = nullptr);
Expand Down
19 changes: 19 additions & 0 deletions include/Ark/Compiler/AST/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ namespace Ark::internal
*/
void setFilename(const std::string& filename) noexcept;

/**
* @brief Set the comment field with the nearest comment before this node
* @param comment
* @return Node& reference to this node after updating it
*/
Node& attachNearestCommentBefore(const std::string& comment);

Node& attachCommentAfter(const std::string& comment);

/**
* @brief Get the line at which this node was created
*
Expand All @@ -148,6 +157,14 @@ namespace Ark::internal
*/
[[nodiscard]] const std::string& filename() const noexcept;

/**
* @brief Return the comment attached to this node, if any
* @return const std::string&
*/
[[nodiscard]] const std::string& comment() const noexcept;

[[nodiscard]] const std::string& commentAfter() const noexcept;

/**
* @brief Compute a representation of the node without any comments or additional sugar, colors, types
* @return String representation of the node
Expand All @@ -165,6 +182,8 @@ namespace Ark::internal
// position of the node in the original code, useful when it comes to parser errors
std::size_t m_line = 0, m_col = 0;
std::string m_filename;
std::string m_comment;
std::string m_after_comment; ///< Comment after node
};

ARK_API std::ostream& operator<<(std::ostream& os, const std::vector<Node>& node) noexcept;
Expand Down
Loading