This commit is contained in:
Vitor Santos Costa 2017-10-04 09:18:17 +01:00
parent d05b1f4b2b
commit dd48ba6f91
9 changed files with 814 additions and 859 deletions

View File

@ -28,7 +28,7 @@
* mirroring * mirroring
*/ */
#include "../utf8proc/utf8proc.h" #include "utf8proc.h"
#include "Yap.h" #include "Yap.h"
/// allocate a temporary text block /// allocate a temporary text block
@ -51,15 +51,15 @@ extern void *export_block(void *blk);
/* Character types for tokenizer and write.c */ /* Character types for tokenizer and write.c */
extern int AllocLevel(void); extern int AllocLevel(void);
#define push_text_stack() \ #define push_text_stack() \
(/* fprintf(stderr, "^ %*c %s:%s:%d\n", AllocLevel(), AllocLevel()+'0', \ (/* fprintf(stderr, "^ %*c %s:%s:%d\n", AllocLevel(), AllocLevel()+'0', \
__FILE__, __FUNCTION__, __LINE__), */ \ __FILE__, __FUNCTION__, __LINE__), */ \
push_text_stack__(PASS_REGS1)) push_text_stack__(PASS_REGS1))
extern int push_text_stack__(USES_REGS1); extern int push_text_stack__(USES_REGS1);
#define pop_text_stack(lvl) \ #define pop_text_stack(lvl) \
(/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, \ (/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, \
__FUNCTION__, __LINE__),*/ \ __FUNCTION__, __LINE__),*/ \
pop_text_stack__(lvl)) pop_text_stack__(lvl))
extern int pop_text_stack__(int lvl USES_REGS); extern int pop_text_stack__(int lvl USES_REGS);

200
H/Yatom.h
View File

