opaque terms
This commit is contained in:
parent
7cd3fffe13
commit
9100e797f8
10
C/bignum.c
10
C/bignum.c
@ -167,7 +167,7 @@ int Yap_CleanOpaqueVariable(CELL d) {
|
||||
"clean opaque: bad blob with tag " UInt_FORMAT, blob_tag);
|
||||
return FALSE;
|
||||
}
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
blob_info = blob_tag;
|
||||
if (!GLOBAL_OpaqueHandlers)
|
||||
return false;
|
||||
if (!GLOBAL_OpaqueHandlers[blob_info].fail_handler)
|
||||
@ -192,7 +192,7 @@ YAP_Opaque_CallOnWrite Yap_blob_write_handler(Term t) {
|
||||
"clean opaque: bad blob with tag " UInt_FORMAT, blob_tag);
|
||||
return FALSE;
|
||||
}
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
blob_info = blob_tag;
|
||||
if (!GLOBAL_OpaqueHandlers) {
|
||||
return NULL;
|
||||
}
|
||||
@ -214,7 +214,7 @@ YAP_Opaque_CallOnGCMark Yap_blob_gc_mark_handler(Term t) {
|
||||
if (blob_tag < USER_BLOB_START || blob_tag >= USER_BLOB_END) {
|
||||
return NULL;
|
||||
}
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
blob_info = blob_tag;
|
||||
if (!GLOBAL_OpaqueHandlers)
|
||||
return NULL;
|
||||
return GLOBAL_OpaqueHandlers[blob_info].mark_handler;
|
||||
@ -237,7 +237,7 @@ YAP_Opaque_CallOnGCRelocate Yap_blob_gc_relocate_handler(Term t) {
|
||||
"clean opaque: bad blob with tag " UInt_FORMAT, blob_tag);
|
||||
return FALSE;
|
||||
}
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
blob_info = blob_tag;
|
||||
if (!GLOBAL_OpaqueHandlers)
|
||||
return NULL;
|
||||
return GLOBAL_OpaqueHandlers[blob_info].relocate_handler;
|
||||
@ -509,4 +509,4 @@ void Yap_InitBigNums(void) {
|
||||
Yap_InitCPred("string", 1, p_is_string, SafePredFlag);
|
||||
Yap_InitCPred("opaque", 1, p_is_opaque, SafePredFlag);
|
||||
Yap_InitCPred("nb_set_bit", 2, p_nb_set_bit, SafePredFlag);
|
||||
}
|
||||
}
|
||||
|
@ -1893,34 +1893,36 @@ X_API void *YAP_ExternalDataInStackFromTerm(Term t) {
|
||||
|
||||
X_API YAP_opaque_tag_t YAP_NewOpaqueType(struct YAP_opaque_handler_struct *f) {
|
||||
int i;
|
||||
if (!GLOBAL_OpaqueHandlers) {
|
||||
if (!GLOBAL_OpaqueHandlersCount) {
|
||||
GLOBAL_OpaqueHandlers =
|
||||
malloc(sizeof(YAP_opaque_handler_t) * (USER_BLOB_END - USER_BLOB_START));
|
||||
malloc(sizeof(YAP_opaque_handler_t) *USER_BLOB_END );
|
||||
if (!GLOBAL_OpaqueHandlers) {
|
||||
/* no room */
|
||||
return -1;
|
||||
}
|
||||
} else if (GLOBAL_OpaqueHandlersCount == USER_BLOB_END - USER_BLOB_START) {
|
||||
GLOBAL_OpaqueHandlersCount = USER_BLOB_START;
|
||||
} else if (GLOBAL_OpaqueHandlersCount == USER_BLOB_END) {
|
||||
/* all types used */
|
||||
return -1;
|
||||
}
|
||||
i = GLOBAL_OpaqueHandlersCount++;
|
||||
memcpy(GLOBAL_OpaqueHandlers + i, f, sizeof(YAP_opaque_handler_t));
|
||||
return i + USER_BLOB_START;
|
||||
return i;
|
||||
}
|
||||
|
||||
X_API Term YAP_NewOpaqueObject(YAP_opaque_tag_t blob_tag, size_t bytes) {
|
||||
CELL *pt;
|
||||
Term t = Yap_AllocExternalDataInStack((CELL) blob_tag, bytes, &pt);
|
||||
if (t == TermNil)
|
||||
return 0L;
|
||||
if (t == TermNil)
|
||||
return 0L;
|
||||
pt = RepAppl(t);
|
||||
blob_tag = pt[1];
|
||||
if (blob_tag < USER_BLOB_START ||
|
||||
blob_tag >= USER_BLOB_END) {
|
||||
Yap_Error(SYSTEM_ERROR_INTERNAL, AbsAppl(pt), "clean opaque: bad blob with tag " UInt_FORMAT ,blob_tag);
|
||||
return FALSE;
|
||||
}
|
||||
YAP_opaque_tag_t blob_info = blob_tag - USER_BLOB_START;
|
||||
YAP_opaque_tag_t blob_info = blob_tag;
|
||||
if (GLOBAL_OpaqueHandlers[blob_info].cut_handler ||
|
||||
GLOBAL_OpaqueHandlers[blob_info].fail_handler ) {
|
||||
*HR++ = t;
|
||||
|
@ -95,10 +95,10 @@ typedef enum {
|
||||
ARRAY_INT = 0x21,
|
||||
ARRAY_FLOAT = 0x22,
|
||||
CLAUSE_LIST = 0x40,
|
||||
EXTERNAL_BLOB = 0x100, /* generic data */
|
||||
GOAL_CUT_POINT = 0x200,
|
||||
USER_BLOB_START = 0x1000, /* user defined blob */
|
||||
USER_BLOB_END = 0x1100 /* end of user defined blob */
|
||||
EXTERNAL_BLOB = 0x0A0, /* generic data */
|
||||
GOAL_CUT_POINT = 0x0A1,
|
||||
USER_BLOB_START = 0x0100, /* user defined blob */
|
||||
USER_BLOB_END = 0x0200 /* end of user defined blob */
|
||||
} big_blob_type;
|
||||
|
||||
INLINE_ONLY inline EXTERN blob_type BlobOfFunctor(Functor f);
|
||||
|
Reference in New Issue
Block a user