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

Commit c5c7717

Browse files
committed
chore: refactor interpreter module
1 parent d2cbf91 commit c5c7717

24 files changed

Lines changed: 100 additions & 96 deletions

‎CMakeLists.txt‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ add_library(frontend STATIC
1515
${CMAKE_SOURCE_DIR}/src/frontend/parser.cpp
1616
)
1717

18-
add_library(intp STATIC
19-
${CMAKE_SOURCE_DIR}/src/intp/types.cpp
20-
${CMAKE_SOURCE_DIR}/src/intp/interpreter.cpp
21-
${CMAKE_SOURCE_DIR}/src/intp/builtins.cpp
22-
${CMAKE_SOURCE_DIR}/src/intp/builtin-modules/builtin_module_core.cpp
23-
${CMAKE_SOURCE_DIR}/src/intp/builtin-modules/builtin_module_list.cpp
24-
${CMAKE_SOURCE_DIR}/src/intp/builtin-modules/builtin_module_io.cpp
18+
add_library(interpreter STATIC
19+
${CMAKE_SOURCE_DIR}/src/interpreter/type.cpp
20+
${CMAKE_SOURCE_DIR}/src/interpreter/interpreter.cpp
21+
${CMAKE_SOURCE_DIR}/src/interpreter/builtins.cpp
22+
${CMAKE_SOURCE_DIR}/src/interpreter/builtin-modules/builtin_module_core.cpp
23+
${CMAKE_SOURCE_DIR}/src/interpreter/builtin-modules/builtin_module_list.cpp
24+
${CMAKE_SOURCE_DIR}/src/interpreter/builtin-modules/builtin_module_io.cpp
2525
)
2626

2727
add_executable(lbd
@@ -30,7 +30,7 @@ add_executable(lbd
3030
${CMAKE_SOURCE_DIR}/src/repl.cpp
3131
)
3232

33-
target_link_libraries(lbd PRIVATE frontend intp -static)
33+
target_link_libraries(lbd PRIVATE frontend interpreter -static)
3434

3535
# TODO: Add build tests
3636
# EXAMPLE: add_executable(lexer_test ../tests/lexer_test.cc)

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ lbd [options]
120120
## TODO
121121

122122
- TODO: Add better examples (e.g., Advent of Code snippets).
123-
- TODO: Maybe use rere.py for testing
123+
- TODO: CI/CD for testing.
124124
- TODO: Fix tests output in README.

‎include/lbd/frontend/ast.h‎

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

33
#include <lbd/frontend/location.h>
4-
#include <lbd/intp/types.h>
4+
#include <lbd/interpreter/type.h>
55
#include <string>
66
#include <variant>
77
#include <vector>
@@ -32,12 +32,12 @@ namespace frontend {
3232

3333
struct LambdaExpression {
3434
IdentifierAstNode argument;
35-
intp::types::Type argumentType;
35+
interpreter::type::Type argumentType;
3636
std::unique_ptr<Expression> expression;
3737
Location location;
3838
/// Maybe, this is redundant.
3939
// TODO: Remove after checking.
40-
intp::types::CompoundType lambdaExpressionType;
40+
interpreter::type::CompoundType lambdaExpressionType;
4141

4242
void print(std::ostream &stream, size_t indent) const;
4343

@@ -92,7 +92,7 @@ namespace frontend {
9292

9393
struct DefinitionAstNode {
9494
IdentifierAstNode definitionName;
95-
intp::types::Type definitionType;
95+
interpreter::type::Type definitionType;
9696
Expression expression;
9797
Location location;
9898

‎include/lbd/frontend/lexer.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace frontend {
1515

1616
struct Lexer {
1717
// TODO: Make factory instead of these constructors.
18-
Lexer(const std::string &filepath, FromFile, options::Options options_ = {});
18+
Lexer(const std::string &filepath, FromFile, global::Options options_ = {});
1919

20-
Lexer(std::string str, FromRepl, options::Options options_ = {});
20+
Lexer(std::string str, FromRepl, global::Options options_ = {});
2121

2222
token::Token nextToken();
2323

‎include/lbd/frontend/parser.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
#include <lbd/options.h>
44
#include <lbd/frontend/ast.h>
55
#include <lbd/frontend/token.h>
6-
#include <lbd/intp/types.h>
6+
#include <lbd/interpreter/type.h>
77
#include <vector>
88

99
namespace frontend {
1010
struct Parser {
1111
Program program;
1212

13-
explicit Parser(const std::vector<token::Token> &tokens, options::Options options_ = {});
13+
explicit Parser(const std::vector<token::Token> &tokens, global::Options options_ = {});
1414

1515
private:
1616
// TODO: Add checks for T to be a variant of frontend::TokenType
@@ -22,9 +22,9 @@ namespace frontend {
2222

2323
static IdentifierAstNode consumeIdentifier(const std::vector<token::Token> &tokens, size_t &index);
2424

25-
static intp::types::PrimitiveType consumePrimitiveTypeName(const std::vector<token::Token> &tokens, size_t &index);
25+
static interpreter::type::PrimitiveType consumePrimitiveTypeName(const std::vector<token::Token> &tokens, size_t &index);
2626

27-
static intp::types::Type parseType(const std::vector<token::Token> &tokens, size_t &index);
27+
static interpreter::type::Type parseType(const std::vector<token::Token> &tokens, size_t &index);
2828

2929
static Expression parseExpression(const std::vector<token::Token> &tokens, size_t &index);
3030

include/lbd/intp/builtin-modules/builtin_module_core.h renamed to include/lbd/interpreter/builtin-modules/builtin_module_core.h

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

3-
#include <lbd/intp/builtins.h>
3+
#include <lbd/interpreter/builtins.h>
44

5-
namespace intp::interp::builtins {
5+
namespace interpreter::builtins {
66
NativeFunction makePrint();
77

88
NativeFunction makeAdd();

include/lbd/intp/builtin-modules/builtin_module_io.h renamed to include/lbd/interpreter/builtin-modules/builtin_module_io.h

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

3-
#include <lbd/intp/builtins.h>
3+
#include <lbd/interpreter/builtins.h>
44

5-
namespace intp::interp::builtins {
5+
namespace interpreter::builtins {
66
NativeFunction makeSlurpFile();
77

88
NativeFunction makeLines();

include/lbd/intp/builtin-modules/builtin_module_list.h renamed to include/lbd/interpreter/builtin-modules/builtin_module_list.h

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

3-
#include <lbd/intp/builtins.h>
3+
#include <lbd/interpreter/builtins.h>
44

5-
namespace intp::interp::builtins {
5+
namespace interpreter::builtins {
66
NativeFunction makeList();
77

88
NativeFunction makeListSize();

‎include/lbd/interpreter/builtins.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include <lbd/interpreter/interpreter.h>
4+
#include <lbd/options.h>
5+
6+
namespace interpreter::builtins {
7+
extern global::Options optionsValue;
8+
9+
std::vector<NativeFunction> getBuiltins(global::Options options_ = {});
10+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <lbd/frontend/parser.h>
99
#include <lbd/options.h>
1010

11-
namespace intp::interp {
11+
namespace interpreter {
1212
struct NativeFunction;
1313
struct Thunk;
1414
struct Environment;
@@ -54,6 +54,7 @@ namespace intp::interp {
5454
struct ResultOptions {
5555
bool sideEffects = false;
5656

57+
// TODO: _ may not be needed here
5758
void interpolate(const ResultOptions &resultOptions_);
5859
};
5960

@@ -91,8 +92,8 @@ namespace intp::interp {
9192
void set(const frontend::Expression *expression_, std::shared_ptr<Environment> environment_,
9293
std::optional<frontend::Location> origin_ = std::nullopt);
9394

94-
void set_owned(frontend::Expression expression_, std::shared_ptr<Environment> environment_,
95-
std::optional<frontend::Location> origin_ = std::nullopt);
95+
void setOwned(frontend::Expression expression_, std::shared_ptr<Environment> environment_,
96+
std::optional<frontend::Location> origin_ = std::nullopt);
9697
};
9798

9899
struct Environment : std::enable_shared_from_this<Environment> {
@@ -121,8 +122,9 @@ namespace intp::interp {
121122
ResultOptions options = {};
122123
};
123124

124-
Result interpret(frontend::Program &program, std::optional<std::shared_ptr<Environment> > globalEnvironment = std::nullopt,
125-
options::Options options_ = {});
125+
Result interpret(frontend::Program &program,
126+
std::optional<std::shared_ptr<Environment> > globalEnvironment = std::nullopt,
127+
global::Options options_ = {});
126128

127129
/// Add builtins Native Functions into Environment.
128130
void installBuiltins(const std::shared_ptr<Environment> &environment);

0 commit comments

Comments
 (0)