All: move metadata, atoms, readline, conj to stepA.
[jackhill/mal.git] / cs / step1_read_print.cs
1 using System;
2 using System.IO;
3 using Mal;
4 using MalVal = Mal.types.MalVal;
5
6 namespace Mal {
7 class step1_read_print {
8 // read
9 static MalVal READ(string str) {
10 return reader.read_str(str);
11 }
12
13 // eval
14 static MalVal EVAL(MalVal ast, string env) {
15 return ast;
16 }
17
18 // print
19 static string PRINT(MalVal exp) {
20 return printer._pr_str(exp, true);
21 }
22
23 // repl
24 static void Main(string[] args) {
25 Func<string, MalVal> RE = (string str) => EVAL(READ(str), "");
26
27 if (args.Length > 0 && args[0] == "--raw") {
28 Mal.readline.mode = Mal.readline.Mode.Raw;
29 }
30
31 // repl loop
32 while (true) {
33 string line;
34 try {
35 line = Mal.readline.Readline("user> ");
36 if (line == null) { break; }
37 if (line == "") { continue; }
38 } catch (IOException e) {
39 Console.WriteLine("IOException: " + e.Message);
40 break;
41 }
42 try {
43 Console.WriteLine(PRINT(RE(line)));
44 } catch (Mal.types.MalContinue) {
45 continue;
46 } catch (Exception e) {
47 Console.WriteLine("Error: " + e.Message);
48 Console.WriteLine(e.StackTrace);
49 continue;
50 }
51 }
52 }
53 }
54 }