:- dynamic(disabled_init_file/0).
:- dynamic(started/0).
+:- dynamic(custom_toplevel/1).
load_scryerrc :-
( '$home_directory'(HomeDir) ->
; true
),
(\+ disabled_init_file -> load_scryerrc ; true),
- repl.
+ start_toplevel.
+
+start_toplevel :-
+ ( custom_toplevel(Goal) ->
+ user:call(Goal)
+ ; repl
+ ).
args_consults_goals([], [], []).
args_consults_goals([Arg|Args], Consults, Goals) :-
args_consults_goals(Goals1, Consults, Goals),
run_goals(Consults),
run_goals(Goals),
- repl.
+ start_toplevel.
delegate_task([Arg0|Args], Goals0) :-
( ( member(Arg0, ["-h", "--help"]) -> print_help
; member(Arg0, ["-v", "--version"]) -> print_version
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
+ ; member(Arg0, ["-t"]) -> gather_toplevel(Args, Goals0)
; member(Arg0, ["-f"]) -> disable_init_file
; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg
),
write('Print version information and exit'), nl,
write(' -g, --goal GOAL '),
write('Run the query GOAL'), nl,
+ write(' -t GOAL '),
+ write('Use GOAL as custom toplevel (arity 0 predicate)'), nl,
write(' -f '),
write('Fast startup. Do not load initialization file (~/.scryerrc)'), nl,
write(' --no-add-history '),
Gs =.. [Type, Gs1],
delegate_task(Args, [Gs|Goals]).
+gather_toplevel(Args0, Goals0) :-
+ length(Args0, N),
+ ( N < 1 -> print_help, halt
+ ; true
+ ),
+ [TopLevel|Args] = Args0,
+ atom_chars(Goal, TopLevel),
+ retractall(custom_toplevel(_)),
+ asserta(custom_toplevel(Goal)),
+ delegate_task(Args, Goals0).
+
disable_init_file :-
asserta('disabled_init_file').
Exception,
( write_term(Goal, [variable_names(VNs),double_quotes(DQ)]),
write(' causes: '),
- write_term(Exception, [double_quotes(DQ)]), nl % halt?
+ write_term(Exception, [double_quotes(DQ)]), nl
)
) -> true
; write('% Warning: initialization failed for: '),