Commit | Line | Data |
---|---|---|
8bd091e3 ST |
1 | #include "MAL.h" |
2 | ||
3 | #include "ReadLine.h" | |
4 | #include "Types.h" | |
5 | ||
6 | #include <iostream> | |
7 | #include <memory> | |
8 | ||
9 | malValuePtr READ(const String& input); | |
10 | String PRINT(malValuePtr ast); | |
11 | ||
12 | static ReadLine s_readLine("~/.mal-history"); | |
13 | ||
179e8eaf ST |
14 | static String rep(const String& input); |
15 | static malValuePtr EVAL(malValuePtr ast); | |
16 | ||
8bd091e3 ST |
17 | int main(int argc, char* argv[]) |
18 | { | |
19 | String prompt = "user> "; | |
20 | String input; | |
21 | while (s_readLine.get(prompt, input)) { | |
22 | String out; | |
23 | try { | |
24 | out = rep(input); | |
25 | } | |
26 | catch (malEmptyInputException&) { | |
27 | continue; // no output | |
28 | } | |
29 | catch (String& s) { | |
30 | out = s; | |
31 | }; | |
32 | std::cout << out << "\n"; | |
33 | } | |
34 | return 0; | |
35 | } | |
36 | ||
179e8eaf | 37 | static String rep(const String& input) |
8bd091e3 ST |
38 | { |
39 | return PRINT(EVAL(READ(input))); | |
40 | } | |
41 | ||
42 | malValuePtr READ(const String& input) | |
43 | { | |
44 | return readStr(input); | |
45 | } | |
46 | ||
179e8eaf | 47 | static malValuePtr EVAL(malValuePtr ast) |
8bd091e3 ST |
48 | { |
49 | return ast; | |
50 | } | |
51 | ||
52 | String PRINT(malValuePtr ast) | |
53 | { | |
54 | return ast->print(true); | |
55 | } | |
179e8eaf ST |
56 | |
57 | // These have been added after step 1 to keep the linker happy. | |
dc9b184b | 58 | malValuePtr EVAL(malValuePtr ast, malEnvPtr) |
179e8eaf ST |
59 | { |
60 | return ast; | |
61 | } | |
62 | ||
494c1608 | 63 | malValuePtr APPLY(malValuePtr ast, malValueIter, malValueIter) |
179e8eaf ST |
64 | { |
65 | return ast; | |
66 | } |