Changeset f1e42c1 for src/examples


Ignore:
Timestamp:
May 12, 2016, 10:14:36 AM (8 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:
bf5a70da
Parents:
273080f
Message:

added some basic tests and modified compilation to support them

Location:
src/examples/gc_no_raii
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/src/gc.h

    r273080f rf1e42c1  
    22
    33#include "gcpointers.h"
     4#include "internal/collector.h"
    45
    5 // forall( dtype T )
    6 // gcpointer_t gcmalloc()
    7 // {
    8 //
    9 // }
     6forall(otype T)
     7static inline gcpointer(T) gcmalloc()
     8{
     9    gcpointer(T) test;
     10    // ctor(&test, gc_allocate(sizeof(T)));
     11    // gc_conditional_collect();
     12    return test;
     13}
  • src/examples/gc_no_raii/src/gcpointers.c

    r273080f rf1e42c1  
    8484
    8585//Logical operators
    86 int gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs)
     86bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs)
    8787{
    8888        return this->ptr == rhs->ptr;
    8989}
    9090
    91 int gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs)
     91bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs)
    9292{
    9393        return this->ptr != rhs->ptr;
    9494}
    9595
    96 int gcpointer_null(gcpointer_t* this)
     96bool gcpointer_null(gcpointer_t* this)
    9797{
    9898        return this->ptr == (intptr_t)NULL;
  • src/examples/gc_no_raii/src/gcpointers.h

    r273080f rf1e42c1  
    11#pragma once
    22
     3#include <stdbool.h>
    34#include <stdint.h>
    45
     
    1011
    1112void gcpointer_ctor(gcpointer_t* this);
    12 void gcpointer_ctor(gcpointer_t* ptr, int null);
    1313void gcpointer_ctor(gcpointer_t* this, void* address);
    1414void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other);
    15 
    1615void gcpointer_dtor(gcpointer_t* this);
    17 
    1816gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs);
    1917
    2018//Logical operators
    21 int gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs);
    22 int gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs);
    23 int gcpointer_null(gcpointer_t* this);
     19bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs);
     20bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs);
     21bool gcpointer_null(gcpointer_t* this);
     22
     23forall(otype T)
     24struct gcpointer
     25{
     26        gcpointer_t internal;
     27};
     28
     29forall(otype T)
     30static inline void ctor(gcpointer(T)* this)
     31{
     32        gcpointer_ctor(&this->internal);
     33}
     34
     35// forall(otype T)
     36// static inline void ctor(gcpointer(T)* this, int null)
     37// {
     38//      gcpointer_ctor(&this->internal, NULL);
     39// }
     40
     41forall(otype T)
     42static inline void ctor(gcpointer(T)* this, void* address)
     43{
     44        gcpointer_ctor(&this->internal, address);
     45}
     46
     47forall(otype T)
     48static inline void ctor(gcpointer(T)* this, gcpointer(T)* other)
     49{
     50        gcpointer_ctor(&this->internal, other);
     51}
     52
     53forall(otype T)
     54static inline void dtor(gcpointer(T)* this)
     55{
     56        gcpointer_dtor(&this->internal);
     57}
     58
     59forall(otype T)
     60static inline gcpointer(T)* ?=?(gcpointer(T)* this, gcpointer(T)* rhs)
     61{
     62        gcpointer_assign(&this->internal, &rhs->internal);
     63        return this;
     64}
     65
     66forall(otype T)
     67static inline T *?(gcpointer(T) this)
     68{
     69        return *(T*)this.internal.ptr;
     70}
     71
     72//Logical operators
     73forall(otype T)
     74static inline int ?!=?(gcpointer(T) this, gcpointer(T) rhs)
     75{
     76        return this.internal.ptr != rhs.internal.ptr;
     77}
     78
     79forall(otype T)
     80static inline int ?==?(gcpointer(T) this, gcpointer(T) rhs)
     81{
     82        return !(this == rhs);
     83}
     84
     85forall(otype T)
     86extern struct gcpointer(T) 0;
  • src/examples/gc_no_raii/src/test_include.c

    r273080f rf1e42c1  
    22#define xstr(s) sstr(s)
    33#define sstr(s) #s
    4 #error "test" # xstr(TEST_FILE.c)
    5 #include "test" # xstr(TEST_FILE.c)
     4#include xstr(../test/TEST_FILE.c)
  • src/examples/gc_no_raii/src/vector.h

    r273080f rf1e42c1  
    11#pragma once
    22
     3#include <stdbool.h>
    34#include <stdlib>
    45
  • src/examples/gc_no_raii/test/badlll.c

    r273080f rf1e42c1  
    66        int val;
    77};
     8
     9typedef gcpointer(List_t) LLL;
     10
     11#define MAX (1024 * 1024)
     12
     13LLL buildLLL(int sz)
     14{
     15        int i;
     16        LLL ll0, lll, llc;
     17        ctor(&ll0);
     18        ctor(&lll);
     19        ctor(&llc);
     20
     21        ll0 = gcmalloc();
     22        ll0->val = 0;
     23        lll = ll0;
     24
     25        return ll0;
     26}
Note: See TracChangeset for help on using the changeset viewer.