YAP 7.1.0
YapHeap.h
1/*************************************************************************
2* *
3* YAP Prolog %W% %G% *
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: YapHeap.h *
11* mods: *
12* comments: Heap Init Structure *
13* version: $Id: Heap.h,v 1.136 2008-08-08 14:05:34 vsc Exp $ *
14*************************************************************************/
15
16/* information that can be stored in Code Space */
17
18#ifndef HEAP_H
19#define HEAP_H 1
20
21#include "Yap.h"
22
23#include "Atoms.h"
24
25#include "alloc.h"
26
27#if LOW_PROF
28#include <stdio.h>
29#endif
30
31typedef int (*SWI_PutFunction)(int, void *);
32typedef int (*SWI_GetFunction)(void *);
33typedef int (*SWI_PutWideFunction)(int, void *);
34typedef int (*SWI_GetWideFunction)(void *);
35typedef int (*SWI_CloseFunction)(void *);
36typedef int (*SWI_FlushFunction)(void *);
37typedef int (*SWI_PLGetStreamFunction)(void *);
38typedef int (*SWI_PLGetStreamPositionFunction)(void *);
39
40#ifndef INT_KEYS_DEFAULT_SIZE
41#define INT_KEYS_DEFAULT_SIZE 256
42#endif
43
44#if USE_DL_MALLOC
45
46#define MAX_DLMALLOC_HOLES 32
47
48typedef struct memory_hole {
49 ADDR start;
50 ADDR end;
51} memory_hole_type;
52#endif // USE_DL_MALLOC
53
54typedef struct swi_reverse_hash {
55 ADDR key;
56 Int pos;
58
59//#define GC_MAVARS_HASH_SIZE 512
60//
61// typedef struct gc_ma_hash_entry_struct {
62// UInt timestmp;
63//#ifdef TABLING
64// tr_fr_ptr loc;
65// struct gc_ma_hash_entry_struct *more;
66//#endif
67// CELL* addr;
68// struct gc_ma_hash_entry_struct *next;
69//} gc_ma_hash_entry;
70
71typedef void (*HaltHookFunc)(int, void *);
72
73typedef struct halt_hook {
74 void *environment;
75 HaltHookFunc hook;
76 struct halt_hook *next;
78
79int Yap_HaltRegisterHook(HaltHookFunc, void *);
80
81typedef struct atom_hash_entry {
82#if defined(YAPOR) || defined(THREADS)
83 rwlock_t AERWLock;
84#endif
85 Atom Entry;
87
88// typedef struct scratch_block_struct {
89// char *ptr;
90// UInt sz, msz;
91//} scratch_block;
92
93typedef struct record_list {
94 /* a list of dbterms associated with a clause */
95 struct DB_TERM *dbrecord;
96 struct record_list *next_rec, *prev_rec;
98
99/* SWI Emulation */
100#define SWI_BUF_SIZE 512
101#define SWI_TMP_BUF_SIZE 2 * SWI_BUF_SIZE
102#define SWI_BUF_RINGS 16
103
104/* ricardo
105#ifdef THREADS
106typedef struct thandle {
107 int in_use;
108 int zombie;
109 UInt ssize;
110 UInt tsize;
111 UInt sysize;
112 void *stack_address;
113 Term tdetach;
114 Term cmod, texit_mod;
115 struct DB_TERM *tgoal, *texit;
116 int id;
117 int ret;
118 REGSTORE *default_yaam_regs;
119 REGSTORE *current_yaam_regs;
120 struct pred_entry *local_preds;
121 pthread_t pthread_handle;
122 int ref_count;
123#ifdef LOW_LEVEL_TRACER
124 long long int thread_inst_count;
125 int been_here1;
126 int been_here2;
127#endif
128#ifdef DEBUG
129 int been_here;
130#endif
131 pthread_mutex_t tlock;
132 pthread_mutex_t tlock_status;
133#if HAVE_GETRUSAGE||defined(_WIN32)
134 struct timeval *start_of_timesp;
135 struct timeval *last_timep;
136#endif
137} yap_thandle;
138#endif */
139
140// typedef int (*Agc_hook)(Atom);
141
142/*******************
143 this is the data base: everything here should be possible to restore
144********************/
145#if __INIT_C__ || defined(MSC_VER)
146#define EXTERNAL
147#else
148#define EXTERNAL extern
149#endif
150
151
152#if YAPOR
153
154typedef struct various_codes {
155 /* memory allocation and management */
156 special_functors funcs;
157
158#include "struct.h"
159
161
162#include "hglobals.h"
163
164#include "dhstruct.h"
165#include "dglobals.h"
166#else
167typedef struct various_codes {
168 /* memory allocation and management */
169 special_functors funcs;
170
171
173
174
175#include "generated/tatoms.h"
176
177#include "generated/h0struct.h"
178
179#include "generated/h0globals.h"
180
181#endif
182
183#include "generated/hlocals.h"
184
185#include "dlocals.h"
186
187#include "YapSignals.h"
188
189/* ricardo
190#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
191extern struct global_data *Yap_global;
192extern long Yap_worker_area_size;
193#else
194extern struct global_data Yap_Global;
195#define Yap_global (&Yap_Global)
196#endif
197
198#if defined(THREADS)
199extern struct worker_local *Yap_local[MAX_THREADS];
200#define REMOTE(wid) (Yap_local[wid])
201#elif defined(YAPOR)
202extern struct worker_local *Yap_local;
203#define REMOTE(wid) (Yap_local + wid)
204#else
205extern struct worker_local Yap_local;
206#define REMOTE(wid) (&Yap_local)
207#endif
208*/
209
210#ifdef USE_SYSTEM_MALLOC
211extern struct various_codes *Yap_heap_regs;
212#else
213#define Yap_heap_regs ((all_heap_codes *)HEAP_INIT_BASE)
214#endif
215
220static inline yamop *gc_P(yamop *p, yamop *cp) {
221 yamop *n= (p && p->opc == EXECUTE_CPRED_OPCODE ? cp : p);
222 if (p->opc == Yap_opcode(_try_c) ||
223 p->opc == Yap_opcode(_try_userc) ||
224 p->opc == Yap_opcode(_retry_c) ||
225 p->opc == Yap_opcode(_retry_userc))
226 return cp;
227 return n;
228}
229
235#define Yap_CurrentModule() Yap_CurrentModule__(PASS_REGS1)
236
237INLINE_ONLY Term Yap_CurrentModule__(USES_REGS1);
238
239INLINE_ONLY Term Yap_CurrentModule__(USES_REGS1) {
240 if (CurrentModule)
241 return CurrentModule;
242 return TermProlog;
243}
244
245/*******************
246 these are the global variables: they need not be restored...
247********************/
248
249#define UPDATE_MODE_IMMEDIATE 0
250#define UPDATE_MODE_LOGICAL 1
251#define UPDATE_MODE_LOGICAL_ASSERT 2
252
253/* initially allow for files with up to 1024 predicates. This number**
254 is extended whenever needed */
255
256
257#define InitialConsultCapacity 16
258
259#if (defined(USE_SYSTEM_MALLOC) && HAVE_MALLINFO) || USE_DL_MALLOC
260extern UInt Yap_givemallinfo(void);
261#endif
262
263extern ADDR Yap_ExpandPreAllocCodeSpace(UInt, void *, int);
264#define Yap_ReleasePreAllocCodeSpace(x)
265extern ADDR Yap_InitPreAllocCodeSpace(int);
266
267#include "inline-only.h"
268INLINE_ONLY ADDR Yap_PreAllocCodeSpace(void);
269
270INLINE_ONLY ADDR Yap_PreAllocCodeSpace(void) {
271 CACHE_REGS
272 return AuxBase;
273}
274
275#endif /* HEAP_H */
Main definitions.
Definition: Yatom.h:689
Definition: YapHeap.h:81
Definition: amidefs.h:264