Skip to content

Commit ba76d26

Browse files
committed
cleaning
1 parent 8810173 commit ba76d26

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
# clo
22

33
![](https://github.com/sdingcn/clo/actions/workflows/CI.yml/badge.svg)
4-
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/sdingcn/clo)
54

65
**Clo** is a small, dynamically-typed, garbage-collected, functional programming language.
7-
Here is its syntax.
86
```
97
<comment> := "#" [^\n]* "\n"
108
<intrinsic> := "." [^\s]+
119
<binding> := <var> <expr>
10+
<callee> := <intrinsic> | <expr>
1211
<expr> := <int-literal> | <str-literal> | <var>
1312
| lambda ( <var>* ) <expr>
1413
| letrec ( <binding>* ) <expr>
1514
| if <expr> <expr> <expr>
1615
| { <expr>+ } // sequenced evaluation
17-
| ( <intrinsic> <expr>* )
18-
| ( <expr> <expr>* )
16+
| ( <callee> <expr>* )
1917
| @ <var> <expr> // access var in closure's env (can simulate structs)
2018
```
2119

@@ -49,7 +47,7 @@ The source code of the interpreter
4947
is standard C++20 and thus can be compiled
5048
by any C++20-conforming compiler.
5149
The current `Makefile` and `CI.py`
52-
need `clang++` (with C++20 support), `make`, and `python3`.
50+
need `clang++` with C++20 support (for sanitizer), `make`, and `python3`.
5351

5452
## build and run
5553

src/main.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,34 +1777,29 @@ class State {
17771777
while (sin >> word) {
17781778
sentence.push_back(word);
17791779
// special treatment of string values
1780-
// TODO: change this to a better implementation
1781-
if (word == "(") {
1780+
if (word == "sval" && sentence.size() > 1 && *(sentence.rbegin() + 1) == "(") {
17821781
sin >> word;
17831782
sentence.push_back(word);
1784-
if (word == "sval") {
1785-
sin >> word;
1786-
sentence.push_back(word);
1787-
int len = std::stoi(word);
1788-
while (true) {
1789-
if (sin.get() == '"') {
1790-
break;
1791-
}
1792-
if (sin.eof()) {
1793-
utils::panic("serialization", "didn't find start of str val");
1794-
}
1783+
int len = std::stoi(word);
1784+
while (true) {
1785+
if (sin.get() == '"') {
1786+
break;
17951787
}
1796-
word = "\"";
1797-
for (int i = 0; i < len - 1; i++) {
1798-
word.push_back(sin.get());
1799-
if (sin.eof()) {
1800-
utils::panic("serialization", "incomplete string");
1801-
}
1788+
if (sin.eof()) {
1789+
utils::panic("serialization", "didn't find start of str val");
18021790
}
1803-
if (word.back() != '\"') {
1804-
utils::panic("serialization", "invalid string terminator");
1791+
}
1792+
word = "\"";
1793+
for (int i = 0; i < len - 1; i++) {
1794+
word.push_back(sin.get());
1795+
if (sin.eof()) {
1796+
utils::panic("serialization", "incomplete string");
18051797
}
1806-
sentence.push_back(word);
18071798
}
1799+
if (word.back() != '"') {
1800+
utils::panic("serialization", "invalid string terminator");
1801+
}
1802+
sentence.push_back(word);
18081803
}
18091804
}
18101805
}
@@ -2179,6 +2174,7 @@ class State {
21792174
const syntax::ExprNode* getExpr() const {
21802175
return expr;
21812176
}
2177+
// TODO: record GC state?
21822178
std::string serialize() const {
21832179
// std::string source;
21842180
std::string serializedSource =

0 commit comments

Comments
 (0)