Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.

Commit 4894cae

Browse files
committed
Refactor project.
1 parent 42c692d commit 4894cae

117 files changed

Lines changed: 3836 additions & 3788 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ cmake-build-debug/
33
venv/
44
**__pycache__/
55
dump/
6+
.pytest_cache/
67
.lbd_history
78
.direnv.ps1

‎CMakeLists.txt‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,25 @@ FetchContent_MakeAvailable(fmt)
3030
FetchContent_MakeAvailable(replxx)
3131
FetchContent_MakeAvailable(CLI11)
3232

33-
###### WARNINGS ######
34-
35-
add_library(lbdWarnings INTERFACE)
36-
37-
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
38-
target_compile_options(lbdWarnings INTERFACE
39-
-Wall
40-
-Wextra
41-
# -Wpedantic
42-
# -Wconversion
43-
# -Wshadow
44-
)
45-
endif ()
33+
function(enable_warnings target)
34+
if (MSVC)
35+
target_compile_options(${target} PRIVATE
36+
/W4
37+
/permissive-
38+
)
39+
else ()
40+
target_compile_options(${target} PRIVATE
41+
-Wall
42+
-Wextra
43+
# -Wpedantic
44+
# -Wconversion
45+
# -Wshadow
46+
# -Wnon-virtual-dtor
47+
# -Wold-style-cast
48+
# -Woverloaded-virtual
49+
)
50+
endif ()
51+
endfunction()
4652

4753
###### SOURCE ######
4854

@@ -58,10 +64,6 @@ target_include_directories(lbdSource PUBLIC
5864
${PROJECT_SOURCE_DIR}/include
5965
)
6066

61-
target_link_libraries(lbdSource PUBLIC
62-
lbdWarnings
63-
)
64-
6567
###### DIAGNOSTICS ######
6668

