1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/objpascal/step0_repl.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

48 lines
704 B
ObjectPascal

program Mal;
{$H+} // Use AnsiString
Uses CMem,
mal_readline;
var
Repl_Env: string = '';
Line : string;
// read
function READ(const Str: string) : string;
begin
READ := Str;
end;
// eval
function EVAL(Ast: string; Env: string) : string;
begin
EVAL := Ast;
end;
// print
function PRINT(Exp: string) : string;
begin
PRINT := Exp;
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);
end;
end;
end.