From 8a1e32e6a8c441f8358bd580c655d5ff48716fa0 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 16 Jul 2021 20:30:26 +0000 Subject: Handle -d option in prolog --- builtins.c | 2 +- dat.h | 4 +--- eval.c | 4 ++-- flags.c | 4 ++-- main.c | 8 -------- module.c | 2 +- repl.pl | 13 ++++++++++++- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/builtins.c b/builtins.c index 74b1bc4..d723e7c 100644 --- a/builtins.c +++ b/builtins.c @@ -1418,7 +1418,7 @@ builtincollectgarbage(Term *goal, Binding **bindings, Module *module) USED(bindings); USED(module); vlong amount = collectgarbage(); - if(amount != 0 & debug) + if(amount != 0 & flagdebug) print("Collected %lld bytes of garbage\n", amount); return 1; } \ No newline at end of file diff --git a/dat.h b/dat.h index 5cf3001..d634435 100644 --- a/dat.h +++ b/dat.h @@ -105,8 +105,6 @@ enum { CompoundTerm, }; -int debug; - /* Flags */ enum { BoundedTrue, @@ -124,8 +122,8 @@ enum { }; enum { - DebugOn, DebugOff, + DebugOn, }; enum { diff --git a/eval.c b/eval.c index f957553..09bb009 100644 --- a/eval.c +++ b/eval.c @@ -25,7 +25,7 @@ evalquery(Term *query) if(catcher) continue; - if(debug) + if(flagdebug) print("Working goal: %S:%S\n", module->name, prettyprint(goal, 0, 0, 0, nil)); Binding *bindings = nil; @@ -76,7 +76,7 @@ evalquery(Term *query) Backtrack: if(choicestack == nil) return 0; - if(debug) + if(flagdebug) print("Backtracking..\n"); Choicepoint *cp = choicestack; choicestack = cp->next; diff --git a/flags.c b/flags.c index c8e872d..8181cdd 100644 --- a/flags.c +++ b/flags.c @@ -26,8 +26,8 @@ static Rune *charconversionvals[] = { }; static Rune *debugvals[] = { - [DebugOn] = L"on", - [DebugOff] = L"off" + [DebugOff] = L"off", + [DebugOn] = L"on" }; static Rune *unknownvals[] = { diff --git a/main.c b/main.c index f546384..f83fe89 100644 --- a/main.c +++ b/main.c @@ -11,14 +11,6 @@ void repl(int, char **); void main(int argc, char *argv[]) { - ARGBEGIN{ - case 'd': - debug = 1; - break; - default: - usage(); - }ARGEND - clausenr = 2; /* Start at two since 0 is for the facts in the database, and 1 is for queries */ initflags(); initstreams(); diff --git a/module.c b/module.c index 7d23f85..5a74c1d 100644 --- a/module.c +++ b/module.c @@ -51,7 +51,7 @@ parsemodule(char *file) print("Module name should be an atom in: %S\n", prettyprint(directive, 0, 0, 0, nil)); return nil; } - if(debug) + if(flagdebug) print("Public list for module '%S': %S\n", modulename->text, prettyprint(publiclist, 0, 0, 0, nil)); m = getmodule(modulename->text); } diff --git a/repl.pl b/repl.pl index 1a2087a..a936535 100644 --- a/repl.pl +++ b/repl.pl @@ -1,13 +1,24 @@ :- module(repl, []). -repl(Args) :- +repl([ProgName|Args]) :- write('Welcome to p-prolog version 1'), nl, write('Started with args: '), write(Args), nl, + handle_args(Args), repl_loop. +handle_arg('-d') :- + set_prolog_flag(debug, on). +handle_arg(Arg) :- + write('Unhandled command line argument: '), + writeq(Arg), + nl. + +handle_args([Arg|Rest]) :- handle_arg(Arg), !, handle_args(Rest). +handle_args([]). + repl_loop :- catch(read_eval_print, E, print_exception(E)), '$collect_garbage', -- cgit v1.2.3