Merge pull request #345 from asarhaddon/ada.2
[jackhill/mal.git] / objpascal / step1_read_print.pas
CommitLineData
0067158f
JM
1program Mal;
2
bc6a1f15
JM
3{$H+} // Use AnsiString
4
0067158f
JM
5Uses sysutils,
6 CMem,
bc6a1f15 7 mal_readline,
0067158f
JM
8 mal_types,
9 reader,
10 printer;
11
12var
bc6a1f15
JM
13 Repl_Env : string = '';
14 Line : string;
0067158f
JM
15
16// read
17function READ(const Str: string) : TMal;
18begin
19 READ := read_str(Str);
20end;
21
22// eval
23function EVAL(Ast: TMal; Env: string) : TMal;
24begin
25 EVAL := Ast;
26end;
27
28// print
29function PRINT(Exp: TMal) : string;
30begin
31 PRINT := pr_str(Exp, True);
32end;
33
34// repl
35function REP(Str: string) : string;
36begin
37 REP := PRINT(EVAL(READ(Str), Repl_Env));
38end;
39
40begin
41 while True do
42 begin
0067158f 43 try
bc6a1f15
JM
44 Line := _readline('user> ');
45 if Line = '' then continue;
0067158f
JM
46 WriteLn(REP(Line))
47 except
bc6a1f15 48 On E : MalEOF do Halt(0);
0067158f
JM
49 On E : Exception do
50 begin
51 WriteLn('Error: ' + E.message);
52 WriteLn('Backtrace:');
53 WriteLn(GetBacktrace(E));
54 end;
55 end;
56 end;
57end.