@ -1,19 +1,19 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog %W% %G% * YAP Prolog %W% %G%
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: YAtom.h.m4 * * File: YAtom.h.m4 *
* Last rev: 19/2/88 * * Last rev: 19/2/88 *
* mods: * * mods: *
* comments: atom properties header file for YAP * * comments: atom properties header file for YAP *
* * * *
*************************************************************************/ *************************************************************************/
/* This code can only be defined *after* including Regs.h!!! */ /* This code can only be defined *after* including Regs.h!!! */
@ -106,73 +106,73 @@ INLINE_ONLY inline EXTERN Prop AbsFunctorProp(FunctorEntry *p) {
#endif #endif
INLINE_ONLY inline EXTERN arity_t ArityOfFunctor(Functor); INLINE_ONLY inline EXTERN arity_t ArityOfFunctor(Functor);
INLINE_ONLY inline EXTERN arity_t ArityOfFunctor(Functor Fun) { INLINE_ONLY inline EXTERN arity_t ArityOfFunctor(Functor Fun) {
return (arity_t)(((FunctorEntry *)Fun)->ArityOfFE); return (arity_t)(((FunctorEntry *)Fun)->ArityOfFE);
} }
INLINE_ONLY inline EXTERN Atom NameOfFunctor(Functor); INLINE_ONLY inline EXTERN Atom NameOfFunctor(Functor);
INLINE_ONLY inline EXTERN Atom NameOfFunctor(Functor Fun) { INLINE_ONLY inline EXTERN Atom NameOfFunctor(Functor Fun) {
return (Atom)(((FunctorEntry *)Fun)->NameOfFE); return (Atom)(((FunctorEntry *)Fun)->NameOfFE);
} }
INLINE_ONLY inline EXTERN PropFlags IsFunctorProperty(int); INLINE_ONLY inline EXTERN PropFlags IsFunctorProperty(int);
INLINE_ONLY inline EXTERN PropFlags IsFunctorProperty(int flags) { INLINE_ONLY inline EXTERN PropFlags IsFunctorProperty(int flags) {
return (PropFlags)((flags == FunctorProperty)); return (PropFlags)((flags == FunctorProperty));
} }
/* summary of property codes used /* summary of property codes used
00 00 predicate entry 00 00 predicate entry
80 00 db property 80 00 db property
bb 00 functor entry bb 00 functor entry
ff df sparse functor ff df sparse functor
ff ex arithmetic property ff ex arithmetic property
ff f4 translation ff f4 translation
ff f5 blob ff f5 blob
ff f6 hold ff f6 hold
ff f7 array ff f7 array
ff f8 wide atom ff f8 wide atom
ff fa module property ff fa module property
ff fb blackboard property ff fb blackboard property
ff fc value property ff fc value property
ff fd global property ff fd global property
ff fe flag property ff fe flag property
ff ff op property ff ff op property
*/ */
/* Global Variable property */ /* Global Variable property */
typedef struct global_entry { typedef struct global_entry {
Prop NextOfPE; /* used to chain properties */ Prop NextOfPE; /* used to chain properties */
PropFlags KindOfPE; /* kind of property */ PropFlags KindOfPE; /* kind of property */
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
rwlock_t GRWLock; /* a simple lock to protect this entry */ rwlock_t GRWLock; /* a simple lock to protect this entry */
#if THREADS #if THREADS
unsigned int owner_id; /* owner thread */ unsigned int owner_id; /* owner thread */
#endif #endif
#endif #endif
struct AtomEntryStruct *AtomOfGE; /* parent atom for deletion */ struct AtomEntryStruct *AtomOfGE; /* parent atom for deletion */
struct global_entry *NextGE; /* linked list of global entries */ struct global_entry *NextGE; /* linked list of global entries */
Term global; /* index in module table */ Term global; /* index in module table */
Term AttChain; /* index in module table */ Term AttChain; /* index in module table */
} GlobalEntry; } GlobalEntry;
#if USE_OFFSETS_IN_PROPS #if USE_OFFSETS_IN_PROPS
INLINE_ONLY inline EXTERN GlobalEntry *RepGlobalProp(Prop p); INLINE_ONLY inline EXTERN GlobalEntry *RepGlobalProp(Prop p);
INLINE_ONLY inline EXTERN GlobalEntry *RepGlobalProp(Prop p) { INLINE_ONLY inline EXTERN GlobalEntry *RepGlobalProp(Prop p) {
return (GlobalEntry *)(AtomBase + Unsigned(p)); return (GlobalEntry *)(AtomBase + Unsigned(p));
} }
INLINE_ONLY inline EXTERN Prop AbsGlobalProp(GlobalEntry *p); INLINE_ONLY inline EXTERN Prop AbsGlobalProp(GlobalEntry *p);
INLINE_ONLY inline EXTERN Prop AbsGlobalProp(GlobalEntry *p) { INLINE_ONLY inline EXTERN Prop AbsGlobalProp(GlobalEntry *p) {
return (Prop)(Addr(p) - AtomBase); return (Prop)(Addr(p) - AtomBase);
} }
#else #else
@ -443,40 +443,53 @@ don't forget to also add in qly.h
*/ */
/// Different predicate flags /// Different predicate flags
typedef uint64_t pred_flags_t; typedef uint64_t pred_flags_t;
#define UndefPredFlag ((pred_flags_t)0x4000000000) //< Predicate not explicitely defined. #define UndefPredFlag \
#define ProfiledPredFlag ((pred_flags_t)0x2000000000) //< pred is being profiled ((pred_flags_t)0x4000000000) //< Predicate not explicitely defined.
#define DiscontiguousPredFlag ((pred_flags_t)0x1000000000) //< predicates whose clauses may be all-over the place.. #define ProfiledPredFlag ((pred_flags_t)0x2000000000) //< pred is being profiled
#define SysExportPredFlag ((pred_flags_t)0x800000000) //< reuse export list to prolog module. #define DiscontiguousPredFlag \
#define NoTracePredFlag ((pred_flags_t)0x400000000) //< cannot trace this predicate ((pred_flags_t)0x1000000000) //< predicates whose clauses may be all-over the
#define NoSpyPredFlag ((pred_flags_t)0x200000000) //< cannot spy this predicate // place..
#define QuasiQuotationPredFlag ((pred_flags_t)0x100000000) //< SWI-like quasi quotations #define SysExportPredFlag \
#define MegaClausePredFlag ((pred_flags_t)0x80000000) //< predicate is implemented as a mega-clause ((pred_flags_t)0x800000000) //< reuse export list to prolog module.
#define NoTracePredFlag \
((pred_flags_t)0x400000000) //< cannot trace this predicate
#define NoSpyPredFlag ((pred_flags_t)0x200000000) //< cannot spy this predicate
#define QuasiQuotationPredFlag \
((pred_flags_t)0x100000000) //< SWI-like quasi quotations
#define MegaClausePredFlag \
((pred_flags_t)0x80000000) //< predicate is implemented as a mega-clause
#define ThreadLocalPredFlag ((pred_flags_t)0x40000000) //< local to a thread #define ThreadLocalPredFlag ((pred_flags_t)0x40000000) //< local to a thread
#define MultiFileFlag ((pred_flags_t)0x20000000) //< is multi-file #define MultiFileFlag ((pred_flags_t)0x20000000) //< is multi-file
#define UserCPredFlag ((pred_flags_t)0x10000000) //< CPred defined by the user #define UserCPredFlag ((pred_flags_t)0x10000000) //< CPred defined by the user
#define LogUpdatePredFlag ((pred_flags_t)0x08000000) //< dynamic predicate with log. upd. sem. #define LogUpdatePredFlag \
((pred_flags_t)0x08000000) //< dynamic predicate with log. upd. sem.
#define InUsePredFlag ((pred_flags_t)0x04000000) //< count calls to pred #define InUsePredFlag ((pred_flags_t)0x04000000) //< count calls to pred
#define CountPredFlag ((pred_flags_t)0x02000000) //< count calls to pred #define CountPredFlag ((pred_flags_t)0x02000000) //< count calls to pred
#define HiddenPredFlag ((pred_flags_t)0x01000000) //< invisible predicate #define HiddenPredFlag ((pred_flags_t)0x01000000) //< invisible predicate
#define CArgsPredFlag ((pred_flags_t)0x00800000) //< SWI-like C-interface pred. #define CArgsPredFlag ((pred_flags_t)0x00800000) //< SWI-like C-interface pred.
#define SourcePredFlag ((pred_flags_t)0x00400000) //< static predicate with source declaration #define SourcePredFlag \
#define MetaPredFlag ((pred_flags_t)0x00200000) //< predicate subject to a meta declaration ((pred_flags_t)0x00400000) //< static predicate with source declaration
#define SyncPredFlag ((pred_flags_t)0x00100000) //< has to synch before it can execute #define MetaPredFlag \
#define NumberDBPredFlag ((pred_flags_t)0x00080000) //< entry for an atom key ((pred_flags_t)0x00200000) //< predicate subject to a meta declaration
#define AtomDBPredFlag ((pred_flags_t)0x00040000) //< entry for a number key #define SyncPredFlag \
// #define GoalExPredFlag ((pred_flags_t)0x00020000) /// predicate that is called by goal_expand ((pred_flags_t)0x00100000) //< has to synch before it can execute
#define TestPredFlag ((pred_flags_t)0x00010000) //< is a test (optim. comit) #define NumberDBPredFlag ((pred_flags_t)0x00080000) //< entry for an atom key
#define AsmPredFlag ((pred_flags_t)0x00008000) //< inline #define AtomDBPredFlag ((pred_flags_t)0x00040000) //< entry for a number key
// #define GoalExPredFlag ((pred_flags_t)0x00020000) /// predicate that is
// called by goal_expand
#define TestPredFlag ((pred_flags_t)0x00010000) //< is a test (optim. comit)
#define AsmPredFlag ((pred_flags_t)0x00008000) //< inline
#define StandardPredFlag ((pred_flags_t)0x00004000) //< system predicate #define StandardPredFlag ((pred_flags_t)0x00004000) //< system predicate
#define DynamicPredFlag ((pred_flags_t)0x00002000) //< dynamic predicate #define DynamicPredFlag ((pred_flags_t)0x00002000) //< dynamic predicate
#define CPredFlag ((pred_flags_t)0x00001000) //< written in C #define CPredFlag ((pred_flags_t)0x00001000) //< written in C
#define SafePredFlag ((pred_flags_t)0x00000800) //< does not alter arguments #define SafePredFlag ((pred_flags_t)0x00000800) //< does not alter arguments
#define CompiledPredFlag ((pred_flags_t)0x00000400) //< is static #define CompiledPredFlag ((pred_flags_t)0x00000400) //< is static
#define IndexedPredFlag ((pred_flags_t)0x00000200) //< has indexing code #define IndexedPredFlag ((pred_flags_t)0x00000200) //< has indexing code
#define SpiedPredFlag ((pred_flags_t)0x00000100) //< is a spy point #define SpiedPredFlag ((pred_flags_t)0x00000100) //< is a spy point
#define BinaryPredFlag ((pred_flags_t)0x00000080) //< test predicate #define BinaryPredFlag ((pred_flags_t)0x00000080) //< test predicate
#define TabledPredFlag ((pred_flags_t)0x00000040) //< is tabled #define TabledPredFlag ((pred_flags_t)0x00000040) //< is tabled
#define SequentialPredFlag ((pred_flags_t)0x00000020) //< may not create parallel choice points! #define SequentialPredFlag \
((pred_flags_t)0x00000020) //< may not create parallel choice points!
#define BackCPredFlag ((pred_flags_t)0x00000008) //< Myddas Imported pred #define BackCPredFlag ((pred_flags_t)0x00000008) //< Myddas Imported pred
#define ModuleTransparentPredFlag ((pred_flags_t)0x00000004) #define ModuleTransparentPredFlag ((pred_flags_t)0x00000004)
#define SWIEnvPredFlag ((pred_flags_t)0x00000002) //< new SWI interface #define SWIEnvPredFlag ((pred_flags_t)0x00000002) //< new SWI interface
@ -487,9 +500,9 @@ typedef uint64_t pred_flags_t;
#define ForeignPredFlags \ #define ForeignPredFlags \
(AsmPredFlag | SWIEnvPredFlag | CPredFlag | BinaryPredFlag | UDIPredFlag | \ (AsmPredFlag | SWIEnvPredFlag | CPredFlag | BinaryPredFlag | UDIPredFlag | \
CArgsPredFlag | UserCPredFlag | SafePredFlag | BackCPredFlag) CArgsPredFlag | UserCPredFlag | SafePredFlag | BackCPredFlag)
#define LivePredFlags \ #define LivePredFlags \
(LogUpdatePredFlag|MultiFileFlag|TabledPredFlag|ForeignPredFlags) (LogUpdatePredFlag | MultiFileFlag | TabledPredFlag | ForeignPredFlags)
#define StatePredFlags \ #define StatePredFlags \
(InUsePredFlag | CountPredFlag | SpiedPredFlag | IndexedPredFlag) (InUsePredFlag | CountPredFlag | SpiedPredFlag | IndexedPredFlag)
#define is_system(pe) (pe->PredFlags & SystemPredFlags) #define is_system(pe) (pe->PredFlags & SystemPredFlags)
@ -705,8 +718,8 @@ typedef struct DB_STRUCT {
struct DB_STRUCT *p, *n; /* entry's age, negative if from recorda, struct DB_STRUCT *p, *n; /* entry's age, negative if from recorda,
positive if it was recordz */ positive if it was recordz */
CELL Mask; /* parts that should be cleared */ CELL Mask; /* parts that should be cleared */
CELL Key; /* A mask that can be used to check before CELL Key; /* A mask that can be used to check before
you unify */ you unify */
DBTerm DBT; DBTerm DBT;
} DBStruct; } DBStruct;
@ -1178,7 +1191,7 @@ INLINE_ONLY inline EXTERN bool IsArrayProperty(PropFlags flags) {
typedef struct YAP_blob_prop_entry { typedef struct YAP_blob_prop_entry {
Prop NextOfPE; /* used to chain properties */ Prop NextOfPE; /* used to chain properties */
PropFlags KindOfPE; /* kind of property */ PropFlags KindOfPE; /* kind of property */
struct YAP_blob_t *blob_type; /* type of blob */ struct _PL_blob_t *blob_type; /* type of blob */
} YAP_BlobPropEntry; } YAP_BlobPropEntry;
#if USE_OFFSETS_IN_PROPS #if USE_OFFSETS_IN_PROPS
@ -1501,7 +1514,8 @@ INLINE_ONLY EXTERN inline Prop PredPropByAtomAndMod(Atom at, Term cur_mod)
p0 = ae->PropsOfAE; p0 = ae->PropsOfAE;
while (p0) { while (p0) {
PredEntry *pe = RepPredProp(p0); PredEntry *pe = RepPredProp(p0);
if (pe->KindOfPE == PEProp && (pe->ModuleOfPred == cur_mod || pe->ModuleOfPred == 0)) { if (pe->KindOfPE == PEProp &&
(pe->ModuleOfPred == cur_mod || pe->ModuleOfPred == 0)) {
#ifdef THREADS #ifdef THREADS
/* Thread Local Predicates */ /* Thread Local Predicates */
if (pe->PredFlags & ThreadLocalPredFlag) { if (pe->PredFlags & ThreadLocalPredFlag) {
@ -1539,8 +1553,8 @@ INLINE_ONLY EXTERN inline void AddPropToAtom(AtomEntry *, PropEntry *p);
INLINE_ONLY EXTERN inline void AddPropToAtom(AtomEntry *ae, PropEntry *p) { INLINE_ONLY EXTERN inline void AddPropToAtom(AtomEntry *ae, PropEntry *p) {
/* old properties should be always last, and wide atom properties /* old properties should be always last, and wide atom properties
should always be first */ should always be first */
p->NextOfPE = ae->PropsOfAE; p->NextOfPE = ae->PropsOfAE;
ae->PropsOfAE = AbsProp(p); ae->PropsOfAE = AbsProp(p);
} }
// auxiliary functions // auxiliary functions

View File

@ -1,81 +0,0 @@
//
// blobs.h
// yap
//
// Created by VITOR SANTOS COSTA on 09/05/15.
// Copyright (c) 2015 VITOR SANTOS COSTA. All rights reserved.
//
// based on the SWI Blob implementation, an extension of atoms for SWI-Prolog
#ifndef BLOBS_H
#define BLOBS_H
#if !defined(X_API) && !defined(SWIGYAP)
#if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(PL_KERNEL)
#define X_API __declspec(dllexport)
#else
#define X_API
#endif
#endif
/*******************************
* BLOBS *
*******************************/
#define YAP_BLOB_MAGIC_B 0x75293a00 /* Magic to validate a blob-type */
#define PL_BLOB_VERSION (YAP_BLOB_MAGIC_B|PL_BLOB_VERSION)
#define PL_BLOB_UNIQUE 0x01 /* Blob content is unique */
#define PL_BLOB_TEXT 0x02 /* blob contains text */
#define PL_BLOB_NOCOPY 0x04 /* do not copy the data */
#define PL_BLOB_WCHAR 0x08 /* wide character string */
typedef struct YAP_blob_t
{ uintptr_t magic; /* YAP_BLOB_MAGIC */
uintptr_t flags; /* YAP_BLOB_* */
char * name; /* name of the type */
int (*release)(Atom a);
int (*compare)(Atom a, Atom b);
#ifdef SIO_MAGIC
int (*write)(FILE *s, Atom a, int flags);
#else
int (*write)(void *s, Atom a, int flags);
#endif
void (*acquire)(Atom a);
#ifdef SIO_MAGIC
int (*save)(Atom a, FILE *s);
Atom (*load)(FILE *s);
#else
int (*save)(Atom a, void*);
Atom (*load)(void *s);
#endif
/* private */
void * reserved[10]; /* for future extension */
int registered; /* Already registered? */
int rank; /* Rank for ordering atoms */
struct YAP_blob_t * next; /* next in registered type-chain */
Atom atom_name; /* Name as atom */
} blob_type_t;
int Yap_write_blob(AtomEntry *ref, FILE *stream);
char * Yap_blob_to_string(AtomEntry *ref, const char *s, size_t sz);
X_API bool YAP_is_blob(YAP_Term t, blob_type_t **type);
X_API bool YAP_unify_blob(YAP_Term *t, void *blob, size_t len,
blob_type_t *type);
X_API bool YAP_put_blob(YAP_Term *t, void *blob, size_t len,
blob_type_t *type);
X_API bool YAP_get_blob(YAP_Term t, void **blob, size_t *len,
blob_type_t **type);
X_API void* YAP_blob_data(Atom a,
size_t *len,
struct YAP_blob_t **type);
X_API void YAP_register_blob_type(blob_type_t *type);
X_API blob_type_t* YAP_find_blob_type(const char* name);
//YAP_blob_type_t* YAP_find_blob_type(Atom at);
X_API bool YAP_unregister_blob_type(blob_type_t *type);
#endif

File diff suppressed because it is too large Load Diff

95
include/blobs.h Normal file
View File

@ -0,0 +1,95 @@
//
// blobs.h
// yap
//
// Created by VITOR SANTOS COSTA on 09/05/15.
// Copyright (c) 2015 VITOR SANTOS COSTA. All rights reserved.
//
// based on the SWI Blob implementation, an extension of atoms for SWI-Prolog
#ifndef BLOBS_H
#define BLOBS_H
/*******************************
* BLOBS *
*******************************/
#define PL_BLOB_MAGIC_B 0x75293a00 /* Magic to validate a blob-type */
#define PL_BLOB_VERSION 1
#define PL_BLOB_MAGIC (PL_BLOB_MAGIC_B | PL_BLOB_VERSION)
#define PL_BLOB_UNIQUE 0x01 /* Blob content is unique */
#define PL_BLOB_TEXT 0x02 /* blob contains text */
#define PL_BLOB_NOCOPY 0x04 /* do not copy the data */
#define PL_BLOB_WCHAR 0x08 /* wide character string */
typedef struct _PL_blob_t {
uintptr_t magic; /* YAP_BLOB_MAGIC */
uintptr_t flags; /* YAP_BLOB_* */
char *name; /* name of the type */
int (*release)(YAP_Atom a);
int (*compare)(YAP_Atom a, YAP_Atom b);
#ifdef SIO_MAGIC
int (*write)(FILE *s, YAP_Atom a, int flags);
#else
int (*write)(void *s, YAP_Atom a, int flags);
#endif
void (*acquire)(YAP_Atom a);
#ifdef SIO_MAGIC
int (*save)(YAP_Atom a, FILE *s);
YAP_Atom (*load)(FILE *s);
#else
int (*save)(YAP_Atom a, void *);
YAP_Atom (*load)(void *s);
#endif
/* private */
void *reserved[10]; /* for future extension */
int registered; /* Already registered? */
int rank; /* Rank for ordering atoms */
struct _PL_blob_t *next; /* next in registered type-chain */
YAP_Atom atom_name; /* Name as atom */
} blob_type_t;
// typedef struct _PL_blob_t PL_blob_t;
#define YAP_BLOB_MAGIC_B PL_BLOB_MAGIC_B
#define YAP_blob_t blob_type_t
#define PL_blob_t blob_type_t
#ifdef SWI_PROLOG_H
PL_EXPORT(int) PL_is_blob(term_t t, PL_blob_t **type);
PL_EXPORT(int) PL_unify_blob(term_t t, void *blob, size_t len, PL_blob_t *type);
PL_EXPORT(int) PL_put_blob(term_t t, void *blob, size_t len, PL_blob_t *type);
PL_EXPORT(int)
PL_get_blob(term_t t, void **blob, size_t *len, PL_blob_t **type);
PL_EXPORT(void *) PL_blob_data(atom_t a, size_t *len, PL_blob_t **type);
PL_EXPORT(void) PL_register_blob_type(PL_blob_t *type);
PL_EXPORT(PL_blob_t *) PL_find_blob_type(const char *name);
PL_EXPORT(int) PL_unregister_blob_type(PL_blob_t *type);
PL_EXPORT(int) PL_raise(int sig);
#endif
#ifdef YATOM_H
extern int Yap_write_blob(AtomEntry *ref, FILE *stream);
extern char *Yap_blob_to_string(AtomEntry *ref, const char *s, size_t sz);
#endif
extern X_API bool YAP_is_blob(YAP_Term t, YAP_blob_t **type);
extern X_API bool YAP_unify_blob(YAP_Term *t, void *blob, size_t len,
YAP_blob_t *type);
extern X_API bool YAP_put_blob(YAP_Term *t, void *blob, size_t len,
YAP_blob_t *type);
extern X_API bool YAP_get_blob(YAP_Term t, void **blob, size_t *len,
YAP_blob_t **type);
extern X_API void *YAP_blob_data(YAP_Atom a, size_t *len, YAP_blob_t **type);
extern X_API void YAP_register_blob_type(YAP_blob_t *type);
extern X_API YAP_blob_t *YAP_find_blob_type(const char *name);
// extern X_API YAP_blob_t *YAP_find_blob_type(YAP_Atom at);
extern X_API bool YAP_unregister_blob_type(YAP_blob_t *type);
#endif

View File

@ -1,23 +1,23 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright V.Santos Costa and Universidade do Porto 1985-- * * Copyright V.Santos Costa and Universidade do Porto 1985-- *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: blobs.c * * File: blobs.c *
* comments: support blobs in YAP definition * * comments: support blobs in YAP definition *
* * * *
* Last rev: $Date: $,$Author: vsc $ * * Last rev: $Date: $,$Author: vsc $ *
* * * *
* * * *
*************************************************************************/ *************************************************************************/
/** /**
* *
* @{ * @{
* @file swi/fli/blobs.c * @file swi/fli/blobs.c
* *
* @addtogroup swi-c-interface * @addtogroup swi-c-interface
* *
@ -59,7 +59,7 @@ X_API int PL_is_blob(term_t t, PL_blob_t **type) {
if (!IsBlob(a)) if (!IsBlob(a))
return FALSE; return FALSE;
b = RepBlobProp(a->PropsOfAE); b = RepBlobProp(a->PropsOfAE);
*type = (struct PL_blob_t *)b->blob_type; *type = (PL_blob_t *)b->blob_type;
return TRUE; return TRUE;
} }
@ -77,7 +77,7 @@ PL_unify_blob(term_t t, void *blob, size_t len, PL_blob_t *type) {
return FALSE; return FALSE;
} }
if (type->acquire) { if (type->acquire) {
type->acquire(AtomToSWIAtom(AbsAtom(ae))); type->acquire((AbsAtom(ae)));
} }
return Yap_unify(Yap_GetFromSlot(t), MkAtomTerm(AbsAtom(ae))); return Yap_unify(Yap_GetFromSlot(t), MkAtomTerm(AbsAtom(ae)));
} }
@ -95,7 +95,7 @@ PL_put_blob(term_t t, void *blob, size_t len, PL_blob_t *type) {
return FALSE; return FALSE;
} }
if (type->acquire) { if (type->acquire) {
type->acquire(AtomToSWIAtom(AbsAtom(ae))); type->acquire((AbsAtom(ae)));
} }
Yap_PutInSlot(t, MkAtomTerm(AbsAtom(ae))); Yap_PutInSlot(t, MkAtomTerm(AbsAtom(ae)));
return ret; return ret;
@ -118,7 +118,7 @@ PL_get_blob(term_t t, void **blob, size_t *len, PL_blob_t **type) {
return FALSE; return FALSE;
ae = RepAtom(a); ae = RepAtom(a);
if (type) if (type)
*type = (struct PL_blob_t *)RepBlobProp(ae->PropsOfAE)->blob_type; *type = (PL_blob_t *)RepBlobProp(ae->PropsOfAE)->blob_type;
if (len) if (len)
*len = ae->rep.blob[0].length; *len = ae->rep.blob[0].length;
if (blob) if (blob)
@ -127,7 +127,7 @@ PL_get_blob(term_t t, void **blob, size_t *len, PL_blob_t **type) {
} }
PL_EXPORT(void *) PL_EXPORT(void *)
PL_blob_data(atom_t a, size_t *len, struct PL_blob_t **type) { PL_blob_data(atom_t a, size_t *len, PL_blob_t **type) {
Atom x = SWIAtomToAtom(a); Atom x = SWIAtomToAtom(a);
if (!IsBlob(x)) { if (!IsBlob(x)) {
@ -140,22 +140,22 @@ PL_blob_data(atom_t a, size_t *len, struct PL_blob_t **type) {
if (len) if (len)
*len = x->rep.blob[0].length; *len = x->rep.blob[0].length;
if (type) if (type)
*type = (struct PL_blob_t *)RepBlobProp(x->PropsOfAE)->blob_type; *type = (PL_blob_t *)RepBlobProp(x->PropsOfAE)->blob_type;
return x->rep.blob[0].data; return x->rep.blob[0].data;
} }
PL_EXPORT(void) PL_EXPORT(void)
PL_register_blob_type(PL_blob_t *type) { PL_register_blob_type(PL_blob_t *type) {
type->next = (PL_blob_t *)BlobTypes; type->next = BlobTypes;
BlobTypes = (struct YAP_blob_t *)type; BlobTypes = type;
} }
PL_EXPORT(PL_blob_t *) PL_EXPORT(PL_blob_t *)
PL_find_blob_type(const char *name) { PL_find_blob_type(const char *name) {
Atom at = Yap_LookupAtom((char *)name); Atom at = Yap_LookupAtom((char *)name);
return YAP_find_blob_type((YAP_Atom)at); return YAP_find_blob_type(RepAtom(at)->StrOfAE);
} }
PL_EXPORT(int) PL_EXPORT(int)

View File

@ -48,18 +48,20 @@ else()
# ) # )
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4y)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/os) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/pl) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/os)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/pl)
add_custom_target( YAP4PY ALL
# COMMAND ${CMAKE_COMMAND} -E copy ${YAP_DLLS} ${CMAKE_BINARY_DIR}/startup.yss ${CMAKE_CURRENT_BINARY_DIR}/yap4py add_custom_target( YAP4PY ALL
# COMMAND ${CMAKE_COMMAND} -E copy ${YAP_DLLS} ${CMAKE_BINARY_DIR}/startup.yss ${CMAKE_CURRENT_BINARY_DIR}/yap4py
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS STARTUP ${PYTHON_SOURCES} ${PROLOG_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/setup.py ${SWIG_MODULE_Py2YAP_REAL_NAME} ) DEPENDS STARTUP ${PYTHON_SOURCES} ${PROLOG_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/setup.py ${SWIG_MODULE_Py2YAP_REAL_NAME} )
function(f_copy filename output ) function(f_copy filename output )
get_filename_component(base ${filename} NAME_WE) get_filename_component(base ${filename} NAME_WE)
set(outfile ${output}/${base}) set(outfile ${output}/${base})
file (COPY ${filename} DESTiNATION ${output}) file (COPY ${filename} DESTiNATION ${output})
@ -69,34 +71,33 @@ function(f_copy filename output )
DEPENDS ${filename} DEPENDS ${filename}
) )
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE) set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
endfunction() endfunction()
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install .
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index -f dist yap4py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})"
DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} ) DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} )
if (WITH_DOCS AND DOXYGEN_FOUND) if (WITH_DOCS AND DOXYGEN_FOUND)
set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND}) set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
# Run doxygen to only generate the xml # Run doxygen to only generate the xml
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/doc COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile.xml COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile.xml
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers} DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
) )
# generate .i from doxygen .xml # generate .i from doxygen .xml
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
${CMAKE_BINARY_DIR}/doc/xm11l/ftdi_8c.xml ${CMAKE_BINARY_DIR}/doc/xm11l/ftdi_8c.xml
${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml DEPENDS ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
) )
add_custom_target(doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i) add_custom_target(doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i)
add_dependencies(${SWIG_MODULE_ftdi1_REAL_NAME} doc_i) add_dependencies(${SWIG_MODULE_ftdi1_REAL_NAME} doc_i)
ENDIF () ENDIF ()

View File

@ -11,6 +11,7 @@ from setuptools.extension import Extension
from codecs import open from codecs import open
from os import path, makedirs, walk from os import path, makedirs, walk
from shutil import copytree, rmtree, copy2, move from shutil import copytree, rmtree, copy2, move
import sysconfig
from glob import glob from glob import glob
from pathlib import Path from pathlib import Path
import platform import platform
@ -42,15 +43,16 @@ from shutil import copytree, rmtree, copy2, move
from glob import glob from glob import glob
from pathlib import Path from pathlib import Path
import platform import platform
import os.path from os.path import dirname, join,abspath
import os import os
import shutil import shutil
from distutils.core import setup from distutils.core import setup
pjoin = os.path.join here = abspath(dirname(__file__))
here = os.path.abspath(os.path.dirname(__file__)) libpydir = abspath(dirname(os.path.dirname('stdlib')))
#pkg_root = pjoin(here, name) libpyauxdir = abspath(os.path.dirname('stdlib'))
#pkg_root = join(here, name)
sys.path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}") sys.path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}")
@ -61,15 +63,15 @@ if platform.system() == 'Windows':
my_extra_link_args = ['-Wl,-export-all-symbols'] my_extra_link_args = ['-Wl,-export-all-symbols']
else: else:
# if platform.system() == 'Darwin': # if platform.system() == 'Darwin':
my_extra_link_args = ['-Wl,-rpath', '-Wl,${_ABS_PYTHON_MODULE_PATH}'] my_extra_link_args = ['-Wl,-rpath', '-Wl,'+libpydir,'-Wl,-rpath', '-Wl,'+libpyauxdir, ]
win_libs = [] win_libs = []
local_libs = ['YAP++','Py4YAP'] local_libs = ['Py4YAP']
# or dll in glob('yap/dlls/*'): # or dll in glob('yap/dlls/*'):
# move( dll ,'lib' ) # move( dll ,'lib' )
native_sources = ["yap.i"] native_sources = ["yap.i",'yapi.cpp']
for i in '${PYTHON_SOURCES}'.split(";"): for i in '${PYTHON_SOURCES}'.split(";"):
copy2(i, 'yap4py') copy2(i, 'yap4py')
for i in '${pl_library}'.split(";") + '${pl_swi_library}'.split(";") : for i in '${pl_library}'.split(";") + '${pl_swi_library}'.split(";") :
copy2(i, 'yap4py/prolog') copy2(i, 'yap4py/prolog')
@ -83,7 +85,16 @@ for i in my_libs0:
my_libs = glob(i) + my_libs my_libs = glob(i) + my_libs
for i in my_libs: for i in my_libs:
copy2(i, 'yap4py') copy2(i, 'yap4py')
bpy2yap = [] my_includes = ['${CMAKE_SOURCE_DIR}/CXX', '${CMAKE_SOURCE_DIR}/include',
'${CMAKE_SOURCE_DIR}/H', '${CMAKE_SOURCE_DIR}/H/generated',
'${CMAKE_SOURCE_DIR}/os', '${CMAKE_SOURCE_DIR}/OPTYap',
'${CMAKE_SOURCE_DIR}/utf8proc',
'${CMAKE_SOURCE_DIR}/packages/python',
'${CMAKE_BINARY_DIR}']
for i in my_includes:
includes = glob(i+"/*.??h")
for j in includes:
copy2(j, 'yap4py/include')
here = path.abspath(path.dirname(__file__)) here = path.abspath(path.dirname(__file__))
#gmp_dir = path.abspath(path.dirname("${GMP_LIBRARIES}")) #gmp_dir = path.abspath(path.dirname("${GMP_LIBRARIES}"))
#python_libdir = path.abspath(path.dirname("${PYTHON_LIBRARIES}") #python_libdir = path.abspath(path.dirname("${PYTHON_LIBRARIES}")
@ -99,25 +110,14 @@ extensions = [Extension('_yap', native_sources,
('_GNU_SOURCE', '1')], ('_GNU_SOURCE', '1')],
runtime_library_dirs=['yap4py', '${libdir}', '${bindir}', '${gmp_dir}', '${python_libdir}'], runtime_library_dirs=['yap4py', '${libdir}', '${bindir}', '${gmp_dir}', '${python_libdir}'],
swig_opts=['-modern', '-c++', '-py3', swig_opts=['-modern', '-c++', '-py3',
'-DX_API', '-I${CMAKE_SOURCE_DIR}/CXX', '-I${CMAKE_SOURCE_DIR}/include', '-DX_API', '-Iyap4py/include' ],
'-I${CMAKE_SOURCE_DIR}/H', '-I${CMAKE_SOURCE_DIR}/H/generated', library_dirs=['../../..', '../../../CXX', 'yap4py/include', '..', "${bindir}"],
'-I${CMAKE_SOURCE_DIR}/os', '-I${CMAKE_SOURCE_DIR}/OPTYap',
'-I${CMAKE_SOURCE_DIR}/packages/python'],
library_dirs=['../../..', '../../../CXX', '..', "${bindir}"],
extra_link_args=my_extra_link_args, extra_link_args=my_extra_link_args,
libraries=['Yap','gmp']+win_libs+local_libs, libraries=['Yap','gmp']+win_libs+local_libs,
include_dirs=['../../..', include_dirs=['yap4py/include']
'${GMP_INCLUDE_DIRS}', )]
'${CMAKE_SOURCE_DIR}/H',
'${CMAKE_SOURCE_DIR}/H/generated',
'${CMAKE_SOURCE_DIR}/OPTYap',
'${CMAKE_SOURCE_DIR}/os',
'${CMAKE_SOURCE_DIR}/packages/python',
'${CMAKE_SOURCE_DIR}/include',
'${CMAKE_SOURCE_DIR}/CXX', '.']
)]#
packages = packages = setuptools.find_packages('${CMAKE_CURRENT_SOURCE_DIR}') packages = setuptools.find_packages('${CMAKE_CURRENT_SOURCE_DIR}')
@ -131,21 +131,21 @@ version_ns = {'__version__': '6.3.5', 'minor-version': '6', 'minor-version': '3'
setup_args = dict( setup_args = dict(
name=name, name=name,
version=version_ns['__version__'], version=version_ns['__version__'],
scripts=glob(pjoin('scripts', '*')), scripts=glob(join('scripts', '*')),
packages=packages, packages=packages,
py_modules=['yap','yap4py'], py_modules=['yap','yap4py'],
package_data=package_data, package_data=package_data,
include_package_data=True, include_package_data=True,
requirements=[ # requirements=[
'm2w64-gmp', # 'm2w64-gmp',
'm2-msys2-keyring', # 'm2-msys2-keyring',
'm2-msys2-launcher-git', # 'm2-msys2-launcher-git',
'm2-msys2-runtime', # 'm2-msys2-runtime',
], # ],
description="YAP in Python", description="YAP in Python",
author='YAP Development Team', author='YAP Development Team',
author_email='ipython-dev@scipy.org', author_email='vsc@dcc.fc.up.pt',
url='http://ipython.org', url='http://www.dcc.fc.up/~vsc/yap',
license='BSD', license='BSD',
ext_modules=extensions, ext_modules=extensions,
platforms="Linux, Mac OS X, Windows", platforms="Linux, Mac OS X, Windows",

View File

@ -659,8 +659,9 @@ class YAPEngine;
//%template(YAPTermVector) vector<YAPTerm>; //%template(YAPTermVector) vector<YAPTerm>;
//%feature("novaluewrapper") vector<YAPTerm>; //%feature("novaluewrapper") vector<YAPTerm>;
}; };
%init %{
%init %{ %}
%}