-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl.c
58 lines (45 loc) · 989 Bytes
/
repl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*! \file
* This file implements the Read-Eval-Print Loop (REPL) for the simple CS24
* Python interpreter.
*/
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <malloc.h>
#include "eval.h"
#include "global.h"
#include "myalloc.h"
#include "parse.h"
void read_eval_print_loop() {
char *line;
size_t size;
MEMORY_SIZE = 0x0fff;
init_myalloc();
while (true) {
printf("> ");
line = NULL;
size = 0;
if (getline(&line, &size, stdin) == -1) {
// Probably end of file?
// Hard to check.
free(line);
break;
}
if (setjmp(error_jmp)) {
goto free_loop;
}
ParseStatement *stmt = read(line);
if (stmt == NULL) {
goto free_loop;
}
eval_stmt(stmt);
memdump();
free_loop:
free(line);
parse_free_all();
}
}
int main() {
read_eval_print_loop();
return 0;
}