From 1c8789198373a52da9e80dc9b2b1ee2b67af61c4 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 16 Jul 2021 00:42:49 +0000 Subject: Make operators local to each module, and implement some more correct prettyprint code, used by write_term --- dat.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'dat.h') diff --git a/dat.h b/dat.h index f2e7e81..b5f6f4f 100644 --- a/dat.h +++ b/dat.h @@ -1,3 +1,6 @@ +#define PrecedenceLevels 1200 + +typedef struct Operator Operator; typedef struct Term Term; typedef struct Binding Binding; typedef struct Goal Goal; @@ -7,6 +10,14 @@ typedef struct Predicate Predicate; typedef struct Module Module; typedef int (*Builtin)(Term *, Binding **, Module *); +struct Operator +{ + int type; + int level; + Rune *spelling; + Operator *next; +}; + struct Term { int tag; @@ -70,9 +81,21 @@ struct Module /* What about imports */ Rune *name; Predicate *predicates; + Operator *operators[PrecedenceLevels]; Module *next; }; +/* Operator types */ +enum { + Xf = 1<<0, /* 1 */ + Yf = 1<<1, /* 2 */ + Xfx = 1<<2, /* 4 */ + Xfy = 1<<3, /* 8 */ + Yfx = 1<<4, /* 16 */ + Fy = 1<<5, /* 32 */ + Fx = 1<<6, /* 64 */ +}; + /* Sorted so that a lower value means it comes earlier in the standard ordering */ enum { VariableTerm, -- cgit v1.2.3