Reader: Prevent infinite loop during List and Vector creation
This commit is contained in:
+1
-3
@@ -3,12 +3,10 @@
|
||||
#+LANGUAGE: en
|
||||
#+OPTIONS: toc:nil
|
||||
|
||||
This is my implementation of the [[https://github.com/kanaka/mal][Make A Lisp]] project, done in C++20.
|
||||
This is an implementation of the [[https://github.com/kanaka/mal][Make A Lisp]] project, done in C++20.
|
||||
|
||||
** Usage
|
||||
|
||||
Change the ~#if 0~ macro at the top of the ~stepX.cpp~ to ~#if 1~.
|
||||
|
||||
*** Run the REPL
|
||||
|
||||
#+BEGIN_SRC shell-script
|
||||
|
||||
@@ -168,7 +168,6 @@ ADD_FUNCTION(
|
||||
return makePtr<Constant>((result) ? Constant::True : Constant::False);
|
||||
});
|
||||
|
||||
// FIXME: (count {1}) infinite loop
|
||||
ADD_FUNCTION(
|
||||
"count",
|
||||
{
|
||||
|
||||
+10
-2
@@ -146,7 +146,11 @@ ValuePtr Reader::readList()
|
||||
|
||||
auto list = makePtr<List>();
|
||||
while (!isEOF() && peek().type != Token::Type::ParenClose) {
|
||||
list->add(readImpl());
|
||||
auto node = readImpl();
|
||||
if (node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
list->add(node);
|
||||
}
|
||||
|
||||
if (!consumeSpecific(Token { .type = Token::Type::ParenClose })) { // )
|
||||
@@ -163,7 +167,11 @@ ValuePtr Reader::readVector()
|
||||
|
||||
auto vector = makePtr<Vector>();
|
||||
while (!isEOF() && peek().type != Token::Type::BracketClose) {
|
||||
vector->add(readImpl());
|
||||
auto node = readImpl();
|
||||
if (node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
vector->add(node);
|
||||
}
|
||||
|
||||
if (!consumeSpecific(Token { .type = Token::Type::BracketClose })) { // ]
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "readline.h"
|
||||
#include "settings.h"
|
||||
|
||||
#if 1
|
||||
namespace blaze {
|
||||
|
||||
static blaze::Readline s_readline;
|
||||
@@ -178,4 +177,3 @@ auto main(int argc, char* argv[]) -> int
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user