Merge pull request #368 from sgtatham/vala
[jackhill/mal.git] / vala / step1_read_print.vala
1 class Mal.Main : GLib.Object {
2 static bool eof;
3
4 static construct {
5 eof = false;
6 }
7
8 public static Mal.Val? READ() {
9 string? line = Readline.readline("user> ");
10 if (line != null) {
11 if (line.length > 0)
12 Readline.History.add(line);
13
14 try {
15 return Reader.read_str(line);
16 } catch (Mal.Error err) {
17 GLib.stderr.printf("%s\n", err.message);
18 return null;
19 }
20 } else {
21 stdout.printf("\n");
22 eof = true;
23 return null;
24 }
25 }
26
27 public static Mal.Val EVAL(Mal.Val expr) {
28 return expr;
29 }
30
31 public static void PRINT(Mal.Val value) {
32 stdout.printf("%s\n", pr_str(value));
33 }
34
35 public static void rep() {
36 Mal.Val? val = READ();
37 if (val != null) {
38 val = EVAL(val);
39 PRINT(val);
40 }
41 }
42
43 public static int main(string[] args) {
44 while (!eof)
45 rep();
46 return 0;
47 }
48 }