Ignore:
Timestamp:
May 4, 2016, 10:45:18 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
eb4f201
Parents:
8a74081
Message:

fixed compilation of garbage collector

Location:
src/examples/gc_no_raii/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/src/internal/memory_pool.c

    r8a74081 r4ef8fb3  
    33#include <stdlib>
    44
    5 // const size_t gc_pool_header_size = (size_t)(  &(((gc_memory_pool*)NULL)->start_p) );
     5#include "object_header.h"
     6
     7const size_t gc_pool_header_size = (size_t)(  &(((gc_memory_pool*)NULL)->start_p) );
    68
    79void ctor(gc_memory_pool *const this, size_t size, gc_memory_pool* next, gc_memory_pool* mirror, uint8_t type)
     
    1113        this->type_code = type;
    1214
    13         card_table_t* new = malloc();
     15        card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t));
    1416        this->cards = new;
    1517        ctor(this->cards);
     
    1820        this->free_p = this->start_p;
    1921
    20         // check(gc_pool_of(this) == this);
    21         // check(this->cards);
    22         // gc_reset_pool(this);
     22        check(gc_pool_of(this) == this);
     23        check(this->cards);
     24        gc_reset_pool(this);
    2325}
    2426
    25 // void dtor(gc_memory_pool *const this)
    26 // {
    27 //      dtor(this->cards);
    28 //      free(this->cards);
    29 // }
    30 //
    31 // void gc_reset_pool(gc_memory_pool *const this)
    32 // {
    33 //      this->free_p = this->start_p;
    34 //      #if _DEBUG
    35 //              memset(this->start_p, 0xCD, gc_pool_total_size(this));
    36 //      #endif
    37 //
    38 //      check(this->cards);
    39 //      reset(this->cards);
    40 //
    41 //      check(gc_pool_size_left(this) == gc_pool_total_size(this));
    42 // }
    43 //
    44 // void* gc_pool_allocate(gc_memory_pool *const this, size_t size, bool zero)
    45 // {
    46 //      void* ret = this->free_p;
    47 //
    48 //      this->free_p += size;
    49 //
    50 //      if (zero) memset(ret, 0x00, size);
    51 //
    52 //      check(this->cards);
    53 //      register_object(this->cards, ret);
    54 //
    55 //      return ret;
    56 // }
    57 //
    58 // gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member)
    59 // {
    60 //      size_t card = card_of(member);
    61 //      intptr_t member_add = (intptr_t)member;
    62 //      void* start_obj;
    63 //      intptr_t start_obj_add;
    64 //
    65 //      do
    66 //      {
    67 //              check(card < CARDS_COUNT);
    68 //              start_obj = object_at(this->cards, card);
    69 //              check(card != 0 || start_obj);
    70 //              card--;
    71 //              start_obj_add = (intptr_t)start_obj;
    72 //      }
    73 //      while(start_obj_add > member_add || start_obj_add != 0);
    74 //
    75 //      check(start_obj);
    76 //
    77 //      gc_pool_object_iterator it;
    78 //      ctor( &it,
    79 //              (gc_object_header*)start_obj
    80 //              #if _DEBUG
    81 //                      , (intptr_t)this->start_p
    82 //                      , (intptr_t)this->free_p
    83 //              #endif
    84 //      );
    85 //      return it;
    86 // }
    87 //
    88 // void ctor(
    89 //              gc_pool_object_iterator* const this,
    90 //              struct gc_object_header* start_object
    91 //              #if _DEBUG
    92 //                      , intptr_t pool_start
    93 //                      , intptr_t pool_end
    94 //              #endif
    95 //      )
    96 // {
    97 //      this->object = start_object;
    98 //      #if _DEBUG
    99 //              this->lower_limit = pool_start;
    100 //              this->upper_limit = pool_end;
    101 //      #endif
    102 //
    103 //      check( ((intptr_t)start_object) >= lower_limit );
    104 //      check( ((intptr_t)start_object) <= upper_limit );
    105 // }
    106 //
    107 // bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs)
    108 // {
    109 //      return lhs.object != rhs.object;
    110 // }
    111 //
    112 // gc_pool_object_iterator begin(gc_memory_pool* const this)
    113 // {
    114 //      gc_pool_object_iterator it;
    115 //      ctor( &it,
    116 //              (gc_object_header*)this->start_p,
    117 //              #if _DEBUG
    118 //                      , (intptr_t)this->start_p
    119 //                      , (intptr_t)this->free_p
    120 //              #endif
    121 //      );
    122 //      return it;
    123 // }
    124 //
    125 // gc_pool_object_iterator end(gc_memory_pool* const this)
    126 // {
    127 //      gc_pool_object_iterator it;
    128 //      ctor( &it,
    129 //              (gc_object_header*)this->free_p,
    130 //              #if _DEBUG
    131 //                      , (intptr_t)this->start_p
    132 //                      , (intptr_t)this->free_p
    133 //              #endif
    134 //      );
    135 //      return it;
    136 // }
    137 //
    138 // gc_pool_object_iterator* ++?(gc_pool_object_iterator* it)
    139 // {
    140 //      intptr_t next_ptr = ((intptr_t)it->object) + it->object->size;
    141 //      check(next_ptr > lower_limit);
    142 //      check(next_ptr <= upper_limit);
    143 //
    144 //      gc_object_header* next_obj = ((gc_object_header*)next_ptr);
    145 //      check(next_ptr == upper_limit || is_valide(next_obj));
    146 //
    147 //      it->object = next_obj;
    148 //      return it;
    149 // }
    150 //
    151 // const struct gc_object_header* *?(const gc_pool_object_iterator it)
    152 // {
    153 //      return it.object;
    154 // }
    155 //
    156 // struct gc_object_header* *?(gc_pool_object_iterator it)
    157 // {
    158 //      return it.object;
    159 // }
     27void dtor(gc_memory_pool *const this)
     28{
     29        dtor(this->cards);
     30        free(this->cards);
     31}
     32
     33void gc_reset_pool(gc_memory_pool *const this)
     34{
     35        this->free_p = this->start_p;
     36        #if _DEBUG
     37                memset(this->start_p, 0xCD, gc_pool_total_size(this));
     38        #endif
     39
     40        check(this->cards);
     41        reset(this->cards);
     42
     43        check(gc_pool_size_left(this) == gc_pool_total_size(this));
     44}
     45
     46void* gc_pool_allocate(gc_memory_pool *const this, size_t size, bool zero)
     47{
     48        void* ret = this->free_p;
     49
     50        this->free_p += size;
     51
     52        if (zero) memset(ret, 0x00, size);
     53
     54        check(this->cards);
     55        register_object(this->cards, ret);
     56
     57        return ret;
     58}
     59
     60void ctor(
     61                gc_pool_object_iterator* const this,
     62                struct gc_object_header* start_object
     63                #if _DEBUG
     64                        , intptr_t pool_start
     65                        , intptr_t pool_end
     66                #endif
     67        )
     68{
     69        this->object = start_object;
     70        #if _DEBUG
     71                this->lower_limit = pool_start;
     72                this->upper_limit = pool_end;
     73        #endif
     74
     75        check( ((intptr_t)start_object) >= lower_limit );
     76        check( ((intptr_t)start_object) <= upper_limit );
     77}
     78
     79gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member)
     80{
     81        size_t card = card_of(member);
     82        intptr_t member_add = (intptr_t)member;
     83        void* start_obj;
     84        intptr_t start_obj_add;
     85
     86        do
     87        {
     88                check(card < CARDS_COUNT);
     89                start_obj = object_at(this->cards, card);
     90                check(card != 0 || start_obj);
     91                card--;
     92                start_obj_add = (intptr_t)start_obj;
     93        }
     94        while(start_obj_add > member_add || start_obj_add != 0);
     95
     96        check(start_obj);
     97       
     98        struct gc_object_header* start_obj_typed = (struct gc_object_header*)start_obj;
     99
     100        gc_pool_object_iterator it;
     101        ctor( &it,
     102                start_obj_typed,
     103                #if _DEBUG
     104                        , (intptr_t)this->start_p
     105                        , (intptr_t)this->free_p
     106                #endif
     107        );
     108        return it;
     109}
     110
     111bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs)
     112{
     113        return lhs.object != rhs.object;
     114}
     115
     116gc_pool_object_iterator begin(gc_memory_pool* const this)
     117{
     118        struct gc_object_header* start_obj = (struct gc_object_header*)this->start_p;
     119        gc_pool_object_iterator it;
     120        ctor( &it,
     121                start_obj,
     122                #if _DEBUG
     123                        , (intptr_t)this->start_p
     124                        , (intptr_t)this->free_p
     125                #endif
     126        );
     127        return it;
     128}
     129
     130gc_pool_object_iterator end(gc_memory_pool* const this)
     131{
     132        gc_pool_object_iterator it;
     133        ctor( &it,
     134                (struct gc_object_header*)this->free_p,
     135                #if _DEBUG
     136                        , (intptr_t)this->start_p
     137                        , (intptr_t)this->free_p
     138                #endif
     139        );
     140        return it;
     141}
     142
     143gc_pool_object_iterator* ++?(gc_pool_object_iterator* it)
     144{
     145        struct gc_object_header* object = it->object;
     146        intptr_t next_ptr = ((intptr_t)object) + object->size;
     147        check(next_ptr > lower_limit);
     148        check(next_ptr <= upper_limit);
     149
     150        struct gc_object_header* next_obj = ((struct gc_object_header*)next_ptr);
     151        check(next_ptr == upper_limit || is_valide(next_obj));
     152
     153        it->object = next_obj;
     154        return it;
     155}
     156
     157const struct gc_object_header* *?(const gc_pool_object_iterator it)
     158{
     159        return it.object;
     160}
     161
     162struct gc_object_header* *?(gc_pool_object_iterator it)
     163{
     164        return it.object;
     165}
  • src/examples/gc_no_raii/src/internal/state.c

    r8a74081 r4ef8fb3  
    1010
    1111//gc internal includes
     12#include "collector.h"
    1213#include "globals.h"
    1314#include "memory_pool.h"
    1415#include "object_header.h"
     16#include "tools/worklist.h"
    1517
    1618void gc_state_swap(gc_state *const this);
  • src/examples/gc_no_raii/src/internal/state.h

    r8a74081 r4ef8fb3  
    77#include "vector.h"
    88
    9 // typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
     9typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
    1010
    1111struct gc_state
     
    1919        size_t used_space;
    2020
    21         // pools_table_t        pools_table;
     21        pools_table_t   pools_table;
    2222        size_t          pools_table_count;
    2323};
  • src/examples/gc_no_raii/src/tools/worklist.h

    r8a74081 r4ef8fb3  
    11#pragma once
    22
     3#ifdef __cforall
     4extern "C" {
     5#endif
    36#include <stddef.h>
    47#include <stdint.h>
     8#ifdef __cforall
     9}
     10#endif
    511
    612#include "vector.h"
  • src/examples/gc_no_raii/src/vector.h

    r8a74081 r4ef8fb3  
    2121        size_t size;
    2222};
    23 //
    24 // //------------------------------------------------------------------------------
    25 // //Initialization
    26 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    27 // void ctor(vector(T, allocator_t) *const this);
    28 //
    29 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    30 // void dtor(vector(T, allocator_t) *const this);
    31 //
    32 // //------------------------------------------------------------------------------
    33 // //Capacity
    34 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    35 // static inline bool empty(vector(T, allocator_t) *const this)
    36 // {
    37 //      return this->size == 0;
    38 // }
    39 //
    40 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    41 // static inline bool size(vector(T, allocator_t) *const this)
    42 // {
    43 //      return this->size;
    44 // }
    45 //
    46 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    47 // static inline void reserve(vector(T, allocator_t) *const this, size_t size)
    48 // {
    49 //      realloc(&this->storage, this->size+1);
    50 // }
    51 //
    52 // //------------------------------------------------------------------------------
    53 // //Element access
    54 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    55 // static inline T at(vector(T, allocator_t) *const this, size_t index)
    56 // {
    57 //      return data(&this->storage)[index];
    58 // }
    59 //
    60 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    61 // static inline T ?[?](vector(T, allocator_t) *const this, size_t index)
    62 // {
    63 //      return data(&this->storage)[index];
    64 // }
    65 //
    66 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    67 // static inline T front(vector(T, allocator_t) *const this)
    68 // {
    69 //      return data(&this->storage)[0];
    70 // }
    71 //
    72 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    73 // static inline T back(vector(T, allocator_t) *const this)
    74 // {
    75 //      return data(&this->storage)[this->size - 1];
    76 // }
    77 //
    78 // //------------------------------------------------------------------------------
    79 // //Modifiers
    80 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    81 // void push_back(vector(T, allocator_t) *const this, T value);
    82 //
    83 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    84 // void pop_back(vector(T, allocator_t) *const this);
    85 //
    86 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    87 // void clear(vector(T, allocator_t) *const this);
    88 //
    89 // //------------------------------------------------------------------------------
    90 // //Iterators
    91 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    92 // static inline T* begin(vector(T, allocator_t) *const this)
    93 // {
    94 //      return data(&this->storage);
    95 // }
    96 //
    97 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    98 // static inline const T* cbegin(const vector(T, allocator_t) *const this)
    99 // {
    100 //      return data(&this->storage);
    101 // }
    102 //
    103 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    104 // static inline T* end(vector(T, allocator_t) *const this)
    105 // {
    106 //      return data(&this->storage) + this->size;
    107 // }
    108 //
    109 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    110 // static inline const T* cend(const vector(T, allocator_t) *const this)
    111 // {
    112 //      return data(&this->storage) + this->size;
    113 // }
    114 //
    115 // //------------------------------------------------------------------------------
    116 // //Allocator
    117 // forall(otype T)
    118 // struct heap_allocator
    119 // {
    120 //      T* storage;
    121 //      size_t capacity;
    122 // };
    123 //
    124 // forall(otype T)
    125 // void ctor(heap_allocator(T) *const this);
    126 //
    127 // forall(otype T)
    128 // void dtor(heap_allocator(T) *const this);
    129 //
    130 // forall(otype T)
    131 // void realloc(heap_allocator(T) *const this, size_t size);
    132 //
    133 // forall(otype T)
    134 // static inline T* data(heap_allocator(T) *const this)
    135 // {
    136 //      return this->storage;
    137 // }
     23
     24//------------------------------------------------------------------------------
     25//Initialization
     26forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     27void ctor(vector(T, allocator_t) *const this);
     28
     29forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     30void dtor(vector(T, allocator_t) *const this);
     31
     32//------------------------------------------------------------------------------
     33//Capacity
     34forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     35static inline bool empty(vector(T, allocator_t) *const this)
     36{
     37        return this->size == 0;
     38}
     39
     40forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     41static inline bool size(vector(T, allocator_t) *const this)
     42{
     43        return this->size;
     44}
     45
     46forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     47static inline void reserve(vector(T, allocator_t) *const this, size_t size)
     48{
     49        realloc(&this->storage, this->size+1);
     50}
     51
     52//------------------------------------------------------------------------------
     53//Element access
     54forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     55static inline T at(vector(T, allocator_t) *const this, size_t index)
     56{
     57        return data(&this->storage)[index];
     58}
     59
     60forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     61static inline T ?[?](vector(T, allocator_t) *const this, size_t index)
     62{
     63        return data(&this->storage)[index];
     64}
     65
     66forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     67static inline T front(vector(T, allocator_t) *const this)
     68{
     69        return data(&this->storage)[0];
     70}
     71
     72forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     73static inline T back(vector(T, allocator_t) *const this)
     74{
     75        return data(&this->storage)[this->size - 1];
     76}
     77
     78//------------------------------------------------------------------------------
     79//Modifiers
     80forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     81void push_back(vector(T, allocator_t) *const this, T value);
     82
     83forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     84void pop_back(vector(T, allocator_t) *const this);
     85
     86forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     87void clear(vector(T, allocator_t) *const this);
     88
     89//------------------------------------------------------------------------------
     90//Iterators
     91forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     92static inline T* begin(vector(T, allocator_t) *const this)
     93{
     94        return data(&this->storage);
     95}
     96
     97forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     98static inline const T* cbegin(const vector(T, allocator_t) *const this)
     99{
     100        return data(&this->storage);
     101}
     102
     103forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     104static inline T* end(vector(T, allocator_t) *const this)
     105{
     106        return data(&this->storage) + this->size;
     107}
     108
     109forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     110static inline const T* cend(const vector(T, allocator_t) *const this)
     111{
     112        return data(&this->storage) + this->size;
     113}
     114
     115//------------------------------------------------------------------------------
     116//Allocator
     117forall(otype T)
     118struct heap_allocator
     119{
     120        T* storage;
     121        size_t capacity;
     122};
     123
     124forall(otype T)
     125void ctor(heap_allocator(T) *const this);
     126
     127forall(otype T)
     128void dtor(heap_allocator(T) *const this);
     129
     130forall(otype T)
     131void realloc(heap_allocator(T) *const this, size_t size);
     132
     133forall(otype T)
     134static inline T* data(heap_allocator(T) *const this)
     135{
     136        return this->storage;
     137}
Note: See TracChangeset for help on using the changeset viewer.