YAP 7.1.0
YapDefs.h
1/*************************************************************************
2 * *
3 * YAP Prolog @(#)c_interface.h 2.2 *
4 * Yap Prolog was developed at NCCUP - Universidade do Porto *
5 * *
6 * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
7 * *
8 **************************************************************************
9 * *
10 * File: yap_structs.h *
11 * Last rev: 15/5/2000 *
12 * mods: *
13 * comments: Data structures and defines used in the Interface *
14 * *
15 *************************************************************************/
16
17#ifndef _YAPDEFS_H
18
19#define _YAPDEFS_H 1
20
21#include "YapConfig.h"
22#if HAVE_SETJMP_H
23#include <setjmp.h>
24#endif
25
36#if _WIN32
37#if defined(_EXPORT_KERNEL)
38// __declspec(dllexport)
39#define X_API
40#else
41// __declspec(dllimport)
42#define X_API
43#endif
44// __declspec(dllexport)
45#define O_API
46// __declspec(dllimport)
47#define I_API
48#else
49#define O_API
50#define I_API
51#define X_API
52#endif
53
54#include <stdio.h>
55#include <stdlib.h>
56
57/* The YAP main types */
58#include "YapTerm.h"
59
60#if HAVE_STDINT_H
61#include <stdint.h>
62#endif
63#if HAVE_INTTYPES_H
64#include <inttypes.h>
65#endif
66#if HAVE_NORETURNSTD_H
67#include <noreturnstd.h>
68#endif
69
74#ifndef TRUE
75#define TRUE true
76#endif
77#ifndef FALSE
78#define FALSE false
79#endif
80#ifndef YAP_Bool
81typedef bool YAP_Bool;
82#endif
83
88#define TermZERO ((Term)0)
89
90
91typedef void *YAP_PredEntryPtr;
92
93typedef size_t YAP_Arity;
94
95typedef YAP_Term YAP_Module;
96
97typedef YAP_Int YAP_handle_t;
98
99typedef void *YAP_PredEntryPtr;
100
101typedef YAP_Bool (*YAP_UserCPred)(void);
102
103typedef int (*YAP_agc_hook)(void *_Atom);
104
105#include "YapError.h"
106
107#include "../os/encoding.h"
108
109typedef encoding_t YAP_encoding_t;
110
111#if __ANDROID__
112#include <android/asset_manager.h>
113#include <android/native_activity.h>
114#endif
115
117 size_t ssize;
118 size_t tsize;
119 size_t sysize;
120 int (*cancel)(int thread);
121 YAP_Term egoal, alias;
123
124#ifdef YAP_H
125#include <threads.h>
126
127#endif
128
129typedef enum {
130YAP_OBJ = 0x0008,
131 YAP_PL = 0x0010,
132 YAP_SOURCE_PL = 0x0030,
133 YAP_QLY = 0x0040,
134 YAP_EXE = 0x0080,
135 YAP_FOUND_BOOT_ERROR = 0x0100,
136 YAP_DIR = 0x0200
137} YAP_file_type_t;
138
139
140#define YAP_ANY_FILE (0x00ff)
141
142typedef enum {
143 YAP_TAG_ATT = 0x1,
144 YAP_TAG_UNBOUND = 0x2,
145 YAP_TAG_REF = 0x4,
146 YAP_TAG_PAIR = 0x8,
147 YAP_TAG_ATOM = 0x10,
148 YAP_TAG_INT = 0x20,
149 YAP_TAG_LONG_INT = 0x40,
150 YAP_TAG_BIG_INT = 0x80,
151 YAP_TAG_RATIONAL = 0x100,
152 YAP_TAG_FLOAT = 0x200,
153 YAP_TAG_OPAQUE = 0x400,
154 YAP_TAG_APPL = 0x800,
155 YAP_TAG_DBREF = 0x1000,
156 YAP_TAG_STRING = 0x2000,
157 YAP_TAG_ARRAY = 0x4000
158} YAP_tag_t;
159#define YAP_BOOT_FROM_SAVED_CODE 1
160#define YAP_BOOT_FROM_SAVED_STACKS 2
161#define YAP_BOOT_ERROR -1
162
163#define YAP_WRITE_QUOTED 1
164#define YAP_WRITE_IGNORE_OPS 2
165#define YAP_WRITE_HANDLE_VARS 4
166#define YAP_WRITE_USE_PORTRAY 8
167#define YAP_WRITE_HANDLE_CYCLES 0x20
168#define YAP_WRITE_BACKQUOTE_STRING 0x80
169#define YAP_WRITE_ATTVAR_NONE 0x100
170#define YAP_WRITE_ATTVAR_DOTS 0x200
171#define YAP_WRITE_ATTVAR_PORTRAY 0x400
172#define YAP_WRITE_BLOB_PORTRAY 0x800
173
174#define YAP_CONSULT_MODE 0
175#define YAP_RECONSULT_MODE 1
176#define YAP_BOOT_MODE 2
177
178X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
179 int Argc, char *Argv[]);
180
181#include "YapInit.h"
182
183
184/* this should be opaque to the user */
185typedef struct {
186 unsigned long b0; //> choice-point before entry
187 unsigned long b_entry; //> choice-point at entry
188 unsigned long b_exit; //> choice-point at exit
189 unsigned long env0; //>environment at entry
190 unsigned long h; //> HR at entry
191 unsigned long tr; //> TR at entry
192 YAP_handle_t CurSlot; //> variables at entry
193 YAP_handle_t EndSlot; //> variables at successful execution
194 struct yami *p; //> Program Counter at entry
195 struct yami *cp; //> Continuation PC at entry
196 int lvl; //> Memory allocator.
198
199// query manipulation support
200
201typedef struct open_query_struct {
202 int q_open;
203 int q_state;
204 YAP_handle_t q_g;
205 struct pred_entry *q_pe;
206 struct yami *q_p, *q_cp;
207 jmp_buf q_env;
208 int q_flags;
209 YAP_dogoalinfo q_h;
210 struct open_query_struct *oq;
212
213typedef void (*YAP_halt_hook)(int exit_code, void *closure);
214
217/* each type has a tag */
218typedef YAP_Int YAP_opaque_tag_t;
219
220typedef YAP_Bool (*YAP_Opaque_CallOnFail)(YAP_Term);
221typedef YAP_Bool (*YAP_Opaque_CallOnCut)(YAP_Term);
222typedef YAP_Bool (*YAP_Opaque_CallOnWrite)(FILE *, YAP_opaque_tag_t, void *,
223 int);
224typedef YAP_Int (*YAP_Opaque_CallOnGCMark)(YAP_opaque_tag_t, void *, YAP_Term *,
225 YAP_Int);
226typedef YAP_Bool (*YAP_Opaque_CallOnGCRelocate)(YAP_opaque_tag_t, void *,
227 YAP_Term *, YAP_Int);
230 YAP_Opaque_CallOnCut cut_handler; //< called at cut, which may be a forward
231 // cut or an exception.
232 YAP_Opaque_CallOnFail
233 fail_handler; //< called at exit, it can be used to cleanup resources
234 YAP_Opaque_CallOnWrite write_handler; //< text representation
235 YAP_Opaque_CallOnGCMark
236 mark_handler; //< useful if you include pointers to stack
237 YAP_Opaque_CallOnGCRelocate
238 relocate_handler; //< useful if you include pointers to stack
240
241extern YAP_Opaque_CallOnWrite Yap_blob_write_handler_from_slot(YAP_Int slot);
242extern YAP_Opaque_CallOnGCMark Yap_blob_gc_mark_handler(YAP_Term t);
243extern YAP_Opaque_CallOnGCRelocate Yap_blob_gc_relocate_handler(YAP_Term t);
244extern YAP_Int Yap_blob_tag_from_slot(YAP_Int slot);
245extern void *Yap_blob_info_from_slot(YAP_Int slot);
246
247/********* execution mode ***********************/
248
249
250/*************************************************************************************************
251 Prolog may be in several modes
252*************************************************************************************************/
253
254typedef enum {
255 BootMode = 0x1,
256 UserMode = 0x2,
257 CritMode = 0x4,
258 AbortMode = 0x8,
259 InterruptMode = 0x10, /*8 under an interrupt */
260 InErrorMode = 0x20,
261 ConsoleGetcMode = 0x40,
262 ExtendStackMode = 0x80,
263 GrowHeapMode = 0x100,
264 GrowStackMode = 0x200,
265 GCMode = 0x400,
266 ErrorHandlingMode = 0x800,
267 CCallMode = 0x1000,
268 UnifyMode = 0x2000,
269 UserCCallMode = 0x4000,
270 MallocMode = 0x8000,
271 SystemMode = 0x10000,
272 AsyncIntMode = 0x20000,
273 InReadlineMode =
274 0x40000,
275 TopGoalMode = 0x40000
276} prolog_exec_mode;
277
278typedef enum {
279 YAPC_INTERPRETED, /* interpreted */
280 YAPC_MIXED_MODE_USER, /* mixed mode only for user predicates */
281 YAPC_MIXED_MODE_ALL, /* mixed mode for all predicates */
282 YAPC_COMPILE_USER, /* compile all user predicates*/
283 YAPC_COMPILE_ALL /* compile all predicates */
284} execution_t;
285
286
288typedef enum stream_f {
289 Free_Stream_f = 0x000001,
290 Input_Stream_f = 0x000002,
291 Output_Stream_f = 0x000004,
292 Append_Stream_f = 0x000008,
293 Eof_Stream_f = 0x000010,
294 Null_Stream_f = 0x000020,
295 Tty_Stream_f = 0x000040,
296 Socket_Stream_f = 0x000080,
297 Binary_Stream_f = 0x000100,
298 Eof_Error_Stream_f =
299 0x000200,
300 Reset_Eof_Stream_f =
301 0x000400,
302 Past_Eof_Stream_f = 0x000800,
303 Push_Eof_Stream_f = 0x001000,
304 Seekable_Stream_f =
305 0x002000,
306 Promptable_Stream_f = 0x004000,
307 Client_Socket_Stream_f = 0x008000,
308 Server_Socket_Stream_f = 0x010000,
309 InMemory_Stream_f = 0x020000,
310 Pipe_Stream_f = 0x040000,
311 Popen_Stream_f = 0x080000,
312 User_Stream_f = 0x100000,
313 HAS_BOM_f = 0x200000,
314 RepError_Prolog_f =
315 0x400000,
316 RepError_Xml_f = 0x800000,
317 DoNotCloseOnAbort_Stream_f =
318 0x1000000,
319 Readline_Stream_f = 0x2000000,
320 FreeOnClose_Stream_f =
321 0x4000000,
322 CloseOnException_Stream_f =
323 0x8000000,
324 RepFail_Prolog_f =
325 0x01000000,
326 Aliased_Stream_f =
327 0x01000000
328 } estream_f;
329
330
331typedef uint64_t stream_flags_t;
332
333/********* YAP C-Flags ***********************/
334
335typedef enum {
336 YAPC_ENABLE_GC, /* enable or disable garbage collection */
337 YAPC_ENABLE_AGC /* enable or disable atom garbage collection */
338} yap_flag_gc_t;
339
340typedef enum yap_enum_reset_t {
341 YAP_EXEC_ABSMI = 0,
342 YAP_FULL_RESET = 1,
343 YAP_RESET_FROM_RESTORE = 3
344} yap_reset_t;
345
346typedef bool (*YAP_ModInit_t)(void);
347
348typedef struct {
349 YAP_ModInit_t f;
350 const char *s;
352
353#endif /* _YAPDEFS_H */
opaque variables can interact with the system
Definition: YapDefs.h:229
Definition: Yatom.h:544
Definition: amidefs.h:264