Skip to content

Commit eadf315

Browse files
authored
Merge pull request #405 from ArkScript-lang/feat/logging-strategy
chore: updating the logging strategy (streams/printf removed, using fmt::print)
2 parents dfb2964 + 1c4c479 commit eadf315

File tree

24 files changed

+247
-364
lines changed

24 files changed

+247
-364
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
- more documentation about the compiler implementation
1111
- more documentation about the virtual machine
1212
- closures can be now be compared field per field: `(= closure1 closure2)` will work only if they have the same fields (name) and if the values match
13+
- upgraded lib fmt to 9.1.0
14+
- using fmtlib nearly everywhere possible to replace streams and printf mixed with termcolor
1315

1416
### Removed
1517
- removing the custom string, replacing it with std::string (the format engine of the custom string had a lot of memory leaks)
1618
- `Utils::digPlaces` and `Utils::decPlaces` got removed as they were no longer needed
1719
- removed unused `NodeType::Closure`
1820
- removed deprecated code (`list:removeAt`, `ark` executable now replaced by `arkscript`)
21+
- removed unused debug level attribute from the lexer, macro executor, macro processor, json compiler and compiler
1922

2023
## [3.4.0] - 2022-09-12
2124
### Added

CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2626

2727
# files needed for the library ArkReactor
2828
file(GLOB_RECURSE SOURCE_FILES
29-
${ark_SOURCE_DIR}/src/arkreactor/*.cpp
30-
${ark_SOURCE_DIR}/lib/fmt/src/*.cc)
29+
${ark_SOURCE_DIR}/src/arkreactor/*.cpp)
3130

3231
add_library(ArkReactor SHARED ${SOURCE_FILES})
3332

@@ -97,15 +96,15 @@ endif()
9796

9897
# Link libraries
9998

100-
add_subdirectory("${ark_SOURCE_DIR}/lib/termcolor" EXCLUDE_FROM_ALL)
99+
add_subdirectory(${ark_SOURCE_DIR}/lib/termcolor EXCLUDE_FROM_ALL)
100+
add_subdirectory(${ark_SOURCE_DIR}/lib/fmt EXCLUDE_FROM_ALL)
101101

102102
target_include_directories(ArkReactor
103103
PUBLIC
104-
"${ark_SOURCE_DIR}/lib/utf8_decoder/"
105-
"${ark_SOURCE_DIR}/lib/picosha2/"
106-
"${ark_SOURCE_DIR}/lib/fmt/include")
104+
${ark_SOURCE_DIR}/lib/utf8_decoder/
105+
${ark_SOURCE_DIR}/lib/picosha2/)
107106

108-
target_link_libraries(ArkReactor PUBLIC termcolor)
107+
target_link_libraries(ArkReactor PUBLIC termcolor fmt::fmt-header-only)
109108

110109
if (UNIX OR LINUX)
111110
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)

include/Ark/Compiler/AST/Lexer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ namespace Ark::internal
2929
/**
3030
* @brief Construct a new Lexer object
3131
*
32-
* @param debug the debug level
3332
*/
34-
explicit Lexer(unsigned debug) noexcept;
33+
Lexer() noexcept;
3534

3635
/**
3736
* @brief Give code to tokenize and create the list of tokens
@@ -48,7 +47,6 @@ namespace Ark::internal
4847
std::vector<Token>& tokens() noexcept;
4948

5049
private:
51-
unsigned m_debug;
5250
std::vector<Token> m_tokens;
5351

5452
inline constexpr bool isHexChar(char chr)

include/Ark/Compiler/BytecodeReader.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* @file BytecodeReader.hpp
33
* @author Alexandre Plateau (lexplt.dev@gmail.com)
44
* @brief A bytecode disassembler for ArkScript
5-
* @version 0.3
5+
* @version 0.4
66
* @date 2020-10-27
7-
*
8-
* @copyright Copyright (c) 2020-2021
9-
*
7+
*
8+
* @copyright Copyright (c) 2020-2022
9+
*
1010
*/
1111

1212
#ifndef ARK_COMPILER_BYTECODEREADER_HPP
@@ -37,35 +37,35 @@ namespace Ark
3737
* @brief This class is just a helper to
3838
* - check if a bytecode is valid
3939
* - display it in a human readable way by using the opcode names
40-
*
40+
*
4141
*/
4242
class ARK_API BytecodeReader
4343
{
4444
public:
4545
/**
4646
* @brief Construct a new Bytecode Reader object
47-
*
47+
*
4848
*/
4949
BytecodeReader() = default;
5050

5151
/**
5252
* @brief Construct needed data before displaying information about a given file
53-
*
53+
*
5454
* @param file filename of the bytecode file
5555
*/
5656
void feed(const std::string& file);
5757

5858
/**
5959
* @brief Return the bytecode object constructed
60-
*
61-
* @return const bytecode_t&
60+
*
61+
* @return const bytecode_t&
6262
*/
6363
const bytecode_t& bytecode() noexcept;
6464

6565
/**
6666
* @brief Return the read timestamp from the bytecode file
67-
*
68-
* @return unsigned long long
67+
*
68+
* @return unsigned long long
6969
*/
7070
unsigned long long timestamp();
7171

@@ -87,7 +87,7 @@ namespace Ark
8787

8888
/**
8989
* @brief Read a number from the bytecode, under the instruction pointer i
90-
*
90+
*
9191
* @param i this parameter is being modified to point to the next value
9292
* @return uint16_t the number we read (big endian)
9393
*/

include/Ark/Compiler/Compiler.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ namespace Ark
8585
std::vector<internal::ValTableElem> m_values;
8686
std::vector<std::vector<internal::Word>> m_code_pages;
8787
std::vector<std::vector<internal::Word>> m_temp_pages; ///< we need temporary code pages for some compilations passes
88-
8988
bytecode_t m_bytecode;
90-
unsigned m_debug; ///< the debug level of the compiler
9189

9290
/**
9391
* @brief Push the file headers (magic, version used, timestamp)

include/Ark/Compiler/JsonCompiler.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ namespace Ark
4242
internal::Parser m_parser;
4343
internal::Optimizer m_optimizer;
4444
uint16_t m_options;
45-
unsigned m_debug; ///< the debug level of the compiler
4645

4746
/**
4847
* @brief Compile a single node and return its representation

include/Ark/Compiler/Macros/Executor.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ namespace Ark::internal
3131
* @brief Construct a new Macro Executor object
3232
*
3333
* @param macroprocessor
34-
* @param debug
3534
*/
36-
MacroExecutor(MacroProcessor* macroprocessor, unsigned debug = 0);
35+
explicit MacroExecutor(MacroProcessor* macroprocessor);
3736

3837
/**
3938
* @brief Need a virtual destructor to correctly destory object.
@@ -59,7 +58,6 @@ namespace Ark::internal
5958
virtual bool canHandle(Node& node) = 0;
6059

6160
protected:
62-
unsigned int m_debug;
6361
MacroProcessor* m_macroprocessor; // Note: Non owned pointer.
6462

6563
/**

include/Ark/Compiler/Macros/Processor.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ namespace Ark::internal
3232
/**
3333
* @brief Construct a new Macro Processor object
3434
*
35-
* @param debug the debug level
3635
* @param options the options flags
3736
*/
38-
MacroProcessor(unsigned debug, uint16_t options) noexcept;
37+
MacroProcessor(uint16_t options) noexcept;
3938

4039
/**
4140
* @brief Send the complete AST (after the inclusions and stuff), and work on it
@@ -54,7 +53,6 @@ namespace Ark::internal
5453
friend class MacroExecutor;
5554

5655
private:
57-
unsigned m_debug; ///< The debug level
5856
uint16_t m_options;
5957
Node m_ast; ///< The modified AST
6058
std::vector<std::unordered_map<std::string, Node>> m_macros; ///< Handling macros in a scope fashion

include/Ark/REPL/Repl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ namespace Ark
4747
std::vector<std::string> m_libenv;
4848

4949
inline void print_repl_header();
50-
int count_open_parentheses(const std::string& line);
51-
int count_open_braces(const std::string& line);
50+
int count_open_group(const std::string& line, char left, char right);
5251
void trim_whitespace(std::string& line);
5352
void cui_setup();
5453
};

include/Ark/Utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifndef INCLUDE_ARK_UTILS_HPP
1313
#define INCLUDE_ARK_UTILS_HPP
1414

15-
#include <algorithm> // std::min
15+
#include <algorithm>
1616
#include <string>
1717
#include <iostream>
1818
#include <fstream>
@@ -41,7 +41,7 @@ namespace Ark::Utils
4141
if (c != sep)
4242
output.back() += c;
4343
else
44-
output.emplace_back(); // add empty string
44+
output.emplace_back();
4545
}
4646

4747
return output;

0 commit comments

Comments
 (0)