Browse Source

clean reader

master
Gabriel Pariat 3 years ago
parent
commit
3e793e8c71
  1. 9
      implementations/c/src/lisp.c
  2. 11
      implementations/c/src/reader.c

9
implementations/c/src/lisp.c

@ -324,14 +324,7 @@ void init(void) { @@ -324,14 +324,7 @@ void init(void) {
void repl(void) {
while(true) {
printf(">>> ");
Pointer reader = read_fn(NIL, NIL);
char c;
while((c = getc(stdin)) && isspace(c) && c != '\n');
if (c != '\n') ungetc(c, stdin);
/* read_char_fn(NIL, NIL); */
/* read_char_fn(NIL, NIL); */
/* printf("eof?: %d", feof(stdin)); */
print(eval(reader, NIL), stdout);
print(eval(read_fn(NIL, NIL), NIL), stdout);
printf("\n");
}
}

11
implementations/c/src/reader.c

@ -143,14 +143,11 @@ Pointer read1(Pointer streamPtr, Pointer env) { @@ -143,14 +143,11 @@ Pointer read1(Pointer streamPtr, Pointer env) {
Pointer read_fn(Pointer args, Pointer env) {
Pointer streamPtr = CAR(args);
streamPtr = streamPtr == NIL ? environment_get(env, STANDARD_INPUT) : streamPtr;
/* Stream stream = STREAM(streamPtr); */
Stream stream = STREAM(streamPtr);
Pointer result = read1(streamPtr, env);
/* peek_char(T, stream); */
/* getc(stream); */
/* char c; */
/* getc(stream); */
/* while((c = getc(stream)) >= 0 && c == ' ') ungetc(c, stream); */
/* if (c != EOF) ungetc(c, stream); */
char c;
while((c = getc(stream)) && isspace(c) && c != '\n');
if (c != '\n') ungetc(c, stream);
return result;
}

Loading…
Cancel
Save