shithub: pprolog

ref: 3f316c5c9265618fe7095cc39c4cb10909cbe468
dir: /main.c/

View raw version
#include <u.h>
#include <libc.h>
#include <bio.h>

#include "dat.h"
#include "fns.h"

void usage(void);
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();
	initmodules();
	repl(argc, argv);

	exits(nil);
}

void
usage(void)
{
	fprint(2, "Usage: pprolog [-d] modulefiles\n");
	exits("Usage");
}

void
repl(int argc, char *argv[])
{
	Term *args = nil;
	while(argc > 0){
		Term *arg = mkatom(runesmprint("%s", argv[argc-1]));
		args = appendterm(arg, args);
		argc--;
	}
	args = mklist(args);
	Term *mod = mkatom(L"repl");
	Term *pred = mkcompound(L"repl", 1, args);

	mod->next = pred;
	Term *goal = mkcompound(L":", 2, mod);
	evalquery(goal);	
}