Changes in / [101e0bd:5b639ee]


Ignore:
Location:
src
Files:
1 added
1 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r101e0bd r5b639ee  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Sep 14 23:13:28 2016
    13 // Update Count     : 502
     12// Last Modified On : Mon Sep 12 21:03:18 2016
     13// Update Count     : 491
    1414//
    1515
     
    383383}
    384384
     385static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
     386        if ( src && dst ) {
     387                if ( src->forall && dst->kind == TypeData::Function ) {
     388                        if ( dst->forall ) {
     389                                dst->forall->appendList( src->forall );
     390                        } else {
     391                                dst->forall = src->forall;
     392                        } // if
     393                        src->forall = 0;
     394                } // if
     395                if ( dst->base ) {
     396                        addQualifiersToType( src, dst->base );
     397                } else if ( dst->kind == TypeData::Function ) {
     398                        dst->base = src;
     399                        src = 0;
     400                } else {
     401                        dst->qualifiers |= src->qualifiers;
     402                } // if
     403        } // if
     404}
     405
    385406void appendError( string & dst, const string & src ) {
    386407        if ( src.empty() ) return;
     
    424445} // DeclarationNode::copyStorageClasses
    425446
    426 static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
    427         if ( src->forall && dst->kind == TypeData::Function ) {
    428                 if ( dst->forall ) {
    429                         dst->forall->appendList( src->forall );
     447DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
     448        if ( q ) {
     449                checkStorageClasses( q );
     450                copyStorageClasses( q );
     451                if ( q->type ) {
     452                        if ( ! type ) {
     453                                type = new TypeData;
     454                        } else {
     455                                checkQualifiers( q->type, type );
     456                        } // if
     457                        addQualifiersToType( q->type, type );
     458                        if ( q->type && q->type->forall ) {
     459                                if ( type->forall ) {
     460                                        type->forall->appendList( q->type->forall );
     461                                } else {
     462                                        if ( type->kind == TypeData::Aggregate ) {
     463                                                type->aggregate.params = q->type->forall;
     464                                                // change implicit typedef from TYPEDEFname to TYPEGENname
     465                                                typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
     466                                        } else {
     467                                                type->forall = q->type->forall;
     468                                        } // if
     469                                } // if
     470                                q->type->forall = 0;
     471                        } // if
     472                } // if
     473        } // if
     474        delete q;
     475        return this;
     476}
     477
     478static void addTypeToType( TypeData *&src, TypeData *&dst ) {
     479        if ( src && dst ) {
     480                if ( src->forall && dst->kind == TypeData::Function ) {
     481                        if ( dst->forall ) {
     482                                dst->forall->appendList( src->forall );
     483                        } else {
     484                                dst->forall = src->forall;
     485                        } // if
     486                        src->forall = 0;
     487                } // if
     488                if ( dst->base ) {
     489                        addTypeToType( src, dst->base );
    430490                } else {
    431                         dst->forall = src->forall;
    432                 } // if
    433                 src->forall = 0;
    434         } // if
    435         if ( dst->base ) {
    436                 addQualifiersToType( src, dst->base );
    437         } else if ( dst->kind == TypeData::Function ) {
    438                 dst->base = src;
    439                 src = 0;
    440         } else {
    441                 dst->qualifiers |= src->qualifiers;
    442         } // if
    443 } // addQualifiersToType
    444 
    445 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    446         if ( ! q ) return this;
    447 
    448         checkStorageClasses( q );
    449         copyStorageClasses( q );
    450 
    451         if ( ! q->type ) { delete q; return this; }
    452 
    453         if ( ! type ) {
    454 //              type = new TypeData;
    455                 type = q->type;
    456                 return this;
    457         } // if
    458 
    459         checkQualifiers( q->type, type );
    460         addQualifiersToType( q->type, type );
    461 
    462         if ( q->type->forall ) {
    463                 if ( type->forall ) {
    464                         type->forall->appendList( q->type->forall );
    465                 } else {
    466                         if ( type->kind == TypeData::Aggregate ) {
    467                                 type->aggregate.params = q->type->forall;
    468                                 // change implicit typedef from TYPEDEFname to TYPEGENname
    469                                 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    470                         } else {
    471                                 type->forall = q->type->forall;
    472                         } // if
    473                 } // if
    474                 q->type->forall = 0;
    475         } // if
    476         delete q;
    477         return this;
    478 } // addQualifiers
    479 
    480 static void addTypeToType( TypeData *&src, TypeData *&dst ) {
    481         if ( src->forall && dst->kind == TypeData::Function ) {
    482                 if ( dst->forall ) {
    483                         dst->forall->appendList( src->forall );
    484                 } else {
    485                         dst->forall = src->forall;
    486                 } // if
    487                 src->forall = 0;
    488         } // if
    489         if ( dst->base ) {
    490                 addTypeToType( src, dst->base );
    491         } else {
    492                 switch ( dst->kind ) {
    493                   case TypeData::Unknown:
    494                         src->qualifiers |= dst->qualifiers;
    495                         dst = src;
    496                         src = 0;
    497                         break;
    498                   case TypeData::Basic:
    499                         dst->qualifiers |= src->qualifiers;
    500                         if ( src->kind != TypeData::Unknown ) {
    501                                 assert( src->kind == TypeData::Basic );
    502 
    503                                 if ( dst->basictype == DeclarationNode::NoBasicType ) {
    504                                         dst->basictype = src->basictype;
    505                                 } else if ( src->basictype != DeclarationNode::NoBasicType )
    506                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
    507 
    508                                 if ( dst->complextype == DeclarationNode::NoComplexType ) {
    509                                         dst->complextype = src->complextype;
    510                                 } else if ( src->complextype != DeclarationNode::NoComplexType )
    511                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
    512 
    513                                 if ( dst->signedness == DeclarationNode::NoSignedness ) {
    514                                         dst->signedness = src->signedness;
    515                                 } else if ( src->signedness != DeclarationNode::NoSignedness )
    516                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
    517 
    518                                 if ( dst->length == DeclarationNode::NoLength ) {
    519                                         dst->length = src->length;
    520                                 } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {
    521                                         dst->length = DeclarationNode::LongLong;
    522                                 } else if ( src->length != DeclarationNode::NoLength )
    523                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
    524                         } // if
    525                         break;
    526                   default:
    527                         switch ( src->kind ) {
    528                           case TypeData::Aggregate:
    529                           case TypeData::Enum:
    530                                 dst->base = new TypeData( TypeData::AggregateInst );
    531                                 dst->base->aggInst.aggregate = src;
    532                                 if ( src->kind == TypeData::Aggregate ) {
    533                                         dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    534                                 } // if
    535                                 dst->base->qualifiers |= src->qualifiers;
     491                        switch ( dst->kind ) {
     492                          case TypeData::Unknown:
     493                                src->qualifiers |= dst->qualifiers;
     494                                dst = src;
    536495                                src = 0;
    537496                                break;
     497                          case TypeData::Basic:
     498                                dst->qualifiers |= src->qualifiers;
     499                                if ( src->kind != TypeData::Unknown ) {
     500                                        assert( src->kind == TypeData::Basic );
     501
     502                                        if ( dst->basictype == DeclarationNode::NoBasicType ) {
     503                                                dst->basictype = src->basictype;
     504                                        } else if ( src->basictype != DeclarationNode::NoBasicType )
     505                                                throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
     506
     507                                        if ( dst->complextype == DeclarationNode::NoComplexType ) {
     508                                                dst->complextype = src->complextype;
     509                                        } else if ( src->complextype != DeclarationNode::NoComplexType )
     510                                                throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
     511
     512                                        if ( dst->signedness == DeclarationNode::NoSignedness ) {
     513                                                dst->signedness = src->signedness;
     514                                        } else if ( src->signedness != DeclarationNode::NoSignedness )
     515                                                throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
     516
     517                                        if ( dst->length == DeclarationNode::NoLength ) {
     518                                                dst->length = src->length;
     519                                        } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {
     520                                                dst->length = DeclarationNode::LongLong;
     521                                        } else if ( src->length != DeclarationNode::NoLength )
     522                                                throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
     523                                } // if
     524                                break;
    538525                          default:
    539                                 if ( dst->forall ) {
    540                                         dst->forall->appendList( src->forall );
    541                                 } else {
    542                                         dst->forall = src->forall;
    543                                 } // if
    544                                 src->forall = 0;
    545                                 dst->base = src;
    546                                 src = 0;
     526                                switch ( src->kind ) {
     527                                  case TypeData::Aggregate:
     528                                  case TypeData::Enum:
     529                                        dst->base = new TypeData( TypeData::AggregateInst );
     530                                        dst->base->aggInst.aggregate = src;
     531                                        if ( src->kind == TypeData::Aggregate ) {
     532                                                dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
     533                                        } // if
     534                                        dst->base->qualifiers |= src->qualifiers;
     535                                        src = 0;
     536                                        break;
     537                                  default:
     538                                        if ( dst->forall ) {
     539                                                dst->forall->appendList( src->forall );
     540                                        } else {
     541                                                dst->forall = src->forall;
     542                                        } // if
     543                                        src->forall = 0;
     544                                        dst->base = src;
     545                                        src = 0;
     546                                } // switch
    547547                        } // switch
    548                 } // switch
     548                } // if
    549549        } // if
    550550}
  • src/examples/gc_no_raii/bug-repro/field.c

    r101e0bd r5b639ee  
    6262{
    6363        struct gc_object_header* object;
    64         #ifndef NDEBUG
     64        #if _DEBUG
    6565                intptr_t lower_limit;
    6666                intptr_t upper_limit;
     
    7171                gc_pool_object_iterator* const this,
    7272                void* start_object
    73                 #ifndef NDEBUG
     73                #if _DEBUG
    7474                        , intptr_t pool_start
    7575                        , intptr_t pool_end
  • src/examples/gc_no_raii/src/gcpointers.c

    r101e0bd r5b639ee  
    1414                gc_object_header* obj = gc_get_object_for_ref(gc_get_state(), (void*)this);
    1515                check(obj);
    16                 check(is_valid(obj));
    17                 check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || !obj->type_chain);
     16                check(gc_obj_is_valide(obj));
     17                check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
    1818                this->next = obj->type_chain;
    1919                obj->type_chain = this;
    20                 check(is_valid(obj));
     20                check(obj->is_valide());
    2121        }
    2222        else
     
    2424                gc_object_header* obj = gc_get_object_ptr((void*)this->ptr);
    2525                check(obj);
    26                 check(is_valid(obj));
    27                 check(!obj->root_chain || this->ptr == obj->root_chain->ptr);
    28                 check(!obj->root_chain || gc_is_managed(this) == gc_is_managed(obj->root_chain));
     26                check(gc_obj_is_valide(obj));
     27                check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL);
    2928                this->next = obj->root_chain;
    3029                obj->root_chain = this;
    31                 check(is_valid(obj));
     30                check(gc_obj_is_valide(obj));
    3231        }
    3332}
     
    7069}
    7170
    72 gcpointer_t ?=?(gcpointer_t* this, gcpointer_t rhs)
     71gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs)
    7372{
    74         unregister_ptr(this);
    75         this->ptr = rhs.ptr;
    76         register_ptr(this);
     73        if(this != rhs)
     74        {
     75                unregister_ptr(this);
    7776
    78         return *this;
     77                this->ptr = rhs->ptr;
     78
     79                register_ptr(this);
     80        }
     81
     82        return this;
    7983}
    8084
    8185//Logical operators
    82 bool gcpointer_equal(const gcpointer_t* this, const gcpointer_t* rhs)
     86bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs)
    8387{
    8488        return this->ptr == rhs->ptr;
    8589}
    8690
    87 bool gcpointer_not_equal(const gcpointer_t* this, const gcpointer_t* rhs)
     91bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs)
    8892{
    8993        return this->ptr != rhs->ptr;
    9094}
    9195
    92 bool gcpointer_null(const gcpointer_t* this)
     96bool gcpointer_null(gcpointer_t* this)
    9397{
    9498        return this->ptr == (intptr_t)NULL;
    9599}
    96 
    97 #ifndef NDEBUG
    98         bool is_valid(const gcpointer_t* this) {
    99                 if(gcpointer_null(this)) return true;
    100 
    101                 gc_object_header* obj = gc_get_object_ptr((void*)this->ptr);
    102                 check(obj);
    103                 check(is_valid(obj));
    104                 check(!obj->root_chain || this->ptr == obj->root_chain->ptr);
    105 
    106                 if( !gc_is_managed(this))
    107                 {
    108                         check( !(this->next) || this->ptr == this->next->ptr );
    109                 }
    110 
    111                 return true;
    112         }
    113 #endif
    114100
    115101forall(otype T) void ?{}(gcpointer(T)* this) {
     
    121107}
    122108
    123 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other) {
    124         (&this->internal) { other.internal };
     109forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other) {
     110        (&this->internal) { other->internal };
    125111}
    126112
     
    129115}
    130116
    131 forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) {
    132         this->internal = rhs.internal;
    133         return *this;
    134 }
     117// forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs);
    135118//
    136119// forall(otype T) T *?(gcpointer(T) this);
     
    141124//
    142125// //Logical operators
    143 forall(otype T) int ?!=?(gcpointer(T) this, int zero) {
    144         return this.internal.ptr != 0;
    145 }
    146126// forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);
    147127// forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs);
  • src/examples/gc_no_raii/src/gcpointers.h

    r101e0bd r5b639ee  
    33#include <stdbool.h>
    44#include <stdint.h>
    5 
    6 forall(dtype T)
    7 struct gcpointer;
    85
    96struct gcpointer_t
     
    1714void ?{}(gcpointer_t* this, gcpointer_t other);
    1815void ^?{}(gcpointer_t* this);
    19 gcpointer_t ?=?(gcpointer_t* this, gcpointer_t rhs);
     16gcpointer_t* ?=?(gcpointer_t this, gcpointer_t rhs);
    2017
    2118//Logical operators
    2219bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs);
    2320bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs);
    24 bool gcpointer_null(const gcpointer_t* this);
     21bool gcpointer_null(gcpointer_t* this);
    2522
    26 
    27 #ifndef NDEBUG
    28         bool is_valid(const gcpointer_t* this);
    29 #endif
    30 
    31 forall(dtype T)
     23forall(otype T)
    3224struct gcpointer
    3325{
     
    3830forall(otype T) void ?{}(gcpointer(T)* this);
    3931forall(otype T) void ?{}(gcpointer(T)* this, void* address);
    40 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other);
     32forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other);
    4133forall(otype T) void ^?{}(gcpointer(T)* this);
    42 forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs);
     34forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs);
    4335
    4436
    45 // forall(otype T) T *?(gcpointer(T) this);
     37forall(otype T) T *?(gcpointer(T) this);
    4638forall(otype T) T* get(gcpointer(T)* this);
    4739
    4840//Logical operators
    49 forall(otype T) int ?!=?(gcpointer(T) this, int zero);
    5041forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);
    5142forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs);
  • src/examples/gc_no_raii/src/internal/card_table.h

    r101e0bd r5b639ee  
    11#pragma once
     2
     3#include <stdlib>
    24
    35#include "globals.h"
     
    79{
    810        size_t card = ( ((intptr_t)address) & CARDS_OFFSET_MASK ) >> CARDS_SIZE_EXP;
    9         checkf(card < CARDS_COUNT, (const char*)"%lu %lu = (%lx & %lx) >> %lu\n", (size_t)CARDS_COUNT, (size_t)card, (size_t)address, (size_t)CARDS_OFFSET_MASK, (size_t)CARDS_SIZE_EXP);
    1011        check(card < CARDS_COUNT);
    1112        return card;
     
    1819};
    1920
    20 static inline void ctor_card(card_table_t* const this)
     21static inline void ctor(card_table_t* const this)
    2122{
    2223        this->count = 0;
    2324}
    2425
    25 static inline void dtor_card(card_table_t* const this)
     26static inline void dtor(card_table_t* const this)
    2627{
    2728
     
    4748        else
    4849        {
    49                 check(card == this->count);
     50                check(card == count);
    5051                this->count++;
    5152                this->cards_start[card] = object;
  • src/examples/gc_no_raii/src/internal/collector.c

    r101e0bd r5b639ee  
    2525        gc_object_header* obj = gc_get_object_ptr((void*)target->ptr);
    2626
    27         check(is_valid(obj));
     27        check(gc_is_valide(obj));
    2828
    2929        gcpointer_t** prev_next_ptr = managed ? &obj->type_chain : &obj->root_chain;
     
    3838void* gc_allocate(size_t target_size)
    3939{
    40         // sout | "Allocating " | target_size | " bytes" | endl;
     40        sout | "Allocating " | target_size | " bytes" | endl;
    4141
    4242        size_t size = gc_compute_size(target_size + sizeof(gc_object_header));
    4343
    44         // sout | "Object header size: " | sizeof(gc_object_header) | " bytes" | endl;
    45         // sout | "Actual allocation size: " | size | " bytes" | endl;
     44        sout | "Object header size: " | sizeof(gc_object_header) | " bytes" | endl;
     45        sout | "Actual allocation size: " | size | " bytes" | endl;
    4646
    4747        check(size < POOL_SIZE_BYTES);
     
    6060        if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
    6161
    62         checkf( (int) 0, "ERROR: allocation in new pool failed");
     62        checkf(false, "ERROR: allocation in new pool failed");
    6363
    6464        return NULL;
     
    6767void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size)
    6868{
    69         intptr_t data = ((intptr_t)block) + sizeof(gc_object_header);
     69        void* data = (void*)(((intptr_t)block) + sizeof(gc_object_header));
    7070        void* header = block;
    7171
    72         check( data > ((intptr_t)block));
    73         check( data >= ((intptr_t)header));
    74         check( gc_is_aligned( (void*)data ) );
    75         check( data + target_size <= ((intptr_t)block) + actual_size );
     72        check(((intptr_t)data) > ((intptr_t)block));
     73        check(((intptr_t)data) >= ((intptr_t)header));
     74        check(is_aligned(data));
     75        check(((intptr_t)data) + target_size <= ((intptr_t)block) + actual_size);
    7676
    7777        gc_object_header* obj = placement_ctor(header, actual_size);
    7878
    7979        (void)obj; //remove unsused warning since this is for debug
    80         check(obj == gc_get_object_ptr( (void*)data ));
     80        check(obj == get_object_ptr(data));
    8181
    8282        gc_register_allocation(gc_get_state(), actual_size);
    8383
    84         return (void*)data;
     84        return data;
    8585}
    8686
     
    119119        check(!ptr->forward);
    120120        check(!ptr->is_forwarded);
    121         check(gc_pool_is_from_space(gc_pool_of(ptr)));
     121        check(gc_is_from_space(gc_pool_of(ptr)));
    122122
    123123        gc_memory_pool* pool = gc_pool_of(ptr)->mirror;
     
    143143                check(((intptr_t)field) < ((intptr_t)((intptr_t)object) + object->size));
    144144
    145                 check(gc_is_in_to_space(gc_get_state(), &field->ptr));
     145                check(gc_is_in_to_space(gc_get_state(), &type->ptr));
    146146
    147147                intptr_t* ref = &field->ptr;
  • src/examples/gc_no_raii/src/internal/collector.h

    r101e0bd r5b639ee  
    11#pragma once
    22
    3 #include <stdlib.h>
     3#include <stdlib>
    44
    55#include "tools.h"
  • src/examples/gc_no_raii/src/internal/memory_pool.c

    r101e0bd r5b639ee  
    11#include "memory_pool.h"
    22
    3 extern "C" {
    4         #include <stdlib.h>
    5         #include <string.h>
    6 }
     3#include <stdlib>
    74
    8 #include "collector.h"
    95#include "object_header.h"
    106
     
    1915        card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t));
    2016        this->cards = new;
    21         ctor_card(this->cards);
     17        ctor(this->cards);
    2218
    2319        this->end_p = ((uint8_t*)this) + size;
    2420        this->free_p = this->start_p;
    2521
    26         check( gc_pool_of( (void*)this ) == this);
     22        check(gc_pool_of(this) == this);
    2723        check(this->cards);
    2824        gc_reset_pool(this);
     
    3127void dtor(gc_memory_pool *const this)
    3228{
    33         dtor_card(this->cards);
     29        dtor(this->cards);
    3430        free(this->cards);
    3531}
     
    3834{
    3935        this->free_p = this->start_p;
    40         #ifndef NDEBUG
    41                 memset(this->start_p, 0xCD, gc_pool_size_total(this));
     36        #if _DEBUG
     37                memset(this->start_p, 0xCD, gc_pool_total_size(this));
    4238        #endif
    4339
     
    4541        reset(this->cards);
    4642
    47         check(gc_pool_size_left(this) == gc_pool_size_total(this));
     43        check(gc_pool_size_left(this) == gc_pool_total_size(this));
    4844}
    4945
     
    6258}
    6359
    64 void ?{}(       gc_pool_object_iterator* this,
     60void ctor(
     61                gc_pool_object_iterator* const this,
    6562                struct gc_object_header* start_object
    66                 #ifndef NDEBUG
     63                #if _DEBUG
    6764                        , intptr_t pool_start
    6865                        , intptr_t pool_end
     
    7168{
    7269        this->object = start_object;
    73         #ifndef NDEBUG
     70        #if _DEBUG
    7471                this->lower_limit = pool_start;
    7572                this->upper_limit = pool_end;
    7673        #endif
    7774
    78         check( ((intptr_t)start_object) >= this->lower_limit );
    79         check( ((intptr_t)start_object) <= this->upper_limit );
     75        check( ((intptr_t)start_object) >= lower_limit );
     76        check( ((intptr_t)start_object) <= upper_limit );
    8077}
    81 
    82 void ^?{}( gc_pool_object_iterator* this ) {}
    8378
    8479gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member)
     
    8681        size_t card = card_of(member);
    8782        intptr_t member_add = (intptr_t)member;
    88         intptr_t start_obj;
     83        void* start_obj;
     84        intptr_t start_obj_add;
    8985
    9086        do
    9187        {
    9288                check(card < CARDS_COUNT);
    93                 start_obj = (intptr_t)object_at(this->cards, card);
     89                start_obj = object_at(this->cards, card);
    9490                check(card != 0 || start_obj);
    9591                card--;
     92                start_obj_add = (intptr_t)start_obj;
    9693        }
    97         while(start_obj > member_add || !(start_obj));
     94        while(start_obj_add > member_add || start_obj_add != 0);
    9895
    99         check( start_obj );
    100 
     96        check(start_obj);
     97       
    10198        struct gc_object_header* start_obj_typed = (struct gc_object_header*)start_obj;
    10299
    103         return (gc_pool_object_iterator) {
    104                 start_obj_typed
    105                 #ifndef NDEBUG
     100        gc_pool_object_iterator it;
     101        ctor( &it,
     102                start_obj_typed,
     103                #if _DEBUG
    106104                        , (intptr_t)this->start_p
    107105                        , (intptr_t)this->free_p
    108106                #endif
    109         };
     107        );
     108        return it;
    110109}
    111110
     
    118117{
    119118        struct gc_object_header* start_obj = (struct gc_object_header*)this->start_p;
    120         return (gc_pool_object_iterator) {
    121                 start_obj
    122                 #ifndef NDEBUG
     119        gc_pool_object_iterator it;
     120        ctor( &it,
     121                start_obj,
     122                #if _DEBUG
    123123                        , (intptr_t)this->start_p
    124124                        , (intptr_t)this->free_p
    125125                #endif
    126         };
     126        );
     127        return it;
    127128}
    128129
    129130gc_pool_object_iterator end(gc_memory_pool* const this)
    130131{
    131         return (gc_pool_object_iterator) {
    132                 (struct gc_object_header*)this->free_p
    133                 #ifndef NDEBUG
     132        gc_pool_object_iterator it;
     133        ctor( &it,
     134                (struct gc_object_header*)this->free_p,
     135                #if _DEBUG
    134136                        , (intptr_t)this->start_p
    135137                        , (intptr_t)this->free_p
    136138                #endif
    137         };
     139        );
     140        return it;
    138141}
    139142
     
    142145        struct gc_object_header* object = it->object;
    143146        intptr_t next_ptr = ((intptr_t)object) + object->size;
    144         check(next_ptr > it->lower_limit);
    145         check(next_ptr <= it->upper_limit);
     147        check(next_ptr > lower_limit);
     148        check(next_ptr <= upper_limit);
    146149
    147150        struct gc_object_header* next_obj = ((struct gc_object_header*)next_ptr);
    148         check(next_ptr == it->upper_limit || is_valid(next_obj));
     151        check(next_ptr == upper_limit || is_valide(next_obj));
    149152
    150153        it->object = next_obj;
  • src/examples/gc_no_raii/src/internal/memory_pool.h

    r101e0bd r5b639ee  
    3939{
    4040        struct gc_object_header* object;
    41         #ifndef NDEBUG
     41        #if _DEBUG
    4242                intptr_t lower_limit;
    4343                intptr_t upper_limit;
     
    4646
    4747
    48 void ?{}(       gc_pool_object_iterator* this,
     48void ctor(
     49                gc_pool_object_iterator* const this,
    4950                struct gc_object_header* start_object
    50                 #ifndef NDEBUG
     51                #if _DEBUG
    5152                        , intptr_t pool_start
    5253                        , intptr_t pool_end
    5354                #endif
    5455        );
    55 
    56 void ^?{}( gc_pool_object_iterator* this );
    5756
    5857bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
  • src/examples/gc_no_raii/src/internal/object_header.c

    r101e0bd r5b639ee  
    33#include <stdint.h>
    44
    5 #include "collector.h"
    65#include "globals.h"
    76#include "gcpointers.h"
     
    98void ctor(gc_object_header* const this, size_t inSize)
    109{
    11         #ifndef NDEBUG
     10        #if _DEBUG
    1211                this->canary_start = CANARY_VALUE;
    1312        #endif
     
    1918        this->is_forwarded = false;
    2019
    21         #ifndef NDEBUG
     20        #if _DEBUG
    2221                this->canary_end = CANARY_VALUE;
    2322        #endif
     
    2625void copy_ctor(gc_object_header* const this, const gc_object_header* const other)
    2726{
    28         #ifndef NDEBUG
     27        #if _DEBUG
    2928                this->canary_start = CANARY_VALUE;
    3029        #endif
     
    3635        this->is_forwarded = false;
    3736
    38         #ifndef NDEBUG
     37        #if _DEBUG
    3938                this->canary_end = CANARY_VALUE;
    4039        #endif
     
    4342        while(root)
    4443        {
    45                 check(gc_get_object_ptr( (void*)root->ptr ) == other);
     44                check(get_object_ptr(root->ptr) == other);
    4645                root->ptr = ((intptr_t)this) + sizeof(gc_object_header);
    4746
    48                 check(gc_get_object_ptr( (void*)root->ptr ) == this);
     47                check(get_object_ptr(root->ptr) == this);
    4948                root = root->next;
    5049        }
     
    5756
    5857                size_t offset = (intptr_t)type - (intptr_t)other;
    59                 check(offset < this->size);
     58                check(offset < size);
    6059
    6160                gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset );
     
    6463
    6564                size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0;
    66                 check(next_offset < this->size);
     65                check(next_offset < size);
    6766
    6867                gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL;
     
    7473        }
    7574
    76         check(is_valid(this));
     75        check(is_valide(this));
    7776}
    7877
    79 #ifndef NDEBUG
    80         bool is_valid(const gc_object_header* const this)
     78#if _DEBUG
     79        bool is_valide(const gc_object_header* const this)
    8180        {
    82                 check((intptr_t)this->canary_start == (intptr_t)CANARY_VALUE);
    83                 check((intptr_t)this->canary_end == (intptr_t)CANARY_VALUE);
     81                check(this->canary_start == CANARY_VALUE);
     82                check(this->canary_end == CANARY_VALUE);
    8483
    85                 check(this->is_forwarded == ( (intptr_t)this->forward != (intptr_t)NULL));
     84                check(this->is_forwarded == (this->forward != nullptr));
    8685
    8786                check(this->size < POOL_SIZE_BYTES);
     
    9089                while(root)
    9190                {
    92                         checkf(gc_get_object_ptr( (void*)root->ptr ) == this, (const char*)"Expected %lX got %lX\n", gc_get_object_ptr( (void*)root->ptr ), this);
     91                        check(get_object_ptr(root->ptr) == this);
    9392
    9493                        root = root->next;
    9594                }
    9695
    97                 gcpointer_t* type = this->type_chain;
     96                gcpointer_t* type = type_chain;
    9897                while(type)
    9998                {
    10099                        check((intptr_t)type > (intptr_t)this);
    101                         check((intptr_t)type < (intptr_t)(((intptr_t)this) + this->size));
     100                        check((intptr_t)type < (intptr_t)((intptr_t)this + size));
    102101
    103102                        type = type->next;
     
    106105                return true;
    107106        }
    108         #else
    109         #error blarg
    110107#endif
  • src/examples/gc_no_raii/src/internal/object_header.h

    r101e0bd r5b639ee  
    77#include "tools.h"
    88
    9 #ifndef NDEBUG
    10         static void* const CANARY_VALUE = (void*)0xCAFEBABACAFEBABA;
     9#if DEBUG
     10        static const long unsigned int CANARY_VALUE = 0xCAFEBABACAFEBABA;
    1111#endif
    1212
     
    1616struct gc_object_header
    1717{
    18         #ifndef NDEBUG
     18        #if DEBUG
    1919                void* canary_start;
    2020        #endif
     
    2626        bool                    is_forwarded;
    2727
    28         #ifndef NDEBUG
     28        #if DEBUG
    2929                void* canary_end;
    3030        #endif
     
    4747        return this;
    4848}
    49 
    50 #ifndef NDEBUG
    51         bool is_valid(const gc_object_header* const this);
    52 #endif
  • src/examples/gc_no_raii/src/internal/state.c

    r101e0bd r5b639ee  
    2121void gc_state_calc_usage(gc_state *const this);
    2222
    23 #ifndef NDEBUG
     23#if DEBUG
    2424        bool gc_state_roots_match(gc_state *const this);
    2525        bool gc_state_no_from_space_ref(gc_state *const this);
     
    7676gc_object_header* gc_get_object_for_ref(gc_state* state, void* member)
    7777{
    78         volatile int stage = 0;
    7978        intptr_t target = ((intptr_t)member);
    8079        if(!gc_is_in_heap(state, member)) return NULL;
    81         stage++;
    8280
    8381        gc_memory_pool* pool = gc_pool_of(member);
    84         stage++;
    8582        gc_pool_object_iterator it = gc_pool_iterator_for(pool, member);
    86         stage++;
    8783        gc_pool_object_iterator end = end(pool);
    88         stage++;
    8984
    9085        while(it != end)
    9186        {
    9287                gc_object_header* object = *it;
    93                 check(object);
    94                 check( is_valid(object) );
    9588                {
    9689                        intptr_t start = ((intptr_t)object);
     
    10194                        }
    10295                }
    103                 stage++;
    10496                ++it;
    10597        }
    10698
    107         checkf( (int) 0, "is_in_heap() and iterator_for() return inconsistent data");
     99        checkf(false, "is_in_heap() and iterator_for() return inconsistent data");
    108100        abort();
    109101        return NULL;
     
    184176        this->from_code = (~this->from_code) & 0x01;
    185177
    186         #ifndef NDEBUG
     178        #if _DEBUG
    187179                {
    188180                        gc_memory_pool* pool = this->from_space;
     
    259251}
    260252
    261 #ifndef NDEBUG
     253#if _DEBUG
    262254        bool gc_state_roots_match(gc_state* const this)
    263255        {
     
    273265                                size += object->size;
    274266
    275                                 gcpointer_t* ptr = object->root_chain;
     267                                gcpointer_base* ptr = object->root_chain;
    276268                                while(ptr)
    277269                                {
    278                                         check(gc_get_object_ptr( (void*)ptr->ptr ) == object);
    279                                         ptr = ptr->next;
     270                                        check(get_object_ptr(ptr->m_ptr) == object);
     271                                        ptr = ptr->m_next;
    280272                                }
    281273                        }
    282274
    283                         checkf(size + gc_pool_size_left(pool) == gc_pool_size_total(pool),
    284                                 (const char*)"expected %lu + %lu == %lu\n",
    285                                 (size_t)size,
    286                                 (size_t)gc_pool_size_left(pool),
    287                                 (size_t)gc_pool_size_total(pool));
     275                        check(size + gc_pool_size_used(pool) == gc_pool_size_total(pool));
    288276
    289277                        pool = pool->next;
     
    298286                while(pool)
    299287                {
    300                         void** potential_ref = (void**)pool->start_p;
    301                         while(potential_ref < (void**)pool->free_p)
     288                        void** potential_ref = (void**)pool->m_start;
     289                        while(potential_ref < (void**)pool->m_free)
    302290                        {
    303291                                check(!gc_is_in_heap(this, *potential_ref));
  • src/examples/gc_no_raii/src/internal/state.h

    r101e0bd r5b639ee  
    3838static inline bool gc_needs_collect(gc_state* state)
    3939{
    40         // sout | "Used Space: " | state->used_space | " bytes" | endl;
     40        sout | "Used Space: " | state->used_space | " bytes" | endl;
    4141        return state->used_space * 2 > state->total_space;
    4242}
  • src/examples/gc_no_raii/src/tools/checks.h

    r101e0bd r5b639ee  
    11#pragma once
    22
    3 #ifdef NDEBUG
    4 
    5 #define check(x)
    6 
    7 #define checkf(x, format, ...)
    8 
    9 #warning no debug checks
    10 
    11 #else
     3#if _DEBUG
    124
    135#include <stdlib.h>
     
    1810                printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
    1911                abort();\
    20         }}while( (int)0 )\
     12        }}while(0)\
    2113
    2214#define checkf(x, ...) do {\
     
    2517                printf(__VA_ARGS__);\
    2618                abort();\
    27         }}while( (int)0 )\
     19        }}while(0)\
     20
     21#else
     22
     23#define check(x)
     24
     25#define checkf(x, format, ...)
    2826
    2927#endif //NO_CHECKS
  • src/examples/gc_no_raii/src/tools/print.c

    r101e0bd r5b639ee  
    11#include "tools.h"
    22
    3 #ifndef NDEBUG
    4         // ofstream *sout = ofstream_stdout();
     3#if _DEBUG
     4        ofstream *sout = ofstream_stdout();
    55#endif
  • src/examples/gc_no_raii/src/tools/print.h

    r101e0bd r5b639ee  
    11#pragma once
    22
    3 // #ifndef NDEBUG
    4 //
    5 // #include <fstream>
    6 //
    7 // #define DEBUG_OUT(x) sout | x | endl;
    8 //
    9 // #else
     3#if _DEBUG
     4
     5#include <fstream>
     6
     7#define DEBUG_OUT(x) sout | x | endl;
     8
     9#else
    1010
    1111#define DEBUG_OUT(x)
    1212
    13 // #endif //NO_CHECKS
     13#endif //NO_CHECKS
  • src/examples/gc_no_raii/test/badlll.c

    r101e0bd r5b639ee  
    11#include "gc.h"
    2 
    3 #include <stdio.h>
    42
    53struct List_t
     
    97};
    108
     9void ?{}(List_t* this);
     10List_t* ?=?(List_t* this, List_t* rhs);
     11
    1112typedef gcpointer(List_t) LLL;
    1213
    13 #define MAX (1024 * 1)
     14#define MAX (1024 * 1024)
    1415
    15 LLL buildLLL(int sz)
     16// LLL buildLLL(int sz)
     17void bla()
    1618{
    17         int i = 0;
    18         LLL ll0;
    19 
    20         gcmalloc( &ll0 );
    21         List_t* ll0_ptr = get( &ll0 );
    22         ll0_ptr->val = i;
    23         LLL lll = ll0;
    24 
    25         for (i = 1; i < sz; i++)
    26         {
    27                 LLL llc;
    28                 gcmalloc( &llc );
    29                 List_t* llc_ptr = get( &llc );
    30                 llc_ptr->val = i;
    31                 List_t* lll_ptr = get( &lll );
    32                 lll_ptr->next = llc;
    33 
    34                 lll = llc;
    35         }
    36 
    37         check(is_valid( &ll0.internal ));
    38 
    39         return ll0;
     19        int i;
     20        // LLL ll0;//, lll, llc;
     21//
     22//      ll0 = gcmalloc();
     23//      ll0->val = 0;
     24//      lll = ll0;
     25//
     26//      for (i = 1; i < sz; i++)
     27//      {
     28//              llc = gcmalloc();
     29//              llc->val = i;
     30//              lll->next = llc;
     31//              lll = llc;
     32//      }
     33//
     34        // return ll0;
    4035}
    41 
    42 void testLLL(LLL lll)
    43 {
    44         unsigned char *counted;
    45 
    46         counted = (unsigned char *) calloc(MAX, sizeof(unsigned char));
    47         while (lll)
    48         {
    49                 List_t* lll_ptr = get( &lll );
    50                 counted[lll_ptr->val]++;
    51                 if (counted[lll_ptr->val] > 1)
    52                 {
    53                         fprintf(stderr, "ERROR! Encountered %d twice!\n", lll_ptr->val);
    54                         exit(1);
    55                 }
    56                 lll = lll_ptr->next;
    57         }
    58 
    59         return;
    60 }
     36//
     37// void testLLL(LLL lll)
     38// {
     39//      unsigned char *counted;
     40//
     41//      counted = (unsigned char *) calloc(MAX, sizeof(unsigned char));
     42//      while (lll)
     43//      {
     44//              counted[lll->val]++;
     45//              if (counted[lll->val] > 1)
     46//              {
     47//                      fprintf(stderr, "ERROR! Encountered %d twice!\n", lll->val);
     48//                      exit(1);
     49//              }
     50//              lll = lll->next;
     51//      }
     52//
     53//      return;
     54// }
    6155
    6256int main(void)
     
    6458        LLL mylll;
    6559
    66         mylll = buildLLL(MAX);
    67 
    68         testLLL(mylll);
     60        // mylll = buildLLL(MAX);
     61        //
     62        // testLLL(mylll);
    6963
    7064        return 0;
  • src/tests/avltree/avl_test.c

    r101e0bd r5b639ee  
    1414
    1515  // int -> int
    16   tree(int, int) * imap = create(-1, (int)0);
     16  tree(int, int) * imap = create(-1, 0);
    1717  insert(&imap, 12, 13);
    1818  insert(&imap, 2, 3);
Note: See TracChangeset for help on using the changeset viewer.