Changeset 16cfd8c for src/examples


Ignore:
Timestamp:
Apr 21, 2016, 4:54:33 PM (9 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:
8a74081
Parents:
8c8b614
Message:

1 error left

Location:
src/examples/gc_no_raii
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/src/allocate-pool.c

    r8c8b614 r16cfd8c  
    22#define _DARWIN_C_SOURCE /* for MAP_ANON on OS X */
    33
     4#ifdef __cforall
     5extern "C"{
     6#else
     7#error missing cfa define
     8#endif
    49
    510/* for standards info */
     
    2429#if _POSIX_VERSION
    2530#include <sys/mman.h>
    26 #endif
    27 
    28 #ifdef CFA
    29 extern "C"{
    3031#endif
    3132
     
    5960}
    6061
    61 #ifdef CFA
     62#ifdef __cforall
    6263}
    6364#endif
  • src/examples/gc_no_raii/src/allocate-pool.h

    r8c8b614 r16cfd8c  
    22#define _GGGGC_ALlOCATE_POOL_H_
    33
    4 #ifdef __cplusplus
     4#ifdef __cforall
    55extern "C" {
    66#endif
     
    88void* pal_allocPool(size_t size, int mustSucceed);
    99
    10 #ifdef __cplusplus
     10#ifdef __cforall
    1111}
    1212#endif
  • src/examples/gc_no_raii/src/internal/collector.c

    r8c8b614 r16cfd8c  
    11#include "collector.h"
    22
    3 #include <stdbool.h>
    4 #include <stdint.h>
    5 #include <stdlib.h>
     3#ifdef __cforall
     4extern "C" {
     5#endif
    66#include <string.h>
    7 
    8 #include <fstream>
     7#ifdef __cforall
     8}
     9#endif
    910
    1011#include "state.h"
     
    138139
    139140                intptr_t* ref = &field->ptr;
    140                 // push_back(worklist, ref);
     141                push_back(worklist, ref);
    141142
    142143                field = field->next;
  • src/examples/gc_no_raii/src/internal/collector.h

    r8c8b614 r16cfd8c  
    11#pragma once
    22
    3 #include <stddef.h>
    4 #include <stdint.h>
     3#include <stdlib>
    54
    65#include "tools.h"
     
    1413#include "tools/worklist.h"
    1514
    16 inline bool gc_is_managed(void* address)
     15static inline bool gc_is_managed(void* address)
    1716{
    1817        return gc_is_in_heap(gc_get_state(), address);
    1918}
    2019
    21 inline gc_object_header* gc_get_object_ptr(void* ptr)
     20static inline gc_object_header* gc_get_object_ptr(void* ptr)
    2221{
    2322        void* clean = gc_get_aligned_ptr(ptr);
     
    2524}
    2625
    27 inline struct gc_memory_pool* gc_pool_of(void* address)
     26static inline struct gc_memory_pool* gc_pool_of(void* address)
    2827{
    2928        return (struct gc_memory_pool*)(((intptr_t)address) & POOL_PTR_MASK);
    3029}
    3130
    32 inline void gc_conditional_collect()
     31static inline void gc_conditional_collect()
    3332{
    3433        if(gc_needs_collect(gc_get_state()))
  • src/examples/gc_no_raii/src/internal/gc_tools.h

    r8c8b614 r16cfd8c  
    77#include "globals.h"
    88
    9 inline bool gc_is_aligned(void* address)
     9static inline bool gc_is_aligned(void* address)
    1010{
    1111        return (((intptr_t)address) & (~OBJECT_PTR_MASK)) == 0;
    1212}
    1313
    14 inline void* gc_get_aligned_ptr(void* address)
     14static inline void* gc_get_aligned_ptr(void* address)
    1515{
    1616        return (void*)(((intptr_t)address) & (OBJECT_PTR_MASK));
    1717}
    1818
    19 inline void* gc_write_aligned_ptr(void** reference, void* address)
     19static inline void* gc_write_aligned_ptr(void** reference, void* address)
    2020{
    2121        size_t ref_last_bits = ((intptr_t)*reference) & (~OBJECT_PTR_MASK);
     
    2828}
    2929
    30 inline size_t gc_compute_size(size_t size)
     30static inline size_t gc_compute_size(size_t size)
    3131{
    3232        size_t word_size = ((size - 1) / OBJECT_ALLIGNMENT) + 1;
  • src/examples/gc_no_raii/src/internal/memory_pool.h

    r8c8b614 r16cfd8c  
    11#pragma once
    22
     3extern "C" {
     4#include <stdbool.h>
    35#include <stdint.h>
     6}
    47
    58#include "tools.h"
    69
    7 // #include "card_table.h"
    8 #include "collector.h"
     10#include "card_table.h"
    911#include "globals.h"
    10 
    11 typedef int cardtable_ptr_t;
     12#include "state.h"
    1213
    1314struct gc_memory_pool
     
    1819        uint8_t type_code;
    1920
    20         cardtable_ptr_t cards;
     21        card_table_t* cards;
    2122
    2223        uint8_t* end_p;
     
    2526};
    2627
    27 void gc_memory_pool_ctor(gc_memory_pool *const this,
    28         size_t size,
    29         gc_memory_pool* next,
    30         gc_memory_pool* mirror,
    31      uint8_t type
     28void ctor(      gc_memory_pool *const this,
     29                size_t size,
     30                gc_memory_pool* next,
     31                gc_memory_pool* mirror,
     32                uint8_t type
    3233        );
     34
     35void dtor(gc_memory_pool *const this);
    3336
    3437struct gc_pool_object_iterator
    3538{
    36 
    3739        struct gc_object_header* object;
    3840        #if _DEBUG
     
    4345
    4446
    45 void gc_pool_object_iterator_ctor(
     47void ctor(
     48                gc_pool_object_iterator* const this,
    4649                struct gc_object_header* start_object
    4750                #if _DEBUG
     
    5356bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
    5457
    55 gc_pool_object_iterator begin(gc_memory_pool* const);
     58gc_pool_object_iterator begin(gc_memory_pool* const this);
    5659gc_pool_object_iterator end(gc_memory_pool* const);
    5760
     
    6164struct gc_object_header* *?(gc_pool_object_iterator it);
    6265
    63 inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
     66static inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
    6467{
    6568        return gc_from_space_code(gc_get_state()) == pool->type_code;
    6669}
    6770
    68 void gc_reset_pool(gc_memory_pool* pool);
     71void gc_reset_pool(gc_memory_pool* const pool);
    6972
    70 inline size_t gc_pool_size_used(const gc_memory_pool* pool)
     73static inline size_t gc_pool_size_used(const gc_memory_pool* pool)
    7174{
    7275        return pool->free_p - pool->start_p;
    7376}
    7477
    75 inline size_t gc_pool_size_total(const gc_memory_pool* pool)
     78static inline size_t gc_pool_size_total(const gc_memory_pool* pool)
    7679{
    7780        return pool->end_p - pool->start_p;
    7881}
    7982
    80 inline size_t gc_pool_size_left(const gc_memory_pool* pool)
     83static inline size_t gc_pool_size_left(const gc_memory_pool* pool)
    8184{
    8285        return pool->end_p - pool->free_p;
    8386}
    8487
    85 void* gc_pool_allocate(gc_memory_pool* pool, size_t size, bool zero);
     88void* gc_pool_allocate(gc_memory_pool* const pool, size_t size, bool zero);
    8689
    87 gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* pool, void* member);
    88 
    89 gc_pool_object_iterator gc_pool_end(gc_memory_pool* pool);
     90gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const pool, void* member);
  • src/examples/gc_no_raii/src/internal/object_header.c

    r8c8b614 r16cfd8c  
    66#include "gcpointers.h"
    77
    8 placement_copy_ctor(void* address, const gc_object_header* const other)
     8void ctor(gc_object_header* const this, size_t inSize)
    99{
    10         gc_object_header* const this = (gc_object_header*)address;
    1110        #if _DEBUG
    1211                this->canary_start = CANARY_VALUE;
    1312        #endif
     13
     14        this->size = inSize;
     15        this->root_chain = NULL;
     16        this->type_chain = NULL;
     17        this->forward = NULL;
     18        this->is_forwarded = false;
     19
     20        #if _DEBUG
     21                this->canary_end = CANARY_VALUE;
     22        #endif
     23}
     24
     25void copy_ctor(gc_object_header* const this, const gc_object_header* const other)
     26{
     27        #if _DEBUG
     28                this->canary_start = CANARY_VALUE;
     29        #endif
     30
    1431        this->size = other->size;
    1532        this->root_chain = other->root_chain;
     
    1734        this->forward = NULL;
    1835        this->is_forwarded = false;
     36
    1937        #if _DEBUG
    2038                this->canary_end = CANARY_VALUE;
    2139        #endif
     40
     41        gcpointer_t* root = this->root_chain;
     42        while(root)
    2243        {
    23                 gcpointer_t* root = this->root_chain;
    24                 while(root)
    25                 {
    26                         check(get_object_ptr(root->ptr) == other);
    27                         intptr_t int_this = (intptr_t)this;
    28                         intptr_t int_next = int_this + sizeof(gc_object_header);
    29                         intptr_t* root_ptr = root->ptr;
    30                         *root_ptr = int_next;
     44                check(get_object_ptr(root->ptr) == other);
     45                root->ptr = ((intptr_t)this) + sizeof(gc_object_header);
    3146
    32                         check(get_object_ptr(root->ptr) == this);
    33                         root = root->next;
    34                 }
     47                check(get_object_ptr(root->ptr) == this);
     48                root = root->next;
     49        }
    3550
    36                 gcpointer_t* type = other->type_chain;
     51        gcpointer_t* type = other->type_chain;
    3752
    38                 while(type)
    39                 {
    40                         check((intptr_t)type < (intptr_t)((intptr_t)other + other->size));
     53        while(type)
     54        {
     55                check((intptr_t)type < (intptr_t)((intptr_t)other + other->size));
    4156
    42                         size_t offset = (intptr_t)type - (intptr_t)other;
    43                         check(offset < size);
     57                size_t offset = (intptr_t)type - (intptr_t)other;
     58                check(offset < size);
    4459
    45                         gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset );
     60                gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset );
    4661
    47                         if(!this->type_chain) this->type_chain = member_ptr;
     62                if(!this->type_chain) this->type_chain = member_ptr;
    4863
    49                         size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0;
    50                         check(next_offset < size);
     64                size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0;
     65                check(next_offset < size);
    5166
    52                         gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL;
     67                gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL;
    5368
    54                         member_ptr->ptr = type->ptr;
    55                         member_ptr->next = next_ptr;
     69                member_ptr->ptr = type->ptr;
     70                member_ptr->next = next_ptr;
    5671
    57                         type = type->next;
    58                 }
     72                type = type->next;
     73        }
    5974
    60                 check(is_valide(this));
    61         }
     75        check(is_valide(this));
    6276}
    6377
  • src/examples/gc_no_raii/src/internal/object_header.h

    r8c8b614 r16cfd8c  
    3030};
    3131
    32 gc_object_header* placement_ctor(void* address, size_t size);
    33 gc_object_header* placement_copy_ctor(void* address, const gc_object_header* const other);
     32void ctor(gc_object_header* const this, size_t size);
     33void copy_ctor(gc_object_header* const this, const gc_object_header* const other);
     34
     35static inline gc_object_header* placement_ctor(void* address, size_t size)
     36{
     37        gc_object_header* const this = (gc_object_header* const) address;
     38        ctor(this, size);
     39        return this;
     40}
     41
     42static inline gc_object_header* placement_copy_ctor(void* address, const gc_object_header* const other)
     43{
     44        gc_object_header* const this = (gc_object_header* const) address;
     45        copy_ctor(this, other);
     46        return this;
     47}
  • src/examples/gc_no_raii/src/internal/state.c

    r8c8b614 r16cfd8c  
    1212#include "globals.h"
    1313#include "memory_pool.h"
    14 // #include "memory_pool_iterator.h"
    1514#include "object_header.h"
    1615
     
    4645}
    4746
    48 bool gc_state_is_in_heap(const gc_state* const this, void* address)
     47void dtor(gc_state *const this)
     48{
     49        dtor(&this->pools_table);
     50        this->is_initialized = false;
     51}
     52
     53bool gc_is_in_heap(const gc_state* const this, const void* const address)
    4954{
    5055        gc_memory_pool* target_pool = gc_pool_of(address);
     
    5661}
    5762
    58 bool gc_state_is_in_to_space(const gc_state* const this, void* address)
     63bool gc_is_in_to_space(const gc_state* const this, const void* const address)
    5964{
    6065        gc_memory_pool* target_pool = gc_pool_of(address);
     
    7378        gc_memory_pool* pool = gc_pool_of(member);
    7479        gc_pool_object_iterator it = gc_pool_iterator_for(pool, member);
    75         gc_pool_object_iterator end = gc_pool_end(pool);
     80        gc_pool_object_iterator end = end(pool);
    7681
    7782        while(it != end)
     
    9499}
    95100
    96 void* gc_try_allocate(gc_state *const this, size_t size)
     101void* gc_try_allocate(gc_state* const this, size_t size)
    97102{
    98103        gc_memory_pool* pool = this->from_space;
     
    109114}
    110115
    111 void gc_state_allocate_pool(gc_state *const this)
     116void gc_allocate_pool(gc_state *const this)
    112117{
    113118        gc_memory_pool* old_from_space = this->from_space;
     
    117122      this->to_space = (gc_memory_pool*)(pal_allocPool(POOL_SIZE_BYTES, 1));
    118123
    119       gc_memory_pool_ctor(this->from_space, POOL_SIZE_BYTES, old_from_space, this->to_space,   this->from_code);
    120       gc_memory_pool_ctor(this->to_space,   POOL_SIZE_BYTES, old_to_space,   this->from_space, (~this->from_code) & 0x01);
     124      ctor(this->from_space, POOL_SIZE_BYTES, old_from_space, this->to_space,   this->from_code);
     125      ctor(this->to_space,   POOL_SIZE_BYTES, old_to_space,   this->from_space, (~this->from_code) & 0x01);
    121126
    122127        this->total_space += gc_pool_size_used(this->from_space);
     
    126131}
    127132
    128 void gc_state_collect(gc_state* const this)
     133void gc_collect(gc_state* const this)
    129134{
    130135        // DEBUG("collecting");
     
    149154        gc_state_calc_usage(this);
    150155
    151         if(gc_needs_collect(this)) gc_state_allocate_pool(this);
     156        if(gc_needs_collect(this)) gc_allocate_pool(this);
    152157
    153158        // DEBUG("done");
     
    281286                        while(potential_ref < (void**)pool->m_free)
    282287                        {
    283                                 check(!gc_is_in_heap(*potential_ref));
     288                                check(!gc_is_in_heap(this, *potential_ref));
    284289                                potential_ref++;
    285290                        }
  • src/examples/gc_no_raii/src/internal/state.h

    r8c8b614 r16cfd8c  
    77#include "vector.h"
    88
    9 typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
     9// typedef 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};
    2424
    25 void ctor(struct gc_state* state);
     25void ctor(gc_state* const state);
     26
     27void dtor(gc_state* const state);
    2628
    2729gc_state* gc_get_state();
    2830
    29 inline bool gc_needs_collect(gc_state* state)
     31static inline bool gc_needs_collect(gc_state* state)
    3032{
    3133        return state->used_space * 2 > state->total_space;
    3234}
    3335
    34 void gc_collect(gc_state* state);
     36void gc_collect(gc_state* const this);
    3537
    36 void* gc_try_allocate(gc_state* state, size_t size);
     38void* gc_try_allocate(gc_state* const this, size_t size);
    3739
    38 void gc_allocate_pool(gc_state* state);
     40void gc_allocate_pool(gc_state* const state);
    3941
    40 bool gc_is_in_heap(const gc_state* state, void* address);
     42bool gc_is_in_heap(const gc_state* const state, const void* const address);
    4143
    42 bool gc_is_in_to_space(const gc_state* state, void* address);
     44bool gc_is_in_to_space(const gc_state* const state, const void* const address);
    4345
    44 inline uint8_t gc_from_space_code(const gc_state *const this)
     46static inline uint8_t gc_from_space_code(const gc_state *const this)
    4547{
    4648        return this->from_code;
     
    4951struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
    5052
    51 inline void gc_register_allocation(gc_state* state, size_t size)
     53static inline void gc_register_allocation(gc_state* state, size_t size)
    5254{
    5355        state->used_space += size;
  • src/examples/gc_no_raii/src/tools.h

    r8c8b614 r16cfd8c  
    2727
    2828forall(otype T | has_equal(T), otype InputIterator | InputIterator_t(T, InputIterator))
    29 inline InputIterator find( InputIterator first, const InputIterator* const last, T val)
     29static inline InputIterator find( InputIterator first, const InputIterator* const last, T val)
    3030{
    3131        while ( first != *last)
  • src/examples/gc_no_raii/src/vector.c

    r8c8b614 r16cfd8c  
    11#include "vector.h"
     2
     3#include <stdlib>
    24
    35//------------------------------------------------------------------------------
    46//Initialization
    57forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    6 void vector_ctor(vector(T, allocator_t) *const this)
     8void ctor(vector(T, allocator_t) *const this)
    79{
    810        ctor(&this->storage);
     
    1315void dtor(vector(T, allocator_t) *const this)
    1416{
     17        clear(this);
    1518        dtor(&this->storage);
    1619}
     
    5558void dtor(heap_allocator(T) *const this)
    5659{
    57         free((void*)this->storage);
     60        free(this->storage);
    5861}
    5962
  • src/examples/gc_no_raii/src/vector.h

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