summaryrefslogtreecommitdiff
path: root/repl.c
diff options
context:
space:
mode:
Diffstat (limited to 'repl.c')
-rw-r--r--repl.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/repl.c b/repl.c
index 14e833c..8127184 100644
--- a/repl.c
+++ b/repl.c
@@ -6,6 +6,7 @@
#include "fns.h"
Rune parsefindmore(int);
+void dogc(void);
void
repl(void)
@@ -13,14 +14,15 @@ repl(void)
int fd = 0; /* Standard input */
while(1){
print("?- ");
- Term *query = parse(fd, nil, 1);
- Binding *bindings = nil;
+ replquery = parse(fd, nil, 1);
+ replbindings = nil;
choicestack = nil;
goalstack = nil;
int success;
int firsttime = 1;
FindMore:
- success = evalquery(query, &bindings);
+ success = evalquery(replquery, &replbindings);
+ dogc();
if(firsttime){
print(" ");
firsttime = 0;
@@ -28,15 +30,15 @@ FindMore:
if(success == 0)
print(" false.\n");
else{
- if(bindings == nil)
+ if(replbindings == nil)
print(" true");
else{
- while(bindings){
+ while(replbindings){
print(" %S = %S%s",
- bindings->name,
- prettyprint(bindings->value, 0, 0, 0),
- bindings->next ? ",\n " : "");
- bindings = bindings->next;
+ replbindings->name,
+ prettyprint(replbindings->value, 0, 0, 0),
+ replbindings->next ? ",\n " : "");
+ replbindings = replbindings->next;
}
}
if(choicestack != nil){
@@ -50,10 +52,6 @@ FindMore:
print(".\n");
}
}
-
- vlong amount = collectgarbage();
- if(amount != 0)
- print("Collected %lld bytes of garbage\n", amount);
}
}
@@ -78,4 +76,12 @@ parsefindmore(int fd)
close(consctl);
}
return peek;
+}
+
+void
+dogc(void)
+{
+ vlong amount = collectgarbage();
+ if(amount != 0 && debug)
+ print("Collected %lld bytes of garbage\n", amount);
} \ No newline at end of file