YAP 7.1.0
locals.h
1
2
3#include "Yap.h"
4#include "YapHeap.h"
5
6// Macro support
7#ifndef LOCAL
8#define LOCAL(A, B) A B
9#define LOCAL_INIT(A, B, C) \
10 A B; \
11 B = C
12#define LOCAL_ARRAY(A, B, C) A B[C]
13#define LOCAL_ARRAY_ARRAY(A, B, C,D) A B[C][D]
14#define LOCAL_INIT(A, B, C, D) A B[C][D]
15#define LOCAL_INITF(A, B, C) \
16 A B; \
17 C
18 #define LOCAL_INIT_RESTORE(A,B,C,D) A B; C; D;
19#endif
20
22LOCAL_INIT(int, c_input_stream, 0);
23LOCAL_INIT(int, c_output_stream, 1);
24LOCAL_INIT(int, c_error_stream, 2);
25LOCAL_INIT(bool, sockets_io, false);
26LOCAL_INIT(bool, within_print_message, false);
27//
28
29// Used by the prompts to check if they are after a newline, and then a
30// prompt should be output, or if we are in the middle of a line.
31//
32LOCAL_INIT(bool, newline, true);
33
34LOCAL_INIT(Atom, AtPrompt, AtomNil);
35LOCAL_ARRAY(char, Prompt, MAX_PROMPT + 1);
36
37LOCAL_ARRAY(Term, debugger_state, DEBUG_NUMBER_OF_OPTS);
38
39LOCAL_INITF(encoding_t, encoding, Yap_DefaultEncoding());
40LOCAL_INIT(bool, quasi_quotations, false);
41LOCAL_INIT(UInt, default_priority, 1200);
42LOCAL_INIT(bool, eot_before_eof, false);
43LOCAL_INIT(UInt, max_depth, 0);
44LOCAL_INIT(UInt, max_list, 0);
45LOCAL_INIT(UInt, max_write_args, 0);
46// Restore info
47LOCAL_INIT(CELL *, OldASP, NULL);
48LOCAL_INIT(CELL *, OldLCL0, NULL);
49LOCAL_INIT(tr_fr_ptr, OldTR, NULL);
50LOCAL_INIT(CELL *, OldGlobalBase, NULL);
51LOCAL_INIT(CELL *, OldH, NULL);
52LOCAL_INIT(CELL *, OldH0, NULL);
53LOCAL_INIT(ADDR, OldTrailBase, NULL);
54LOCAL_INIT(ADDR, OldTrailTop, NULL);
55LOCAL_INIT(ADDR, OldHeapBase, NULL);
56LOCAL_INIT(ADDR, OldHeapTop, NULL);
57LOCAL_INIT(Int, ClDiff, 0L);
58LOCAL_INIT(Int, GDiff, 0L);
59LOCAL_INIT(Int, HDiff, 0L);
60LOCAL_INIT(Int, GDiff0, 0L);
61LOCAL_INIT(CELL *, GSplit, NULL);
62LOCAL_INIT(Int, LDiff, 0L);
63LOCAL_INIT(Int, TrDiff, 0L);
64LOCAL_INIT(Int, XDiff, 0L);
65LOCAL_INIT(Int, DelayDiff, 0L);
66LOCAL_INIT(Int, BaseDiff, 0L);
67// A term containing a copy with all current live registrt
68// Reduction counters
69LOCAL_INIT(YAP_ULONG_LONG, ReductionsCounter, 0L);
70LOCAL_INIT(YAP_ULONG_LONG, PredEntriesCounter, 0L);
71LOCAL_INIT(YAP_ULONG_LONG, RetriesCounter, 0L);
72LOCAL_INIT(int, ReductionsCounterOn, 0L);
73LOCAL_INIT(int, PredEntriesCounterOn, 0L);
74LOCAL_INIT(int, RetriesCounterOn, 0L);
75// support for consulting files
76/* current consult stack */
77LOCAL_INIT(union CONSULT_OBJ *, ConsultSp, NULL);
78/* current maximum number of cells in consult stack */
79LOCAL(UInt, ConsultCapacity);
80/* top of consult stack */
81LOCAL_INIT(union CONSULT_OBJ *, ConsultBase, NULL);
82/* low-water mark for consult */
83LOCAL_INIT(union CONSULT_OBJ *, ConsultLow, NULL);
84LOCAL_INIT(Term, VarNames, ((Term)0));
85LOCAL_INIT(Atom, SourceFileName, NULL);
86LOCAL_INIT(UInt, SourceFileLineno, 0);
87// global variables
88LOCAL_INIT_RESTORE(Term, GlobalArena, 0L, TermToGlobalOrAtomAdjust);
89LOCAL_INIT(UInt, GlobalArenaOverflows, 0L);
90LOCAL_INIT(Int, ArenaOverflows, 0L);
91LOCAL_INIT(Int, DepthArenas, 0);
92LOCAL_INIT(struct pred_entry *, LastAssertedPred, NULL);
93LOCAL_INIT(struct pred_entry *, TmpPred, NULL);
94LOCAL_INIT(char *, ScannerStack, NULL);
95LOCAL_INIT(struct scanner_extra_alloc *, ScannerExtraBlocks, NULL);
96
99LOCAL_INIT(Int, CBorder, 0);
100LOCAL_INIT(yhandle_t , HandleBorder, 1);
102LOCAL_INIT(UInt, MaxActiveSignals, 64L);
104LOCAL_INIT(uint64_t, Signals, 0L);
106LOCAL_INIT(UInt, IPredArity, 0L);
107LOCAL_INIT(yamop *, ProfEnd, NULL);
108LOCAL_INIT(int, DoingUndefp, FALSE);
109LOCAL(yamop, OpBuffer);
110LOCAL_INIT(Int, StartCharCount, 0L);
111LOCAL_INIT(Int, StartLineCount, 0L);
112LOCAL_INIT(Int, StartLinePos, 0L);
113LOCAL_INITF(scratch_block, ScratchPad, InitScratchPad(wid));
114LOCAL_INIT_RESTORE(Term, WokenGoals, 0L, TermToGlobalAdjust);
115LOCAL_INIT(bool, DoNotWakeUp, false);
116LOCAL_INIT_RESTORE(Term, AttsMutableList, 0L, TermToGlobalAdjust);
117
118// gc_stuff
119LOCAL_INIT(Term, GcGeneration, 0);
120LOCAL_INIT(Term, GcPhase, 0L);
121LOCAL_INIT(UInt, GcCurrentPhase, 0L);
122LOCAL_INIT(UInt, GcCalls, 0);
123LOCAL_INIT(Int, TotGcTime, 0L);
124LOCAL_INIT(YAP_ULONG_LONG, TotGcRecovered, 0L);
125LOCAL_INIT(Int, LastGcTime, 0L);
126LOCAL_INIT(Int, LastSSTime, 0L);
127LOCAL_INIT(CELL *, OpenArray, NULL);
128/* in a single gc */
129LOCAL_INIT(int, MallocDepth, 0L);
130LOCAL_INIT(Int, total_marked, 0L);
131LOCAL_INIT(Int, total_oldies, 0L);
132LOCAL_INIT(struct choicept *, current_B, NULL);
133LOCAL_INIT(CELL *, prev_HB, NULL);
134LOCAL_INIT(CELL *, HGEN, NULL);
135LOCAL_INIT(CELL **, iptop, NULL);
136#if defined(GC_NO_TAGS)
137LOCAL_INIT(char *, bp, NULL);
138#endif
139LOCAL_INIT(tr_fr_ptr, sTR, NULL);
140LOCAL_INIT(tr_fr_ptr, sTR0, NULL);
141LOCAL_INIT(tr_fr_ptr, new_TR, NULL);
142LOCAL_INIT(struct gc_mark_continuation *, cont_top0, NULL);
143LOCAL_INIT(struct gc_mark_continuation *, cont_top, NULL);
144LOCAL_INIT(int, discard_trail_entries, 0);
145LOCAL_ARRAY(gc_ma_hash_entry, gc_ma_hash_table, GC_MAVARS_HASH_SIZE);
146LOCAL_INIT(gc_ma_hash_entry *, gc_ma_h_top, NULL);
147LOCAL_INIT(gc_ma_hash_entry *, gc_ma_h_list, NULL);
148LOCAL_INIT(UInt, gc_timestamp, 0L);
149LOCAL_INIT(ADDR, db_vec, NULL);
150LOCAL_INIT(ADDR, db_vec0, NULL);
151LOCAL_INIT(struct RB_red_blk_node *, db_root, NULL);
152LOCAL_INIT(struct RB_red_blk_node *, db_nil, NULL);
153LOCAL_INIT(CELL *, GC_min_regs, NULL);
154LOCAL_INIT(CELL *, GC_Max_regs, NULL);
155
156LOCAL_INIT(void *, aux, malloc(1024*16) );
157LOCAL_INIT(size_t, aux_sz, 1024*16 );
158
159/* parser stack, used to be AuxSp, now is Malloc */
160LOCAL( CELL *, ParserAuxSp);
161LOCAL( CELL *, ParserAuxMax);
162LOCAL( CELL *, ParserAuxBase);
163
164LOCAL(sigjmp_buf , gc_restore);
165LOCAL(CELL *, extra_gc_cells);
166LOCAL(CELL *, extra_gc_cells_base);
167LOCAL(CELL *, extra_gc_cells_top);
168LOCAL_INIT(UInt, extra_gc_cells_size, 256);
169LOCAL_INIT_RESTORE(struct array_entry *, DynamicArrays, NULL, PtoArrayEAdjust);
170LOCAL_INIT_RESTORE(struct static_array_entry *, StaticArrays, NULL, PtoArraySAdjust);
171LOCAL_INIT_RESTORE(struct global_entry *, GlobalVariables, NULL, PtoGlobalEAdjust);
172LOCAL_INIT(int, AllowRestart, FALSE);
173
174// Thread Local Area for Fast Storage of Intermediate Compiled Code
175LOCAL_INIT(struct mem_blk *, CMemFirstBlock, NULL);
176LOCAL_INIT(UInt, CMemFirstBlockSz, 0L);
177
178// Variable used by the compiler to store number of permanent vars in a clause
179LOCAL_INIT(int, nperm, 0);
180LOCAL_INIT(int, jMP, 0);
181// Thread Local Area for Labels
182LOCAL_INIT(Int *, LabelFirstArray, NULL);
183LOCAL_INIT(UInt, LabelFirstArraySz, 0L);
184
185// Thread Local Area for SWI-Prolog emulation routines.
186// stInitSruct LOCAL_INIT( PL_local_data*, PL_local_data_p, Yap_InitThreadIO(wid));
187#ifdef THREADS
188LOCAL_INITF(struct thandle, ThreadHandle, InitThreadHandle(wid));
189#endif /* THREADS */
190
191#if defined(YAPOR) || defined(TABLING)
192LOCAL_INITF(struct local_optyap_data, optyap_data,Yap_init_local_optyap_data(wid));
193LOCAL_INIT(UInt, TabMode, 0L);
194#endif /* YAPOR || TABLING */
195
196LOCAL_INIT(int, InterruptsDisabled, FALSE);
197
198LOCAL_INIT(struct open_query_struct *, execution, NULL);
199
200#if LOW_LEVEL_TRACER
201LOCAL_INIT(Int, total_choicepoints, 0);
202#endif
203
204LOCAL_INIT(int, consult_level, 0);
205
206// Variables related to memory allocation
207LOCAL(ADDR, LocalBase);
208LOCAL(ADDR, GlobalBase);
209LOCAL(ADDR, TrailBase);
210LOCAL(ADDR, TrailTop);
211
212/* error handling info, designed to be easy to pass to the foreign world */
213LOCAL_INIT(yap_error_descriptor_t *, ActiveError, calloc(sizeof(yap_error_descriptor_t), 1));
214LOCAL_INIT(yap_error_descriptor_t *, CommittedError, NULL);
215LOCAL_INIT(bool, delay, false);
217LOCAL(jmp_buf, IOBotch);
218
220LOCAL(TokEntry *, tokptr);
221LOCAL(TokEntry *, toktide);
222LOCAL(VarEntry *, VarTable);
223LOCAL(VarEntry *, AnonVarTable);
224LOCAL(VarEntry *, VarList);
225LOCAL(VarEntry *, VarTail);
226LOCAL(Term, Comments);
227LOCAL(CELL *, CommentsTail);
228LOCAL(CELL *, CommentsNextChar);
229LOCAL(wchar_t *, CommentsBuff);
230LOCAL(size_t, CommentsBuffPos);
231LOCAL(size_t, CommentsBuffLim);
232LOCAL_INIT(sigjmp_buf *, RestartEnv, NULL);
233LOCAL_INIT(struct TextBuffer_manager *, TextBuffer, Yap_InitTextAllocator());
234
235// Prolog State
236LOCAL_INIT(UInt, BreakLevel, 0);
237LOCAL_INIT(Int, PrologMode, BootMode);
238LOCAL_INIT(int, CritLocks, 0);
239
240// Prolog execution and state flags
241LOCAL(union flagTerm *, Flags);
242LOCAL(UInt, flagCount);
243// analyst.c
244/* used to find out how many instructions of each kind are executed */
245#ifdef ANALYST
246LOCAL_ARRAY(YAP_ULONG_LONG, opcount, _std_top + 1);
247LOCAL_ARRAY_ARRAY(YAP_ULONG_LONG, 2opcount, _std_top + 1, _std_top + 1);
248#endif /* ANALYST */
249
250// dbase.c
251LOCAL(struct db_globs *, s_dbg);
252
253// eval.c
254LOCAL(Term, mathtt);
255LOCAL_INIT(char *, mathstring, NULL);
256LOCAL_INIT(struct eval_context *, ctx, NULL);
257
258
259// grow.c
260LOCAL_INIT(int, heap_overflows, 0);
261LOCAL_INIT(Int, total_heap_overflow_time, 0);
262LOCAL_INIT(int, stack_overflows, 0);
263LOCAL_INIT(Int, total_stack_overflow_time, 0);
264LOCAL_INIT(int, delay_overflows, 0);
265LOCAL_INIT(Int, total_delay_overflow_time, 0);
266LOCAL_INIT(int, trail_overflows, 0);
267LOCAL_INIT(Int, total_trail_overflow_time, 0);
268LOCAL_INIT(int, atom_table_overflows, 0);
269LOCAL_INIT(Int, total_atom_table_overflow_time, 0);
270
271// load_dyld
272#ifdef LOAD_DYLD
273LOCAL_INIT(int, dl_errno, 0);
274#endif
275
276// tracer.c
277#ifdef LOW_LEVEL_TRACER
278LOCAL_INIT(int, do_trace_primitives, TRUE);
279#endif
280
281// quick loader
282LOCAL_INIT(struct export_atom_hash_entry_struct *, ExportAtomHashChain, NULL);
283LOCAL_INIT(UInt, ExportAtomHashTableSize, 0);
284LOCAL_INIT(UInt, ExportAtomHashTableNum, 0);
285LOCAL_INIT(struct export_functor_hash_entry_struct *, ExportFunctorHashChain,NULL);
286LOCAL_INIT(UInt, ExportFunctorHashTableSize, 0);
287LOCAL_INIT(UInt, ExportFunctorHashTableNum, 0);
288LOCAL_INIT(struct export_pred_entry_hash_entry_struct *,ExportPredEntryHashChain, NULL);
289LOCAL_INIT(UInt, ExportPredEntryHashTableSize, 0);
290LOCAL_INIT(UInt, ExportPredEntryHashTableNum, 0);
291LOCAL_INIT(struct export_dbref_hash_entry_struct *, ExportDBRefHashChain, NULL);
292LOCAL_INIT(UInt, ExportDBRefHashTableSize, 0);
293LOCAL_INIT(UInt, ExportDBRefHashTableNum, 0);
294LOCAL_INIT(struct import_atom_hash_entry_struct **, ImportAtomHashChain, NULL);
295LOCAL_INIT(UInt, ImportAtomHashTableSize, 0);
296LOCAL_INIT(UInt, ImportAtomHashTableNum, 0);
297LOCAL_INIT(struct import_functor_hash_entry_struct **, ImportFunctorHashChain, NULL);
298LOCAL_INIT(UInt, ImportFunctorHashTableSize, 0);
299LOCAL_INIT(UInt, ImportFunctorHashTableNum, 0);
300LOCAL_INIT(struct import_opcode_hash_entry_struct **, ImportOPCODEHashChain, NULL);
301LOCAL_INIT(UInt, ImportOPCODEHashTableSize, 0);
302LOCAL_INIT(struct import_pred_entry_hash_entry_struct **, ImportPredEntryHashChain, NULL);
303LOCAL_INIT(UInt, ImportPredEntryHashTableSize, 0);
304LOCAL_INIT(UInt, ImportPredEntryHashTableNum, 0);
305LOCAL_INIT(struct import_dbref_hash_entry_struct **, ImportDBRefHashChain, NULL);
306LOCAL_INIT(UInt, ImportDBRefHashTableSize, 0);
307LOCAL_INIT(UInt, ImportDBRefHashTableNum, 0);
308LOCAL_INIT(yamop *, ImportFAILCODE, NULL);
309
310// exo indexing
311
312LOCAL_ARRAY(UInt, ibnds, 256);
313LOCAL_INIT(struct index_t *, exo_it, NULL);
314LOCAL_INIT(CELL *, exo_base, NULL);
315LOCAL_INIT(UInt, exo_arity, 0);
316LOCAL_INIT(UInt, exo_arg, 0);
317
318// atom completion
319LOCAL(struct scan_atoms *, search_atoms);
320LOCAL(struct pred_entry *, SearchPreds);
321
323LOCAL_INIT(yhandle_t, CurSlot, 0);
324LOCAL_INIT(yhandle_t, FrozenHandles, 0);
325LOCAL_INIT(yhandle_t, NSlots, 0);
326LOCAL_INIT(CELL *, SlotBase, InitHandles(wid));
327
328// Mutexes
329LOCAL_INIT(struct swi_mutex *, Mutexes, NULL);
330
331LOCAL_INIT(Term, SourceModule, 0);
332LOCAL_INIT(Term, Including, TermNil);
333
334LOCAL_INIT(size_t, MAX_SIZE, 1024L);
335
336/* last call to walltime. */
337LOCAL_INIT(uint64_t, LastWTime, 0);
338
339LOCAL(scratch_sys_struct_t, WorkerBuffer);
340
341
342
343
Main definitions.
thread view of the scratch buffer
Definition: alloc.h:164
Definition: qly.h:37
Definition: qly.h:82
Definition: qly.h:47
Definition: qly.h:66
Definition: qly.h:41
Definition: qly.h:88
Definition: qly.h:53
Definition: qly.h:59
Definition: qly.h:76
@ encoding
support for coding systens, YAP relies on UTF-8 internally
Definition: YapLFlagInfo.h:83
Definition: arrays.h:92
Definition: Yap.h:681
Definition: Yatom.h:151
Definition: Yatom.h:544
all we need to know about an error/throw
Definition: YapError.h:205
Definition: arrays.h:76
Definition: amidefs.h:264
a flag is represented as a Prolog term
Definition: YapFlags.h:189