rename 'scf__auto_*()' to '__builtin_auto_*()' as C compiler habits. master
authoryu.dongliang <18588496441@163.com>
Thu, 24 Sep 2026 03:52:17 +0000 (11:52 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 24 Sep 2026 03:52:17 +0000 (11:52 +0800)
28 files changed:
core/scf_auto_gc_3ac.c
core/scf_auto_gc_find.c
core/scf_optimizer_auto_gc.c
core/scf_optimizer_auto_gc_find.c
examples/auto_gc_0.c
examples/auto_gc_multi_rets.c
examples/mat.c
examples/mat2.c
examples/recursive_pointer.c
examples/ret2_err.c
examples/scf_malloc.c [deleted file]
examples/str.c
examples/string.c
examples/vla_0.c [deleted file]
examples/vla_2.c [deleted file]
parse/main.c
parse/scf_dfa_type.c
parse/scf_operator_handler_semantic.c
sysroot/lib/_start_x64.s [moved from sysroot/lib/x64/_start.s with 100% similarity]
sysroot/lib/scf_atomic_x64.s [new file with mode: 0644]
sysroot/lib/scf_capi.c
sysroot/lib/scf_linux_api.c [deleted file]
sysroot/lib/scf_object.c
sysroot/lib/x64/_start.o [new file with mode: 0644]
sysroot/lib/x64/scf_atomic.o [new file with mode: 0644]
sysroot/lib/x64/scf_atomic.s [deleted file]
sysroot/lib/x64/scf_object.o [new file with mode: 0644]
sysroot/lib/x64/scf_syscall.s [deleted file]

index 9362d8436b0e8519b38e541a546912ca342b0bfd..25b4a87db89b6a44c12aa0e52fb7be299189e730 100644 (file)
@@ -49,7 +49,7 @@ static scf_3ac_code_t* _auto_gc_code_ref(scf_list_t* dag_list_head, scf_ast_t* a
        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;
 
@@ -191,7 +191,7 @@ static scf_3ac_code_t* _auto_gc_code_free_array(scf_list_t* dag_list_head, scf_a
        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;
 
@@ -253,7 +253,7 @@ static scf_3ac_code_t* _auto_gc_code_freep_array(scf_list_t* dag_list_head, scf_
        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;
 
index 012d2dfe9c97312f4bedeec1389ddf61e7fb0572..0a96c7a0d6ddc54522d03c160d5f540a733705be 100644 (file)
@@ -272,7 +272,7 @@ static int _bfs_sort_function(scf_vector_t* fqueue, scf_vector_t* functions)
 
                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;
        }
 
index 57f2a3ba47362a2539ad28c9a0696ba820caad53..9efe1bf45abf7e1553b26fb7610fa0017c088c2d 100644 (file)
@@ -757,7 +757,7 @@ static int _auto_gc_retval(scf_dn_status_t* ds_obj, scf_dag_node_t* dn, scf_vect
        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];
@@ -983,7 +983,7 @@ static int _optimize_auto_gc(scf_ast_t* ast, scf_function_t* f, scf_vector_t* fu
        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;
index 5b0ea3dcb72f32e51cae9ebb6830ec4cc92969e3..fb3775c820bbaa27d74634492fbbbc521bfb941e 100644 (file)
@@ -495,7 +495,7 @@ static int _auto_gc_find_ref(scf_dn_status_t* ds_obj, scf_dag_node_t* dn, scf_3a
 
                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;
                }
@@ -896,7 +896,7 @@ static int _optimize_auto_gc_find(scf_ast_t* ast, scf_function_t* f, scf_vector_
                        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);
index 2f7143273f56e88123905d2e0ddef72b5218c18b..8474cce5ec754b7ed4b6abba34910a0f932581d1 100644 (file)
@@ -1,8 +1,8 @@
-#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()
index e2b92e59b09873387c16fb853048fec1911b6d17..3d7c7efa6233976115e0eaf83422926c77cd06ef 100644 (file)
@@ -1,9 +1,9 @@
-#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;
index 8f696a0cec1fac102bae99e2d3181166f1e46a06..98af4917fe436b59f383ef80354b60cd60daf4b4 100644 (file)
@@ -56,7 +56,7 @@ struct mat
                } else
                        return -1;
 
-               this->data = scf__auto_malloc(size);
+               this->data = __builtin_auto_malloc(size);
                if (!this->data)
                        return -1;
 
@@ -68,7 +68,7 @@ struct mat
        void __release(mat* this)
        {
                if (this->data)
-                       scf__auto_freep(&this->data, NULL);
+                       __builtin_auto_freep(&this->data, NULL);
        }
 };
 
index 78499f38fdf6a7fc625135b4d47de23e64c00f34..826abfa2cc49d00f2dc086f393a43c19d3c111ef 100644 (file)
@@ -56,7 +56,7 @@ struct mat
                } else
                        return -1;
 
-               this->data = scf__auto_malloc(size);
+               this->data = __builtin_auto_malloc(size);
                if (!this->data)
                        return -1;
 
@@ -126,7 +126,7 @@ struct mat
        void __release(mat* this)
        {
                if (this->data)
-                       scf__auto_freep(&this->data, NULL);
+                       __builtin_auto_freep(&this->data, NULL);
        }
 };
 
