Ada: rewrote reader to remove opentoken dependency
[jackhill/mal.git] / ada / step3_env.adb
1 with Ada.Command_Line;
2 with Ada.Text_IO;
3 with Ada.IO_Exceptions;
4 with Core;
5 with Envs;
6 with Evaluation;
7 with Printer;
8 with Reader;
9 with Types;
10
11 procedure Step3_Env is
12
13 function Read (Param : String) return Types.Mal_Handle is
14 begin
15 return Reader.Read_Str (Param);
16 end Read;
17
18
19 -- Eval can't be here because there are function pointers that point
20 -- at it. Thus it must be at library level. See evaluation.ads
21
22
23 function Print (Param : Types.Mal_Handle) return String is
24 begin
25 return Printer.Pr_Str (Param);
26 end Print;
27
28 function Rep (Param : String) return String is
29 AST, Evaluated_AST : Types.Mal_Handle;
30 begin
31
32 AST := Read (Param);
33
34 if Types.Is_Null (AST) then
35 return "";
36 else
37 Evaluated_AST := Evaluation.Eval (AST, Envs.Get_Current);
38 return Print (Evaluated_AST);
39 end if;
40
41 end Rep;
42
43 S : String (1..Reader.Max_Line_Len);
44 Last : Natural;
45
46 begin
47
48 if Ada.Command_Line.Argument_Count > 0 then
49 if Ada.Command_Line.Argument (1) = "-d" then
50 Evaluation.Debug := True;
51 end if;
52 end if;
53
54 Core.Init;
55
56 loop
57 Ada.Text_IO.Put ("user> ");
58 Ada.Text_IO.Get_Line (S, Last);
59 Ada.Text_IO.Put_Line (Rep (S (1..Last)));
60 end loop;
61
62 exception
63 when Ada.IO_Exceptions.End_Error => null;
64 -- i.e. exit without textual output
65 end Step3_Env;