shithub: pprolog

ref: 44ab8a339c78bcc3460d44b2f435116f21faa60a
dir: /dat.h/

View raw version
typedef struct Term Term;
typedef struct Binding Binding;
typedef struct Goal Goal;
typedef struct Choicepoint Choicepoint;
typedef struct Clause Clause;
typedef struct Module Module;
typedef int (*Builtin)(Term *, Binding **);

struct Term
{
	int tag;

	Rune *text;
	int arity;
	Term *next;
	Term *children;
	int numbertype;
	vlong ival;
	double dval;
	uvlong clausenr;
};

struct Binding
{
	Rune *name;
	uvlong nr; /* Unique number for each clause. Every time a clause is used, it gets a new number. */
	Term *value;
	Binding *next;
};

struct Goal
{
	Term *goal;
	Term *catcher; /* When this is non-nil, the goal is a catch frame, goal is the recovery. */
	Goal *next;
};

struct Choicepoint
{
	Goal *goalstack;
	Clause *retryclause;
	uvlong id; /* Unique number for each clause. Used to know where to cut to. */
	Module *currentmodule;
	Choicepoint *next;
};

struct Clause
{
	Term *head;
	Term *body;
	uvlong clausenr;
	int public;
	Clause *next;
};

struct Module
{
	/* What about imports */
	Rune *name;
	Clause *clauses;
	Module *next;
};

/* Sorted so that a lower value means it comes earlier in the standard ordering */
enum {
	VariableTerm,
	NumberTerm,
	AtomTerm,
	CompoundTerm,
};

enum {
	NumberFloat,
	NumberInt,
};

int debug;

/* Flags */
enum {
	DoubleQuotesChars,
	DoubleQuotesCodes,
	DoubleQuotesAtom,
};

int flagdoublequotes;

/* State of the running system */
Choicepoint *choicestack;
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 */