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
33 changes: 14 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR APPLE)
target_compile_options(ArkReactor
PUBLIC
-Wall -Wextra -pedantic -Wstrict-aliasing
-Wno-unknown-pragmas # We use pragmas to disable warnings we understand.
-Wshadow
-Wconversion
-Werror
# Allow deprecation warnings to not be treated as errors
-Wno-error=deprecated-declarations
# We use pragmas to disable warnings we understand.
# So we need to disable the warning about pragmas.
-Wno-unknown-warning-option # Disable warnings about disabling warnings we have
# disabled.
-Wno-unknown-pragmas
# Disable warnings about disabling warnings we have disabled.
-Wno-unknown-warning-option
)

if (CMAKE_COMPILER_IS_GNUCXX)
# The package utf8 has an issue with constant overflow.
# Once this is fixed remove this flag:
target_compile_options(ArkReactor PUBLIC -Wno-overflow)
endif ()

if (APPLE)
# The standard SSH libraries are depreciate on APPLE.
# Thus they currently generate a warning that we have to ignore for now.
Expand Down Expand Up @@ -105,7 +105,7 @@ add_subdirectory("${ark_SOURCE_DIR}/lib/termcolor" EXCLUDE_FROM_ALL)
target_link_libraries(ArkReactor PUBLIC termcolor)

target_include_directories(ArkReactor
PUBLIC
SYSTEM PUBLIC
"${ark_SOURCE_DIR}/lib/picosha2/"
"${ark_SOURCE_DIR}/lib/fmt/include")

Expand Down Expand Up @@ -161,7 +161,10 @@ if (ARK_PROFILER_MIPS)
endif ()

if (ARK_BUILD_MODULES)
get_directory_property(old_dir_compile_options COMPILE_OPTIONS)
add_compile_options(-w)
add_subdirectory(${ark_SOURCE_DIR}/lib/modules)
set_directory_properties(PROPERTIES COMPILE_OPTIONS "${old_dir_compile_options}")
endif ()

# TODO: consider using ctest
Expand Down Expand Up @@ -201,18 +204,10 @@ if (ARK_BUILD_EXE)
${ark_SOURCE_DIR}/lib/fmt/src/format.cc)
add_executable(arkscript ${EXE_SOURCES})

if (MSVC)
# Disable warnings for lib/replxx
# This is a separate module we don't control so can't fix the code without help.
# Disable warnings when compiling this package remove when resolved.
# /wd4267: conversion from 'size_t' to 'type', possible loss of data
# /wd4244: conversion from 'type1' to 'type2', possible loss of data
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4244")
endif ()

add_subdirectory("${ark_SOURCE_DIR}/lib/replxx" EXCLUDE_FROM_ALL)
add_subdirectory("${ark_SOURCE_DIR}/lib/clipp" EXCLUDE_FROM_ALL)

target_include_directories(arkscript SYSTEM PUBLIC "${ark_SOURCE_DIR}/lib/clipp/include")
target_link_libraries(arkscript PUBLIC ArkReactor replxx clipp termcolor)
target_compile_features(arkscript PRIVATE cxx_std_20)

Expand Down
13 changes: 7 additions & 6 deletions include/Ark/Compiler/AST/Optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file Optimizer.hpp
* @author Alexandre Plateau ([email protected])
* @brief Optimizes a given ArkScript AST
* @version 0.4
* @date 2020-10-27
* @version 1.0
* @date 2024-07-09
*
* @copyright Copyright (c) 2020-2021
* @copyright Copyright (c) 2020-2024
*
*/

Expand All @@ -32,8 +32,9 @@ namespace Ark::internal
/**
* @brief Construct a new Optimizer
*
* @param debug level of debug
*/
explicit Optimizer(uint16_t options) noexcept;
explicit Optimizer(unsigned debug) noexcept;

