Changeset 58daf53


Ignore:
Timestamp:
May 25, 2017, 3:29:25 PM (7 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
f851015
Parents:
a4943d8c
Message:

Made maybe and result mutable, they should now qualify as otypes. Also added a few details to cfa.nanorc.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/maybe

    ra4943d8c r58daf53  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Wed May 25 14:43:00 2017
     10// Created On       : Wed May 24 14:43:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Apr 25 16:58:00 2017
     12// Last Modified On : Thr May 25 16:36:00 2017
    1313// Update Count     : 1
    1414//
     
    4141
    4242forall(otype T)
     43maybe(T) ?=?(maybe(T) * this, maybe(T) other);
     44
     45forall(otype T)
    4346bool ?!=?(maybe(T) this, zero_t);
    4447
     
    5558T get(maybe(T) * this);
    5659
     60forall(otype T)
     61void set(maybe(T) * this, T value);
     62
     63forall(otype T)
     64void set_none(maybe(T) * this);
     65
    5766#endif // MAYBE_H
  • src/libcfa/containers/maybe.c

    ra4943d8c r58daf53  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Wed May 25 15:40:00 2017
     10// Created On       : Wed May 24 15:40:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 25 17:00:00 2017
     12// Last Modified On : Thr May 25 15:24:00 2017
    1313// Update Count     : 1
    1414//
     
    2626void ?{}(maybe(T) * this, T value) {
    2727        this->has_value = true;
    28         this->value = value;
     28        (&this->value){value};
    2929}
    3030
     
    3333        this->has_value = other.has_value;
    3434        if (other.has_value) {
    35                 this->value = other.value;
     35                (&this->value){other.value};
     36        }
     37}
     38
     39forall(otype T)
     40maybe(T) ?=?(maybe(T) * this, maybe(T) that) {
     41        if (this->has_value & that.has_value) {
     42                this->value = that.value;
     43        } else if (this->has_value) {
     44                ^(&this->value){};
     45                this->has_value = false;
     46        } else if (that.has_value) {
     47                this->has_value = true;
     48                (&this->value){that.value};
    3649        }
    3750}
     
    4659forall(otype T)
    4760bool ?!=?(maybe(T) this, zero_t) {
    48         return !this.has_value;
     61        return this.has_value;
    4962}
    5063
     
    6982        return this->value;
    7083}
     84
     85forall(otype T)
     86void set(maybe(T) * this, T value) {
     87        if (this->has_value) {
     88                this->value = value;
     89        } else {
     90                this->has_value = true;
     91                (&this->value){value};
     92        }
     93}
     94
     95forall(otype T)
     96void set_none(maybe(T) * this) {
     97        if (this->has_value) {
     98                this->has_value = false;
     99                ^(&this->value){};
     100        }
     101}
  • src/libcfa/containers/result

    ra4943d8c r58daf53  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Wed May 25 14:45:00 2017
     10// Created On       : Wed May 24 14:45:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 25 16:57:00 2017
     12// Last Modified On : Thr May 25 16:39:00 2017
    1313// Update Count     : 1
    1414//
     
    5050
    5151forall(otype T, otype E)
     52result(T, E) ?=?(result(T, E) * this, result(T, E) other);
     53
     54forall(otype T, otype E)
    5255bool ?!=?(result(T, E) this, zero_t);
    5356
     
    6770E get_error(result(T, E) * this);
    6871
     72forall(otype T, otype E)
     73void set(result(T, E) * this, T value);
     74
     75forall(otype T, otype E)
     76void set_error(result(T, E) * this, E error);
     77
    6978#endif // RESULT_H
  • src/libcfa/containers/result.c

    ra4943d8c r58daf53  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Wed May 25 15:40:00 2017
     10// Created On       : Wed May 24 15:40:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 25 17:02:00 2017
     12// Last Modified On : Thr May 25 15:27:00 2017
    1313// Update Count     : 1
    1414//
     
    2727void ?{}(result(T, E) * this, one_t, T value) {
    2828        this->has_value = true;
    29         this->value = value;
     29        (&this->value){value};
    3030}
    3131
     
    3333void ?{}(result(T, E) * this, zero_t, E error) {
    3434        this->has_value = false;
    35         this->error = error;
     35        (&this->error){error};
    3636}
    3737
     
    4040        this->has_value = other.has_value;
    4141        if (other.has_value) {
    42                 this->value = other.value;
     42                (&this->value){other.value};
    4343        } else {
    44                 this->error = other.error;
     44                (&this->error){other.error};
     45        }
     46}
     47
     48forall(otype T, otype E)
     49result(T, E) ?=?(result(T, E) * this, result(T, E) that) {
     50        if (this->has_value & that.has_value) {
     51                this->value = that.value;
     52        } else if (this->has_value) {
     53                ^(&this->value){};
     54                this->has_value = false;
     55                (&this->error){that.error};
     56        } else if (that.has_value) {
     57                ^(&this->error){};
     58                this->has_value = true;
     59                (&this->value){that.value};
     60        } else {
     61                this->error = that.error;
    4562        }
    4663}
     
    86103        return this->error;
    87104}
     105
     106forall(otype T, otype E)
     107void set(result(T, E) * this, T value) {
     108        if (this->has_value) {
     109                this->value = value;
     110        } else {
     111                ^(&this->error){};
     112                this->has_value = true;
     113                (&this->value){value};
     114        }
     115}
     116
     117forall(otype T, otype E)
     118void set_error(result(T, E) * this, E error) {
     119        if (this->has_value) {
     120                ^(&this->value){};
     121                this->has_value = false;
     122                (&this->error){error};
     123        } else {
     124                this->error = error;
     125        }
     126}
  • tools/cfa.nanorc

    ra4943d8c r58daf53  
    1212color green "\<(float|double|bool|char|int|short|long|sizeof|enum|void|auto)\>"
    1313color green "\<(static|const|struct|union|typedef|extern|(un)?signed|inline)\>"
    14 color green "\<((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\>"
     14color green "\<((s?size)|one|zero|((u_?)?int(8|16|32|64|ptr)))_t\>"
    1515
    1616# Declarations
     
    3939
    4040# Values
     41# Booleans
     42color blue "\<(true|false)\>"
    4143# Characters
    4244color brightmagenta "'([^'\]|(\\")|(\\['abfnrtv\\]))'"
Note: See TracChangeset for help on using the changeset viewer.