~eshel/eshellisp

2b52b2e919bc8ef6e2d635dbb80f9088ff625c54 — Eshel Yaron 2 years ago 1a56b97 main
Enhanched exception formatting
3 files changed, 23 insertions(+), 19 deletions(-)

M prolog/eshellisp/eval.pl
M prolog/eshellisp/main.pl
M prolog/eshellisp/write.pl
M prolog/eshellisp/eval.pl => prolog/eshellisp/eval.pl +12 -12
@@ 19,7 19,7 @@ evaluate_program(Forms, File, Layout, Vars, Value0, Value) :-
    evaluate_forms(Forms, File, Layout, Vars, Value0, Value, _).


evaluate_forms(_, _, _, _, exception(What, Where), exception(What, Where), []) :-
evaluate_forms(_, _, _, _, exception(What, Who, Where), exception(What, Who, Where), []) :-
    !.
evaluate_forms([H|T], File, Layouts, Vars, Value0, Value, [Value1|RT]) :-
    !,


@@ 32,7 32,7 @@ evaluate_forms([], _, _, _, Value, Value, []).
evaluate_form(Form, Value) :-
    evaluate_form(Form, dyn, dyn, [], '#f', Value).

evaluate_form(_, File, Layout, _, exception(What, Where), exception(What, [File:Layout|Where])) :- !.
evaluate_form(_, File, Layout, _, exception(What, Who, Where), exception(What, Who, [File:Layout|Where])) :- !.
evaluate_form([import, SpecList], File, Layout, Vars, Value0, Value) :-
    !,
    Spec =.. SpecList,


@@ 42,7 42,7 @@ evaluate_form([import, SpecList], File, Layout, Vars, Value0, Value) :-
    ->  read_program(file(Path), Program, [positions(Positions)]),
        evaluate_program(Program, Path, Positions, Vars, Value0, Value)
    ;   sub_layout(2, Layout, SpecLayout),
        Value = exception(import_error(Spec), [File:SpecLayout])
        Value = exception(import_error, Spec, [File:SpecLayout])
    ).
evaluate_form([define, Name, Args | Body], File, Layout, _, _, quote(Name)) :-
    !,


@@ 65,8 65,8 @@ evaluate_form([Name | Args], File, Layout, Vars, Value0, Value) :-
    sub_layout(1, Layout, PName),
    sub_layouts(1, Layout, PArgs),
    evaluate_forms(Args, File, PArgs, Vars, Value0, Value1, Vals),
    (   Value1 = exception(What, Where)
    ->  Value  = exception(What, [File:Layout|Where])
    (   Value1 = exception(What, Who, Where)
    ->  Value  = exception(What, Who, [File:Layout|Where])
    ;   defined(Name, A, Body, F, P)
    ->  (   maplist([Arg,Val,Arg=Val]>>true, A, Vals, Vars1)
        ->  append(Vars1, Vars, Vars2),


@@ 74,11 74,11 @@ evaluate_form([Name | Args], File, Layout, Vars, Value0, Value) :-
        ;   Value = Value1
        )
    ;   primitive(Name, Vals, Value2)
    ->  (   Value2 = exception(What)
        ->  Value  = exception(What, [File:PName])
    ->  (   Value2 = exception(What, Who)
        ->  Value  = exception(What, Who, [File:PName])
        ;   Value  = Value2
        )
    ;   Value = exception(no_such_function(Name), [File:PName])
    ;   Value = exception(no_such_function, Name, [File:PName])
    ).
evaluate_form(quote(E), _, _, _, _, E) :- !.
evaluate_form('#t', _, _, _, _, '#t') :- !.


@@ 95,7 95,7 @@ evaluate_form(Symbol, File, Layout, Vars, _, Value) :-
    !,
    (   memberchk(Symbol=Value, Vars)
    ->  true
    ;   Value = exception(no_such_symbol(Symbol), [File:Layout])
    ;   Value = exception(no_such_symbol, Symbol, [File:Layout])
    ).




@@ 109,14 109,14 @@ primitive('equal?', [_, _], '#f') :- !.
primitive('read',   []    , O) :- !, read_form(O).
primitive('eval',   [O]   , R) :- !, evaluate_form(O, R).
primitive('write',  [O]   , '#t') :- !, write_form(O).
primitive('raise',  [O]   , exception(O)) :- !.
primitive('raise',  [O]   , exception(raise, O)) :- !.
primitive('pair?',  [[_|_]], '#t') :- !.
primitive('pair?',  [_]   , '#f') :- !.
primitive('cons',   [H,T] , [H|T]) :- !.
primitive('car',    [[H|_]] , H) :- !.
primitive('car',    [O] , exception(no_cons(O))) :- !.
primitive('car',    [O] , exception(no_cons, O)) :- !.
primitive('cdr',    [[_|T]] , T) :- !.
primitive('cdr',    [O] , exception(no_cons(O))) :- !.
primitive('cdr',    [O] , exception(no_cons, O)) :- !.




M prolog/eshellisp/main.pl => prolog/eshellisp/main.pl +1 -1
@@ 25,7 25,7 @@ main(Argv) :-
        ->  show_help(OptsSpec)
        ;   read_program(file(Path), Program, [positions(Positions)]),
            evaluate_program(Program, Path, Positions, Value),
            (   Value = exception(_What, _Where)
            (   Value = exception(_What, _Who, _Where)
            ->  write_form(Value), halt(1)
            ;   halt(0)
            )

M prolog/eshellisp/write.pl => prolog/eshellisp/write.pl +10 -6
@@ 14,9 14,9 @@ prolog:message(eshellisp(Value)) -->
    form(Value).


form(exception(What, [H|T])) -->
form(exception(What, Who, [H|T])) -->
    !,
    exception(What, H),
    exception(What, Who, H),
    stack(T).
form(quote(Value)) -->
    !,


@@ 53,13 53,17 @@ cdr(Form) -->
    [ ')'-[] ].


exception(What, dyn:dyn) -->
exception(What, Who, dyn:dyn) -->
    !,
    [ 'Exception ~w'-[What] ].
exception(What, Path:layout(position(Line, Column, _), _, _)) -->
    [ 'Exception ~w('-[What] ],
    form(Who),
    [ ')'-[] ].
exception(What, Who, Path:layout(position(Line, Column, _), _, _)) -->
    !,
    { absolute_file_name(Path, Abs) },
    [ 'Exception ~w at '-[What], url(Abs:Line:Column) ].
    [ 'Exception ~w('-[What] ],
    form(Who),
    [ ') at '-[], url(Abs:Line:Column) ].

stack([dyn:dyn|T]) -->
    !,