diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-22 21:54:46 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-22 21:54:46 +0000 |
commit | 48da622d4ad0b4acfe9005dd318ac3f20b4e8672 (patch) | |
tree | 9eed593702dc2fbd7f93689f53605241560f51e9 /loader.pl | |
parent | 0f347162b74d945f509955b6c57e506ab800db7b (diff) |
Big commit changing the way the system is loaded at startup.
1) The loader and system modules are loaded by the C directly into the user module
2) The system module is then loaded with the loader from the user module
3) The loader module is then loaded with the loader from the user module
4) The repl is then loaded with the loader from the loader module
5) The user module is cleared
Diffstat (limited to 'loader.pl')
-rw-r--r-- | loader.pl | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -1,14 +1,29 @@ :- module(loader, []). start(Args) :- - catch((load_module_from_file('/sys/lib/prolog/repl.pl'), ReplLoaded = true), E, (print_exception(E), ReplLoaded = false)), - !, - ( ReplLoaded = true - -> repl:repl(Args) + ( bootstrap([system, loader, repl]) + -> call(repl:repl(Args)) + ; write('Booting pprolog failed..'), halt ). -print_exception(E) :- - write('Caught exception while loading /sys/lib/prolog/repl.pl: '), +bootstrap([]) :- '$delete_module'(user), '$new_empty_module'(user). +bootstrap([Mod|Mods]) :- + system_mod_path(Mod, File), + catch(load_module_from_file(File), E, (print_exception(File, E), fail)), + ( Mod == system + -> '$activate_system_module' + ; true + ), + bootstrap(Mods). + +system_mod_path(Mod, Path) :- + atom_concat('/sys/lib/prolog/', Mod, Path0), + atom_concat(Path0, '.pl', Path). + +print_exception(File, E) :- + write('Caught exception while loading '), + write(File), + write(': '), write(E), nl. @@ -25,7 +40,8 @@ load_module_from_file(File) :- run_initialization_goals(Module) :- ( retract(initialization_goals(Module, Goal)), catch(Module:Goal, E, print_initialization_goal_error(Module, Goal, E)), - fail % Backtrack to find more goals + !, + run_initialization_goals(Module) ; true ). @@ -89,7 +105,7 @@ handle_term(Head, Singles, Module, Module) :- handle_clause(Head, Body, Singletons, Module) :- functor(Head, Name, Arity), PredicateIndicator = Name / Arity, - warn_singletons(PredicateIndicator, Singletons), + warn_singletons(PredicateIndicator, Module, Singletons), Module:'$insert_clause'(Head :- Body). handle_directive(dynamic(PI), Module, Module) :- @@ -125,15 +141,17 @@ handle_directive(D, Module, Module) :- write(D), nl. -warn_singletons(_, []). -warn_singletons(PI, Singles) :- - write('Warning: singleton variables in '), - write(PI), - write(': '), +warn_singletons(_, Module, []). +warn_singletons(PI, Module, Singles) :- + write('Warning: singleton variables '), write(Singles), + write(' in '), + write(Module:PI), write('.'), nl. + +:- dynamic(ensure_loads/1). ensure_loads(_) :- fail. ensure_load(F) :- |