LD should be local to threads.
get rid of write_depth on YAP side.
This commit is contained in:
parent
31909e3741
commit
cce6bb6354
49
C/iopreds.c
49
C/iopreds.c
@ -87,7 +87,6 @@ static char SccsId[] = "%W% %G%";
|
||||
STATIC_PROTO (Int p_set_read_error_handler, (void));
|
||||
STATIC_PROTO (Int p_get_read_error_handler, (void));
|
||||
STATIC_PROTO (Int p_read, (void));
|
||||
STATIC_PROTO (Int p_write_depth, (void));
|
||||
STATIC_PROTO (Int p_startline, (void));
|
||||
STATIC_PROTO (Int p_change_type_of_char, (void));
|
||||
STATIC_PROTO (Int p_type_of_char, (void));
|
||||
@ -912,52 +911,6 @@ p_stream_select(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static Int
|
||||
p_write_depth (void)
|
||||
{ /* write_depth(Old,New) */
|
||||
Term t1 = Deref (ARG1);
|
||||
Term t2 = Deref (ARG2);
|
||||
Term t3 = Deref (ARG3);
|
||||
|
||||
if (!IsVarTerm (t1) && !IsIntegerTerm (t1)) {
|
||||
Yap_Error(TYPE_ERROR_INTEGER,t1,"write_depth/3");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsVarTerm (t2) && !IsIntegerTerm (t2)) {
|
||||
Yap_Error(TYPE_ERROR_INTEGER,t2,"write_depth/3");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsVarTerm (t3) && !IsIntegerTerm (t3)) {
|
||||
Yap_Error(TYPE_ERROR_INTEGER,t3,"write_depth/3");
|
||||
return FALSE;
|
||||
}
|
||||
if (IsVarTerm (t1))
|
||||
{
|
||||
Term t = MkIntegerTerm (max_depth);
|
||||
if (!Yap_unify_constant(t1, t))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
max_depth = IntegerOfTerm (t1);
|
||||
if (IsVarTerm (t2))
|
||||
{
|
||||
Term t = MkIntegerTerm (max_list);
|
||||
if (!Yap_unify_constant (t2, t))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
max_list = IntegerOfTerm (t2);
|
||||
if (IsVarTerm (t3))
|
||||
{
|
||||
Term t = MkIntegerTerm (max_write_args);
|
||||
if (!Yap_unify_constant (t3, t))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
max_write_args = IntegerOfTerm (t3);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_change_type_of_char (void)
|
||||
{ /* change_type_of_char(+char,+type) */
|
||||
@ -1194,8 +1147,6 @@ Yap_InitIOPreds(void)
|
||||
Yap_InitCPred ("$read", 6, p_read, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("$read", 7, p_read2, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("$start_line", 1, p_startline, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
|
||||
Yap_InitCPred ("write_depth", 3, p_write_depth, SafePredFlag|SyncPredFlag);
|
||||
Yap_InitCPred ("$change_type_of_char", 2, p_change_type_of_char, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$type_of_char", 2, p_type_of_char, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("char_conversion", 2, p_char_conversion, SyncPredFlag);
|
||||
|
10
C/tracer.c
10
C/tracer.c
@ -39,7 +39,6 @@ TracePutchar(int sno, int ch)
|
||||
static void
|
||||
send_tracer_message(char *start, char *name, Int arity, char *mname, CELL *args)
|
||||
{
|
||||
UInt omax_depth, omax_list, omax_write_args;
|
||||
|
||||
if (name == NULL) {
|
||||
#ifdef YAPOR
|
||||
@ -66,16 +65,7 @@ send_tracer_message(char *start, char *name, Int arity, char *mname, CELL *args)
|
||||
Yap_Portray_delays = TRUE;
|
||||
#endif
|
||||
#endif
|
||||
omax_depth = max_depth;
|
||||
omax_list = max_list;
|
||||
omax_write_args = max_write_args;
|
||||
max_depth = 5;
|
||||
max_list = 5;
|
||||
max_write_args = 10;
|
||||
Yap_plwrite(args[i], TracePutchar, Handle_vars_f, 1200);
|
||||
max_depth = omax_depth;
|
||||
max_list = omax_list;
|
||||
max_write_args = omax_write_args;
|
||||
#if DEBUG
|
||||
#if COROUTINING
|
||||
Yap_Portray_delays = FALSE;
|
||||
|
@ -1094,8 +1094,8 @@ Yap_plwrite(Term t, int (*mywrite) (int, wchar_t), int flags, int priority)
|
||||
wglb.Quote_illegal = flags & Quote_illegal_f;
|
||||
wglb.Handle_vars = flags & Handle_vars_f;
|
||||
wglb.Use_portray = flags & Use_portray_f;
|
||||
wglb.MaxDepth = max_depth;
|
||||
wglb.MaxArgs = max_write_args;
|
||||
wglb.MaxDepth = 0L;
|
||||
wglb.MaxArgs = 0L;
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
wglb.keep_terms = (flags & (Use_portray_f|To_heap_f));
|
||||
|
@ -155,6 +155,7 @@
|
||||
#define SWI_buffers WL->SWI_buffers_
|
||||
#define SWI_buffers_sz WL->SWI_buffers_sz_
|
||||
#define SWI_buf_index WL->SWI_buf_index_
|
||||
#define LD WL->Yap_ld_
|
||||
#define execution WL->_execution
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
|
@ -274,10 +274,6 @@
|
||||
#define CharConversionTable Yap_heap_regs->char_conversion_table
|
||||
#define CharConversionTable2 Yap_heap_regs->char_conversion_table2
|
||||
|
||||
#define max_depth Yap_heap_regs->maxdepth
|
||||
#define max_list Yap_heap_regs->axlist
|
||||
#define max_write_args Yap_heap_regs->maxwriteargs
|
||||
|
||||
#define ParserErrorStyle Yap_heap_regs->parser_error_style
|
||||
|
||||
#define Yap_LibDir Yap_heap_regs->yap_lib_dir
|
||||
|
@ -157,6 +157,7 @@ typedef struct worker_local {
|
||||
char* SWI_buffers_[1+SWI_BUF_RINGS];
|
||||
size_t SWI_buffers_sz_[1+SWI_BUF_RINGS];
|
||||
int SWI_buf_index_;
|
||||
struct PL_local_data *Yap_ld_;
|
||||
struct open_query_struct* _execution;
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
|
@ -274,10 +274,6 @@
|
||||
char *char_conversion_table;
|
||||
char *char_conversion_table2;
|
||||
|
||||
UInt maxdepth;
|
||||
UInt axlist;
|
||||
UInt maxwriteargs;
|
||||
|
||||
int parser_error_style;
|
||||
|
||||
char *yap_lib_dir;
|
||||
|
@ -155,6 +155,7 @@ static void InitWorker(int wid) {
|
||||
InitSWIBuffers(wid);
|
||||
|
||||
FOREIGN_WL(wid)->SWI_buf_index_ = 0;
|
||||
FOREIGN_WL(wid)->Yap_ld_ = NULL;
|
||||
FOREIGN_WL(wid)->_execution = NULL;
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
|
@ -274,10 +274,6 @@
|
||||
Yap_heap_regs->char_conversion_table = NULL;
|
||||
Yap_heap_regs->char_conversion_table2 = NULL;
|
||||
|
||||
Yap_heap_regs->maxdepth = 0L;
|
||||
Yap_heap_regs->axlist = 0L;
|
||||
Yap_heap_regs->maxwriteargs = 0L;
|
||||
|
||||
Yap_heap_regs->parser_error_style = EXCEPTION_ON_PARSER_ERROR;
|
||||
|
||||
Yap_heap_regs->yap_lib_dir = NULL;
|
||||
|
@ -157,6 +157,7 @@ static void RestoreWorker(int wid) {
|
||||
|
||||
|
||||
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
|
||||
#endif
|
||||
|
@ -276,10 +276,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Yap_heap_regs->yap_lib_dir = CodeCharPAdjust(Yap_heap_regs->yap_lib_dir);
|
||||
|
||||
Yap_heap_regs->last_wtime = CodeVoidPAdjust(Yap_heap_regs->last_wtime);
|
||||
|
@ -122,6 +122,7 @@ IOLIB_HEADERS=$(srcdir)/packages/PLStream/atoms.h $(srcdir)/packages/PLStream/pl
|
||||
$(srcdir)/packages/PLStream/pl-codelist.h \
|
||||
$(srcdir)/packages/PLStream/pl-dtoa.h $(srcdir)/dtoa.c \
|
||||
$(srcdir)/packages/PLStream/pl-incl.h \
|
||||
$(srcdir)/packages/PLStream/pl-global.h \
|
||||
$(srcdir)/packages/PLStream/pl-mswchar.h \
|
||||
$(srcdir)/packages/PLStream/pl-option.h \
|
||||
$(srcdir)/packages/PLStream/pl-opts.h \
|
||||
|
44
docs/yap.tex
44
docs/yap.tex
@ -5675,50 +5675,6 @@ opened or closed.
|
||||
Switches on the file_errors flag so that in certain error conditions
|
||||
I/O predicates will produce an appropriated message and abort.
|
||||
|
||||
@item write_depth(@var{T},@var{L},@var{A})
|
||||
@findex write_depth/3
|
||||
@snindex write_depth/3
|
||||
@cnindex write_depth/3
|
||||
Unifies @var{T} with the value of the maximum depth of a term to be
|
||||
written, @var{L} with the maximum length of a list to write, and @var{A}
|
||||
with the maximum number of arguments of a compound term to write. The
|
||||
setting will be used by @code{write/1} or @code{write/2}. The default
|
||||
value for all arguments is 0, meaning unlimited depth and length.
|
||||
|
||||
@example
|
||||
?- write_depth(3,5,5).
|
||||
yes
|
||||
?- write(a(b(c(d(e(f(g))))))).
|
||||
a(b(c(....)))
|
||||
yes
|
||||
?- write([1,2,3,4,5,6,7,8]).
|
||||
[1,2,3,4,5,...]
|
||||
yes
|
||||
?- write(a(1,2,3,4,5,6,7,8)).
|
||||
a(1,2,3,4,5,...)
|
||||
yes
|
||||
@end example
|
||||
|
||||
@item write_depth(@var{T},@var{L})
|
||||
@findex write_depth/2
|
||||
@snindex write_depth/2
|
||||
Same as @code{write_depth(@var{T},@var{L},_)}. Unifies @var{T} with the
|
||||
value of the maximum depth of a term to be
|
||||
written, and @var{L} with the maximum length of a list to write. The
|
||||
setting will be used by @code{write/1} or @code{write/2}. The default
|
||||
value for all arguments is 0, meaning unlimited depth and length.
|
||||
|
||||
@example
|
||||
?- write_depth(3,5,5).
|
||||
yes
|
||||
?- write(a(b(c(d(e(f(g))))))).
|
||||
a(b(c(....)))
|
||||
yes
|
||||
?- write([1,2,3,4,5,6,7,8]).
|
||||
[1,2,3,4,5,...]
|
||||
yes
|
||||
@end example
|
||||
|
||||
@item always_prompt_user
|
||||
@findex always_prompt_user/0
|
||||
@snindex always_prompt_user/0
|
||||
|
@ -171,6 +171,7 @@ char* SWI_buffers_[1+SWI_BUF_RINGS] SWI_buffers InitSWIBuffers(wid)
|
||||
size_t SWI_buffers_sz_[1+SWI_BUF_RINGS] SWI_buffers_sz void
|
||||
int SWI_buf_index_ SWI_buf_index =0
|
||||
|
||||
struct PL_local_data *Yap_ld_ LD =NULL
|
||||
|
||||
struct open_query_struct* _execution execution =NULL
|
||||
|
||||
|
@ -309,11 +309,6 @@ char prompt[MAX_PROMPT] Prompt void void
|
||||
char *char_conversion_table CharConversionTable =NULL CodeCharPAdjust
|
||||
char *char_conversion_table2 CharConversionTable2 =NULL CodeCharPAdjust
|
||||
|
||||
/* write depth */
|
||||
UInt maxdepth max_depth =0L void
|
||||
UInt axlist max_list =0L void
|
||||
UInt maxwriteargs max_write_args =0L void
|
||||
|
||||
/* what to do when the parser gives an error: should be thread bound? */
|
||||
int parser_error_style ParserErrorStyle =EXCEPTION_ON_PARSER_ERROR void
|
||||
|
||||
|
@ -4707,6 +4707,7 @@ get_stream_position(IOSTREAM *s, term_t t)
|
||||
static void
|
||||
init_yap(void)
|
||||
{
|
||||
LD = (struct PL_local_data *)malloc(sizeof(struct PL_local_data));
|
||||
setPrologFlagMask(PLFLAG_TTY_CONTROL);
|
||||
initCharTypes();
|
||||
initFiles();
|
||||
|
274
packages/PLStream/pl-global.h
Normal file
274
packages/PLStream/pl-global.h
Normal file
@ -0,0 +1,274 @@
|
||||
typedef struct _PL_thread_info_t
|
||||
{ int pl_tid; /* Prolog thread id */
|
||||
size_t local_size; /* Stack sizes */
|
||||
size_t global_size;
|
||||
size_t trail_size;
|
||||
size_t stack_size; /* system (C-) stack */
|
||||
int (*cancel)(int id); /* cancel function */
|
||||
int open_count; /* for PL_thread_detach_engine() */
|
||||
bool detached; /* detached thread */
|
||||
int status; /* PL_THREAD_* */
|
||||
pthread_t tid; /* Thread identifier */
|
||||
int has_tid; /* TRUE: tid = valid */
|
||||
#ifdef __linux__
|
||||
pid_t pid; /* for identifying */
|
||||
#endif
|
||||
#ifdef __WINDOWS__
|
||||
unsigned long w32id; /* Win32 thread HANDLE */
|
||||
#endif
|
||||
struct PL_local_data *thread_data; /* The thread-local data */
|
||||
module_t module; /* Module for starting goal */
|
||||
record_t goal; /* Goal to start thread */
|
||||
record_t return_value; /* Value (term) returned */
|
||||
atom_t name; /* Name of the thread */
|
||||
ldata_status_t ldata_status; /* status of forThreadLocalData() */
|
||||
} PL_thread_info_t;
|
||||
|
||||
|
||||
/* The GD global variable */
|
||||
typedef struct {
|
||||
int io_initialised;
|
||||
cleanup_status cleaning; /* Inside PL_cleanup() */
|
||||
|
||||
pl_defaults_t defaults; /* system default settings */
|
||||
|
||||
struct
|
||||
{ Table table; /* global (read-only) features */
|
||||
} prolog_flag;
|
||||
|
||||
struct
|
||||
{ Table tmp_files; /* Known temporary files */
|
||||
CanonicalDir _canonical_dirlist;
|
||||
char * myhome; /* expansion of ~ */
|
||||
char * fred; /* last expanded ~user */
|
||||
char * fredshome; /* home of fred */
|
||||
OnHalt on_halt_list; /* list of onhalt hooks */
|
||||
int halting; /* process is shutting down */
|
||||
int gui_app; /* Win32: Application is a gui app */
|
||||
IOFUNCTIONS iofunctions; /* initial IO functions */
|
||||
IOFUNCTIONS org_terminal; /* IO+Prolog terminal functions */
|
||||
IOFUNCTIONS rl_functions; /* IO+Terminal+Readline functions */
|
||||
} os;
|
||||
|
||||
struct
|
||||
{ size_t heap; /* heap in use */
|
||||
size_t atoms; /* No. of atoms defined */
|
||||
size_t atomspace; /* # bytes used to store atoms */
|
||||
size_t stack_space; /* # bytes on stacks */
|
||||
#ifdef O_ATOMGC
|
||||
size_t atomspacefreed; /* Freed atom-space */
|
||||
#endif
|
||||
int functors; /* No. of functors defined */
|
||||
int predicates; /* No. of predicates defined */
|
||||
int modules; /* No. of modules in the system */
|
||||
intptr_t codes; /* No. of byte codes generated */
|
||||
#ifdef O_PLMT
|
||||
int threads_created; /* # threads created */
|
||||
int threads_finished; /* # finished threads */
|
||||
double thread_cputime; /* Total CPU time of threads */
|
||||
#endif
|
||||
double start_time; /* When Prolog was started */
|
||||
} statistics;
|
||||
|
||||
struct
|
||||
{ atom_t * array; /* index --> atom */
|
||||
size_t count; /* elements in array */
|
||||
atom_t *for_code[256]; /* code --> one-char-atom */
|
||||
} atoms;
|
||||
|
||||
struct
|
||||
{ ExtensionCell _ext_head; /* head of registered extensions */
|
||||
ExtensionCell _ext_tail; /* tail of this chain */
|
||||
|
||||
InitialiseHandle initialise_head; /* PL_initialise_hook() */
|
||||
InitialiseHandle initialise_tail;
|
||||
PL_dispatch_hook_t dispatch_events; /* PL_dispatch_hook() */
|
||||
|
||||
int _loaded; /* system extensions are loaded */
|
||||
} foreign;
|
||||
|
||||
#ifdef O_PLMT
|
||||
FreeChunk left_over_pool; /* Left-over from threads */
|
||||
|
||||
struct
|
||||
{ struct _at_exit_goal *exit_goals; /* Global thread_at_exit/1 goals */
|
||||
int enabled; /* threads are enabled */
|
||||
Table mutexTable; /* Name --> mutex table */
|
||||
int mutex_next_id; /* next id for anonymous mutexes */
|
||||
struct pl_mutex* MUTEX_load; /* The $load mutex */
|
||||
#ifdef __WINDOWS__
|
||||
HINSTANCE instance; /* Win32 process instance */
|
||||
#endif
|
||||
counting_mutex *mutexes; /* Registered mutexes */
|
||||
int thread_max; /* Maximum # threads */
|
||||
PL_thread_info_t **threads; /* Pointers to thread-info */
|
||||
} thread;
|
||||
#endif /*O_PLMT*/
|
||||
|
||||
struct /* pl-format.c */
|
||||
{ Table predicates;
|
||||
} format;
|
||||
|
||||
struct
|
||||
{/* Procedure dgarbage_collect1; */
|
||||
/* Procedure catch3; */
|
||||
/* Procedure true0; */
|
||||
/* Procedure fail0; */
|
||||
/* Procedure equals2; /\* =/2 *\/ */
|
||||
/* Procedure is2; /\* is/2 *\/ */
|
||||
/* Procedure strict_equal2; /\* ==/2 *\/ */
|
||||
/* Procedure event_hook1; */
|
||||
/* Procedure exception_hook4; */
|
||||
/* Procedure print_message2; */
|
||||
/* Procedure foreign_registered2; /\* $foreign_registered/2 *\/ */
|
||||
/* Procedure prolog_trace_interception4; */
|
||||
predicate_t portray; /* portray/1 */
|
||||
/* Procedure dcall1; /\* $call/1 *\/ */
|
||||
/* Procedure setup_call_catcher_cleanup4; /\* setup_call_catcher_cleanup/4 *\/ */
|
||||
/* Procedure undefinterc4; /\* $undefined_procedure/4 *\/ */
|
||||
/* Procedure dthread_init0; /\* $thread_init/0 *\/ */
|
||||
/* Procedure dc_call_prolog0; /\* $c_call_prolog/0 *\/ */
|
||||
/* #ifdef O_ATTVAR */
|
||||
/* Procedure dwakeup1; /\* system:$wakeup/1 *\/ */
|
||||
predicate_t portray_attvar1; /* $attvar:portray_attvar/1 */
|
||||
/* #endif */
|
||||
/* #ifdef O_CALL_RESIDUE */
|
||||
/* Procedure call_residue_vars2; /\* $attvar:call_residue_vars/2 *\/ */
|
||||
/* #endif */
|
||||
|
||||
/* SourceFile reloading; /\* source file we are re-loading *\/ */
|
||||
/* int active_marked; /\* #prodedures marked active *\/ */
|
||||
/* int static_dirty; /\* #static dirty procedures *\/ */
|
||||
|
||||
/* #ifdef O_CLAUSEGC */
|
||||
/* DefinitionChain dirty; /\* List of dirty static procedures *\/ */
|
||||
/* #endif */
|
||||
} procedures;
|
||||
|
||||
} gds_t;
|
||||
|
||||
extern gds_t gds;
|
||||
|
||||
#define GD (&gds)
|
||||
#define GLOBAL_LD (&gds)
|
||||
|
||||
|
||||
/* The LD macro layer */
|
||||
typedef struct PL_local_data {
|
||||
|
||||
struct /* Local IO stuff */
|
||||
{ IOSTREAM *streams[6]; /* handles for standard streams */
|
||||
struct input_context *input_stack; /* maintain input stream info */
|
||||
struct output_context *output_stack; /* maintain output stream info */
|
||||
} IO;
|
||||
|
||||
struct
|
||||
{ Table table; /* Feature table */
|
||||
pl_features_t mask; /* Masked access to booleans */
|
||||
int write_attributes; /* how to write attvars? */
|
||||
occurs_check_t occurs_check; /* Unify and occurs check */
|
||||
} feature;
|
||||
|
||||
source_location read_source; /* file, line, char of last term */
|
||||
|
||||
struct
|
||||
{ int active; /* doing pipe I/O */
|
||||
jmp_buf context; /* context of longjmp() */
|
||||
} pipe;
|
||||
|
||||
struct
|
||||
{ atom_t current; /* current global prompt */
|
||||
atom_t first; /* how to prompt first line */
|
||||
int first_used; /* did we do the first line? */
|
||||
int next; /* prompt on next read operation */
|
||||
} prompt;
|
||||
|
||||
struct
|
||||
{ Table table; /* Feature table */
|
||||
pl_features_t mask; /* Masked access to booleans */
|
||||
int write_attributes; /* how to write attvars? */
|
||||
occurs_check_t occurs_check; /* Unify and occurs check */
|
||||
} prolog_flag;
|
||||
|
||||
void * glob_info; /* pl-glob.c */
|
||||
IOENC encoding; /* default I/O encoding */
|
||||
|
||||
struct
|
||||
{ char * _CWDdir;
|
||||
size_t _CWDlen;
|
||||
#ifdef __BEOS__
|
||||
status_t dl_error; /* dlopen() emulation in pl-beos.c */
|
||||
#endif
|
||||
int rand_initialised; /* have we initialised random? */
|
||||
} os;
|
||||
|
||||
struct
|
||||
{ int64_t pending; /* PL_raise() pending signals */
|
||||
int current; /* currently processing signal */
|
||||
int is_sync; /* current signal is synchronous */
|
||||
record_t exception; /* Pending exception from signal */
|
||||
#ifdef O_PLMT
|
||||
simpleMutex sig_lock; /* lock delivery and processing */
|
||||
#endif
|
||||
} signal;
|
||||
|
||||
int critical; /* heap is being modified */
|
||||
|
||||
struct
|
||||
{ term_t term; /* exception term */
|
||||
term_t bin; /* temporary handle for exception */
|
||||
term_t printed; /* already printed exception */
|
||||
term_t tmp; /* tmp for errors */
|
||||
term_t pending; /* used by the debugger */
|
||||
int in_hook; /* inside exception_hook() */
|
||||
int processing; /* processing an exception */
|
||||
exception_frame *throw_environment; /* PL_throw() environments */
|
||||
} exception;
|
||||
const char *float_format; /* floating point format */
|
||||
|
||||
struct {
|
||||
buffer _discardable_buffer; /* PL_*() character buffers */
|
||||
buffer _buffer_ring[BUFFER_RING_SIZE];
|
||||
int _current_buffer_id;
|
||||
} fli;
|
||||
|
||||
#ifdef O_GMP
|
||||
struct
|
||||
{
|
||||
int persistent; /* do persistent operations */
|
||||
} gmp;
|
||||
#endif
|
||||
|
||||
} PL_local_data_t;
|
||||
|
||||
#define usedStack(D) 0
|
||||
|
||||
#define features (LD->feature.mask)
|
||||
|
||||
extern PL_local_data_t lds;
|
||||
|
||||
#define exception_term (LD->exception.term)
|
||||
|
||||
// THIS HAS TO BE ABSTRACTED
|
||||
|
||||
#define LOCAL_LD (WL->Yap_ld_)
|
||||
|
||||
#define ARG_LD
|
||||
#define GET_LD
|
||||
#define PRED_LD
|
||||
#define PASS_LD
|
||||
|
||||
#define Suser_input (LD->IO.streams[0])
|
||||
#define Suser_output (LD->IO.streams[1])
|
||||
#define Suser_error (LD->IO.streams[2])
|
||||
#define Scurin (LD->IO.streams[3])
|
||||
#define Scurout (LD->IO.streams[4])
|
||||
#define Sprotocol (LD->IO.streams[5])
|
||||
#define Sdin Suser_input /* not used for now */
|
||||
#define Sdout Suser_output
|
||||
|
||||
#define source_line_no (LD->read_source.line)
|
||||
#define source_file_name (LD->read_source.file)
|
||||
#define source_line_pos (LD->read_source.linepos)
|
||||
#define source_char_no (LD->read_source.character)
|
||||
|
@ -15,6 +15,27 @@
|
||||
#define O_PLMT 1
|
||||
#endif
|
||||
|
||||
#include "Yap.h"
|
||||
#include "YapHeap.h"
|
||||
/* try not to pollute the SWI space */
|
||||
#ifdef P
|
||||
#undef P
|
||||
#endif
|
||||
#ifdef B
|
||||
#undef B
|
||||
#endif
|
||||
#ifdef S
|
||||
#undef S
|
||||
#endif
|
||||
#ifdef H
|
||||
#undef H
|
||||
#endif
|
||||
#ifdef LOCK
|
||||
#undef LOCK
|
||||
#endif
|
||||
#ifdef UNLOCK
|
||||
#undef UNLOCK
|
||||
#endif
|
||||
#include <SWI-Stream.h>
|
||||
#include <SWI-Prolog.h>
|
||||
typedef int bool;
|
||||
@ -313,33 +334,6 @@ typedef enum
|
||||
LDATA_ANSWERED
|
||||
} ldata_status_t;
|
||||
|
||||
typedef struct _PL_thread_info_t
|
||||
{ int pl_tid; /* Prolog thread id */
|
||||
size_t local_size; /* Stack sizes */
|
||||
size_t global_size;
|
||||
size_t trail_size;
|
||||
size_t stack_size; /* system (C-) stack */
|
||||
int (*cancel)(int id); /* cancel function */
|
||||
int open_count; /* for PL_thread_detach_engine() */
|
||||
bool detached; /* detached thread */
|
||||
int status; /* PL_THREAD_* */
|
||||
pthread_t tid; /* Thread identifier */
|
||||
int has_tid; /* TRUE: tid = valid */
|
||||
#ifdef __linux__
|
||||
pid_t pid; /* for identifying */
|
||||
#endif
|
||||
#ifdef __WINDOWS__
|
||||
unsigned long w32id; /* Win32 thread HANDLE */
|
||||
#endif
|
||||
struct PL_local_data *thread_data; /* The thread-local data */
|
||||
module_t module; /* Module for starting goal */
|
||||
record_t goal; /* Goal to start thread */
|
||||
record_t return_value; /* Value (term) returned */
|
||||
atom_t name; /* Name of the thread */
|
||||
ldata_status_t ldata_status; /* status of forThreadLocalData() */
|
||||
} PL_thread_info_t;
|
||||
|
||||
|
||||
|
||||
typedef struct tempfile * TempFile; /* pl-os.c */
|
||||
typedef struct canonical_dir * CanonicalDir; /* pl-os.c */
|
||||
@ -347,134 +341,6 @@ typedef struct on_halt * OnHalt; /* pl-os.c */
|
||||
typedef struct extension_cell * ExtensionCell; /* pl-ext.c */
|
||||
typedef struct initialise_handle * InitialiseHandle;
|
||||
|
||||
/* The GD global variable */
|
||||
typedef struct {
|
||||
int io_initialised;
|
||||
cleanup_status cleaning; /* Inside PL_cleanup() */
|
||||
|
||||
pl_defaults_t defaults; /* system default settings */
|
||||
|
||||
struct
|
||||
{ Table table; /* global (read-only) features */
|
||||
} prolog_flag;
|
||||
|
||||
struct
|
||||
{ Table tmp_files; /* Known temporary files */
|
||||
CanonicalDir _canonical_dirlist;
|
||||
char * myhome; /* expansion of ~ */
|
||||
char * fred; /* last expanded ~user */
|
||||
char * fredshome; /* home of fred */
|
||||
OnHalt on_halt_list; /* list of onhalt hooks */
|
||||
int halting; /* process is shutting down */
|
||||
int gui_app; /* Win32: Application is a gui app */
|
||||
IOFUNCTIONS iofunctions; /* initial IO functions */
|
||||
IOFUNCTIONS org_terminal; /* IO+Prolog terminal functions */
|
||||
IOFUNCTIONS rl_functions; /* IO+Terminal+Readline functions */
|
||||
} os;
|
||||
|
||||
struct
|
||||
{ size_t heap; /* heap in use */
|
||||
size_t atoms; /* No. of atoms defined */
|
||||
size_t atomspace; /* # bytes used to store atoms */
|
||||
size_t stack_space; /* # bytes on stacks */
|
||||
#ifdef O_ATOMGC
|
||||
size_t atomspacefreed; /* Freed atom-space */
|
||||
#endif
|
||||
int functors; /* No. of functors defined */
|
||||
int predicates; /* No. of predicates defined */
|
||||
int modules; /* No. of modules in the system */
|
||||
intptr_t codes; /* No. of byte codes generated */
|
||||
#ifdef O_PLMT
|
||||
int threads_created; /* # threads created */
|
||||
int threads_finished; /* # finished threads */
|
||||
double thread_cputime; /* Total CPU time of threads */
|
||||
#endif
|
||||
double start_time; /* When Prolog was started */
|
||||
} statistics;
|
||||
|
||||
struct
|
||||
{ atom_t * array; /* index --> atom */
|
||||
size_t count; /* elements in array */
|
||||
atom_t *for_code[256]; /* code --> one-char-atom */
|
||||
} atoms;
|
||||
|
||||
struct
|
||||
{ ExtensionCell _ext_head; /* head of registered extensions */
|
||||
ExtensionCell _ext_tail; /* tail of this chain */
|
||||
|
||||
InitialiseHandle initialise_head; /* PL_initialise_hook() */
|
||||
InitialiseHandle initialise_tail;
|
||||
PL_dispatch_hook_t dispatch_events; /* PL_dispatch_hook() */
|
||||
|
||||
int _loaded; /* system extensions are loaded */
|
||||
} foreign;
|
||||
|
||||
#ifdef O_PLMT
|
||||
FreeChunk left_over_pool; /* Left-over from threads */
|
||||
|
||||
struct
|
||||
{ struct _at_exit_goal *exit_goals; /* Global thread_at_exit/1 goals */
|
||||
int enabled; /* threads are enabled */
|
||||
Table mutexTable; /* Name --> mutex table */
|
||||
int mutex_next_id; /* next id for anonymous mutexes */
|
||||
struct pl_mutex* MUTEX_load; /* The $load mutex */
|
||||
#ifdef __WINDOWS__
|
||||
HINSTANCE instance; /* Win32 process instance */
|
||||
#endif
|
||||
counting_mutex *mutexes; /* Registered mutexes */
|
||||
int thread_max; /* Maximum # threads */
|
||||
PL_thread_info_t **threads; /* Pointers to thread-info */
|
||||
} thread;
|
||||
#endif /*O_PLMT*/
|
||||
|
||||
struct /* pl-format.c */
|
||||
{ Table predicates;
|
||||
} format;
|
||||
|
||||
struct
|
||||
{/* Procedure dgarbage_collect1; */
|
||||
/* Procedure catch3; */
|
||||
/* Procedure true0; */
|
||||
/* Procedure fail0; */
|
||||
/* Procedure equals2; /\* =/2 *\/ */
|
||||
/* Procedure is2; /\* is/2 *\/ */
|
||||
/* Procedure strict_equal2; /\* ==/2 *\/ */
|
||||
/* Procedure event_hook1; */
|
||||
/* Procedure exception_hook4; */
|
||||
/* Procedure print_message2; */
|
||||
/* Procedure foreign_registered2; /\* $foreign_registered/2 *\/ */
|
||||
/* Procedure prolog_trace_interception4; */
|
||||
predicate_t portray; /* portray/1 */
|
||||
/* Procedure dcall1; /\* $call/1 *\/ */
|
||||
/* Procedure setup_call_catcher_cleanup4; /\* setup_call_catcher_cleanup/4 *\/ */
|
||||
/* Procedure undefinterc4; /\* $undefined_procedure/4 *\/ */
|
||||
/* Procedure dthread_init0; /\* $thread_init/0 *\/ */
|
||||
/* Procedure dc_call_prolog0; /\* $c_call_prolog/0 *\/ */
|
||||
/* #ifdef O_ATTVAR */
|
||||
/* Procedure dwakeup1; /\* system:$wakeup/1 *\/ */
|
||||
predicate_t portray_attvar1; /* $attvar:portray_attvar/1 */
|
||||
/* #endif */
|
||||
/* #ifdef O_CALL_RESIDUE */
|
||||
/* Procedure call_residue_vars2; /\* $attvar:call_residue_vars/2 *\/ */
|
||||
/* #endif */
|
||||
|
||||
/* SourceFile reloading; /\* source file we are re-loading *\/ */
|
||||
/* int active_marked; /\* #prodedures marked active *\/ */
|
||||
/* int static_dirty; /\* #static dirty procedures *\/ */
|
||||
|
||||
/* #ifdef O_CLAUSEGC */
|
||||
/* DefinitionChain dirty; /\* List of dirty static procedures *\/ */
|
||||
/* #endif */
|
||||
} procedures;
|
||||
|
||||
} gds_t;
|
||||
|
||||
extern gds_t gds;
|
||||
|
||||
#define GD (&gds)
|
||||
#define GLOBAL_LD (&gds)
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{ unsigned long flags; /* Fast access to some boolean Prolog flags */
|
||||
@ -484,7 +350,6 @@ typedef struct
|
||||
#define setPrologFlagMask(flag) set(&LD->prolog_flag.mask, flag)
|
||||
#define clearPrologFlagMask(flag) clear(&LD->prolog_flag.mask, flag)
|
||||
|
||||
|
||||
// LOCAL variables (heap will get this form LOCAL
|
||||
|
||||
#define FT_ATOM 0 /* atom feature */
|
||||
@ -533,12 +398,14 @@ typedef struct
|
||||
int64_t character; /* current character location */
|
||||
} source_location;
|
||||
|
||||
|
||||
typedef struct exception_frame /* PL_throw exception environments */
|
||||
{ struct exception_frame *parent; /* parent frame */
|
||||
jmp_buf exception_jmp_env; /* longjmp environment */
|
||||
} exception_frame;
|
||||
|
||||
/* vsc: global variables */
|
||||
#include "pl-global.h"
|
||||
|
||||
#define EXCEPTION_GUARDED(code, cleanup) \
|
||||
{ exception_frame __throw_env; \
|
||||
__throw_env.parent = LD->exception.throw_environment; \
|
||||
@ -565,126 +432,6 @@ it mean anything?
|
||||
#define startCritical TRUE
|
||||
#define endCritical TRUE
|
||||
|
||||
/* The LD macro layer */
|
||||
typedef struct PL_local_data {
|
||||
|
||||
struct /* Local IO stuff */
|
||||
{ IOSTREAM *streams[6]; /* handles for standard streams */
|
||||
struct input_context *input_stack; /* maintain input stream info */
|
||||
struct output_context *output_stack; /* maintain output stream info */
|
||||
} IO;
|
||||
|
||||
struct
|
||||
{ Table table; /* Feature table */
|
||||
pl_features_t mask; /* Masked access to booleans */
|
||||
int write_attributes; /* how to write attvars? */
|
||||
occurs_check_t occurs_check; /* Unify and occurs check */
|
||||
} feature;
|
||||
|
||||
source_location read_source; /* file, line, char of last term */
|
||||
|
||||
struct
|
||||
{ int active; /* doing pipe I/O */
|
||||
jmp_buf context; /* context of longjmp() */
|
||||
} pipe;
|
||||
|
||||
struct
|
||||
{ atom_t current; /* current global prompt */
|
||||
atom_t first; /* how to prompt first line */
|
||||
int first_used; /* did we do the first line? */
|
||||
int next; /* prompt on next read operation */
|
||||
} prompt;
|
||||
|
||||
struct
|
||||
{ Table table; /* Feature table */
|
||||
pl_features_t mask; /* Masked access to booleans */
|
||||
int write_attributes; /* how to write attvars? */
|
||||
occurs_check_t occurs_check; /* Unify and occurs check */
|
||||
} prolog_flag;
|
||||
|
||||
void * glob_info; /* pl-glob.c */
|
||||
IOENC encoding; /* default I/O encoding */
|
||||
|
||||
struct
|
||||
{ char * _CWDdir;
|
||||
size_t _CWDlen;
|
||||
#ifdef __BEOS__
|
||||
status_t dl_error; /* dlopen() emulation in pl-beos.c */
|
||||
#endif
|
||||
int rand_initialised; /* have we initialised random? */
|
||||
} os;
|
||||
|
||||
struct
|
||||
{ int64_t pending; /* PL_raise() pending signals */
|
||||
int current; /* currently processing signal */
|
||||
int is_sync; /* current signal is synchronous */
|
||||
record_t exception; /* Pending exception from signal */
|
||||
#ifdef O_PLMT
|
||||
simpleMutex sig_lock; /* lock delivery and processing */
|
||||
#endif
|
||||
} signal;
|
||||
|
||||
int critical; /* heap is being modified */
|
||||
|
||||
struct
|
||||
{ term_t term; /* exception term */
|
||||
term_t bin; /* temporary handle for exception */
|
||||
term_t printed; /* already printed exception */
|
||||
term_t tmp; /* tmp for errors */
|
||||
term_t pending; /* used by the debugger */
|
||||
int in_hook; /* inside exception_hook() */
|
||||
int processing; /* processing an exception */
|
||||
exception_frame *throw_environment; /* PL_throw() environments */
|
||||
} exception;
|
||||
const char *float_format; /* floating point format */
|
||||
|
||||
struct {
|
||||
buffer _discardable_buffer; /* PL_*() character buffers */
|
||||
buffer _buffer_ring[BUFFER_RING_SIZE];
|
||||
int _current_buffer_id;
|
||||
} fli;
|
||||
|
||||
#ifdef O_GMP
|
||||
struct
|
||||
{
|
||||
int persistent; /* do persistent operations */
|
||||
} gmp;
|
||||
#endif
|
||||
|
||||
} PL_local_data_t;
|
||||
|
||||
#define usedStack(D) 0
|
||||
|
||||
#define features (LD->feature.mask)
|
||||
|
||||
extern PL_local_data_t lds;
|
||||
|
||||
#define exception_term (LD->exception.term)
|
||||
|
||||
// THIS HAS TO BE ABSTRACTED
|
||||
|
||||
#define LD (&lds)
|
||||
#define LOCAL_LD (&lds)
|
||||
|
||||
#define ARG_LD
|
||||
#define GET_LD
|
||||
#define PRED_LD
|
||||
#define PASS_LD
|
||||
|
||||
#define Suser_input (LD->IO.streams[0])
|
||||
#define Suser_output (LD->IO.streams[1])
|
||||
#define Suser_error (LD->IO.streams[2])
|
||||
#define Scurin (LD->IO.streams[3])
|
||||
#define Scurout (LD->IO.streams[4])
|
||||
#define Sprotocol (LD->IO.streams[5])
|
||||
#define Sdin Suser_input /* not used for now */
|
||||
#define Sdout Suser_output
|
||||
|
||||
#define source_line_no (LD->read_source.line)
|
||||
#define source_file_name (LD->read_source.file)
|
||||
#define source_line_pos (LD->read_source.linepos)
|
||||
#define source_char_no (LD->read_source.character)
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
typedef YAP_Term Module;
|
||||
typedef YAP_Term *Word; /* Anonymous 4 byte object */
|
||||
typedef YAP_Atom Atom;
|
||||
typedef YAP_Term (*Func)(term_t); /* foreign functions */
|
||||
|
||||
extern const char *Yap_GetCurrentPredName(void);
|
||||
@ -154,10 +153,10 @@ extern term_t Yap_CvtTerm(term_t ts);
|
||||
#define clearNumber(n)
|
||||
|
||||
inline static int
|
||||
charCode(YAP_Term w)
|
||||
{ if ( YAP_IsAtomTerm(w) )
|
||||
charCode(Term w)
|
||||
{ if ( IsAtomTerm(w) )
|
||||
{
|
||||
Atom a = atomValue(w);
|
||||
YAP_Atom a = atomValue(w);
|
||||
|
||||
if ( YAP_AtomNameLength(a) == 1) {
|
||||
if (YAP_IsWideAtom(a)) {
|
||||
|
Reference in New Issue
Block a user