/**
* @brief Send the AST to the optimizer, then run the different optimization strategies on it
Expand All @@ -51,7 +52,7 @@ namespace Ark::internal

private:
Node m_ast;
uint16_t m_options;
unsigned m_debug;
std::unordered_map<std::string, unsigned> m_sym_appearances;

/**
Expand All @@ -74,7 +75,7 @@ namespace Ark::internal
* @param node
* @param func
*/
void runOnGlobalScopeVars(Node& node, const std::function<void(Node&, Node&, int)>& func);
void runOnGlobalScopeVars(Node& node, const std::function<void(Node&, Node&, std::size_t)>& func);

/**
* @brief Count the occurrences of each symbol in the AST, recursively
Expand Down
6 changes: 3 additions & 3 deletions include/Ark/Compiler/AST/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ namespace Ark::internal

std::optional<Node> field()
{
std::string symbol;
if (!name(&symbol))
std::string sym;
if (!name(&sym))
return std::nullopt;

std::optional<Node> leaf { Node(NodeType::Field) };
setNodePosAndFilename(leaf.value());
leaf->push_back(Node(NodeType::Symbol, symbol));
leaf->push_back(Node(NodeType::Symbol, sym));

while (true)
{
Expand Down
2 changes: 1 addition & 1 deletion include/Ark/Compiler/AST/Predicates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace Ark::internal
explicit IsChar(const char c) :
CharPred("'" + std::string(1, c) + "'"), m_k(c)
{}
explicit IsChar(const utf8_char_t c) :
explicit IsChar(const utf8_char_t& c) :
CharPred(std::string(c.c_str())), m_k(c.codepoint())
{}
bool operator()(const utf8_char_t::codepoint_t c) const override
Expand Down
12 changes: 6 additions & 6 deletions include/Ark/Compiler/AST/utf8_char.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Ark::internal
// https://github.com/sheredom/utf8.h/blob/4e4d828174c35e4564c31a9e35580c299c69a063/utf8.h#L1178
static std::pair<std::string::iterator, utf8_char_t> at(std::string::iterator it, const std::string::iterator end)
{
codepoint_t codepoint;
codepoint_t cp;
length_t length;
repr_t repr = {};

Expand All @@ -34,7 +34,7 @@ namespace Ark::internal
if (it + 3 == end || it + 2 == end || it + 1 == end)
return std::make_pair(end, utf8_char_t {});

codepoint = (static_cast<codepoint_t>(0x07 & *it) << 18) |
cp = (static_cast<codepoint_t>(0x07 & *it) << 18) |
(static_cast<codepoint_t>(0x3f & *(it + 1)) << 12) |
(static_cast<codepoint_t>(0x3f & *(it + 2)) << 6) |
static_cast<codepoint_t>(0x3f & *(it + 3));
Expand All @@ -45,7 +45,7 @@ namespace Ark::internal
if (it + 2 == end || it + 1 == end)
return std::make_pair(end, utf8_char_t {});

codepoint = (static_cast<codepoint_t>(0x0f & *it) << 12) |
cp = (static_cast<codepoint_t>(0x0f & *it) << 12) |
(static_cast<codepoint_t>(0x3f & *(it + 1)) << 6) |
static_cast<codepoint_t>(0x3f & *(it + 2));
length = 3;
Expand All @@ -55,21 +55,21 @@ namespace Ark::internal
if (it + 1 == end)
return std::make_pair(end, utf8_char_t {});

codepoint = (static_cast<codepoint_t>(0x1f & *it) << 6) |
cp = (static_cast<codepoint_t>(0x1f & *it) << 6) |
static_cast<codepoint_t>(0x3f & *(it + 1));
length = 2;
}
else // 1 byte utf8 codepoint otherwise
{
codepoint = static_cast<unsigned char>(*it);
cp = static_cast<unsigned char>(*it);
length = 1;
}

for (length_t i = 0; i < length; ++i)
repr[i] = static_cast<unsigned char>(*(it + static_cast<int>(i)));

return std::make_pair(it + static_cast<long>(length),
utf8_char_t(codepoint, length, repr));
utf8_char_t(cp, length, repr));
}

[[nodiscard]] bool isPrintable() const
Expand Down
46 changes: 26 additions & 20 deletions include/Ark/Compiler/Compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ namespace Ark
friend class Welder;

private:
struct Page
{
std::size_t index;
bool is_temp;
};

// tables: symbols, values, plugins and codes
std::vector<internal::Node> m_symbols;
std::vector<std::string> m_defined_symbols;
Expand All @@ -86,27 +92,27 @@ namespace Ark
/**
* @brief helper functions to get a temp or finalized code page
*
* @param i page index, if negative, refers to a temporary code page
* @param page page descriptor
* @return std::vector<internal::Word>&
*/
std::vector<internal::Word>& page(const int i) noexcept
std::vector<internal::Word>& page(const Page page) noexcept
{
if (i >= 0)
return m_code_pages[i];
return m_temp_pages[-i - 1];
if (!page.is_temp)
return m_code_pages[page.index];
return m_temp_pages[page.index];
}

