aboutsummaryrefslogtreecommitdiff
path: root/ps/step0_repl.ps
blob: d26844c56a5d0dd6a2ea8621b41d33aa07f1bd88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
% read
/_readline { print flush (%stdin) (r) file 99 string readline } def

/READ {
    % just "return" the input string
    /str exch def
    str
} def


% eval
/EVAL {
    % just "return" the "ast"
    /env exch def
    /ast exch def
    ast
} def


% print
/PRINT {
    % just "return" the expression
    /exp exch def
    exp
} def


% repl
/REP { READ (stub env) EVAL PRINT } def

% repl loop
{ %loop
    (user> ) _readline
    not { exit } if  % exit if EOF

    REP print (\n) print
} bind loop

(\n) print  % final newline before exit for cleanliness
quit