DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / chuck / step1_read_print.ck
CommitLineData
2e3d457e 1// @import readline.ck
6a287d62
VS
2// @import types/boxed/*.ck
3// @import types/MalObject.ck
98c1ecf2
VS
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
f823ec25 16// @import util/*.ck
e83d6df7
VS
17// @import reader.ck
18// @import printer.ck
19
20fun MalObject READ(string input)
21{
22 return Reader.read_str(input);
23}
24
25fun MalObject EVAL(MalObject m)
26{
27 return m;
28}
29
30fun string PRINT(MalObject m)
31{
32 return Printer.pr_str(m, true);
33}
34
98c1ecf2
VS
35fun string errorMessage(MalObject m)
36{
37 (m$MalError).value() @=> MalObject value;
dd7a4f55 38 return "exception: " + Printer.pr_str(value, true);
98c1ecf2
VS
39}
40
e83d6df7
VS
41fun string rep(string input)
42{
43 READ(input) @=> MalObject m;
44
45 if( m.type == "error" )
46 {
98c1ecf2 47 return errorMessage(m);
e83d6df7
VS
48 }
49 else
50 {
51 return PRINT(EVAL(m));
52 }
53}
54
55fun void main()
56{
2e3d457e 57 int done;
e83d6df7 58
2e3d457e 59 while( !done )
e83d6df7 60 {
2e3d457e 61 Readline.readline("user> ") => string input;
e83d6df7 62
2e3d457e 63 if( input != null )
e83d6df7 64 {
2e3d457e
VS
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 }
e83d6df7
VS
75 }
76 else
77 {
2e3d457e 78 true => done;
e83d6df7
VS
79 }
80 }
81}
82
83main();