1 #ifndef PL_YAP_H
2 #define PL_YAP_H
3
4 #ifdef __YAP_PROLOG__
5
6 #if HAVE_CTYPE_H
7 #include <ctype.h>
8 #endif
9
10 #define SIZE_VOIDP SIZEOF_INT_P
11
12 #if SIZE_DOUBLE==SIZEOF_INT_P
13 #define WORDS_PER_DOUBLE 1
14 #else
15 #define WORDS_PER_DOUBLE 2
16 #endif
17
18 #if SIZEOF_LONG_INT==4
19 #define INT64_FORMAT "%lld"
20 #define INTBITSIZE 32
21 #else
22 #define INT64_FORMAT "%ld"
23 #define INTBITSIZE 64
24 #endif
25
26 typedef uintptr_t word; /* Anonymous 4 byte object */
27 typedef YAP_Term Word; /* Anonymous 4 byte object */
28 typedef YAP_Atom Atom;
29 //move this to SWI
30
31 typedef uintptr_t PL_atomic_t; /* same a word */
32
33 /*** memory allocation stuff: SWI wraps around malloc */
34
35 #define allocHeap(X) YAP_AllocSpaceFromYap(X)
36
37 #define freeHeap(X,Size) YAP_FreeSpaceFromYap(X)
38
39
40 #define stopItimer()
41
42 /* TBD */
43
44 extern atom_t codeToAtom(int chrcode);
45
46 extern word globalString(size_t size, char *s);
47 extern word globalWString(size_t size, wchar_t *s);
48
49 static inline word
INIT_SEQ_CODES(size_t n)50 INIT_SEQ_CODES(size_t n)
51 {
52 return (word)YAP_OpenList(n);
53 }
54
55 static inline word
EXTEND_SEQ_CODES(word gstore,int c)56 EXTEND_SEQ_CODES(word gstore, int c) {
57 return (word)YAP_ExtendList((YAP_Term)gstore, YAP_MkIntTerm(c));
58 }
59
60 static inline word
EXTEND_SEQ_ATOMS(word gstore,int c)61 EXTEND_SEQ_ATOMS(word gstore, int c) {
62 return (word)YAP_ExtendList((YAP_Term)gstore, codeToAtom(c));
63 }
64
65 static inline int
CLOSE_SEQ_OF_CODES(word gstore,word lp,word arg2,word arg3,term_t l)66 CLOSE_SEQ_OF_CODES(word gstore, word lp, word arg2, word arg3, term_t l) {
67 if (arg2 == 0) {
68 if (!YAP_CloseList((YAP_Term)gstore, YAP_TermNil()))
69 return FALSE;
70 } else {
71 if (!YAP_CloseList((YAP_Term)gstore, YAP_GetFromSlot(arg2)))
72 return FALSE;
73 }
74 return YAP_Unify(YAP_GetFromSlot(arg3), lp);
75 }
76
77 static inline Word
valHandle(term_t tt)78 valHandle(term_t tt)
79 {
80 return (word)YAP_GetFromSlot(tt);
81 }
82
83 YAP_Int YAP_PLArityOfSWIFunctor(functor_t f);
84
85 #define arityFunctor(f) YAP_PLArityOfSWIFunctor(f)
86
87 #define stringAtom(w) YAP_AtomName((YAP_Atom)(w))
88 #define isInteger(A) (YAP_IsIntTerm((A)) && YAP_IsBigNumTerm((A)))
89 #define isString(A) FALSE
90 #define isAtom(A) YAP_IsAtomTerm((A))
91 #define isList(A) YAP_IsPairTerm((A))
92 #define isNil(A) ((A) == YAP_TermNil())
93 #define isReal(A) YAP_IsFloatTerm((A))
94 #define isFloat(A) YAP_IsFloatTerm((A))
95 #define isVar(A) YAP_IsVarTerm((A))
96 #define varName(l, buf) buf
97 #define valReal(w) YAP_FloatOfTerm((w))
98 #define valFloat(w) YAP_FloatOfTerm((w))
99 #define AtomLength(w) YAP_AtomNameLength(w)
100 #define atomValue(atom) YAP_AtomOfTerm(atom)
101 #define argTermP(w,i) ((Word)((YAP_ArgsOfTerm(w)+(i))))
102 #define deRef(t) (t = YAP_Deref(t))
103 #define canBind(t) FALSE
104
105 #define clearNumber(n)
106
107 #endif /* __YAP_PROLOG__ */
108
109 #if IN_PL_OS_C
110 static int
stripostfix(const char * s,const char * e)111 stripostfix(const char *s, const char *e)
112 { size_t ls = strlen(s);
113 size_t le = strlen(e);
114
115 if ( ls >= le )
116 return strcasecmp(&s[ls-le], e) == 0;
117
118 return FALSE;
119 }
120 #endif
121
122 #define ERR_NO_ERROR 0
123 #define ERR_INSTANTIATION 1 /* void */
124 #define ERR_TYPE 2 /* atom_t expected, term_t value */
125 #define ERR_DOMAIN 3 /* atom_t domain, term_t value */
126 #define ERR_REPRESENTATION 4 /* atom_t what */
127 #define ERR_MODIFY_STATIC_PROC 5 /* predicate_t proc */
128 #define ERR_EVALUATION 6 /* atom_t what */
129 #define ERR_AR_TYPE 7 /* atom_t expected, Number value */
130 #define ERR_NOT_EVALUABLE 8 /* functor_t func */
131 #define ERR_DIV_BY_ZERO 9 /* void */
132 #define ERR_FAILED 10 /* predicate_t proc */
133 #define ERR_FILE_OPERATION 11 /* atom_t action, atom_t type, term_t */
134 #define ERR_PERMISSION 12 /* atom_t type, atom_t op, term_t obj*/
135 #define ERR_NOT_IMPLEMENTED 13 /* const char *what */
136 #define ERR_EXISTENCE 14 /* atom_t type, term_t obj */
137 #define ERR_STREAM_OP 15 /* atom_t action, term_t obj */
138 #define ERR_RESOURCE 16 /* atom_t resource */
139 #define ERR_NOMEM 17 /* void */
140 #define ERR_SYSCALL 18 /* void */
141 #define ERR_SHELL_FAILED 19 /* term_t command */
142 #define ERR_SHELL_SIGNALLED 20 /* term_t command, int signal */
143 #define ERR_AR_UNDEF 21 /* void */
144 #define ERR_AR_OVERFLOW 22 /* void */
145 #define ERR_AR_UNDERFLOW 23 /* void */
146 #define ERR_UNDEFINED_PROC 24 /* Definition def */
147 #define ERR_SIGNALLED 25 /* int sig, char *name */
148 #define ERR_CLOSED_STREAM 26 /* IOSTREAM * */
149 #define ERR_BUSY 27 /* mutexes */
150 #define ERR_PERMISSION_PROC 28 /* op, type, Definition */
151 #define ERR_DDE_OP 29 /* op, error */
152 #define ERR_SYNTAX 30 /* what */
153 #define ERR_SHARED_OBJECT_OP 31 /* op, error */
154 #define ERR_TIMEOUT 32 /* op, object */
155 #define ERR_NOT_IMPLEMENTED_PROC 33 /* name, arity */
156 #define ERR_FORMAT 34 /* message */
157 #define ERR_FORMAT_ARG 35 /* seq, term */
158 #define ERR_OCCURS_CHECK 36 /* Word, Word */
159 #define ERR_CHARS_TYPE 37 /* char *, term */
160 #define ERR_MUST_BE_VAR 38 /* int argn, term_t term */
161
162 #endif /* PL_YAP_H */
163