Merge pull request #386 from asarhaddon/test-let-recursive-def
[jackhill/mal.git] / ada.2 / step1_read_print.adb
CommitLineData
cbbb51b4 1with Ada.Text_IO.Unbounded_IO;
daffc668 2
00c3a3c3 3with Err;
5a07bb53 4with Garbage_Collected;
cbbb51b4
NB
5with Printer;
6with Reader;
11932a6c 7with Readline;
8185fe14 8with Types;
cbbb51b4
NB
9
10procedure Step1_Read_Print is
11
8185fe14 12 function Read return Types.T_Array with Inline;
daffc668 13
8185fe14 14 function Eval (Ast : in Types.T) return Types.T;
cbbb51b4 15
8185fe14 16 procedure Print (Ast : in Types.T) with Inline;
cbbb51b4 17
11932a6c 18 procedure Rep with Inline;
cbbb51b4
NB
19
20 ----------------------------------------------------------------------
21
8185fe14 22 function Eval (Ast : in Types.T) return Types.T is (Ast);
11932a6c 23
8185fe14 24 procedure Print (Ast : in Types.T) is
11932a6c
NB
25 begin
26 Ada.Text_IO.Unbounded_IO.Put_Line (Printer.Pr_Str (Ast));
27 end Print;
28
8185fe14 29 function Read return Types.T_Array
00c3a3c3 30 is (Reader.Read_Str (Readline.Input ("user> ")));
11932a6c
NB
31
32 procedure Rep is
cbbb51b4 33 begin
00c3a3c3
NB
34 for Expression of Read loop
35 Print (Eval (Expression));
36 end loop;
11932a6c 37 end Rep;
cbbb51b4
NB
38
39 ----------------------------------------------------------------------
40
41begin
11932a6c
NB
42 loop
43 begin
44 Rep;
45 exception
46 when Readline.End_Of_File =>
47 exit;
00c3a3c3
NB
48 when Err.Error =>
49 Ada.Text_IO.Unbounded_IO.Put (Err.Trace);
11932a6c 50 end;
00c3a3c3 51 -- Other exceptions are really unexpected.
5a07bb53
NB
52
53 -- Collect garbage.
8185fe14
NB
54 Err.Data := Types.Nil;
55 -- No data survives at this stage, Repl only contains static
56 -- pointers to built-in functions.
5a07bb53 57 Garbage_Collected.Clean;
11932a6c
NB
58 end loop;
59 Ada.Text_IO.New_Line;
00c3a3c3 60 -- If assertions are enabled, check deallocations.
8185fe14
NB
61 -- Normal runs do not need to deallocate before termination.
62 -- Beware that all pointers are now dangling.
5a07bb53
NB
63 pragma Debug (Garbage_Collected.Clean);
64 Garbage_Collected.Check_Allocations;
cbbb51b4 65end Step1_Read_Print;