From 24cdc7adf5611d536403ae625414bb10f3bc4f93 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Tue, 20 Jul 2021 21:58:46 +0000 Subject: Add a new work in progress loader to load all user defined modules --- repl.pl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'repl.pl') diff --git a/repl.pl b/repl.pl index 3706437..92cdffd 100644 --- a/repl.pl +++ b/repl.pl @@ -1,26 +1,27 @@ :- module(repl, []). repl([ProgName|Args]) :- - write('Welcome to p-prolog version 1'), + write('Welcome to p-prolog version 1.'), nl, write('Started with args: '), write(Args), nl, + flush_output, handle_args(Args), repl_loop. handle_arg('-d') :- set_prolog_flag(debug, on). handle_arg(Arg) :- - ( '$load_module_from_file'(Arg) - -> write('Loaded module from file: ') - ; write('Failed to load module from file: ') - ), - write(Arg), nl. + loader:load_module_from_file(Arg). -handle_args([Arg|Rest]) :- handle_arg(Arg), !, handle_args(Rest). +handle_args([Arg|Rest]) :- catch(handle_arg(Arg), E, handle_arg_error(E)), !, handle_args(Rest). handle_args([]). +handle_arg_error(E) :- + write('Could not handle arg: '), + print_exception(E). + repl_loop :- catch(read_eval_print, E, print_exception(E)), '$collect_garbage', -- cgit v1.2.3