Skip to content

Commit efb0f6f

Browse files
final tweaks
1 parent 4085055 commit efb0f6f

File tree

5 files changed

+206
-30
lines changed

5 files changed

+206
-30
lines changed

README.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
The build process should be relatively straight foreward, thanks to the included CMake instructions.
88
I used a Macbook running macOS Catalina 10.15.6 during the development of this interpreter.
9-
Thus I cannot vouch for any other operating systems but I don't see why it shouldn't work :)
9+
A github action was used to build on ubuntu 20.04 which you can see below. Windows wasn't tested but should hopefully work as well.
1010

1111
```bash
1212
> cd <repo>
@@ -17,6 +17,8 @@ Thus I cannot vouch for any other operating systems but I don't see why it shoul
1717
> ./scheme
1818
```
1919

20+
If you'd like to be able to see more debug messages, build the interpreter with the following command instead: `cmake -DCMAKE_BUILD_TYPE=Debug ..`. You can enable or disable individual log message categories in `scheme.cpp`.
21+
2022
Please also note that this was my first time writing anything substantial in C++. Weird language, especially when coming from python. Nonetheless, this was quite fun but in equal measures also frustrating. Well worth it though!
2123

2224
![CMake](https://github.com/paulfauthmayer/schemeplusplus/workflows/CMake/badge.svg)
@@ -81,31 +83,34 @@ Please also note that this was my first time writing anything substantial in C++
8183
8284
* run `.scm` files on their own by passing it via the cli! `scheme myscript.scm`
8385
* type `exit!` to close repl
86+
* enter a newline 3 times in a row to skip the current repl
8487
* type `help` to show all currently available functions and variables
8588
8689
``` scheme
87-
> help
90+
λ help
8891
======== SYNTAX ========
89-
quote := #<syntax:quote>
90-
if := #<syntax:if>
91-
define := #<syntax:define>
92-
set! := #<syntax:set!>
93-
lambda := #<syntax:lambda>
94-
begin := #<syntax:begin>
95-
help := #<syntax:help>
96-
def := #<syntax:define>
92+
begin := evaluate multiple expressions and return last result
93+
def := defines a value to the given variable name
94+
define := defines a value to the given variable name
95+
help := show help text for a given element
96+
if := returns the first expression if the condition is true, the second otherwise:
97+
lambda := defines a new function
98+
quote := returns the first argument:
99+
set! := defines a value to the given variable name in all environments
97100
======== FUNCTIONS ========
98-
+ := #<primitive:+>
99-
- := #<primitive:->
100-
* := #<primitive:*>
101-
/ := #<primitive:/>
101+
% := ( num denum )
102+
* := multiplies all arguments with each other
103+
+ := adds multiple numbers and/or strings
104+
- := subtracts the sum of multiple numbers from the first argument
105+
/ := divides the first argument by the product of all other arguments>
102106
....
103107
```
104108

105109
* type `(help <function-name>)` to get function/syntax specific help messages
106110

107111
``` scheme
108112
> (help +)
113+
======== + ========
109114
adds multiple numbers and/or strings
110115
(+ 1 2 3) -> 6
111116
(+ 1 2 2.5) -> 5.5
@@ -114,13 +119,35 @@ Please also note that this was my first time writing anything substantial in C++
114119
priority: string > float > integer
115120
```
116121
122+
in case of a user defined function, the help message is replaced with the function implementation
123+
124+
```scheme
125+
λ (help %)
126+
======== % ========
127+
(lambda
128+
( num denum )
129+
(
130+
( define
131+
( helper num denum count )
132+
( if
133+
( < num denum ) num
134+
( helper
135+
( - num denum ) denum
136+
( + count 1 ) ) ) )
137+
( if
138+
( = denum 0 ) nil
139+
( helper num denum 0 ) ) ))
140+
```
141+
142+
* garbage collection using a mark and sweep algorithm (note: currently broken and the actual deleting is deactivated, is currently being worked on)
143+
117144
### Data Types
118145
119146
* numbers (integers & floats)
120147
* strings
121148
* lists / cons
122149
* booleans
123-
* nil '()
150+
* other singletons (nil '(), EOF, ...)
124151
* user defined functions
125152
126153
### Supported Syntax
@@ -184,7 +211,7 @@ Please also note that this was my first time writing anything substantial in C++
184211
185212
* code optimisation
186213
* garbage collection
187-
* full unit test coverage
214+
* full test coverage
188215
189216
---
190217

src/garbage_collection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace scm {
1111
static int totalObjectCount{0};
1212

1313
// keep track of all existing objects
14-
// std::vector<Collectable*> ObjectHeap;
14+
std::vector<Collectable*> ObjectHeap;
1515

1616
// constructor and destructor for Collectable class
1717
Collectable::Collectable() : marked(false)

src/garbage_collection.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Collectable {
2323
virtual ~Collectable();
2424
};
2525

26-
static std::vector<Collectable*> ObjectHeap;
2726
void markAndSweep(Environment& env);
2827
void mark(Environment& env);
2928

0 commit comments

Comments
 (0)