DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / chuck / step1_read_print.ck
1 // @import readline.ck
2 // @import types/boxed/*.ck
3 // @import types/MalObject.ck
4 // @import types/mal/MalAtom.ck
5 // @import types/mal/MalError.ck
6 // @import types/mal/MalNil.ck
7 // @import types/mal/MalFalse.ck
8 // @import types/mal/MalTrue.ck
9 // @import types/mal/MalInt.ck
10 // @import types/mal/MalString.ck
11 // @import types/mal/MalSymbol.ck
12 // @import types/mal/MalKeyword.ck
13 // @import types/mal/MalList.ck
14 // @import types/mal/MalVector.ck
15 // @import types/mal/MalHashMap.ck
16 // @import util/*.ck
17 // @import reader.ck
18 // @import printer.ck
19
20 fun MalObject READ(string input)
21 {
22 return Reader.read_str(input);
23 }
24
25 fun MalObject EVAL(MalObject m)
26 {
27 return m;
28 }
29
30 fun string PRINT(MalObject m)
31 {
32 return Printer.pr_str(m, true);
33 }
34
35 fun string errorMessage(MalObject m)
36 {
37 (m$MalError).value() @=> MalObject value;
38 return "exception: " + Printer.pr_str(value, true);
39 }
40
41 fun string rep(string input)
42 {
43 READ(input) @=> MalObject m;
44
45 if( m.type == "error" )
46 {
47 return errorMessage(m);
48 }
49 else
50 {
51 return PRINT(EVAL(m));
52 }
53 }
54
55 fun void main()
56 {
57 int done;
58
59 while( !done )
60 {
61 Readline.readline("user> ") => string input;
62
63 if( input != null )
64 {
65 rep(input) => string output;
66
67 if( output == "empty input" )
68 {
69 // proceed immediately with prompt
70 }
71 else
72 {
73 Util.println(output);
74 }
75 }
76 else
77 {
78 true => done;
79 }
80 }
81 }
82
83 main();