Commit | Line | Data |
---|---|---|
13ce1681 CM |
1 | with Ada.Command_Line; |
2 | with Ada.Exceptions; | |
3 | with Ada.Text_IO; | |
4 | with Ada.IO_Exceptions; | |
0571a45f | 5 | with Core; |
13ce1681 CM |
6 | with Envs; |
7 | with Evaluation; | |
8 | with Printer; | |
9 | with Reader; | |
10 | with Types; | |
11 | ||
12 | procedure Step4_If_Fn_Do is | |
13 | ||
14 | function Read (Param : String) return Types.Mal_Handle is | |
15 | begin | |
16 | return Reader.Read_Str (Param); | |
17 | end Read; | |
18 | ||
19 | ||
20 | -- Eval can't be here because there are function pointers that point | |
21 | -- at it. Thus it must be at library level. See evaluation.ads | |
22 | ||
23 | ||
24 | function Print (Param : Types.Mal_Handle) return String is | |
25 | begin | |
26 | return Printer.Pr_Str (Param); | |
27 | end Print; | |
28 | ||
29 | function Rep (Param : String) return String is | |
30 | AST, Evaluated_AST : Types.Mal_Handle; | |
31 | begin | |
32 | ||
33 | AST := Read (Param); | |
34 | ||
35 | if Types.Is_Null (AST) then | |
36 | return ""; | |
37 | else | |
38 | Evaluated_AST := Evaluation.Eval (AST, Envs.Get_Current); | |
39 | return Print (Evaluated_AST); | |
40 | end if; | |
41 | ||
42 | end Rep; | |
43 | ||
44 | S : String (1..Reader.Max_Line_Len); | |
45 | Last : Natural; | |
46 | Cmd_Args : Natural; | |
47 | ||
48 | begin | |
49 | ||
50 | Cmd_Args := 0; | |
51 | while Ada.Command_Line.Argument_Count > Cmd_Args loop | |
52 | Cmd_Args := Cmd_Args + 1; | |
53 | if Ada.Command_Line.Argument (Cmd_Args) = "-d" then | |
54 | Evaluation.Debug := True; | |
55 | elsif Ada.Command_Line.Argument (Cmd_Args) = "-e" then | |
56 | Envs.Debug := True; | |
57 | end if; | |
58 | end loop; | |
59 | ||
0571a45f | 60 | Core.Init; |
13ce1681 | 61 | |
9d466456 CM |
62 | Ada.Text_IO.Put_Line (Rep ("(def! not (fn* (a) (if a false true)))")); |
63 | ||
13ce1681 CM |
64 | loop |
65 | begin | |
66 | Ada.Text_IO.Put ("user> "); | |
67 | Ada.Text_IO.Get_Line (S, Last); | |
68 | Ada.Text_IO.Put_Line (Rep (S (1..Last))); | |
69 | exception | |
70 | when Ada.IO_Exceptions.End_Error => raise; | |
71 | when E : others => | |
72 | Ada.Text_IO.Put_Line | |
73 | (Ada.Text_IO.Standard_Error, | |
74 | Ada.Exceptions.Exception_Information (E)); | |
75 | end; | |
76 | end loop; | |
77 | ||
78 | exception | |
79 | when Ada.IO_Exceptions.End_Error => null; | |
80 | -- i.e. exit without textual output | |
81 | end Step4_If_Fn_Do; |