Ignore:
Timestamp:
Mar 4, 2021, 7:40:25 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
77d601f
Parents:
342af53 (diff), a5040fe (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/memory.cfa

    r342af53 r8e4aa05  
    1010// Created On       : Tue Jun  2 16:48:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun  3 12:30:00 2020
    13 // Update Count     : 0
     12// Last Modified On : Mon Feb  1 16:10:00 2021
     13// Update Count     : 1
    1414//
    1515
     
    1818
    1919// Internal data object.
    20 forall(dtype T | sized(T), ttype Args | { void ?{}(T &, Args); })
     20forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    2121void ?{}(counter_data(T) & this, Args args) {
    2222        (this.counter){1};
     
    2424}
    2525
    26 forall(dtype T | sized(T) | { void ^?{}(T &); })
     26forall(T & | sized(T) | { void ^?{}(T &); })
    2727void ^?{}(counter_data(T) & this) {
    2828        assert(0 == this.counter);
     
    3131
    3232// This is one of many pointers keeping this alive.
    33 forall(dtype T | sized(T))
     33forall(T & | sized(T))
    3434void ?{}(counter_ptr(T) & this) {
    3535        this.data = 0p;
    3636}
    3737
    38 forall(dtype T | sized(T))
     38forall(T & | sized(T))
    3939void ?{}(counter_ptr(T) & this, zero_t) {
    4040        this.data = 0p;
    4141}
    4242
    43 forall(dtype T | sized(T) | { void ^?{}(T &); })
     43forall(T & | sized(T) | { void ^?{}(T &); })
    4444static void internal_decrement(counter_ptr(T) & this) {
    4545        if (this.data && 0 == --this.data->counter) {
     
    4848}
    4949
    50 forall(dtype T | sized(T))
     50forall(T & | sized(T))
    5151static void internal_copy(counter_ptr(T) & this, counter_ptr(T) & that) {
    5252        this.data = that.data;
     
    5656}
    5757
    58 forall(dtype T | sized(T) | { void ^?{}(T &); })
     58forall(T & | sized(T))
    5959void ?{}(counter_ptr(T) & this, counter_ptr(T) that) {
    6060        // `that` is a copy but it should have neither a constructor
    6161        // nor destructor run on it so it shouldn't need adjustment.
    62         internal_decrement(this);
    6362        internal_copy(this, that);
    6463}
    6564
    66 forall(dtype T | sized(T), ttype Args | { void ?{}(T&, Args); })
     65forall(T & | sized(T), Args... | { void ?{}(T&, Args); })
    6766void ?{}(counter_ptr(T) & this, Args args) {
    68         this.data = (counter_data(T)*)new(args);
     67        this.data = malloc();
     68        this.data->counter = 1;
     69        (this.data->object){args};
    6970}
    7071
    71 forall(dtype T | sized(T) | { void ^?{}(T &); })
     72forall(T & | sized(T) | { void ^?{}(T &); })
    7273void ^?{}(counter_ptr(T) & this) {
    7374        internal_decrement(this);
    7475}
    7576
    76 forall(dtype T | sized(T))
     77forall(T & | sized(T))
    7778T & *?(counter_ptr(T) & this) {
    7879        return *((this.data) ? &this.data->object : 0p);
    7980}
    8081
    81 forall(dtype T | sized(T) | { void ^?{}(T &); })
     82forall(T & | sized(T) | { void ^?{}(T &); })
    8283void ?=?(counter_ptr(T) & this, counter_ptr(T) that) {
    8384        if (this.data != that.data) {
     
    8788}
    8889
    89 forall(dtype T | sized(T) | { void ^?{}(T &); })
     90forall(T & | sized(T) | { void ^?{}(T &); })
    9091void ?=?(counter_ptr(T) & this, zero_t) {
    9192        internal_decrement(this);
     
    9394}
    9495
    95 forall(dtype T | sized(T))
     96forall(T & | sized(T))
    9697int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that) {
    9798        return this.data == that.data;
    9899}
    99100
    100 forall(dtype T | sized(T))
     101forall(T & | sized(T))
    101102int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that) {
    102103        return !?==?(this, that);
    103104}
    104105
    105 forall(dtype T | sized(T))
     106forall(T & | sized(T))
    106107int ?==?(counter_ptr(T) const & this, zero_t) {
    107108        return this.data == 0;
    108109}
    109110
    110 forall(dtype T | sized(T))
     111forall(T & | sized(T))
    111112int ?!=?(counter_ptr(T) const & this, zero_t) {
    112113        return !?==?(this, (zero_t)0);
     
    114115
    115116// This is the only pointer that keeps this alive.
    116 forall(dtype T)
     117forall(T &)
    117118void ?{}(unique_ptr(T) & this) {
    118119        this.data = 0p;
    119120}
    120121
    121 forall(dtype T)
     122forall(T &)
    122123void ?{}(unique_ptr(T) & this, zero_t) {
    123124        this.data = 0p;
    124125}
    125126
    126 forall(dtype T | sized(T), ttype Args | { void ?{}(T &, Args); })
     127forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    127128void ?{}(unique_ptr(T) & this, Args args) {
    128         this.data = (T *)new(args);
     129        this.data = malloc();
     130        (*this.data){args};
    129131}
    130132
    131 forall(dtype T | { void ^?{}(T &); })
     133forall(T & | { void ^?{}(T &); })
    132134void ^?{}(unique_ptr(T) & this) {
    133135        delete(this.data);
    134136}
    135137
    136 forall(dtype T)
     138forall(T &)
    137139T & *?(unique_ptr(T) & this) {
    138140        return *this.data;
    139141}
    140142
    141 forall(dtype T | { void ^?{}(T &); })
     143forall(T & | { void ^?{}(T &); })
    142144void ?=?(unique_ptr(T) & this, zero_t) {
    143145        delete(this.data);
     
    145147}
    146148
    147 forall(dtype T | { void ^?{}(T &); })
     149forall(T & | { void ^?{}(T &); })
    148150void move(unique_ptr(T) & this, unique_ptr(T) & that) {
    149151        delete(this.data);
     
    152154}
    153155
    154 forall(dtype T)
     156forall(T &)
    155157int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
    156158        return this.data == that.data;
    157159}
    158160
    159 forall(dtype T)
     161forall(T &)
    160162int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
    161163        return !?==?(this, that);
    162164}
    163165
    164 forall(dtype T)
     166forall(T &)
    165167int ?==?(unique_ptr(T) const & this, zero_t) {
    166168        return this.data == 0;
    167169}
    168170
    169 forall(dtype T)
     171forall(T &)
    170172int ?!=?(unique_ptr(T) const & this, zero_t) {
    171173        return !?==?(this, (zero_t)0);
Note: See TracChangeset for help on using the changeset viewer.