1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/objpascal/step1_read_print.pas
Joel Martin bc6a1f157e ObjPascal: use CTypes for libedit/readline.
Build with USE_READLINE=1 to switch from libedit to readline.
2016-03-14 00:07:01 -05:00

58 lines
979 B
ObjectPascal

program Mal;
{$H+} // Use AnsiString
Uses sysutils,
CMem,
mal_readline,
mal_types,
reader,
printer;
var
Repl_Env : string = '';
Line : string;
// read
function READ(const Str: string) : TMal;
begin
READ := read_str(Str);
end;
// eval
function EVAL(Ast: TMal; Env: string) : TMal;
begin
EVAL := Ast;
end;
// print
function PRINT(Exp: TMal) : string;
begin
PRINT := pr_str(Exp, True);
end;
// repl
function REP(Str: string) : string;
begin
REP := PRINT(EVAL(READ(Str), Repl_Env));
end;
begin
while True do
begin
try
Line := _readline('user> ');
if Line = '' then continue;
WriteLn(REP(Line))
except
On E : MalEOF do Halt(0);
On E : Exception do
begin
WriteLn('Error: ' + E.message);
WriteLn('Backtrace:');
WriteLn(GetBacktrace(E));
end;
end;
end;
end.