scf_variable_t* v;
scf_type_t* t;
- int ret = scf_ast_find_function(&f, ast, "scf__auto_ref");
+ int ret = scf_ast_find_function(&f, ast, "__builtin_auto_ref");
if (!f)
return NULL;
scf_variable_t* v;
scf_type_t* t;
- int ret = scf_ast_find_function(&f, ast, "scf__auto_free_array");
+ int ret = scf_ast_find_function(&f, ast, "__builtin_auto_free_array");
if (!f)
return NULL;
scf_variable_t* v;
scf_type_t* t;
- int ret = scf_ast_find_function(&f, ast, "scf__auto_freep_array");
+ int ret = scf_ast_find_function(&f, ast, "__builtin_auto_freep_array");
if (!f)
return NULL;
f->visited_flag = 0;
- if (!fmalloc && !strcmp(f->node.w->text->data, "scf__auto_malloc"))
+ if (!fmalloc && !strcmp(f->node.w->text->data, "__builtin_auto_malloc"))
fmalloc = f;
}
f2 = pf->var->func_ptr;
fret = f2->rets->data[i];
- if (!strcmp(f2->node.w->text->data, "scf__auto_malloc") || fret->auto_gc_flag) {
+ if (!strcmp(f2->node.w->text->data, "__builtin_auto_malloc") || fret->auto_gc_flag) {
assert(SCF_OP_RETURN != c->op->type);
// fret = f->rets->data[i];
if (!ast || !f)
return -EINVAL;
- if (!strcmp(f->node.w->text->data, "scf__auto_malloc"))
+ if (!strcmp(f->node.w->text->data, "__builtin_auto_malloc"))
return 0;
scf_list_t* bb_list_head = &f->basic_block_list_head;
scf_logd("f2: %s, rets[%d], auto_gc_flag: %d\n", f2->node.w->text->data, i, fret->auto_gc_flag);
- if (!strcmp(f2->node.w->text->data, "scf__auto_malloc")) {
+ if (!strcmp(f2->node.w->text->data, "__builtin_auto_malloc")) {
_bb_add_ds(cur_bb, ds_obj);
return 1;
}
if (!f->node.define_flag)
continue;
- if (!strcmp(f->node.w->text->data, "scf__auto_malloc"))
+ if (!strcmp(f->node.w->text->data, "__builtin_auto_malloc"))
continue;
ret = _auto_gc_function_find(ast, f, &f->basic_block_list_head);
-#include "../sysroot/lib/scf_capi.c"
+int printf(const char* fmt, ...);
int* f()
{
- return scf__auto_malloc(sizeof(int));
+ return __builtin_auto_malloc(sizeof(int));
}
int main()
-#include "../sysroot/lib/scf_capi.c"
+int printf(const char* fmt, ...);
int*, int* f()
{
- int* p0 = scf__auto_malloc(sizeof(int));
- int* p1 = scf__auto_malloc(sizeof(int));
+ int* p0 = __builtin_auto_malloc(sizeof(int));
+ int* p1 = __builtin_auto_malloc(sizeof(int));
*p0 = 1;
*p1 = 2;
} else
return -1;
- this->data = scf__auto_malloc(size);
+ this->data = __builtin_auto_malloc(size);
if (!this->data)
return -1;
void __release(mat* this)
{
if (this->data)
- scf__auto_freep(&this->data, NULL);
+ __builtin_auto_freep(&this->data, NULL);
}
};
} else
return -1;
- this->data = scf__auto_malloc(size);
+ this->data = __builtin_auto_malloc(size);
if (!this->data)
return -1;
void __release(mat* this)
{
if (this->data)
- scf__auto_freep(&this->data, NULL);
+ __builtin_auto_freep(&this->data, NULL);
}
};
int g(int** s0, int** s1)
{
if (!*s1)
- *s1 = scf__auto_malloc(sizeof(int));
+ *s1 = __builtin_auto_malloc(sizeof(int));
if (!*s0)
f(s0, s1);
int f(int** t0, int **t1)
{
if (!*t0)
- *t0 = scf__auto_malloc(sizeof(int));
+ *t0 = __builtin_auto_malloc(sizeof(int));
if (!*t1)
g(t0, t1);
this->len = 0;
this->capacity = 16;
- this->data = scf__auto_malloc(16);
+ this->data = __builtin_auto_malloc(16);
if (!this->data)
return -1;
void __release(str* this)
{
if (this->data)
- scf__auto_freep(&this->data, NULL);
+ __builtin_auto_freep(&this->data, NULL);
}
};
+++ /dev/null
-
-int brk (uint8_t* addr);
-uint8_t* sbrk(uintptr_t inc);
-
-int printf(const char* fmt, ...);
-
-uint8_t* memset(uint8_t* dst, int c, uintptr_t n);
-uint8_t* memcpy(uint8_t* dst, uint8_t* src, uintptr_t n);
-
-// min size of block is 64, so low 6 bits can be used for flags
-// flags in prev_size:
-// Free Last First
-// 2 1 0
-struct scf_mblock_t
-{
- uintptr_t magic;
- uintptr_t prev_size;
- uintptr_t cur_size;
- uintptr_t free;
-};
-
-scf_mblock_t* scf__mblocks[30];
-scf_mblock_t* scf__free_blocks = NULL;
-uint8_t* scf__last_brk = NULL;
-
-uint8_t* scf__malloc(uintptr_t size)
-{
- scf_mblock_t* b;
- scf_mblock_t* b2;
-
- uintptr_t bytes = (sizeof(scf_mblock_t) + size + 63) >> 6 << 6;
- intptr_t nblocks = sizeof(scf__mblocks) / sizeof(scf__mblocks[0]);
-
- uintptr_t rest;
- uint8_t* addr = NULL;
- uint8_t* p = NULL;
- intptr_t i;
-
- for (i = 0; i < nblocks; i++) {
-
- if ((64 << i) < bytes)
- continue;
-
- if (scf__mblocks[i])
- break;
- }
-
- if (i == nblocks) {
-
- uintptr_t pages = (bytes + 4095) >> 12;
-
- p = sbrk(pages << 12);
- if (!p)
- return NULL;
- scf__last_brk = p + (pages << 12);
-
- rest = (pages << 12) - bytes;
-
- b = (scf_mblock_t*)p;
-
- b->prev_size = 0x3;
- b->cur_size = bytes;
- b->magic = 0x10f0;
- } else {
- b = scf__mblocks[i];
- scf__mblocks[i] = (scf_mblock_t*)b->free;
-
- p = (uint8_t*)b;
-
- rest = b->cur_size - bytes;
-
- b->prev_size &= ~0x4;
- b->magic = 0x10f0;
- }
-
- addr = p + sizeof(scf_mblock_t);
-
- if (0 == rest) {
- printf("%s(),%d, b: %p, scf__last_brk: %p\n", __func__, __LINE__, b, scf__last_brk);
- return addr;
- }
-
- p += bytes;
- b2 = (scf_mblock_t*)p;
-
- for (; i >= 0; i--) {
-
- if (rest >= (64 << i)) {
- b2->free = (uintptr_t)scf__mblocks[i];
- scf__mblocks[i] = b2;
- break;
- }
- }
-
- b ->cur_size = bytes;
- b2->cur_size = rest;
- b2->prev_size = bytes | 0x4;
- b2->magic = 0xf010;
-
- if (b->prev_size & 0x2) {
- b->prev_size &= ~0x2;
- b2->prev_size |= 0x2;
- }
-
- printf("%s(),%d, b: %p, scf__last_brk: %p\n", __func__, __LINE__, b, scf__last_brk);
- return addr;
-}
-
-int scf__free(uint8_t* p)
-{
- p -= sizeof(scf_mblock_t);
-
- scf_mblock_t* b = (scf_mblock_t*)p;
- scf_mblock_t* b2;
- scf_mblock_t* b3;
- scf_mblock_t** pb;
-
- uintptr_t bytes = b->cur_size;
- intptr_t nblocks = sizeof(scf__mblocks) / sizeof(scf__mblocks[0]);
- intptr_t i;
-
- if (b->prev_size & 0x4) {
- printf("%s(), %d, error: double free: %p\n", __func__, __LINE__, p);
- return -1;
- }
-
- if (0x10f0 != b->magic) {
- printf("%s(), %d, error: corruption free: %p\n", __func__, __LINE__, p);
- return -1;
- }
-
- b->prev_size |= 0x4;
- b->magic = 0xf010;
-
- while (!(b->prev_size & 0x2)) {
-
- b2 = (scf_mblock_t*)((uintptr_t)b + bytes);
-
- uintptr_t bytes2 = b2->cur_size;
-
- for (i = nblocks - 1; i >= 0; i--) {
-
- if (bytes2 >= (64 << i))
- break;
- }
-
- for (pb = &scf__mblocks[i]; *pb; pb = (scf_mblock_t**)&(*pb)->free) {
-
- if (*pb == b2)
- break;
- }
- if (!*pb)
- break;
-
- *pb = (scf_mblock_t*)b2->free;
-
- bytes += bytes2;
- b->cur_size = bytes;
-
- if (b2->prev_size & 0x2)
- b->prev_size |= 0x2;
- else {
- b3 = (scf_mblock_t*)((uintptr_t)b2 + bytes2);
-
- b3->prev_size = bytes | (b3->prev_size & 0x7);
- }
- }
-
- while (!(b->prev_size & 0x1)) {
-
- uintptr_t bytes2 = b->prev_size & ~0x7;
-
- b2 = (scf_mblock_t*)((uintptr_t)b - bytes2);
-
- bytes2 = b2->cur_size;
-
- for (i = nblocks - 1; i >= 0; i--) {
-
- if (bytes2 >= (64 << i))
- break;
- }
-
- for (pb = &scf__mblocks[i]; *pb; pb = (scf_mblock_t**)&(*pb)->free) {
- if (*pb == b2)
- break;
- }
- if (!*pb)
- break;
-
- *pb = (scf_mblock_t*)b2->free;
-
- bytes += bytes2;
- b2->cur_size = bytes;
-
- if (b->prev_size & 0x2)
- b2->prev_size |= 0x2;
- else {
- b3 = (scf_mblock_t*)((uintptr_t)b2 + bytes);
-
- b3->prev_size = bytes | (b3->prev_size & 0x7);
- }
-
- b = b2;
- }
-
- bytes = b->cur_size;
-
- if (0x7 == (b->prev_size) & 0x7) {
-
- if (scf__last_brk == (uint8_t*)b + bytes) {
-
- printf("%s(), %d, b: %p, scf__last_brk: %p\n", __func__, __LINE__, b, scf__last_brk);
- scf__last_brk = (uint8_t*)b;
- brk((uint8_t*)b);
-
- int flag = 1;
- while (flag) {
- flag = 0;
-
- pb = &scf__free_blocks;
- while (*pb) {
-
- b = *pb;
- bytes = b->cur_size;
-
- if (scf__last_brk != (uint8_t*)b + bytes) {
-
- pb = (scf_mblock_t**)&b->free;
- continue;
- }
- *pb = (scf_mblock_t*)b->free;
-
- printf("%s(), %d, b: %p, scf__last_brk: %p\n", __func__, __LINE__, b, scf__last_brk);
- scf__last_brk = (uint8_t*)b;
- brk((uint8_t*)b);
- flag = 1;
- }
- }
- } else {
- b->free = (uintptr_t)scf__free_blocks;
- scf__free_blocks = b;
- printf("%s(), %d, b: %p\n", __func__, __LINE__, b);
- }
- return 0;
- }
-
- for (i = nblocks - 1; i >= 0; i--) {
- if (bytes >= (64 << i))
- break;
- }
-
- b->free = (uintptr_t)scf__mblocks[i];
- scf__mblocks[i] = b;
-
- printf("%s(), %d, b: %p\n", __func__, __LINE__, b);
- return 0;
-}
-
-uint8_t* scf__calloc(uintptr_t n, uintptr_t size)
-{
- scf_mblock_t* b;
- uintptr_t bytes;
- uint8_t* p;
-
- size *= n;
-
- p = scf__malloc(size);
- if (!p)
- return NULL;
-
- b = (scf_mblock_t*)(p - sizeof(scf_mblock_t));
-
- bytes = b->cur_size;
- bytes -= sizeof(scf_mblock_t);
- printf("%s(),%d, calloc, b: %p, bytes: %ld\n", __func__, __LINE__, b, bytes);
-
- memset(p, 0, bytes);
-
- return p;
-}
-
-uint8_t* scf__realloc(uint8_t* p, uintptr_t size)
-{
- scf_mblock_t* b;
- scf_mblock_t* b2;
- scf_mblock_t* b3;
- uintptr_t bytes;
- uint8_t* p2;
-
- b = (scf_mblock_t*)(p - sizeof(scf_mblock_t));
-
- bytes = b->cur_size;
- bytes -= sizeof(scf_mblock_t);
-
- if (bytes < size) {
- p2 = scf__malloc(size);
- if (!p2)
- return NULL;
-
- memcpy(p2, p, bytes);
- scf__free(p);
-
- printf("%s(), %d, realloc: %p->%p, size: %ld\n", __func__, __LINE__, p, p2, size);
- return p2;
- }
-
- size = (sizeof(scf_mblock_t) + 63 + size) >> 6 << 6;
- bytes += sizeof(scf_mblock_t);
-
- if (bytes < size + 64)
- return p;
-
- b2 = (scf_mblock_t*)((uintptr_t)b + size);
-
- b ->cur_size = size;
- b2->cur_size = bytes - size;
-
- if (b->prev_size & 0x2) {
- b->prev_size &= ~0x2;
- b2->prev_size = size | 0x2;
- } else {
- b3 = (scf_mblock_t*)((uintptr_t)b + bytes);
-
- b2->prev_size = size;
- b3->prev_size = (bytes - size) | (b3->prev_size & 0x7);
- }
-
- b2->magic = 0x10f0;
-
- p2 = (uint8_t*)b2 + sizeof(scf_mblock_t);
- scf__free(p2);
-
- printf("%s(), %d, realloc: %p, free b2: %p, size: %ld\n", __func__, __LINE__, p, p2, size);
- return p;
-}
-
-int main()
-{
- uint8_t* p0 = scf__malloc(1000);
- uint8_t* p1 = scf__malloc(1320);
- uint8_t* p2 = scf__malloc(2510);
- uint8_t* p3 = scf__malloc(4510);
- uint8_t* p4 = scf__malloc(510);
- uint8_t* p5 = scf__malloc(6510);
- uint8_t* p6 = scf__malloc(510);
- uint8_t* p7 = scf__malloc(11510);
-
- scf__free(p0);
-
- *p1 = 1;
- scf__free(p1);
-
- *p2 = 2;
- *p4 = 4;
-
- scf__free(p4);
- scf__free(p5);
- scf__free(p2);
- scf__free(p6);
- scf__free(p3);
-
- scf__free(p7);
- return 0;
-}
this->len = 0;
this->capacity = 16;
- this->data = scf__auto_malloc(16);
+ this->data = __builtin_auto_malloc(16);
if (!this->data)
return -1;
void __release(str* this)
{
if (this->data)
- scf__auto_freep(&this->data, NULL);
+ __builtin_auto_freep(&this->data, NULL);
}
};
int __init(string* this)
{
- this->data = scf__auto_malloc(16);
+ this->data = __builtin_auto_malloc(16);
if (!this->data)
return -1;
{
int64_t len = strlen(s);
- this->data = scf__auto_malloc(len + 1);
+ this->data = __builtin_auto_malloc(len + 1);
if (!this->data)
return -1;
int __init(string* this, const char* s, int64_t len)
{
- this->data = scf__auto_malloc(len + 1);
+ this->data = __builtin_auto_malloc(len + 1);
if (!this->data)
return -1;
int64_t len = this->len + that->len;
if (len >= this->capacity) {
- uint8_t* p = scf__auto_malloc(len + 16);
+ uint8_t* p = __builtin_auto_malloc(len + 16);
if (!p)
return -1;
int64_t len = this->len + that->len;
if (s->len < len) {
- s->data = scf__auto_malloc(len + 1);
+ s->data = __builtin_auto_malloc(len + 1);
if (!s->data)
return NULL, -1;
}
void __release(string* this)
{
if (this->data)
- scf__auto_freep(&this->data, NULL);
+ __builtin_auto_freep(&this->data, NULL);
}
};
printf("### s0 == s3: %d, s0->data: %s, s2: %s\n", s0 == s3, s0->data, s2->data);
return 0;
}
-
+++ /dev/null
-int printf(const char* fmt, ...);
-
-int main(int argc, char* argv[])
-{
- int i;
- for (i = 1; i < 4; i++) {
- char a[i];
-
- a[0] = '1';
-
- printf("i: %d, a[0]: %c, %lg\n", i, a[0], 3.14);
- }
-
- return 0;
-}
+++ /dev/null
-int printf(const char* fmt, ...);
-
-int main(int argc, char* argv[])
-{
- int i;
- int j;
-
- for (i = 1; i < 4; i++) {
- char a[i];
-
- for (j = 0; j < i; j++) {
-
- a[j] = '1';
-
- printf("i: %d, j: %d, a: %c, %lg\n", i, j, a[j], 3.14);
- }
- }
-
- return 0;
-}
"intptr_t ireg;" \
"intptr_t freg;" \
"}; " \
-"void *memcpy(void *dest, const void *src, uintptr_t n);"
+"struct __builtin_object_t {" \
+" intptr_t refs;" \
+" uintptr_t size;" \
+"};" \
+"void *memcpy(void *dest, const void *src, uintptr_t n);" \
+"void __builtin_atomic_inc(intptr_t* p);" \
+"void __builtin_atomic_dec(intptr_t* p);" \
+"int __builtin_atomic_dec_and_test(intptr_t* p);" \
+"void __builtin_release_pt(void* objdata);" \
+"void* __builtin_auto_malloc(uintptr_t size);" \
+"void __builtin_auto_ref(void* data);" \
+"void __builtin_auto_freep (void** pp, __builtin_release_pt* release);" \
+"void __builtin_auto_freep_array(void** pp, int nb_pointers, __builtin_release_pt* release);" \
+"void __builtin_auto_free_array (void** pp, int size, int nb_pointers, __builtin_release_pt* release);"
static scf_string_t __builtin_h =
{
return SCF_DFA_NEXT_WORD;
}
-static scf_function_t* _type_find_function(scf_block_t* b, const char* name)
-{
- while (b) {
- if (!b->node.file_flag && !b->node.root_flag) {
- b = (scf_block_t*)b->node.parent;
- continue;
- }
-
- assert(b->scope);
-
- scf_function_t* f = scf_scope_find_function(b->scope, name);
- if (f)
- return f;
-
- b = (scf_block_t*)b->node.parent;
- }
-
- return NULL;
-}
-
int _type_find_type(scf_dfa_t* dfa, dfa_identity_t* id)
{
scf_parse_t* parse = dfa->priv;
if (SCF_FUNCTION_PTR == id->type->node.type && !id->type_def) {
- id->func_ptr = _type_find_function(parse->ast->current_block, id->identity->text->data);
+ ret = scf_ast_find_function(&id->func_ptr, parse->ast, id->identity->text->data);
+ if (ret < 0)
+ return SCF_DFA_ERROR;
if (!id->func_ptr) {
scf_loge("can't find funcptr type '%s'\n", id->identity->text->data);
assert(class);
fmalloc = NULL;
- ret = scf_ast_find_function(&fmalloc, ast, "scf__auto_malloc");
+ ret = scf_ast_find_function(&fmalloc, ast, "__builtin_auto_malloc");
if (ret < 0)
return ret;
if (!fmalloc) {
--- /dev/null
+.text
+.global __builtin_atomic_inc, __builtin_atomic_dec, __builtin_atomic_dec_and_test
+
+__builtin_atomic_inc:
+ lock incq (%rdi)
+ ret
+
+__builtin_atomic_dec:
+ lock decq (%rdi)
+ ret
+
+__builtin_atomic_dec_and_test:
+ lock decq (%rdi)
+ setz %al
+ movzbl %al, %eax
+ ret
+.fill 3, 1, 0
void* realloc(void* p, uintptr_t size);
int free (void* p);
-void scf__release_pt (void* objdata);
-
-void* scf__auto_malloc(uintptr_t size);
-void scf__auto_ref(void* data);
-
-void scf__auto_freep (void** pp, scf__release_pt* release);
-void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release);
-void scf__auto_free_array (void** pp, int size, int nb_pointers, scf__release_pt* release);
-
uintptr_t time(uintptr_t* t);
uintptr_t strlen (const char *s);
char* strncpy(char *dst, const char *src, uintptr_t n);
int memcpy (void* dst, const void* src, uintptr_t n);
int memcmp (void* dst, const void* src, uintptr_t n);
-
+++ /dev/null
-intptr_t scf_syscall(intptr_t number, ...);
-
-const intptr_t SCF_read = 0;
-const intptr_t SCF_write = 1;
-const intptr_t SCF_open = 2;
-const intptr_t SCF_close = 3;
-const intptr_t SCF_stat = 4;
-const intptr_t SCF_fstat = 5;
-const intptr_t SCF_lstat = 6;
-const intptr_t SCF_poll = 7;
-const intptr_t SCF_lseek = 8;
-const intptr_t SCF_mmap = 9;
-const intptr_t SCF_mprotect = 10;
-const intptr_t SCF_munmap = 11;
-
-const int O_RDONLY = 0;
-const int O_WRONLY = 1;
-const int O_RDWR = 2;
-const int O_CREAT = 0x40;
-const int O_TRUNC = 0x200;
-const int O_NONBLOCK = 0x800;
-
-const int EBADF = 9;
-const int EAGAIN = 11;
-const int ENOMEM = 12;
-const int EINVAL = 22;
-
-const int PROT_READ = 1;
-const int PROT_WRITE = 2;
-const int PROT_EXEC = 4;
-
-const int MAP_SHARED = 1;
-const int MAP_PRIVATE = 2;
-
-struct timespec
-{
- uint64_t tv_sec; /* seconds */
- intptr_t tv_nsec; /* nanoseconds */
-};
-
-struct stat
-{
- uint64_t st_dev; /* ID of device containing file */
- uint64_t st_ino; /* Inode number */
- uint32_t st_mode; /* File type and mode */
- uint64_t st_nlink; /* Number of hard links */
- uint32_t st_uid; /* User ID of owner */
- uint32_t st_gid; /* Group ID of owner */
- uint64_t st_rdev; /* Device ID (if special file) */
- uint64_t st_size; /* Total size, in bytes */
- uint64_t st_blksize; /* Block size for filesystem I/O */
- uint64_t st_blocks; /* Number of 512B blocks allocated */
-
- struct timespec st_atim; /* Time of last access */
- struct timespec st_mtim; /* Time of last modification */
- struct timespec st_ctim; /* Time of last status change */
-};
-
-struct scf_object_t
-{
- intptr_t refs;
- uintptr_t size;
-};
-
int printf(const char* fmt, ...);
void* malloc (uintptr_t size);
void* realloc(void* p, uintptr_t size);
int free (void* p);
-void scf__atomic_inc(intptr_t* p);
-void scf__atomic_dec(intptr_t* p);
-int scf__atomic_dec_and_test(intptr_t* p);
-
-void scf__release_pt(void* objdata);
-
-void* scf__auto_malloc(uintptr_t size)
+void* __builtin_auto_malloc(uintptr_t size)
{
- scf_object_t* obj = calloc(1, sizeof(scf_object_t) + size);
+ __builtin_object_t* obj = calloc(1, sizeof(__builtin_object_t) + size);
if (!obj)
return NULL;
- scf__atomic_inc(&obj->refs);
+ __builtin_atomic_inc(&obj->refs);
obj->size = size;
- void* data = (void*)obj + sizeof(scf_object_t);
+ void* data = (void*)obj + sizeof(__builtin_object_t);
printf("%s(), obj: %p, size: %d\n", __func__, obj, size);
return data;
}
-void scf__auto_freep(void** pp, scf__release_pt* release)
+void __builtin_auto_freep(void** pp, __builtin_release_pt* release)
{
if (!pp || !*pp) {
printf("%s()\n\n", __func__);
return;
}
- void* data = *pp;
- scf_object_t* obj = data - sizeof(scf_object_t);
+ void* data = *pp;
- if (scf__atomic_dec_and_test(&obj->refs)) {
+ __builtin_object_t* obj = data - sizeof(__builtin_object_t);
+
+ if (__builtin_atomic_dec_and_test(&obj->refs)) {
printf("%s(), obj: %p\n", __func__, obj);
*pp = NULL;
}
-void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release)
+void __builtin_auto_freep_array(void** pp, int nb_pointers, __builtin_release_pt* release)
{
if (!pp || !*pp)
return;
- scf_object_t* obj;
+ __builtin_object_t* obj;
void** p = (void**) *pp;
intptr_t size;
intptr_t i;
- obj = (void*)p - sizeof(scf_object_t);
+ obj = (void*)p - sizeof(__builtin_object_t);
size = obj->size / sizeof(void*);
if (!data)
continue;
- obj = data - sizeof(scf_object_t);
+ obj = data - sizeof(__builtin_object_t);
- scf__auto_freep_array(&p[i], nb_pointers - 1, release);
+ __builtin_auto_freep_array(&p[i], nb_pointers - 1, release);
p[i] = NULL;
}
}
- obj = (void*)p - sizeof(scf_object_t);
+ obj = (void*)p - sizeof(__builtin_object_t);
// printf("%s(), pp: %p, p: %p, nb_pointers: %d\n\n", __func__, pp, p, nb_pointers);
- if (scf__atomic_dec_and_test(&obj->refs)) {
+ if (__builtin_atomic_dec_and_test(&obj->refs)) {
if (release && 1 == nb_pointers)
release(p);
*pp = NULL;
}
-void scf__auto_free_array(void** pp, int size, int nb_pointers, scf__release_pt* release)
+void __builtin_auto_free_array(void** pp, int size, int nb_pointers, __builtin_release_pt* release)
{
if (!pp)
return;
- scf_object_t* obj;
- void* data;
+ __builtin_object_t* obj;
+
+ void* data;
+ int i;
- int i;
for (i = 0; i < size; i++) {
data = pp[i];
if (!data)
continue;
- obj = data - sizeof(scf_object_t);
+ obj = data - sizeof(__builtin_object_t);
- if (scf__atomic_dec_and_test(&obj->refs)) {
+ if (__builtin_atomic_dec_and_test(&obj->refs)) {
printf("%s(), obj: %p, pp: %p, i: %d, nb_pointers: %d\n", __func__, obj, pp, i, nb_pointers);
if (nb_pointers > 1)
- scf__auto_freep_array(&pp[i], nb_pointers - 1, release);
+ __builtin_auto_freep_array(&pp[i], nb_pointers - 1, release);
else {
if (release)
release(data);
}
}
-void scf__auto_ref(void* data)
+void __builtin_auto_ref(void* data)
{
if (data) {
- scf_object_t* obj = data - sizeof(scf_object_t);
+ __builtin_object_t* obj = data - sizeof(__builtin_object_t);
printf("%s(), obj: %p\n", __func__, obj);
- scf__atomic_inc(&obj->refs);
+ __builtin_atomic_inc(&obj->refs);
}
}
-
+++ /dev/null
-.text
-.global scf__atomic_inc, scf__atomic_dec, scf__atomic_dec_and_test
-
-scf__atomic_inc:
- lock incq (%rdi)
- ret
-
-scf__atomic_dec:
- lock decq (%rdi)
- ret
-
-scf__atomic_dec_and_test:
- lock decq (%rdi)
- setz %al
- movzbl %al, %eax
- ret
-.fill 3, 1, 0
+++ /dev/null
-.text
-.global scf_syscall
-
-scf_syscall:
-
- movq %rdi, %rax
- movq %rsi, %rdi
- movq %rdx, %rsi
- movq %rcx, %rdx
- movq %r8, %r10
- movq %r9, %r8
- movq 8(%rsp), %r9
-
-# movq 8(%rsp), %r10
-# movq 16(%rsp), %r8
-# movq 24(%rsp), %r9
-
- syscall
- ret
-.fill 6, 1, 0