summaryrefslogtreecommitdiff
path: root/repl.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 15:25:01 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 15:25:01 +0000
commit480de114963ecee700ece5b8793916726c04b9ab (patch)
tree9c1543307aef92c1c88289a4d07ad4dcbae6b38c /repl.c
parentee65a81ee5b0112ba4480619ca672c569fb28b45 (diff)
Replace the C repl with one written in prolog :)
Diffstat (limited to 'repl.c')
-rw-r--r--repl.c87
1 files changed, 0 insertions, 87 deletions
diff --git a/repl.c b/repl.c
deleted file mode 100644
index 5e619f7..0000000
--- a/repl.c
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-
-#include "dat.h"
-#include "fns.h"
-
-Rune parsefindmore(int);
-void dogc(void);
-
-void
-repl(void)
-{
- int fd = 0; /* Standard input */
- while(1){
- print("?- ");
- replquery = parse(fd, nil, 1);
- replbindings = nil;
- choicestack = nil;
- goalstack = nil;
- int success;
- int firsttime = 1;
-FindMore:
- success = evalquery(replquery, &replbindings);
- dogc();
- if(firsttime){
- print(" ");
- firsttime = 0;
- }
- if(success == 0)
- print(" false.\n");
- else{
- if(replbindings == nil)
- print(" true");
- else{
- while(replbindings){
- print(" %S = %S%s",
- replbindings->name,
- prettyprint(replbindings->value, 0, 0, 0, nil),
- replbindings->next ? ",\n " : "");
- replbindings = replbindings->next;
- }
- }
- if(choicestack != nil){
- print("\n");
- if(parsefindmore(fd) == L';'){
- print(";");
- goto FindMore;
- }else
- print(".\n");
- }else{
- print(".\n");
- }
- }
- }
-}
-
-Rune
-parsefindmore(int fd)
-{
- int consctl = open("/dev/consctl", OWRITE);
- if(consctl > 0)
- write(consctl, "rawon", 5);
- else{
- print("Could not open /dev/consctl\n");
- exits("open");
- }
-
- fd = dup(fd, -1);
- Biobuf *input = Bfdopen(fd, OREAD);
- Rune peek = Bgetrune(input);
- Bterm(input);
-
- if(consctl > 0){
- write(consctl, "rawoff", 6);
- 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