more integration and cleanup work: allow irect access from YAP to swi global and local, to

check flags quickly.
This commit is contained in:
Vitor Santos Costa 2013-11-13 12:57:52 +00:00
parent 4fa9021a7b
commit 220970db6d
11 changed files with 275 additions and 251 deletions

View File

@ -909,7 +909,6 @@ InitFlags(void)
yap_flags[INTEGER_ROUNDING_FLAG] = 0;
yap_flags[YAP_MAX_INTEGER_FLAG] = (Int)(~((CELL)1 << (sizeof(Int)*8-1)));
yap_flags[YAP_MIN_INTEGER_FLAG] = (Int)(((CELL)1 << (sizeof(Int)*8-1)));
yap_flags[CHAR_CONVERSION_FLAG] = 1;
yap_flags[YAP_TO_CHARS_FLAG] = ISO_TO_CHARS;
yap_flags[LANGUAGE_MODE_FLAG] = 0;
yap_flags[STRICT_ISO_FLAG] = FALSE;

View File

@ -29,6 +29,8 @@ static char SccsId[] = "%W% %G%";
#include "YapHeap.h"
#include "yapio.h"
#include "eval.h"
/* stuff we want to use in standard YAP code */
#include "pl-shared.h"
#include <stdlib.h>
#if HAVE_STDARG_H
#include <stdarg.h>
@ -974,7 +976,8 @@ p_char_conversion( USES_REGS1 )
}
/* check if we do have a table for converting characters */
if (CharConversionTable2 == NULL) {
int i;
GET_LD
int i;
/* don't create a table if we don't need to */
if (s0[0] == s1[0])
@ -986,7 +989,7 @@ p_char_conversion( USES_REGS1 )
return(FALSE);
}
}
if (yap_flags[CHAR_CONVERSION_FLAG] != 0) {
if (truePrologFlag(PLFLAG_CHARCONVERSION)) {
if (p_force_char_conversion( PASS_REGS1 ) == FALSE)
return(FALSE);
}

View File

@ -51,6 +51,8 @@ static char SccsId[] = "%W% %G%";
#include "YapHeap.h"
#include "yapio.h"
#include "eval.h"
/* stuff we want to use in standard YAP code */
#include "pl-shared.h"
#if HAVE_STRING_H
#include <string.h>
#endif

View File

@ -39,6 +39,8 @@
#include "yapio.h"
#include "alloc.h"
#include "eval.h"
/* stuff we want to use in standard YAP code */
#include "pl-shared.h"
#if _MSC_VER || defined(__MINGW32__)
#if HAVE_FINITE==1
#undef HAVE_FINITE

View File

@ -1649,11 +1649,6 @@ p_set_yap_flags( USES_REGS1 )
value = IntOfTerm(tvalue);
/* checking should have been performed */
switch(flag) {
case CHAR_CONVERSION_FLAG:
if (value != 0 && value != 1)
return(FALSE);
yap_flags[CHAR_CONVERSION_FLAG] = value;
break;
case YAP_TO_CHARS_FLAG:
if (value != 0 && value != 1)
return(FALSE);

View File

@ -28,6 +28,7 @@ static char SccsId[] = "%W% %G%";
#if COROUTINING
#include "attvar.h"
#endif
#include "pl-shared.h"
#if HAVE_STRING_H
#include <string.h>

25
H/Yap.h
View File

@ -347,7 +347,6 @@ typedef enum
INTEGER_ROUNDING_FLAG = 2,
YAP_MAX_INTEGER_FLAG = 3,
YAP_MIN_INTEGER_FLAG = 4,
CHAR_CONVERSION_FLAG = 5,
YAP_TO_CHARS_FLAG = 7,
LANGUAGE_MODE_FLAG = 8,
STRICT_ISO_FLAG = 9,
@ -376,8 +375,28 @@ typedef enum
#define ISO_CHARACTER_ESCAPES 1
#define SICSTUS_CHARACTER_ESCAPES 2
/* stuff we want to use in standard YAP code */
#include "pl-shared.h"
// SWI Stuff
typedef enum
{ DBG_OFF = 0, /* no debugging */
DBG_ON, /* switch on in current environment */
DBG_ALL /* switch on globally */
} debug_type;
typedef int bool;
typedef struct debuginfo
{ size_t skiplevel; /* current skip level */
bool tracing; /* are we tracing? */
debug_type debugging; /* are we debugging? */
int leashing; /* ports we are leashing */
int visible; /* ports that are visible */
bool showContext; /* tracer shows context module */
int styleCheck; /* source style checking */
int suspendTrace; /* tracing is suspended now */
//LocalFrame retryFrame; /* Frame to retry */
} pl_debugstatus_t;
// over SWI
typedef enum
{

View File

@ -1,3 +1,86 @@
typedef enum
{ LDATA_IDLE = 0,
LDATA_SIGNALLED,
LDATA_ANSWERING,
LDATA_ANSWERED
} ldata_status_t;
typedef enum
{ CLN_NORMAL = 0, /* Normal mode */
CLN_ACTIVE, /* Started cleanup */
CLN_FOREIGN, /* Foreign hooks */
CLN_PROLOG, /* Prolog hooks */
CLN_SHARED, /* Unload shared objects */
CLN_DATA /* Remaining data */
} cleanup_status;
#ifdef O_PLMT
typedef struct free_chunk *FreeChunk; /* left-over chunk */
struct free_chunk
{ FreeChunk next; /* next of chain */
size_t size; /* size of free bit */
};
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;
PL_thread_info_t *SWI_thread_info(int tid, PL_thread_info_t *info);
intptr_t system_thread_id(PL_thread_info_t *info);
#endif
typedef struct
{ unsigned long flags; /* Fast access to some boolean Prolog flags */
} pl_features_t;
typedef enum
{ OCCURS_CHECK_FALSE = 0,
OCCURS_CHECK_TRUE,
OCCURS_CHECK_ERROR
} occurs_check_t;
typedef enum
{ ACCESS_LEVEL_USER = 0, /* Default user view */
ACCESS_LEVEL_SYSTEM /* Allow low-level access */
} access_level_t;
typedef struct exception_frame /* PL_throw exception environments */
{ struct exception_frame *parent; /* parent frame */
jmp_buf exception_jmp_env; /* longjmp environment */
} exception_frame;
typedef struct
{ atom_t file; /* current source file */
int line; /* current line */
int linepos; /* position in the line */
int64_t character; /* current character location */
} source_location;
typedef struct
{ size_t localSize; /* size of local stack */
size_t globalSize; /* size of global stack */

View File

@ -13,12 +13,6 @@
#define EMULATE_DLOPEN 1
#endif
#if defined(__GNUC__) && !defined(MAY_ALIAS)
#define MAY_ALIAS __attribute__ ((__may_alias__))
#else
#define MAY_ALIAS
#endif
#ifndef PL_CONSOLE
#define PL_KERNEL 1
#endif
@ -170,7 +164,6 @@ typedef enum
#if HAVE_STRING_H
#include <string.h>
#endif
#define COMMON(X) X
#ifdef HAVE_LOCALE_H
#include <locale.h>
@ -240,54 +233,12 @@ users foreign language code.
#define WM_SIGNALLED (WM_USER+4201) /* how to select a good number!? */
#endif
// THIS HAS TO BE ABSTRACTED
#define GLOBAL_LD (LOCAL_PL_local_data_p)
#if !defined(O_PLMT) && !defined(YAPOR)
#define LOCAL_LD (GLOBAL_LD)
#define LD (GLOBAL_LD)
#define ARG1_LD void
#define ARG_LD
#define GET_LD
#define PRED_LD
#define PASS_LD
#define PASS_LD1
#define IGNORE_LD
#else
#define LOCAL_LD (__PL_ld)
#define LD LOCAL_LD
#define GET_LD CACHE_REGS struct PL_local_data *__PL_ld = GLOBAL_LD;
#define ARG1_LD struct PL_local_data *__PL_ld
#define ARG_LD , ARG1_LD
#define PASS_LD1 LD
#define PASS_LD , LD
#define PRED_LD GET_LD
#define IGNORE_LD (void)__PL_ld;
#endif
/********************************
* UTILITIES *
*********************************/
#define ROUND(p, n) ((((p) + (n) - 1) & ~((n) - 1)))
/********************************
* HASH TABLES *
*********************************/
#include "pl-table.h"
/********************************
* OS *
*********************************/
#include "pl-os.h"
/********************************
* Error *
*********************************/
@ -300,14 +251,6 @@ users foreign language code.
#include "pl-files.h"
/********************************
* BUFFERS *
*********************************/
#define BUFFER_RING_SIZE 16 /* foreign buffer ring (pl-fli.c) */
#include "pl-buffer.h"
/*******************************
* OPTION LISTS *
*******************************/
@ -409,60 +352,13 @@ typedef struct
#define GF_PROCEDURE 2 /* check for max arity */
#ifdef O_PLMT
typedef struct free_chunk *FreeChunk; /* left-over chunk */
struct free_chunk
{ FreeChunk next; /* next of chain */
size_t size; /* size of free bit */
};
#endif
/*******************************
* LIST BUILDING *
*******************************/
#include "pl-privitf.h"
typedef enum
{ CLN_NORMAL = 0, /* Normal mode */
CLN_ACTIVE, /* Started cleanup */
CLN_FOREIGN, /* Foreign hooks */
CLN_PROLOG, /* Prolog hooks */
CLN_SHARED, /* Unload shared objects */
CLN_DATA /* Remaining data */
} cleanup_status;
typedef struct
{ char *state; /* system's boot file */
char *startup; /* default user startup file */
int local; /* default local stack size (K) */
int global; /* default global stack size (K) */
int trail; /* default trail stack size (K) */
char *goal; /* default initialisation goal */
char *toplevel; /* default top level goal */
bool notty; /* use tty? */
char *arch; /* machine/OS we are using */
char *home; /* systems home directory */
} pl_defaults_t;
typedef struct tempfile * TempFile; /* pl-os.c */
typedef struct canonical_dir * CanonicalDir; /* pl-os.c */
typedef struct on_halt * OnHalt; /* pl-os.c */
typedef struct extension_cell * ExtensionCell; /* pl-ext.c */
typedef struct initialise_handle * InitialiseHandle;
typedef struct
{ unsigned long flags; /* Fast access to some boolean Prolog flags */
} pl_features_t;
#define truePrologFlag(flag) true(&LD->prolog_flag.mask, flag)
#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
@ -475,75 +371,10 @@ typedef struct
#define FT_FROM_VALUE 0x0f /* Determine type from value */
#define FT_MASK 0x0f /* mask to get type */
#define PLFLAG_CHARESCAPE 0x000001 /* handle \ in atoms */
#define PLFLAG_GC 0x000002 /* do GC */
#define PLFLAG_TRACE_GC 0x000004 /* verbose gc */
#define PLFLAG_TTY_CONTROL 0x000008 /* allow for tty control */
#define PLFLAG_READLINE 0x000010 /* readline is loaded */
#define PLFLAG_DEBUG_ON_ERROR 0x000020 /* start tracer on error */
#define PLFLAG_REPORT_ERROR 0x000040 /* print error message */
#define PLFLAG_FILE_CASE 0x000080 /* file names are case sensitive */
#define PLFLAG_FILE_CASE_PRESERVING 0x000100 /* case preserving file names */
#define PLFLAG_DOS_FILE_NAMES 0x000200 /* dos (8+3) file names */
#define ALLOW_VARNAME_FUNCTOR 0x000400 /* Read Foo(x) as 'Foo'(x) */
#define PLFLAG_ISO 0x000800 /* Strict ISO compliance */
#define PLFLAG_OPTIMISE 0x001000 /* -O: optimised compilation */
#define PLFLAG_FILEVARS 0x002000 /* Expand $var and ~ in filename */
#define PLFLAG_AUTOLOAD 0x004000 /* do autoloading */
#define PLFLAG_CHARCONVERSION 0x008000 /* do character-conversion */
#define PLFLAG_LASTCALL 0x010000 /* Last call optimization enabled? */
#define PLFLAG_EX_ABORT 0x020000 /* abort with exception */
#define PLFLAG_BACKQUOTED_STRING 0x040000 /* `a string` */
#define PLFLAG_SIGNALS 0x080000 /* Handle signals */
#define PLFLAG_DEBUGINFO 0x100000 /* generate debug info */
#define PLFLAG_FILEERRORS 0x200000 /* Edinburgh file errors */
typedef enum
{ OCCURS_CHECK_FALSE = 0,
OCCURS_CHECK_TRUE,
OCCURS_CHECK_ERROR
} occurs_check_t;
typedef struct
{ atom_t file; /* current source file */
int line; /* current line */
int linepos; /* position in the line */
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;
/*******************************
* STREAM I/O *
*******************************/
#define REDIR_MAGIC 0x23a9bef3
typedef struct redir_context
{ int magic; /* REDIR_MAGIC */
IOSTREAM *stream; /* temporary output */
int is_stream; /* redirect to stream */
int redirected; /* output is redirected */
term_t term; /* redirect target */
int out_format; /* output type */
int out_arity; /* 2 for difference-list versions */
size_t size; /* size of I/O buffer */
char *data; /* data written */
char buffer[1024]; /* fast temporary buffer */
} redir_context;
#include "pl-file.h"
#define SYSTEM_MODE (LD->prolog_flag.access_level == ACCESS_LEVEL_SYSTEM)
#define PL_malloc_atomic malloc
/* vsc: global variables */
#include "pl-global.h"
#define EXCEPTION_GUARDED(code, cleanup) \
{ exception_frame __throw_env; \
__throw_env.parent = LD->exception.throw_environment; \
@ -684,18 +515,6 @@ void remove_string(char *s);
typedef double real;
#define true(s, a) ((s)->flags & (a))
#define false(s, a) (!true((s), (a)))
#define set(s, a) ((s)->flags |= (a))
#define clear(s, a) ((s)->flags &= ~(a))
#ifdef DEBUG
/* should have messages here */
#undef DEBUG
#define DEBUG(LEVEL, COMMAND)
#else
#define DEBUG(LEVEL, COMMAND)
#endif
#define forwards static /* forwards function declarations */
/* uxnt package interface */

View File

@ -3,26 +3,62 @@
#define PL_SHARED_INCLUDE
#if defined(__GNUC__) && !defined(MAY_ALIAS)
#define MAY_ALIAS __attribute__ ((__may_alias__))
#else
#define MAY_ALIAS
#endif
#define COMMON(X) X
#ifndef PL_HAVE_TERM_T
#define PL_HAVE_TERM_T
typedef uintptr_t term_t;
#endif
#ifndef _FLI_H_INCLUDED
typedef void *record_t;
typedef int bool;
typedef struct mod_entry *module_t;
typedef uintptr_t atom_t;
typedef int (*PL_dispatch_hook_t)(int fd);
typedef struct pred_entry *predicate_t;
typedef uintptr_t PL_fid_t; /* opaque foreign context handle */
#define fid_t PL_fid_t /* avoid AIX name-clash */
#endif
typedef enum
{ ACCESS_LEVEL_USER = 0, /* Default user view */
ACCESS_LEVEL_SYSTEM /* Allow low-level access */
} access_level_t;
#define GLOBAL_LD (LOCAL_PL_local_data_p)
typedef enum
{ LDATA_IDLE = 0,
LDATA_SIGNALLED,
LDATA_ANSWERING,
LDATA_ANSWERED
} ldata_status_t;
#if !defined(O_PLMT) && !defined(YAPOR)
#define LOCAL_LD (GLOBAL_LD)
#define LD (GLOBAL_LD)
#define ARG1_LD void
#define ARG_LD
#define GET_LD
#define PRED_LD
#define PASS_LD
#define PASS_LD1
#define IGNORE_LD
#else
#define LOCAL_LD (__PL_ld)
#define LD LOCAL_LD
#define GET_LD CACHE_REGS struct PL_local_data *__PL_ld = GLOBAL_LD;
#define ARG1_LD struct PL_local_data *__PL_ld
#define ARG_LD , ARG1_LD
#define PASS_LD1 LD
#define PASS_LD , LD
#define PRED_LD GET_LD
#define IGNORE_LD (void)__PL_ld;
#endif
#if _WIN32
#ifndef THREADS
@ -30,39 +66,119 @@ typedef int pthread_t;
#endif
#endif
#if THREADS
#include "SWI-Stream.h"
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;
/*******************************
* STREAM I/O *
*******************************/
PL_thread_info_t *SWI_thread_info(int tid, PL_thread_info_t *info);
intptr_t system_thread_id(PL_thread_info_t *info);
#define REDIR_MAGIC 0x23a9bef3
typedef struct redir_context
{ int magic; /* REDIR_MAGIC */
IOSTREAM *stream; /* temporary output */
int is_stream; /* redirect to stream */
int redirected; /* output is redirected */
term_t term; /* redirect target */
int out_format; /* output type */
int out_arity; /* 2 for difference-list versions */
size_t size; /* size of I/O buffer */
char *data; /* data written */
char buffer[1024]; /* fast temporary buffer */
} redir_context;
#include "pl-file.h"
/********************************
* HASH TABLES *
*********************************/
#include "pl-table.h"
/********************************
* BUFFERS *
*********************************/
#define BUFFER_RING_SIZE 16 /* foreign buffer ring (pl-fli.c) */
#include "pl-buffer.h"
typedef struct canonical_dir * CanonicalDir; /* pl-os.c */
typedef struct
{ char *state; /* system's boot file */
char *startup; /* default user startup file */
int local; /* default local stack size (K) */
int global; /* default global stack size (K) */
int trail; /* default trail stack size (K) */
char *goal; /* default initialisation goal */
char *toplevel; /* default top level goal */
bool notty; /* use tty? */
char *arch; /* machine/OS we are using */
char *home; /* systems home directory */
} pl_defaults_t;
typedef struct on_halt * OnHalt; /* pl-os.c */
typedef struct extension_cell * ExtensionCell; /* pl-ext.c */
typedef struct tempfile * TempFile; /* pl-os.c */
typedef struct initialise_handle * InitialiseHandle;
/********************************
* Operating System *
*********************************/
#include "pl-os.h"
/********************************
* Table *
*********************************/
#include "pl-table.h"
/* vsc: global variables */
#include "pl-global.h"
// THIS HAS TO BE ABSTRACTED
#define true(s, a) ((s)->flags & (a))
#define false(s, a) (!true((s), (a)))
#define set(s, a) ((s)->flags |= (a))
#define clear(s, a) ((s)->flags &= ~(a))
#ifdef DEBUG
/* should have messages here */
#undef DEBUG
#define DEBUG(LEVEL, COMMAND)
#else
#define DEBUG(LEVEL, COMMAND)
#endif
#define PLFLAG_CHARESCAPE 0x000001 /* handle \ in atoms */
#define PLFLAG_GC 0x000002 /* do GC */
#define PLFLAG_TRACE_GC 0x000004 /* verbose gc */
#define PLFLAG_TTY_CONTROL 0x000008 /* allow for tty control */
#define PLFLAG_READLINE 0x000010 /* readline is loaded */
#define PLFLAG_DEBUG_ON_ERROR 0x000020 /* start tracer on error */
#define PLFLAG_REPORT_ERROR 0x000040 /* print error message */
#define PLFLAG_FILE_CASE 0x000080 /* file names are case sensitive */
#define PLFLAG_FILE_CASE_PRESERVING 0x000100 /* case preserving file names */
#define PLFLAG_DOS_FILE_NAMES 0x000200 /* dos (8+3) file names */
#define ALLOW_VARNAME_FUNCTOR 0x000400 /* Read Foo(x) as 'Foo'(x) */
#define PLFLAG_ISO 0x000800 /* Strict ISO compliance */
#define PLFLAG_OPTIMISE 0x001000 /* -O: optimised compilation */
#define PLFLAG_FILEVARS 0x002000 /* Expand $var and ~ in filename */
#define PLFLAG_AUTOLOAD 0x004000 /* do autoloading */
#define PLFLAG_CHARCONVERSION 0x008000 /* do character-conversion */
#define PLFLAG_LASTCALL 0x010000 /* Last call optimization enabled? */
#define PLFLAG_EX_ABORT 0x020000 /* abort with exception */
#define PLFLAG_BACKQUOTED_STRING 0x040000 /* `a string` */
#define PLFLAG_SIGNALS 0x080000 /* Handle signals */
#define PLFLAG_DEBUGINFO 0x100000 /* generate debug info */
#define PLFLAG_FILEERRORS 0x200000 /* Edinburgh file errors */
/* Flags on module. Most of these flags are copied to the read context
in pl-read.c.
*/
@ -81,25 +197,10 @@ intptr_t system_thread_id(PL_thread_info_t *info);
extern unsigned int
getUnknownModule(module_t m);
typedef enum
{ DBG_OFF = 0, /* no debugging */
DBG_ON, /* switch on in current environment */
DBG_ALL /* switch on globally */
} debug_type;
typedef struct debuginfo
{ size_t skiplevel; /* current skip level */
bool tracing; /* are we tracing? */
debug_type debugging; /* are we debugging? */
int leashing; /* ports we are leashing */
int visible; /* ports that are visible */
bool showContext; /* tracer shows context module */
int styleCheck; /* source style checking */
int suspendTrace; /* tracing is suspended now */
//LocalFrame retryFrame; /* Frame to retry */
} pl_debugstatus_t;
#define debugstatus LOCAL_debugstatus /* status of the debugger */
#define truePrologFlag(flag) true(&LD->prolog_flag.mask, flag)
#define setPrologFlagMask(flag) set(&LD->prolog_flag.mask, flag)
#define clearPrologFlagMask(flag) clear(&LD->prolog_flag.mask, flag)
#endif /* PL_SHARED_INCLUDE */

View File

@ -141,7 +141,7 @@ typedef uintptr_t term_t;
typedef struct mod_entry *module_t;
typedef void *record_t;
typedef uintptr_t atom_t;
typedef YAP_Term *predicate_t;
typedef struct pred_entry *predicate_t;
typedef struct open_query_struct *qid_t;
typedef uintptr_t functor_t;
typedef int (*PL_agc_hook_t)(atom_t);