/**
* @brief helper functions to get a temp or finalized code page
*
* @param i page index, if negative, refers to a temporary code page
* @param page page descriptor
* @return std::vector<internal::Word>*
*/
std::vector<internal::Word>* page_ptr(const int i) noexcept
std::vector<internal::Word>* page_ptr(const Page page) noexcept
{
if (i >= 0)
return &m_code_pages[i];
return &m_temp_pages[-i - 1];
if (!page.is_temp)
return &m_code_pages[page.index];
return &m_temp_pages[page.index];
}

/**
Expand Down Expand Up @@ -210,16 +216,16 @@ namespace Ark
* @param is_terminal
* @param var_name
*/
void compileExpression(const internal::Node& x, int p, bool is_result_unused, bool is_terminal, const std::string& var_name = "");

void compileSymbol(const internal::Node& x, int p, bool is_result_unused);
void compileSpecific(const internal::Node& c0, const internal::Node& x, int p, bool is_result_unused);
void compileIf(const internal::Node& x, int p, bool is_result_unused, bool is_terminal, const std::string& var_name);
void compileFunction(const internal::Node& x, int p, bool is_result_unused, const std::string& var_name);
void compileLetMutSet(internal::Keyword n, const internal::Node& x, int p);
void compileWhile(const internal::Node& x, int p);
void compilePluginImport(const internal::Node& x, int p);
void handleCalls(const internal::Node& x, int p, bool is_result_unused, bool is_terminal, const std::string& var_name);
void compileExpression(const internal::Node& x, Page p, bool is_result_unused, bool is_terminal, const std::string& var_name = "");

void compileSymbol(const internal::Node& x, Page p, bool is_result_unused);
void compileSpecific(const internal::Node& c0, const internal::Node& x, Page p, bool is_result_unused);
void compileIf(const internal::Node& x, Page p, bool is_result_unused, bool is_terminal, const std::string& var_name);
void compileFunction(const internal::Node& x, Page p, bool is_result_unused, const std::string& var_name);
void compileLetMutSet(internal::Keyword n, const internal::Node& x, Page p);
void compileWhile(const internal::Node& x, Page p);
void compilePluginImport(const internal::Node& x, Page p);
void handleCalls(const internal::Node& x, Page p, bool is_result_unused, bool is_terminal, const std::string& var_name);

