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

Commit fd93484

Browse files
committed
chore: reformat frontend library
1 parent d02122e commit fd93484

65 files changed

Lines changed: 2173 additions & 1424 deletions

Some content is hidden

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

‎CMakeLists.txt‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
cmake_minimum_required(VERSION 3.20)
22
project(lambda-discipline)
33

4-
set(CMAKE_CXX_STANDARD 20)
4+
set(CMAKE_CXX_STANDARD 23)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

8+
###### SOURCE ######
9+
file(GLOB_RECURSE SOURCE_SOURCE_FILES CONFIGURE_DEPENDS
10+
${PROJECT_SOURCE_DIR}/src/source/*.cpp
11+
)
12+
add_library(lbdSource STATIC)
13+
target_sources(lbdSource PRIVATE ${SOURCE_SOURCE_FILES})
14+
target_include_directories(lbdSource PUBLIC ${PROJECT_SOURCE_DIR}/include)
15+
816
####### FRONTEND #######
917
file(GLOB_RECURSE FRONTEND_SOURCE_FILES CONFIGURE_DEPENDS
1018
${PROJECT_SOURCE_DIR}/src/frontend/*.cpp
1119
)
1220
add_library(lbdFrontend STATIC)
1321
target_sources(lbdFrontend PRIVATE ${FRONTEND_SOURCE_FILES})
22+
target_link_libraries(lbdFrontend PUBLIC
23+
lbdSource
24+
)
1425
target_include_directories(lbdFrontend PUBLIC
1526
${PROJECT_SOURCE_DIR}/include
1627
)
@@ -21,6 +32,9 @@ file(GLOB_RECURSE RUNTIME_SOURCE_FILES CONFIGURE_DEPENDS
2132
)
2233
add_library(lbdRuntime STATIC)
2334
target_sources(lbdRuntime PRIVATE ${RUNTIME_SOURCE_FILES})
35+
target_link_libraries(lbdRuntime PUBLIC
36+
lbdSource
37+
)
2438
target_include_directories(lbdRuntime PUBLIC
2539
${PROJECT_SOURCE_DIR}/include
2640
)

‎include/lbd/Context.hpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <lbd/Options.hpp>
4+
#include <lbd/source/SourceManager.hpp>
5+
6+
namespace lbd
7+
{
8+
class Context
9+
{
10+
public:
11+
explicit Context(Options options);
12+
13+
[[nodiscard]] source::SourceManager& getSourceManager();
14+
15+
[[nodiscard]] Options& getOptions();
16+
17+
// TODO: Add diagnostic emitter and renderer.
18+
19+
private:
20+
Options options;
21+
source::SourceManager sourceManager;
22+
};
23+
}

‎include/lbd/Options.hpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <lbd/logs.h>
4+
5+
namespace lbd
6+
{
7+
class Options
8+
{
9+
public:
10+
explicit Options(bool ownExpression = false, bool forceOnEnvironmentDump = false, bool debug = false);
11+
12+
[[nodiscard]] bool shouldOwnExpression() const;
13+
14+
[[nodiscard]] bool shouldForceOnEnvironmentDump() const;
15+
16+
[[nodiscard]] bool isDebug() const;
17+
18+
void toggleForceOnEnvironmentDump();
19+
20+
void toggleDebug();
21+
22+
// TODO: Instead use diagnostic emitter and renderer.
23+
Logger logger;
24+
25+
private:
26+
bool ownExpression; /// Owning Expression inside Thunk. Turned on for REPL
27+
bool forceOnEnvironmentDump;
28+
bool debug;
29+
};
30+
}

‎include/lbd/cmd.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
#include <optional>
55
#include <string>
66

7-
namespace cmd {
8-
struct Options {
7+
namespace cmd
8+
{
9+
struct Options
10+
{
911
std::optional<std::string> filepath;
1012
bool showHelp = false;
1113
bool repl = false;
1214
bool debug = false;
1315
bool generateDocs = false;
1416
};
1517

16-
void printHelp(std::ostream &outputStream, const std::string &programName);
18+
void printHelp(std::ostream& outputStream, const std::string& programName);
1719

18-
Options parseArguments(int argc, char **argv, const std::string &programName);
20+
Options parseArguments(int argc, char** argv, const std::string& programName);
1921
}

‎include/lbd/docs.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <iostream>
44

5-
namespace docs {
6-
void dumpDocs(std::ostream &outputStream);
5+
namespace lbd::docs
6+
{
7+
void dumpDocs(std::ostream& outputStream);
78
}

‎include/lbd/error.h‎

Lines changed: 1 addition & 1 deletion
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) \

‎include/lbd/exceptions.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
#include <exception>
44

5-
struct ControlledExit final : std::exception {
6-
const char *what() const noexcept override {
5+
struct ControlledExit final : std::exception
6+
{
7+
[[nodiscard]] const char* what() const noexcept override
8+
{
79
return "Controlled non-fatal exit";
810
}
911
};

‎include/lbd/frontend/ast.h‎

Lines changed: 0 additions & 111 deletions
This file was deleted.

‎include/lbd/frontend/ast/Ast.hpp‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <variant>
5+
#include <vector>
6+
#include <lbd/frontend/type.h>
7+
#include <lbd/source/Location.hpp>
8+
9+
namespace lbd::frontend::ast
10+
{
11+
struct IdentifierAstNode
12+
{
13+
// TODO: This can be a std::string_view.
14+
std::string value;
15+
source::Location location;
16+
17+
friend std::ostream& operator<<(std::ostream& outputStream, const IdentifierAstNode& node);
18+
};
19+
20+
struct StringAstNode
21+
{
22+
std::string value;
23+
source::Location location;
24+
25+
friend std::ostream& operator<<(std::ostream& outputStream, const StringAstNode& node);
26+
};
27+
28+
// TODO: Rename this to NumberAstNode.
29+
struct FloatAstNode
30+
{
31+
double value;
32+
source::Location location;
33+
34+
friend std::ostream& operator<<(std::ostream& outputStream, const FloatAstNode& node);
35+
};
36+
37+
struct Expression;
38+
39+
struct LambdaExpression
40+
{
41+
IdentifierAstNode argument;
42+
interpreter::type::Type argumentType;
43+
std::unique_ptr<Expression> expression;
44+
source::Location location;
45+
46+
void print(std::ostream& outputStream, size_t indent) const;
47+
48+
friend std::ostream& operator<<(std::ostream& outputStream, const LambdaExpression& lambdaExpression);
49+
};
50+
51+
struct FunctionApplication
52+
{
53+
IdentifierAstNode functionName;
54+
std::vector<std::unique_ptr<Expression>> arguments;
55+
source::Location location;
56+
57+
void print(std::ostream& outputStream, size_t indent) const;
58+
59+
friend std::ostream& operator<<(std::ostream& outputStream, const FunctionApplication& functionApplication);
60+
};
61+
62+
struct Expression
63+
{
64+
using ExpressionVariant = std::variant<
65+
IdentifierAstNode,
66+
StringAstNode,
67+
FloatAstNode,
68+
LambdaExpression,
69+
FunctionApplication
70+
>;
71+
72+
ExpressionVariant value;
73+
74+
explicit Expression(IdentifierAstNode value);
75+
76+
explicit Expression(StringAstNode value);
77+
78+
explicit Expression(FloatAstNode value);
79+
80+
explicit Expression(LambdaExpression value);
81+
82+
explicit Expression(FunctionApplication value);
83+
84+
void print(std::ostream& outputStream, size_t indent) const;
85+
86+
friend std::ostream& operator<<(std::ostream& outputStream, const Expression& expression);
87+
88+
[[nodiscard]] source::Location getLocation() const;
89+
90+
Expression(const Expression&) = delete;
91+
92+
Expression& operator=(const Expression&) = delete;
93+
94+
Expression(Expression&&) noexcept = default;
95+
96+
Expression& operator=(Expression&&) noexcept = default;
97+
};
98+
99+
struct DefinitionAstNode
100+
{
101+
IdentifierAstNode definitionName;
102+
interpreter::type::Type definitionType;
103+
Expression expression;
104+
source::Location location;
105+
106+
void print(std::ostream& outputStream, size_t indent) const;
107+
108+
friend std::ostream& operator<<(std::ostream& outputStream, const DefinitionAstNode& node);
109+
};
110+
111+
// NOTE: Owning and move-only, not copyable.
112+
struct AstNode
113+
{
114+
using NodeVariant = std::variant<Expression, DefinitionAstNode>;
115+
116+
NodeVariant value;
117+
118+
void print(std::ostream& outputStream, size_t indent) const;
119+
120+
friend std::ostream& operator<<(std::ostream& outputStream, const AstNode& node);
121+
};
122+
}

0 commit comments

Comments
 (0)