index b2f1f8ae7d9a29de47e91d86af9c995dc603ccc7..4605f1ee2808b714274e27fcab2c4f8f43c0d34c 100644 (file)
@@ -5,7 +5,7 @@ int f(int** t0, int **t1);
 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);
@@ -15,7 +15,7 @@ int g(int** s0, int** 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);
index 38dd665176e9a85a4c2b6e87a5151df61325d0c7..d8327fe02b3a47bee82128cd2f0a51cebcf9c8a8 100644 (file)
@@ -11,7 +11,7 @@ struct str
                this->len      = 0;
                this->capacity = 16;
 
-               this->data = scf__auto_malloc(16);
+               this->data = __builtin_auto_malloc(16);
                if (!this->data)
                        return -1;
 
@@ -22,7 +22,7 @@ struct str
        void __release(str* this)
        {
                if (this->data)
-                       scf__auto_freep(&this->data, NULL);
+                       __builtin_auto_freep(&this->data, NULL);
        }
 };
 
diff --git a/examples/scf_malloc.c b/examples/scf_malloc.c
deleted file mode 100644 (file)
index bf204b0..0000000
+++ /dev/null
@@ -1,364 +0,0 @@
-
-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;
-}
index 74bcf54d3706b98d1f8278e7f60b783ce6f2a1e4..992e82dec6a7061d15c3b502cabd78464530d368 100644 (file)
@@ -11,7 +11,7 @@ struct str
                this->len = 0;
                this->capacity = 16;
 
-               this->data = scf__auto_malloc(16);
+               this->data = __builtin_auto_malloc(16);
                if (!this->data)
                        return -1;
 
@@ -22,7 +22,7 @@ struct str
        void __release(str* this)
        {
                if (this->data)
-                       scf__auto_freep(&this->data, NULL);
+                       __builtin_auto_freep(&this->data, NULL);
        }
 };
 
index 9d258abb7771b421869521c41b8c2c71b185790f..6bcb8e24ce2c84199ec95f882a740b9b330bd071 100644 (file)
@@ -8,7 +8,7 @@ struct string
 
        int __init(string* this)
        {
-               this->data = scf__auto_malloc(16);
+               this->data = __builtin_auto_malloc(16);
                if (!this->data)
                        return -1;
 
@@ -23,7 +23,7 @@ struct string
        {
                int64_t len = strlen(s);
 
-               this->data = scf__auto_malloc(len + 1);
+               this->data = __builtin_auto_malloc(len + 1);
                if (!this->data)
                        return -1;
 
@@ -38,7 +38,7 @@ struct string
 
        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;
 
@@ -56,7 +56,7 @@ struct string
                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;
 
@@ -85,7 +85,7 @@ struct string
                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;
                }
@@ -112,7 +112,7 @@ struct string
        void __release(string* this)
        {
                if (this->data)
-                       scf__auto_freep(&this->data, NULL);
+                       __builtin_auto_freep(&this->data, NULL);
        }
 };
 
@@ -133,4 +133,3 @@ int main()
        printf("### s0 == s3: %d, s0->data: %s, s2: %s\n", s0 == s3, s0->data, s2->data);
        return 0;
 }
