diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-16 20:30:26 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-16 20:30:26 +0000 |
commit | 8a1e32e6a8c441f8358bd580c655d5ff48716fa0 (patch) | |
tree | 916964771773b144ba5a4ec7e61ac22860122e99 | |
parent | c8867502df27f516b0d46b1a254f0da572bdadb6 (diff) |
Handle -d option in prolog
-rw-r--r-- | builtins.c | 2 | ||||
-rw-r--r-- | dat.h | 4 | ||||
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | flags.c | 4 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | module.c | 2 | ||||
-rw-r--r-- | repl.pl | 13 |
7 files changed, 19 insertions, 18 deletions
@@ -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 @@ -105,8 +105,6 @@ enum { CompoundTerm, }; -int debug; - /* Flags */ enum { BoundedTrue, @@ -124,8 +122,8 @@ enum { }; enum { - DebugOn, DebugOff, + DebugOn, }; enum { @@ -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; @@ -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[] = { @@ -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(); @@ -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); } @@ -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', |