allow writing of opaque terms.
This commit is contained in:
parent
b79a885480
commit
619d0622e6
65
C/bignum.c
65
C/bignum.c
@ -183,6 +183,71 @@ int Yap_CleanOpaqueVariable(CELL *pt)
|
||||
return (GLOBAL_OpaqueHandlers[blob_info].fail_handler)((void *)(blobp+1));
|
||||
}
|
||||
|
||||
Opaque_CallOnWrite
|
||||
Yap_blob_write_handler_from_slot(Int slot)
|
||||
{
|
||||
CELL blob_info, blob_tag;
|
||||
MP_INT *blobp;
|
||||
Term t = Yap_GetFromSlot(slot);
|
||||
CELL *pt = RepAppl(t);
|
||||
|
||||
#ifdef DEBUG
|
||||
/* sanity checking */
|
||||
if (pt[0] != (CELL)FunctorBigInt) {
|
||||
Yap_Error(SYSTEM_ERROR, TermNil, "CleanOpaqueVariable bad call");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
blob_tag = pt[1];
|
||||
if (blob_tag < USER_BLOB_START ||
|
||||
blob_tag >= USER_BLOB_END) {
|
||||
Yap_Error(SYSTEM_ERROR, AbsAppl(pt), "clean opaque: bad blob with tag " UInt_FORMAT ,blob_tag);
|
||||
return FALSE;
|
||||
}
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
if (!GLOBAL_OpaqueHandlers)
|
||||
return NULL;
|
||||
blobp = (MP_INT *)(pt+2);
|
||||
return GLOBAL_OpaqueHandlers[blob_info].write_handler;
|
||||
}
|
||||
|
||||
extern Int Yap_blob_tag_from_slot(Int slot)
|
||||
{
|
||||
Term t = Yap_GetFromSlot(slot);
|
||||
CELL *pt = RepAppl(t);
|
||||
|
||||
#ifdef DEBUG
|
||||
/* sanity checking */
|
||||
if (pt[0] != (CELL)FunctorBigInt) {
|
||||
Yap_Error(SYSTEM_ERROR, TermNil, "CleanOpaqueVariable bad call");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
return pt[1];
|
||||
}
|
||||
|
||||
void *
|
||||
Yap_blob_info_from_slot(Int slot)
|
||||
{
|
||||
CELL blob_info, blob_tag;
|
||||
MP_INT *blobp;
|
||||
Term t = Yap_GetFromSlot(slot);
|
||||
CELL *pt = RepAppl(t);
|
||||
|
||||
#ifdef DEBUG
|
||||
/* sanity checking */
|
||||
if (pt[0] != (CELL)FunctorBigInt) {
|
||||
Yap_Error(SYSTEM_ERROR, TermNil, "CleanOpaqueVariable bad call");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
if (!GLOBAL_OpaqueHandlers)
|
||||
return FALSE;
|
||||
blobp = (MP_INT *)(pt+2);
|
||||
return (void *)(blobp+1);
|
||||
}
|
||||
|
||||
Term
|
||||
Yap_MkULLIntTerm(YAP_ULONG_LONG n)
|
||||
{
|
||||
|
@ -34,11 +34,17 @@ typedef int (*SWI_PLGetStreamPositionFunction)(void *);
|
||||
#include "../include/dswiatoms.h"
|
||||
|
||||
typedef int (*Opaque_CallOnFail)(void *);
|
||||
typedef int (*Opaque_CallOnWrite)(void *, int, void *, int);
|
||||
|
||||
typedef struct opaque_handler_struct {
|
||||
Opaque_CallOnFail fail_handler;
|
||||
Opaque_CallOnWrite write_handler;
|
||||
} opaque_handler_t;
|
||||
|
||||
extern Opaque_CallOnWrite Yap_blob_write_handler_from_slot(Int slot);
|
||||
extern Int Yap_blob_tag_from_slot(Int slot);
|
||||
extern void *Yap_blob_info_from_slot(Int slot);
|
||||
|
||||
#ifndef INT_KEYS_DEFAULT_SIZE
|
||||
#define INT_KEYS_DEFAULT_SIZE 256
|
||||
#endif
|
||||
|
@ -61,11 +61,7 @@ int STD_PROTO(Yap_AtomDecreaseHold,(Atom));
|
||||
|
||||
Int STD_PROTO(Yap_InitSlot,(Term CACHE_TYPE));
|
||||
Int STD_PROTO(Yap_NewSlots,(int CACHE_TYPE));
|
||||
Term STD_PROTO(Yap_GetFromSlot,(Int CACHE_TYPE));
|
||||
int STD_PROTO(Yap_RecoverSlots,(int CACHE_TYPE));
|
||||
Term STD_PROTO(Yap_GetPtrFromSlot,(Int CACHE_TYPE));
|
||||
Term *STD_PROTO(Yap_AddressFromSlot,(Int CACHE_TYPE));
|
||||
void STD_PROTO(Yap_PutInSlot,(Int, Term CACHE_TYPE));
|
||||
|
||||
|
||||
#ifdef SFUNC
|
||||
|
@ -205,12 +205,14 @@ typedef int (*YAP_agc_hook)(void *_Atom);
|
||||
|
||||
typedef void (*YAP_halt_hook)(int exit_code, void *closure);
|
||||
|
||||
typedef int YAP_opaque_tag_t;
|
||||
typedef YAP_Int YAP_opaque_tag_t;
|
||||
|
||||
typedef int (*YAP_Opaque_CallOnFail)(void *);
|
||||
typedef int (*YAP_Opaque_CallOnWrite)(void *, YAP_opaque_tag_t, void *, int);
|
||||
|
||||
typedef struct YAP_opaque_handler_struct {
|
||||
YAP_Opaque_CallOnFail fail_handler;
|
||||
YAP_Opaque_CallOnFail fail_handler;
|
||||
YAP_Opaque_CallOnWrite write_handler;
|
||||
} YAP_opaque_handler_t;
|
||||
|
||||
/********* execution mode ***********************/
|
||||
|
Reference in New Issue
Block a user