Changeset 8be729f


Ignore:
Timestamp:
Feb 1, 2021, 4:23:55 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
85871478
Parents:
f99f5ba
Message:

That should fix the memory module. Simply removed all the special features.

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/memory.cfa

    rf99f5ba r8be729f  
    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
     
    5656}
    5757
    58 forall(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);
     62        //internal_decrement(this);
    6363        internal_copy(this, that);
    6464}
     
    6666forall(T & | sized(T), Args... | { void ?{}(T&, Args); })
    6767void ?{}(counter_ptr(T) & this, Args args) {
    68         this.data = (counter_data(T)*)new(args);
     68        this.data = malloc();
     69        this.data->counter = 1;
     70        (this.data->object){args};
    6971}
    7072
     
    126128forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    127129void ?{}(unique_ptr(T) & this, Args args) {
    128         this.data = (T *)new(args);
     130        this.data = malloc();
     131        (*this.data){args};
    129132}
    130133
  • libcfa/src/memory.hfa

    rf99f5ba r8be729f  
    1010// Created On       : Tue Jun  2 16:48:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun  3 12:29:00 2020
    13 // Update Count     : 0
     12// Last Modified On : Fri Jan 29 15:52:00 2021
     13// Update Count     : 1
    1414//
    1515
     
    1717
    1818// Internal data object.
    19 forall(T & | sized(T)) {
    20         struct counter_data {
    21                 unsigned int counter;
    22                 T object;
    23         };
     19forall(T & | sized(T))
     20struct counter_data {
     21        unsigned int counter;
     22        T object;
     23};
    2424
    25         forall(Args... | { void ?{}(T &, Args); })
    26         void ?{}(counter_data(T) & this, Args args);
     25forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
     26void ?{}(counter_data(T) & this, Args args);
    2727
    28         forall( | { void ^?{}(T &); })
    29         void ^?{}(counter_data(T) & this);
    30 }
     28forall(T & | sized(T) | { void ^?{}(T &); })
     29void ^?{}(counter_data(T) & this);
    3130
    3231// This is one of many pointers keeping this alive.
    33 forall(T & | sized(T)) {
    34         struct counter_ptr {
    35                 counter_data(T) * data;
    36         };
     32forall(T & | sized(T))
     33struct counter_ptr {
     34        counter_data(T) * data;
     35};
    3736
    38         void ?{}(counter_ptr(T) & this);
    39         void ?{}(counter_ptr(T) & this, zero_t);
    40         forall( | { void ^?{}(T &); })
    41         void ?{}(counter_ptr(T) & this, counter_ptr(T) that);
    42         forall(Args... | { void ?{}(T&, Args); })
    43         void ?{}(counter_ptr(T) & this, Args args);
     37forall(T & | sized(T))
     38void ?{}(counter_ptr(T) & this);
     39forall(T & | sized(T))
     40void ?{}(counter_ptr(T) & this, zero_t);
     41forall(T & | sized(T))
     42void ?{}(counter_ptr(T) & this, counter_ptr(T) that);
     43forall(T & | sized(T), Args... | { void ?{}(T&, Args); })
     44void ?{}(counter_ptr(T) & this, Args args);
    4445
    45         forall( | { void ^?{}(T &); })
    46         void ^?{}(counter_ptr(T) & this);
     46forall(T & | sized(T) | { void ^?{}(T &); })
     47void ^?{}(counter_ptr(T) & this);
    4748
    48         T & *?(counter_ptr(T) & this);
     49forall(T & | sized(T))
     50T & *?(counter_ptr(T) & this);
    4951
    50         forall( | { void ^?{}(T &); })
    51         void ?=?(counter_ptr(T) & this, counter_ptr(T) that);
    52         forall( | { void ^?{}(T &); })
    53         void ?=?(counter_ptr(T) & this, zero_t);
     52forall(T & | sized(T) | { void ^?{}(T &); })
     53void ?=?(counter_ptr(T) & this, counter_ptr(T) that);
     54forall(T & | sized(T) | { void ^?{}(T &); })
     55void ?=?(counter_ptr(T) & this, zero_t);
    5456
    55         int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that);
    56         int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that);
    57         int ?==?(counter_ptr(T) const & this, zero_t);
    58         int ?!=?(counter_ptr(T) const & this, zero_t);
    59 }
     57forall(T & | sized(T))
     58int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that);
     59forall(T & | sized(T))
     60int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that);
     61forall(T & | sized(T))
     62int ?==?(counter_ptr(T) const & this, zero_t);
     63forall(T & | sized(T))
     64int ?!=?(counter_ptr(T) const & this, zero_t);
    6065
    6166// This is the only pointer that keeps this alive.
    62 forall(T &) {
    63         struct unique_ptr {
    64                 T * data;
    65         };
     67forall(T &)
     68struct unique_ptr {
     69        T * data;
     70};
    6671
    67         void ?{}(unique_ptr(T) & this);
    68         void ?{}(unique_ptr(T) & this, zero_t);
    69         void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void;
    70         forall( | sized(T), Args... | { void ?{}(T &, Args); })
    71         void ?{}(unique_ptr(T) & this, Args args);
     72forall(T &)
     73void ?{}(unique_ptr(T) & this);
     74forall(T &)
     75void ?{}(unique_ptr(T) & this, zero_t);
     76forall(T &)
     77void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void;
     78forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
     79void ?{}(unique_ptr(T) & this, Args args);
    7280
    73         forall( | { void ^?{}(T &); })
    74         void ^?{}(unique_ptr(T) & this);
     81forall(T & | { void ^?{}(T &); })
     82void ^?{}(unique_ptr(T) & this);
    7583
    76         T & *?(unique_ptr(T) & this);
     84forall(T & )
     85T & *?(unique_ptr(T) & this);
    7786
    78         void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void;
    79         forall( | { void ^?{}(T &); })
    80         void ?=?(unique_ptr(T) & this, zero_t);
     87forall(T &)
     88void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void;
     89forall(T & | { void ^?{}(T &); })
     90void ?=?(unique_ptr(T) & this, zero_t);
    8191
    82         forall( | { void ^?{}(T &); })
    83         void move(unique_ptr(T) & this, unique_ptr(T) & that);
     92forall(T & | { void ^?{}(T &); })
     93void move(unique_ptr(T) & this, unique_ptr(T) & that);
    8494
    85         int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that);
    86         int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that);
    87         int ?==?(unique_ptr(T) const & this, zero_t);
    88         int ?!=?(unique_ptr(T) const & this, zero_t);
    89 }
     95forall(T &)
     96int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that);
     97forall(T &)
     98int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that);
     99forall(T &)
     100int ?==?(unique_ptr(T) const & this, zero_t);
     101forall(T &)
     102int ?!=?(unique_ptr(T) const & this, zero_t);
  • tests/smart-pointers.cfa

    rf99f5ba r8be729f  
    22
    33#include <memory.hfa>
    4 #include <stdlib.hfa>
     4#include <assert.h>
    55
    66void counter_test(void) {
     
    5353}
    5454
     55void declare_test(void) {
     56        counter_ptr(int) ptr_i0 = 3;
     57        counter_ptr(char) ptr_c0 = 'a';
     58        counter_ptr(float) ptr_f0 = 3.5f;
     59        counter_ptr(double) ptr_d0 = 3.5;
     60
     61        unique_ptr(int) ptr_i1 = 3;
     62        unique_ptr(char) ptr_c1 = 'a';
     63        unique_ptr(float) ptr_f1 = 3.5f;
     64        unique_ptr(double) ptr_d1 = 3.5;
     65}
     66
    5567int main(int argc, char * argv[]) {
    5668        counter_test();
    5769        unique_test();
    5870        pointer_equality();
     71
     72        printf("done\n");
    5973}
Note: See TracChangeset for help on using the changeset viewer.