shithub: pprolog

ref: 66a7040df6897e60ee1a513b95f4b04e687bbf0a
dir: /dat.h/

View raw version
typedef struct Term Term;
typedef struct Binding Binding;
typedef struct Goal Goal;
typedef struct Choicepoint Choicepoint;
typedef int (*Builtin)(Term *, Term *, Goal **, 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;
	Term *retryclause;
	uvlong id; /* Unique number for each clause. Used to know where to cut to. */
	Choicepoint *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;
Term *initgoals;

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

int flagdoublequotes;

/* Staate of the running system */
Choicepoint *choicestack;