/**
* @brief Register a given node in the symbol table
Expand Down
10 changes: 5 additions & 5 deletions include/Ark/Compiler/ValTableElem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ namespace Ark::internal
ValTableElemType type;

// Numbers
explicit ValTableElem(double value) noexcept;
explicit ValTableElem(long value) noexcept;
explicit ValTableElem(double num) noexcept;
explicit ValTableElem(long num) noexcept;
// Strings
explicit ValTableElem(const std::string& value) noexcept;
explicit ValTableElem(const std::string& str) noexcept;
// automatic handling (Number/String/Function)
explicit ValTableElem(const Node& v) noexcept;
explicit ValTableElem(const Node& node) noexcept;
// Functions
explicit ValTableElem(std::size_t value) noexcept;
explicit ValTableElem(std::size_t page) noexcept;

bool operator==(const ValTableElem& A) const noexcept;
};
Expand Down
6 changes: 3 additions & 3 deletions include/Ark/Exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Exceptions.hpp
* @author Alexandre Plateau ([email protected]), Max ([email protected])
* @brief ArkScript homemade exceptions
* @version 1.2
* @version 1.3
* @date 2020-10-27
*
* @copyright Copyright (c) 2020-2024
Expand Down Expand Up @@ -91,13 +91,13 @@ namespace Ark

CodeError(
const std::string& what,
std::string filename,
std::string filename_,
const std::size_t lineNum,
const std::size_t column,
std::string exp,
const std::optional<internal::utf8_char_t> opt_sym = std::nullopt) :
Error(what),
filename(std::move(filename)), line(lineNum), col(column), expr(std::move(exp)), symbol(opt_sym)
filename(std::move(filename_)), line(lineNum), col(column), expr(std::move(exp)), symbol(opt_sym)
{}
};

Expand Down
12 changes: 6 additions & 6 deletions include/Ark/Files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file Files.hpp
* @author Alexandre Plateau ([email protected])
* @brief Lots of utilities about the filesystem
* @version 0.2
* @date 2021-11-25
* @version 0.3
* @date 2024-07-09
*
* @copyright Copyright (c) 2021-2024
*
Expand Down Expand Up @@ -62,16 +62,16 @@ namespace Ark::Utils
if (!ifs.good())
return std::vector<uint8_t> {};

const std::size_t pos = ifs.tellg();
const auto pos = ifs.tellg();
// reserve appropriate number of bytes
std::vector<char> temp(pos);
std::vector<char> temp(static_cast<std::size_t>(pos));
ifs.seekg(0, std::ios::beg);
ifs.read(&temp[0], pos);
ifs.close();

auto bytecode = std::vector<uint8_t>(pos);
auto bytecode = std::vector<uint8_t>(static_cast<std::size_t>(pos));
// TODO would it be faster to memcpy?
for (std::size_t i = 0; i < pos; ++i)
for (std::size_t i = 0; i < static_cast<std::size_t>(pos); ++i)
bytecode[i] = static_cast<uint8_t>(temp[i]);
return bytecode;
}
Expand Down
12 changes: 6 additions & 6 deletions include/Ark/TypeChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file TypeChecker.hpp
* @author Alexandre Plateau ([email protected])
* @brief
* @version 0.4
* @version 1.0
* @date 2022-01-16
*
* @copyright Copyright (c) 2022-2024
Expand Down Expand Up @@ -66,12 +66,12 @@ namespace Ark::types
std::vector<ValueType> types;
bool variadic;

Typedef(const std::string_view name, const ValueType type, const bool variadic = false) :
name(name), types { type }, variadic(variadic)
Typedef(const std::string_view& type_name, const ValueType type, const bool is_variadic = false) :
name(type_name), types { type }, variadic(is_variadic)
{}

Typedef(const std::string_view name, const std::vector<ValueType>& types, const bool variadic = false) :
name(name), types(types), variadic(variadic)
Typedef(const std::string_view& type_name, const std::vector<ValueType>& type_list, const bool is_variadic = false) :
name(type_name), types(type_list), variadic(is_variadic)
{}
};

Expand All @@ -91,7 +91,7 @@ namespace Ark::types
* @param contracts types contracts the function can follow
* @param args provided argument list
*/
ARK_API void generateError [[noreturn]] (std::string_view funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args);
ARK_API void generateError [[noreturn]] (const std::string_view& funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args);
}

#endif
Loading
Loading