Add RefC external type support

The external type must be a Value object for garbage collection reasons.

For completely custom types, use a GCPointer, with appropriate GC function for clearing up your data type.
This commit is contained in:
Robert Wright 2021-05-17 14:01:09 +01:00 committed by G. Allais
parent 204b96fe6c
commit ecde887d7a
3 changed files with 12 additions and 2 deletions

View File

@ -780,7 +780,7 @@ extractValue (CFFun x y) varName = assert_total $ idris_crash ("INTERNAL ERR
extractValue (CFIORes x) varName = extractValue x varName
extractValue (CFStruct x xs) varName = assert_total $ idris_crash ("INTERNAL ERROR: Struct access not implemented: " ++ varName)
-- not really total but this way this internal error does not contaminate everything else
extractValue (CFUser x xs) varName = "Value* " ++ varName
extractValue (CFUser x xs) varName = "(Value*)" ++ varName
packCFType : (cfType:CFType) -> (varName:String) -> String
packCFType CFUnit varName = "NULL"
@ -799,7 +799,7 @@ packCFType CFWorld varName = "makeWorld(" ++ varName ++ ")"
packCFType (CFFun x y) varName = "makeFunction(" ++ varName ++ ")"
packCFType (CFIORes x) varName = packCFType x varName
packCFType (CFStruct x xs) varName = "makeStruct(" ++ varName ++ ")"
packCFType (CFUser x xs) varName = "makeCustomUser(" ++ varName ++ ")"
packCFType (CFUser x xs) varName = varName
discardLastArgument : List ty -> List ty
discardLastArgument [] = []

View File

@ -122,6 +122,15 @@ Value_Pointer *makePointer(void *ptr_Raw)
return p;
}
Value_GCPointer *makeGCPointer(void *ptr_Raw, Value_Closure *onCollectFct)
{
Value_GCPointer *p = (Value_GCPointer *)newValue();
p->header.tag = GC_POINTER_TAG;
p->p = makePointer(ptr_Raw);
p->onCollectFct = onCollectFct;
return p;
}
Value_Array *makeArray(int length)
{
Value_Array *a = (Value_Array *)newValue();

View File

@ -22,6 +22,7 @@ Value_String *makeEmptyString(size_t l);
Value_String *makeString(char *);
Value_Pointer *makePointer(void *);
Value_GCPointer *makeGCPointer(void *ptr_Raw, Value_Closure *onCollectFct);
Value_Array *makeArray(int length);
Value_World *makeWorld(void);