Ignore:
Timestamp:
Sep 15, 2016, 2:57:03 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ba7aa2d, fc4a0fa
Parents:
5b639ee (diff), 50c5cf3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

more refactoring of parser code

File:
1 edited

Legend:

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

    r5b639ee r101e0bd  
    11#include "memory_pool.h"
    22
    3 #include <stdlib>
     3extern "C" {
     4        #include <stdlib.h>
     5        #include <string.h>
     6}
    47
     8#include "collector.h"
    59#include "object_header.h"
    610
     
    1519        card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t));
    1620        this->cards = new;
    17         ctor(this->cards);
     21        ctor_card(this->cards);
    1822
    1923        this->end_p = ((uint8_t*)this) + size;
    2024        this->free_p = this->start_p;
    2125
    22         check(gc_pool_of(this) == this);
     26        check( gc_pool_of( (void*)this ) == this);
    2327        check(this->cards);
    2428        gc_reset_pool(this);
     
    2731void dtor(gc_memory_pool *const this)
    2832{
    29         dtor(this->cards);
     33        dtor_card(this->cards);
    3034        free(this->cards);
    3135}
     
    3438{
    3539        this->free_p = this->start_p;
    36         #if _DEBUG
    37                 memset(this->start_p, 0xCD, gc_pool_total_size(this));
     40        #ifndef NDEBUG
     41                memset(this->start_p, 0xCD, gc_pool_size_total(this));
    3842        #endif
    3943
     
    4145        reset(this->cards);
    4246
    43         check(gc_pool_size_left(this) == gc_pool_total_size(this));
     47        check(gc_pool_size_left(this) == gc_pool_size_total(this));
    4448}
    4549
     
    5862}
    5963
    60 void ctor(
    61                 gc_pool_object_iterator* const this,
     64void ?{}(       gc_pool_object_iterator* this,
    6265                struct gc_object_header* start_object
    63                 #if _DEBUG
     66                #ifndef NDEBUG
    6467                        , intptr_t pool_start
    6568                        , intptr_t pool_end
     
    6871{
    6972        this->object = start_object;
    70         #if _DEBUG
     73        #ifndef NDEBUG
    7174                this->lower_limit = pool_start;
    7275                this->upper_limit = pool_end;
    7376        #endif
    7477
    75         check( ((intptr_t)start_object) >= lower_limit );
    76         check( ((intptr_t)start_object) <= upper_limit );
     78        check( ((intptr_t)start_object) >= this->lower_limit );
     79        check( ((intptr_t)start_object) <= this->upper_limit );
    7780}
     81
     82void ^?{}( gc_pool_object_iterator* this ) {}
    7883
    7984gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member)
     
    8186        size_t card = card_of(member);
    8287        intptr_t member_add = (intptr_t)member;
    83         void* start_obj;
    84         intptr_t start_obj_add;
     88        intptr_t start_obj;
    8589
    8690        do
    8791        {
    8892                check(card < CARDS_COUNT);
    89                 start_obj = object_at(this->cards, card);
     93                start_obj = (intptr_t)object_at(this->cards, card);
    9094                check(card != 0 || start_obj);
    9195                card--;
    92                 start_obj_add = (intptr_t)start_obj;
    9396        }
    94         while(start_obj_add > member_add || start_obj_add != 0);
     97        while(start_obj > member_add || !(start_obj));
    9598
    96         check(start_obj);
    97        
     99        check( start_obj );
     100
    98101        struct gc_object_header* start_obj_typed = (struct gc_object_header*)start_obj;
    99102
    100         gc_pool_object_iterator it;
    101         ctor( &it,
    102                 start_obj_typed,
    103                 #if _DEBUG
     103        return (gc_pool_object_iterator) {
     104                start_obj_typed
     105                #ifndef NDEBUG
    104106                        , (intptr_t)this->start_p
    105107                        , (intptr_t)this->free_p
    106108                #endif
    107         );
    108         return it;
     109        };
    109110}
    110111
     
    117118{
    118119        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
     120        return (gc_pool_object_iterator) {
     121                start_obj
     122                #ifndef NDEBUG
    123123                        , (intptr_t)this->start_p
    124124                        , (intptr_t)this->free_p
    125125                #endif
    126         );
    127         return it;
     126        };
    128127}
    129128
    130129gc_pool_object_iterator end(gc_memory_pool* const this)
    131130{
    132         gc_pool_object_iterator it;
    133         ctor( &it,
    134                 (struct gc_object_header*)this->free_p,
    135                 #if _DEBUG
     131        return (gc_pool_object_iterator) {
     132                (struct gc_object_header*)this->free_p
     133                #ifndef NDEBUG
    136134                        , (intptr_t)this->start_p
    137135                        , (intptr_t)this->free_p
    138136                #endif
    139         );
    140         return it;
     137        };
    141138}
    142139
     
    145142        struct gc_object_header* object = it->object;
    146143        intptr_t next_ptr = ((intptr_t)object) + object->size;
    147         check(next_ptr > lower_limit);
    148         check(next_ptr <= upper_limit);
     144        check(next_ptr > it->lower_limit);
     145        check(next_ptr <= it->upper_limit);
    149146
    150147        struct gc_object_header* next_obj = ((struct gc_object_header*)next_ptr);
    151         check(next_ptr == upper_limit || is_valide(next_obj));
     148        check(next_ptr == it->upper_limit || is_valid(next_obj));
    152149
    153150        it->object = next_obj;
Note: See TracChangeset for help on using the changeset viewer.