6769
file(GLOB_RECURSE DIAGNOSTICS_SOURCE_FILES CONFIGURE_DEPENDS
@@ -78,7 +80,6 @@ target_include_directories(lbdDiagnostics PUBLIC
7880

7981
target_link_libraries(lbdDiagnostics PUBLIC
8082
lbdSource
81-
lbdWarnings
8283
fmt::fmt
8384
)
8485

@@ -88,6 +89,10 @@ file(GLOB_RECURSE FRONTEND_SOURCE_FILES CONFIGURE_DEPENDS
8889
${PROJECT_SOURCE_DIR}/src/frontend/*.cpp
8990
)
9091

92+
list(FILTER FRONTEND_SOURCE_FILES EXCLUDE REGEX
93+
".*/src/frontend/ast/.*\\.cpp$"
94+
)
95+
9196
add_library(lbdFrontend STATIC
9297
${FRONTEND_SOURCE_FILES}
9398
)
@@ -98,7 +103,6 @@ target_include_directories(lbdFrontend PUBLIC
98103

99104
target_link_libraries(lbdFrontend PUBLIC
100105
lbdDiagnostics
101-
lbdWarnings
102106
)
103107

104108
###### RUNTIME ######
@@ -117,7 +121,6 @@ target_include_directories(lbdRuntime PUBLIC
117121

118122
target_link_libraries(lbdRuntime PUBLIC
119123
lbdDiagnostics
120-
lbdWarnings
121124
)
122125

123126
###### MAIN EXECUTABLE ######
@@ -138,15 +141,27 @@ target_include_directories(lbd PRIVATE
138141
)
139142

140143
target_link_libraries(lbd PRIVATE
141-
lbdWarnings
142144
lbdDiagnostics
143145
lbdFrontend
144146
lbdRuntime
145147
replxx
146148
CLI11::CLI11
147149
)
148150

149-
target_link_options(lbd PRIVATE -static-libstdc++)
151+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
152+
target_link_options(lbd PRIVATE
153+
-static-libstdc++
154+
-static-libgcc
155+
)
156+
endif ()
157+
158+
###### WARNINGS ######
159+
160+
enable_warnings(lbdSource)
161+
enable_warnings(lbdDiagnostics)
162+
enable_warnings(lbdFrontend)
163+
enable_warnings(lbdRuntime)
164+
enable_warnings(lbd)
150165

151166
###### TESTS ######
152167

‎README.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,5 @@ SUBCOMMANDS:
119119

120120
## Dependencies
121121

122-
1. [fmt](https://github.com/fmtlib/fmt.git): For formatting strings.
123-
2. [replxx](https://github.com/AmokHuginnsson/replxx.git): For better REPL user experience.
124-
3. [CLI11](https://github.com/CLIUtils/CLI11.git): For better CLI support.
122+
1. [replxx](https://github.com/AmokHuginnsson/replxx.git): For better REPL user experience.
123+
2. [CLI11](https://github.com/CLIUtils/CLI11.git): For better CLI support.

‎editor-plugins/emacs/README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212

1313
![Thumbnail](./resources/repl_thumbnail.png)
1414

15-
To interact with the `lambda-discipline` REPL directly inside Emacs, you can use the provided `lbd-inf-repl.el` script. This sets up an **inferior REPL buffer** powered by `comint-mode`.
15+
To interact with the `lambda-discipline` REPL directly inside Emacs, you can use the provided `lbd-inf-repl.el` script.
16+
This sets up an **inferior REPL buffer** powered by `comint-mode`.
1617

1718
### Getting Started
1819

1920
1. `C-x C-f lbd-inf-repl.el RET`
2021
2. `M-x eval-buffer RET`
2122
3. `M-x lbd-run-inf-repl RET`
2223

23-
This will open a buffer called `*lbd*` and start the REPL using `./cmake-build-debug/lbd.exe --repl` with the project root (`../../`) as the working directory.
24+
This will open a buffer called `*lbd*` and start the REPL using `./cmake-build-debug/lbd.exe --repl` with the project
25+
root (`../../`) as the working directory.
2426

2527
### Sending Code to the REPL
2628

@@ -29,5 +31,6 @@ This will open a buffer called `*lbd*` and start the REPL using `./cmake-build-d
2931

3032
### Notes
3133

32-
- The REPL runs with the project root set as the working directory, so relative paths (e.g. `:load examples/foo.lbd`) work the same as on the command line.
34+
- The REPL runs with the project root set as the working directory, so relative paths (e.g. `:load examples/foo.lbd`)
35+
work the same as on the command line.
3336
- If you update the REPL binary, just restart Emacs or rerun `M-x run-lbd`.

‎include/lbd/Context.hpp‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77

88
namespace lbd
99
{
10-
class Context
11-
{
12-
public:
13-
explicit Context(std::ostream& outputStream, Options options = {});
10+
class Context
11+
{
12+
public:
13+
explicit Context(std::ostream &outputStream, Options options = {});
1414

15-
[[nodiscard]] source::BufferManager& getBufferManager();
15+
[[nodiscard]] source::BufferManager &getBufferManager();
1616

17-
[[nodiscard]] diagnostics::DiagnosticEmitter& getDiagnosticEmitter();
17+
[[nodiscard]] diagnostics::DiagnosticEmitter &getDiagnosticEmitter();
1818

19-
[[nodiscard]] Options& getOptions();
19+
[[nodiscard]] Options &getOptions();
2020

21-
[[nodiscard]] Logger& getLogger();
21+
[[nodiscard]] Logger &getLogger();
2222

23-
/// Emits error upon unable to load the file.
24-
[[nodiscard]] source::BufferId loadFile(const std::string& path, const source::Range& range);
23+
/// Emits error upon unable to load the file.
24+
[[nodiscard]] source::BufferId loadFile(const std::string &path, const source::Range &range);
2525

26-
private:
27-
Options options;
28-
Logger logger;
29-
source::BufferManager bufferManager;
30-
diagnostics::DiagnosticRenderer diagnosticRenderer;
31-
diagnostics::DiagnosticEmitter diagnosticEmitter;
32-
};
33-
}
26+
private:
27+
Options options;
28+
Logger logger;
29+
source::BufferManager bufferManager;
30+
diagnostics::DiagnosticRenderer diagnosticRenderer;
31+
diagnostics::DiagnosticEmitter diagnosticEmitter;
32+
};
33+
}

‎include/lbd/Docs.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
namespace lbd
66
{
7-
void dumpDocs(std::ostream& outputStream);
8-
}
7+
void dumpDocs(std::ostream & outputStream);
8+
}

‎include/lbd/Driver.hpp‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#pragma once
22

33
#include <lbd/Context.hpp>
4-
#include <lbd/runtime/interpreter.h>
4+
#include <lbd/runtime/Interpreter.hpp>
55
#include <lbd/source/Buffer.hpp>
66

77
namespace lbd
88
{
9-
class Driver
10-
{
11-
public:
12-
explicit Driver(Context& context) noexcept;
9+
class Driver
10+
{
11+
public:
12+
explicit Driver(Context &context) noexcept;
1313

14-
[[nodiscard]] runtime::Result run(source::BufferId bufferId) const noexcept;
14+
[[nodiscard]] runtime::Result run(source::BufferId bufferId) const noexcept;
1515

16-
private:
17-
Context& context;
18-
};
19-
}
16+
private:
17+
Context &context;
18+
};
19+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <cassert>
44

5-
template <typename>
5+
template<typename>
66
inline constexpr bool alwaysFalseValue = false;
77

88
#define STATIC_ASSERT(VAL, MSG) \
@@ -25,4 +25,4 @@ inline constexpr bool alwaysFalseValue = false;
2525
#define UNREACHABLE_OP ((void)0)
2626
#endif
2727

28-
#define UNREACHABLE(MSG) (assert(false && (MSG)), UNREACHABLE_OP)
28+
#define UNREACHABLE(MSG) (assert(false && (MSG)), UNREACHABLE_OP)

‎include/lbd/Exceptions.hpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <exception>
4+
5+
struct ControlledExit final : std::exception
6+
{
7+
[[nodiscard]] const char *what() const noexcept override
8+
{
9+
return "Controlled non-fatal exit";
10+
}
11+
};

‎include/lbd/Logger.hpp‎

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,66 @@
11
#pragma once
22

3-
#include <optional>
4-
#include <lbd/exceptions.h>
3+
#include <lbd/Exceptions.hpp>
54
#include <lbd/source/Range.hpp>
65
#include <lbd/utils/terminal/Colors.hpp>
76
#include <lbd/utils/terminal/Terminal.hpp>
87

98
namespace lbd
109
{
11-
struct Logger
12-
{
13-
bool exitOnError = true;
14-
bool useColor = false;
15-
bool showLocation = true;
10+
struct Logger
11+
{
12+
bool exitOnError = true;
13+
bool useColor = false;
14+
bool showLocation = true;
1615

17-
Logger() = default;
16+
Logger() = default;
1817

19-
Logger(const bool exitOnError, const bool useColor, const bool showLocation) : exitOnError(exitOnError),
20-
useColor(useColor), showLocation(showLocation)
21-
{
22-
if (useColor)
23-
{
24-
utils::terminal::enableVirtualTerminal();
25-
}
26-
}
18+
Logger(const bool exitOnError, const bool useColor, const bool showLocation) : exitOnError(exitOnError),
19+
useColor(useColor), showLocation(showLocation)
20+
{
21+
if (useColor)
22+
{
23+
utils::terminal::enableVirtualTerminal();
24+
}
25+
}
2726

28-
template <typename... Arguments>
29-
[[noreturn]] void error(Arguments&&... arguments) const
30-
{
31-
logImplementation(utils::terminal::Colors().red, std::cout, std::forward<Arguments>(arguments)...);
32-
if (exitOnError)
33-
{
34-
exit(EXIT_FAILURE);
35-
}
36-
throw ControlledExit{};
37-
}
27+
template<typename... Arguments>
28+
[[noreturn]] void error(Arguments &&... arguments) const
29+
{
30+
logImplementation(utils::terminal::Colors().red, std::cout, std::forward<Arguments>(arguments)...);
31+
if (exitOnError)
32+
{
33+
exit(EXIT_FAILURE);
34+
}
35+
throw ControlledExit{};
36+
}
3837

39-
template <typename... Arguments>
40-
void info(Arguments&&... arguments) const
41-
{
42-
logImplementation(utils::terminal::Colors().blue, std::cout, std::forward<Arguments>(arguments)...);
43-
}
38+
template<typename... Arguments>
39+
void info(Arguments &&... arguments) const
40+
{
41+
logImplementation(utils::terminal::Colors().blue, std::cout, std::forward<Arguments>(arguments)...);
42+
}
4443

45-
template <typename... Arguments>
46-
void debug(Arguments&&... arguments) const
47-
{
48-
logImplementation(utils::terminal::Colors().yellow, std::cout, std::forward<Arguments>(arguments)...);
49-
}
44+
template<typename... Arguments>
45+
void debug(Arguments &&... arguments) const
46+
{
47+
logImplementation(utils::terminal::Colors().yellow, std::cout, std::forward<Arguments>(arguments)...);
48+
}
5049

51-
private:
52-
template <typename... Arguments>
53-
void logImplementation(const std::string& color, std::ostream& stream, Arguments&&... arguments) const
54-
{
55-
if (useColor)
56-
{
57-
stream << color;
58-
}
59-
(stream << ... << std::forward<Arguments>(arguments));
60-
if (useColor)
61-
{
62-
stream << utils::terminal::Colors().reset;
63-
}
64-
stream << std::endl;
65-
}
66-
};
67-
}
50+
private:
51+
template<typename... Arguments>
52+
void logImplementation(const std::string &color, std::ostream &stream, Arguments &&... arguments) const
53+
{
54+
if (useColor)
55+
{
56+
stream << color;
57+
}
58+
(stream << ... << std::forward<Arguments>(arguments));
59+
if (useColor)
60+
{
61+
stream << utils::terminal::Colors().reset;
62+
}
63+
stream << std::endl;
64+
}
65+
};
66+
}

0 commit comments

Comments
 (0)