Commit | Line | Data |
---|---|---|
36e91db4 DM |
1 | entity step1_read_print is |
2 | end entity step1_read_print; | |
3 | ||
4 | library STD; | |
5 | use STD.textio.all; | |
6 | library WORK; | |
7 | use WORK.pkg_readline.all; | |
8 | use WORK.types.all; | |
9 | use WORK.printer.all; | |
10 | use WORK.reader.all; | |
11 | ||
12 | architecture test of step1_read_print is | |
13 | procedure mal_READ(str: in string; ast: out mal_val_ptr; err: out mal_val_ptr) is | |
14 | begin | |
15 | read_str(str, ast, err); | |
16 | end procedure mal_READ; | |
17 | ||
18 | procedure EVAL(ast: inout mal_val_ptr; env: in string; result: out mal_val_ptr) is | |
19 | begin | |
20 | result := ast; | |
21 | end procedure EVAL; | |
22 | ||
23 | procedure mal_PRINT(exp: inout mal_val_ptr; result: out line) is | |
24 | begin | |
25 | pr_str(exp, true, result); | |
26 | end procedure mal_PRINT; | |
27 | ||
28 | procedure REP(str: in string; result: out line; err: out mal_val_ptr) is | |
29 | variable ast, eval_res, read_err: mal_val_ptr; | |
30 | begin | |
31 | mal_READ(str, ast, read_err); | |
32 | if read_err /= null then | |
33 | err := read_err; | |
34 | result := null; | |
35 | return; | |
36 | end if; | |
37 | if ast = null then | |
38 | result := null; | |
39 | return; | |
40 | end if; | |
41 | EVAL(ast, "", eval_res); | |
42 | mal_PRINT(eval_res, result); | |
43 | end procedure REP; | |
44 | ||
45 | procedure repl is | |
46 | variable is_eof: boolean; | |
47 | variable input_line, result: line; | |
48 | variable err: mal_val_ptr; | |
49 | begin | |
50 | loop | |
51 | mal_readline("user> ", is_eof, input_line); | |
52 | exit when is_eof; | |
53 | next when input_line'length = 0; | |
54 | REP(input_line.all, result, err); | |
55 | if err /= null then | |
56 | pr_str(err, false, result); | |
57 | result := new string'("Error: " & result.all); | |
58 | end if; | |
59 | if result /= null then | |
60 | mal_printline(result.all); | |
61 | end if; | |
62 | deallocate(result); | |
63 | deallocate(err); | |
64 | end loop; | |
65 | mal_printline(""); | |
66 | end procedure repl; | |
67 | ||
68 | begin | |
69 | repl; | |
70 | end architecture test; |