diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-08 21:22:06 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-08 21:22:06 +0000 |
commit | e9f5f2ffcc62eee564d37d5776e701bab548a496 (patch) | |
tree | a69763231838ce43e17579aa2f5c6ae2f08694e5 | |
parent | 6dd50f970be88637fd2799ae8e2868c01002898e (diff) |
Make the repl bindings and query global so the garbage collector can know about them
-rw-r--r-- | dat.h | 4 | ||||
-rw-r--r-- | garbage.c | 4 | ||||
-rw-r--r-- | repl.c | 32 |
3 files changed, 26 insertions, 14 deletions
@@ -97,4 +97,6 @@ Goal *goalstack; Module *modules; Module *systemmodule; /* The module for the builtins. Everything has access to those */ Module *usermodule; /* The default module for user defined predicates */ -uvlong clausenr;
\ No newline at end of file +uvlong clausenr; +Binding *replbindings; /* The bindings used by the repl */ +Term *replquery; /* The currently active repl query */
\ No newline at end of file @@ -65,10 +65,14 @@ collectgarbage(void) 1) The modules 2) The goalstack 3) The choicestack + 4) The replbindings + 5) The replquery */ markmodules(); markgoalstack(goalstack); markchoicestack(); + markbindings(replbindings); + markterm(replquery); /* Free the allocations that were not marked as reachable */ for(i = 0; i < TableSize; i++){ @@ -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 |