-
diff --git a/examples/vla_0.c b/examples/vla_0.c
deleted file mode 100644 (file)
index 1647712..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-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;
-}
diff --git a/examples/vla_2.c b/examples/vla_2.c
deleted file mode 100644 (file)
index d93f8f1..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-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;
-}
index 724853152847a0502f6542dba21c2f8b080d2558..56416ee5c99cc65e54b095e0bfc0f4d3c3a9fcdd 100644 (file)
        "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 =
 {
index b341ccb849183be3d0a7f4f0d58c30c60a454218..22b83af26eb234057a8552502409d2dd5cb2bef7 100644 (file)
@@ -235,26 +235,6 @@ static int _type_action_base_type(scf_dfa_t* dfa, scf_vector_t* words, void* dat
        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;
@@ -294,7 +274,9 @@ int _type_find_type(scf_dfa_t* dfa, dfa_identity_t* id)
 
                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);
index c7429c13bfd199cb4b5c1ccb2596e70b2ca5de22..cde8acebfe86d05fce1365ec858cf1cbde0ff360 100644 (file)
@@ -701,7 +701,7 @@ static int _scf_op_semantic_new(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes
        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) {
diff --git a/sysroot/lib/scf_atomic_x64.s b/sysroot/lib/scf_atomic_x64.s
new file mode 100644 (file)
index 0000000..98aa986
--- /dev/null
@@ -0,0 +1,17 @@
+.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
index 384b9576e9e3ff8498ca2d4654a4859c4ebd6323..c1a2eafba4bce503460e356374c2e8e362c81f60 100644 (file)
@@ -10,15 +10,6 @@ void* calloc (uintptr_t n, uintptr_t size);
 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);
@@ -27,4 +18,3 @@ int       strncmp(const char *s1, const char *s2,  uintptr_t n);
 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);
-
diff --git a/sysroot/lib/scf_linux_api.c b/sysroot/lib/scf_linux_api.c
deleted file mode 100644 (file)
index 3995bd8..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-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 */
-};
-
index 64ae090ed087192ff6ae339d1b562b8a9f35fa6b..94609c248ba56369bda95d2cb6daf420fc8790b0 100644 (file)
@@ -1,10 +1,4 @@
 
-struct scf_object_t
-{
-       intptr_t   refs;
-       uintptr_t  size;
-};
-
 int   printf(const char* fmt, ...);
 
 void* malloc (uintptr_t size);
@@ -12,39 +6,34 @@ void* calloc (uintptr_t n, 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);
 
@@ -59,12 +48,12 @@ void scf__auto_freep(void** pp, scf__release_pt* release)
        *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;
 
@@ -73,7 +62,7 @@ void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release)
                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*);
 
@@ -85,18 +74,18 @@ void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release)
                        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);
@@ -109,15 +98,16 @@ void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release)
        *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];
@@ -125,15 +115,15 @@ void scf__auto_free_array(void** pp, int size, int nb_pointers, scf__release_pt*
                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);
@@ -146,15 +136,14 @@ void scf__auto_free_array(void** pp, int size, int nb_pointers, scf__release_pt*
        }
 }
 
-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);
        }
 }
-
diff --git a/sysroot/lib/x64/_start.o b/sysroot/lib/x64/_start.o
new file mode 100644 (file)
index 0000000..9a65885
Binary files /dev/null and b/sysroot/lib/x64/_start.o differ
diff --git a/sysroot/lib/x64/scf_atomic.o b/sysroot/lib/x64/scf_atomic.o
new file mode 100644 (file)
index 0000000..e388dcf
Binary files /dev/null and b/sysroot/lib/x64/scf_atomic.o differ
diff --git a/sysroot/lib/x64/scf_atomic.s b/sysroot/lib/x64/scf_atomic.s
deleted file mode 100644 (file)
index 15dad0f..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-.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
diff --git a/sysroot/lib/x64/scf_object.o b/sysroot/lib/x64/scf_object.o
new file mode 100644 (file)
index 0000000..fa447a5
Binary files /dev/null and b/sysroot/lib/x64/scf_object.o differ
diff --git a/sysroot/lib/x64/scf_syscall.s b/sysroot/lib/x64/scf_syscall.s
deleted file mode 100644 (file)
index 357a5de..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-.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