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

Commit 6b9b05e

Browse files
committed
feat: add rudimentary support for interpreter
1 parent 6921657 commit 6b9b05e

25 files changed

Lines changed: 907 additions & 29 deletions

‎CMakeLists.txt‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 4.0)
2-
project(lambda_discipline)
2+
project(lambda-discipline)
33

44
set(CMAKE_CXX_STANDARD 20)
55

@@ -17,10 +17,17 @@ add_library(fe STATIC
1717

1818
add_library(intp STATIC
1919
${CMAKE_SOURCE_DIR}/src/intp/types.cpp
20+
${CMAKE_SOURCE_DIR}/src/intp/interpreter.cpp
21+
${CMAKE_SOURCE_DIR}/src/intp/builtins.cpp
2022
)
2123

22-
add_executable(lambda_discipline ${CMAKE_SOURCE_DIR}/src/main.cpp)
23-
target_link_libraries(lambda_discipline PRIVATE fe intp)
24+
add_executable(lbd
25+
${CMAKE_SOURCE_DIR}/src/main.cpp
26+
${CMAKE_SOURCE_DIR}/src/cmd.cpp
27+
${CMAKE_SOURCE_DIR}/src/repl.cpp
28+
)
29+
30+
target_link_libraries(lbd PRIVATE fe intp)
2431

2532
# TODO: Add build tests
2633
# EXAMPLE: add_executable(lexer_test ../tests/lexer_test.cc)

‎README.md‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,18 @@ cmake ..
77
make
88
```
99

10-
> TODO: Add build instructions for Windows as well.
10+
## Usage
11+
12+
```bash
13+
usage: lbd [options]
14+
15+
options:
16+
-f, --file <filename> Specify input source file to run
17+
-h, --help Show this help message and exit
18+
-d, --debug Enable debug mode
19+
-r, --repl Run in interactive REPL node
20+
```
21+
22+
> TODO: Add build instructions for Windows as well.
23+
24+
> TODO: Add small script to print all TODOs and there Loc.

‎examples/ifthen.lbd‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
true: Bool = \x: Any. \y: Any. x
2+
false: Bool = \x: Any. \y: Any. y
3+
4+
ifthen: Any = \condition: Bool -> Any -> Any -> Any.
5+
\then_clause: Any. \else_clause: Any.
6+
(condition then_clause else_clause)
7+
8+
(print (ifthen true "True" "False"))
9+
(print (ifthen false "True" "False"))

‎examples/math_demos.lbd‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fibonacci: Any = \num: Float.
2+
(if_zero (cmp 0 num) 0
3+
(if_zero (cmp 1 num) 1
4+
(add (fibonacci (sub num 1.0)) (fibonacci (sub num 2.0)))))
5+
6+
(print (fibonacci 10))

‎examples/pair.lbd‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pair: Any = \x: Any. \y: Any. \fn: Any. (fn x y)
2+
3+
first: Any = \x: Any. \y: Any. x
4+
second: Any = \x: Any. \y: Any. y
5+
6+
p1: Any = (pair 1.0 2.0)
7+
8+
(print (p1 first))
9+
(print (p1 second))

‎examples/shapes.lbd‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Define Pi as constant
2+
pi: Float = 3.14
3+
4+
-- Define function to calculate square
5+
square: Float -> Float = \x: Float. (mul x x)
6+
7+
-- Define function to calculate area of circle
8+
area_of_circle: Float -> Float = \r: Float.
9+
(mul pi (square r))
10+
11+
-- Define function to calculate volume of cylinder
12+
volume_of_cylinder: Float -> Float -> Float = \r: Float.
13+
\h: Float. (mul (area_of_circle r) h)
14+
15+
-- Calculate the volume of a cylinder
16+
(print "Volume of cylinder is: ")
17+
(print (volume_of_cylinder 5.0 10.0))

‎examples/std.lbd‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
-- TODO: Support for `use`
2+
13
-- booleans and conditions
24
true: Bool = \x: Any. \y: Any. x
35
false: Bool = \x: Any. \y: Any. y
46

5-
ifthen: Any = \condition: Any.
7+
if_then: Any = \condition: Any.
68
\then_clause: Any. \else_clause: Any.
79
(condition then_clause else_clause)
810

@@ -14,4 +16,4 @@ second: Any = \x: Any. \y: Any. y
1416

1517
-- misc
1618
float_eq: Float -> Float -> Bool = \x: Float. \y: Float.
17-
(ifzero (cmp x y) true false)
19+
(if_zero (cmp x y) true false)

‎examples/test.lbd‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Define Pi as constant
2+
pi: Float = 3.14
3+
4+
-- Define function to calculate square
5+
square: Float -> Float = \x: Float. (mul x x)
6+
7+
-- Define function to calculate area of circle
8+
area_of_circle: Float -> Float = \r: Float.
9+
(mul pi (square r))
10+
11+
-- Define function to calculate volume of cylinder
12+
volume_of_cylinder: Float -> Float -> Float = \r: Float.
13+
\h: Float. (mul (area_of_circle r) h)
14+
15+
-- Calculate the volume of a cylinder
16+
(print "Volume of cylinder is: ")
17+
(print (volume_of_cylinder 5.0 10.0))

‎include/lbd/cmd.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <optional>
5+
#include <string>
6+
7+
namespace cmd {
8+
struct Options {
9+
std::optional<std::string> filepath;
10+
bool show_help = false;
11+
bool repl = false;
12+
bool debug = false;
13+
};
14+
15+
void print_help(std::ostream &os, const std::string &program_name);
16+
17+
Options parse_args(int argc, char **argv, const std::string &program_name);
18+
}

‎include/lbd/fe/ast.h‎

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

3-
#include <iostream>
43
#include <lbd/fe/loc.h>
54
#include <lbd/intp/types.h>
65
#include <string>
@@ -36,6 +35,8 @@ namespace fe::ast {
3635
intp::types::Type arg_type;
3736
std::unique_ptr<Expression> expr;
3837
loc::Loc loc;
38+
/// Maybe, this is redundant
39+
/// TODO: Remove after checking
3940
intp::types::CompoundType lmd_expr_type; // Lambda Expression Type
4041

4142
void print(std::ostream &os, size_t indent) const;

0 commit comments

Comments
 (0)