Idris2/support/refc/memoryManagement.c

250 lines
6.6 KiB
C
Raw Normal View History

#include "refc_util.h"
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
#include "runtime.h"
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value *newValue(size_t size) {
2024-03-21 15:32:37 +03:00
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
Value *retVal = (Value *)aligned_alloc(
sizeof(void *),
((size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *));
#else
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value *retVal = (Value *)malloc(size);
2024-03-21 15:32:37 +03:00
#endif
IDRIS2_REFC_VERIFY(retVal && !idris2_vp_is_unboxed(retVal), "malloc failed");
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
retVal->header.refCounter = 1;
retVal->header.tag = NO_TAG;
return retVal;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Arglist *newArglist(int missing, int total) {
Value_Arglist *retVal = IDRIS2_NEW_VALUE(Value_Arglist);
retVal->header.tag = ARGLIST_TAG;
retVal->total = total;
retVal->filled = total - missing;
retVal->args = (Value **)malloc(sizeof(Value *) * total);
memset(retVal->args, 0, sizeof(Value *) * total);
return retVal;
}
Value_Constructor *newConstructor(int total, int tag) {
Value_Constructor *retVal = (Value_Constructor *)newValue(
sizeof(Value_Constructor) + sizeof(Value *) * total);
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
retVal->header.tag = CONSTRUCTOR_TAG;
retVal->total = total;
retVal->tag = tag;
retVal->name = NULL;
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
return retVal;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Closure *makeClosureFromArglist(fun_ptr_t f, Value_Arglist *arglist) {
Value_Closure *retVal = IDRIS2_NEW_VALUE(Value_Closure);
retVal->header.tag = CLOSURE_TAG;
retVal->arglist = arglist; // (Value_Arglist *)newReference((Value*)arglist);
retVal->f = f;
if (retVal->arglist->filled >= retVal->arglist->total) {
retVal->header.tag = COMPLETE_CLOSURE_TAG;
}
return retVal;
}
2024-03-21 15:32:37 +03:00
Value *idris2_mkDouble(double d) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Double *retVal = IDRIS2_NEW_VALUE(Value_Double);
retVal->header.tag = DOUBLE_TAG;
retVal->d = d;
2024-03-21 15:32:37 +03:00
return (Value *)retVal;
}
2024-03-21 15:32:37 +03:00
Value *idris2_mkBits32_Boxed(uint32_t i) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Bits32 *retVal = IDRIS2_NEW_VALUE(Value_Bits32);
retVal->header.tag = BITS32_TAG;
retVal->ui32 = i;
2024-03-21 15:32:37 +03:00
return (Value *)retVal;
}
2024-03-21 15:32:37 +03:00
Value *idris2_mkBits64(uint64_t i) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Bits64 *retVal = IDRIS2_NEW_VALUE(Value_Bits64);
retVal->header.tag = BITS64_TAG;
retVal->ui64 = i;
2024-03-21 15:32:37 +03:00
return (Value *)retVal;
}
2024-03-21 15:32:37 +03:00
Value *idris2_mkInt32_Boxed(int32_t i) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Int32 *retVal = IDRIS2_NEW_VALUE(Value_Int32);
retVal->header.tag = INT32_TAG;
retVal->i32 = i;
2024-03-21 15:32:37 +03:00
return (Value *)retVal;
}
2024-03-21 15:32:37 +03:00
Value *idris2_mkInt64(int64_t i) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Int64 *retVal = IDRIS2_NEW_VALUE(Value_Int64);
retVal->header.tag = INT64_TAG;
retVal->i64 = i;
2024-03-21 15:32:37 +03:00
return (Value *)retVal;
}
2024-03-21 15:32:37 +03:00
Value_Integer *idris2_mkInteger() {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Integer *retVal = IDRIS2_NEW_VALUE(Value_Integer);
retVal->header.tag = INTEGER_TAG;
mpz_init(retVal->i);
return retVal;
}
2024-03-21 15:32:37 +03:00
Value_Integer *idris2_mkIntegerLiteral(char *i) {
Value_Integer *retVal = idris2_mkInteger();
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
mpz_set_str(retVal->i, i, 10);
return retVal;
}
2024-03-21 15:32:37 +03:00
Value_String *idris2_mkEmptyString(size_t l) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_String *retVal = IDRIS2_NEW_VALUE(Value_String);
retVal->header.tag = STRING_TAG;
retVal->str = malloc(l);
memset(retVal->str, 0, l);
return retVal;
}
2024-03-21 15:32:37 +03:00
Value_String *idris2_mkString(char *s) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_String *retVal = IDRIS2_NEW_VALUE(Value_String);
int l = strlen(s);
retVal->header.tag = STRING_TAG;
retVal->str = malloc(l + 1);
memset(retVal->str, 0, l + 1);
memcpy(retVal->str, s, l);
return retVal;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Pointer *makePointer(void *ptr_Raw) {
Value_Pointer *p = IDRIS2_NEW_VALUE(Value_Pointer);
p->header.tag = POINTER_TAG;
p->p = ptr_Raw;
return p;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_GCPointer *makeGCPointer(void *ptr_Raw, Value_Closure *onCollectFct) {
Value_GCPointer *p = IDRIS2_NEW_VALUE(Value_GCPointer);
p->header.tag = GC_POINTER_TAG;
p->p = makePointer(ptr_Raw);
p->onCollectFct = onCollectFct;
return p;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Buffer *makeBuffer(void *buf) {
Value_Buffer *b = IDRIS2_NEW_VALUE(Value_Buffer);
b->header.tag = BUFFER_TAG;
b->buffer = buf;
return b;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value_Array *makeArray(int length) {
Value_Array *a = IDRIS2_NEW_VALUE(Value_Array);
a->header.tag = ARRAY_TAG;
a->capacity = length;
a->arr = (Value **)malloc(sizeof(Value *) * length);
memset(a->arr, 0, sizeof(Value *) * length);
return a;
2021-05-17 16:03:59 +03:00
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
Value *newReference(Value *source) {
// note that we explicitly allow NULL as source (for erased arguments)
2024-03-21 15:32:37 +03:00
if (source && !idris2_vp_is_unboxed(source)) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
source->header.refCounter++;
}
return source;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
void removeReference(Value *elem) {
2024-03-21 15:32:37 +03:00
if (!elem || idris2_vp_is_unboxed(elem)) {
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
return;
}
2024-03-21 15:32:37 +03:00
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
IDRIS2_REFC_VERIFY(elem->header.refCounter > 0, "refCounter %lld",
(long long)elem->header.refCounter);
// remove reference counter
elem->header.refCounter--;
if (elem->header.refCounter == 0)
// recursively remove all references to all children
{
switch (elem->header.tag) {
case BITS32_TAG:
case BITS64_TAG:
case INT32_TAG:
case INT64_TAG:
/* nothing to delete, added for sake of completeness */
break;
case INTEGER_TAG: {
mpz_clear(((Value_Integer *)elem)->i);
break;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
case DOUBLE_TAG:
/* nothing to delete, added for sake of completeness */
break;
case STRING_TAG:
free(((Value_String *)elem)->str);
break;
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
case CLOSURE_TAG: {
Value_Closure *cl = (Value_Closure *)elem;
Value_Arglist *al = cl->arglist;
removeReference((Value *)al);
break;
}
case COMPLETE_CLOSURE_TAG: {
Value_Closure *cl = (Value_Closure *)elem;
Value_Arglist *al = cl->arglist;
removeReference((Value *)al);
break;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
case ARGLIST_TAG: {
Value_Arglist *al = (Value_Arglist *)elem;
for (int i = 0; i < al->filled; i++) {
removeReference(al->args[i]);
}
free(al->args);
break;
}
case CONSTRUCTOR_TAG: {
Value_Constructor *constr = (Value_Constructor *)elem;
for (int i = 0; i < constr->total; i++) {
removeReference(constr->args[i]);
}
break;
}
case IOREF_TAG:
removeReference(((Value_IORef *)elem)->v);
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
break;
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
case BUFFER_TAG: {
Value_Buffer *b = (Value_Buffer *)elem;
free(b->buffer);
break;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
case ARRAY_TAG: {
Value_Array *a = (Value_Array *)elem;
for (int i = 0; i < a->capacity; i++) {
removeReference(a->arr[i]);
}
free(a->arr);
break;
}
case POINTER_TAG:
/* nothing to delete, added for sake of completeness */
break;
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
case GC_POINTER_TAG: {
/* maybe here we need to invoke onCollectAny */
Value_GCPointer *vPtr = (Value_GCPointer *)elem;
Value *closure1 =
apply_closure((Value *)vPtr->onCollectFct, (Value *)vPtr->p);
apply_closure(closure1, NULL);
removeReference((Value *)vPtr->p);
break;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
default:
break;
}
RefC backend improvements (#2425) * RefC backend improvements 1. OnCollect had the wrong number of arguments. The code creator expects 3 arguments, but onCollect in prim.h expected 4 arguments. The first of which was an erased arguments. That is now fixed. 2. OnCollect did not call `newReference` when creating a new reference to the pointer and the freeing function 3. OnCollect and OnCollectAny still had a spurious printf statement Those issues have been fixed, the test case can be found in tests/refc/garbageCollect 4. The IORef mechanism expects that the %World token will be passed around consistently. This is not the case. States in Control.App make use of IORefs, but the function created from Control.App.prim_app_bind had the world token erased to NULL. Now, IORefs are managed using a global variable, IORef_Storage * global_IORef_Storage; referenced in cBackend.h, defined in the created .c file, and set to NULL in main(); 5. While multithreading and forking is still not supported, compiling a program that makes use of Control.App demands a C implementation of prim_fork. Files support/refc/threads.c and support/refc/threads.h provide a dummy implementation for it, so that Control.App programs compile and run. A test for these 2 issues is given in tests/refc/issue2424 * format changes to make the linter happy * format changes to make the linter happy * format changes to make the linter happy * spelling mistake braket -> bracket Co-authored-by: Volkmar Frinken <volkmar@onutechnology.com>
2022-04-27 15:59:32 +03:00
// finally, free element
free(elem);
}
}