Maybe this is the right thing to do?
https://stackoverflow.com/questions/59489221/using-the-gmp-library-with-boehms-garbage-collector
This commit is contained in:
parent
813c5c0a23
commit
5ceab61ca1
|
|
@ -1,5 +1,6 @@
|
||||||
COPTS=-I/usr/local/include
|
COPTS=-I/usr/local/include
|
||||||
|
STATIC_GCLIB=/usr/local/lib/libgc.a /usr/local/lib/libgmp.a
|
||||||
|
|
||||||
joy: joy.c
|
joy: joy.c
|
||||||
cc $(COPTS) joy.c -o joy
|
cc $(COPTS) joy.c $(STATIC_GCLIB) -o joy
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,8 +1,46 @@
|
||||||
#include <gc.h>
|
#include <gc.h>
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
|
|
||||||
|
// Example S-exprs
|
||||||
|
// https://www.hboehm.info/gc/04tutorial.pdf
|
||||||
|
|
||||||
|
typedef union se
|
||||||
|
{
|
||||||
|
struct cons * cp;
|
||||||
|
mpz_t i;
|
||||||
|
} sexpr;
|
||||||
|
|
||||||
|
struct cons
|
||||||
|
{
|
||||||
|
union se head;
|
||||||
|
union se tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define car(s) (s).cp->head
|
||||||
|
#define cdr(s) (s).cp->tail
|
||||||
|
#define from_i(z) ({sexpr tmp; tmp.i=z; tmp;})
|
||||||
|
#define to_i(s) (s).i
|
||||||
|
|
||||||
|
sexpr cons(sexpr a, sexpr b) {
|
||||||
|
sexpr tmp = {GC_MALLOC(sizeof(struct cons))};
|
||||||
|
car(tmp) = a; cdr(tmp) = b;
|
||||||
|
return (tmp);
|
||||||
|
};
|
||||||
|
|
||||||
|
void* reallocate_function (void *ptr, size_t old_size, size_t new_size) {
|
||||||
|
return GC_realloc(ptr, new_size);
|
||||||
|
}
|
||||||
|
void deallocate_function (void *ptr, size_t size) {
|
||||||
|
GC_free(ptr);
|
||||||
|
}
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
mp_set_memory_functions(
|
||||||
|
&GC_malloc,
|
||||||
|
&reallocate_function,
|
||||||
|
&deallocate_function
|
||||||
|
);
|
||||||
return 0;
|
return 0;
|
||||||
|
//return to_i(car(cons(from_i(0),from_i(1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue