summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 20:30:26 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 20:30:26 +0000
commit8a1e32e6a8c441f8358bd580c655d5ff48716fa0 (patch)
tree916964771773b144ba5a4ec7e61ac22860122e99
parentc8867502df27f516b0d46b1a254f0da572bdadb6 (diff)
Handle -d option in prolog
-rw-r--r--builtins.c2
-rw-r--r--dat.h4
-rw-r--r--eval.c4
-rw-r--r--flags.c4
-rw-r--r--main.c8
-rw-r--r--module.c2
-rw-r--r--repl.pl13
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',