- Timestamp:
- Mar 8, 2018, 1:37:46 PM (6 years ago)
- 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:
- 28bc8c8
- Parents:
- f1f8e55
- Location:
- doc/papers/general/evaluation
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/c-bench.c
rf1f8e55 rfb2ce27 5 5 #include "c-stack.h" 6 6 7 _Bool* new_bool( _Bool b) {8 _Bool* q = malloc(sizeof(_Bool)); /***/9 *q = b;7 char* new_char( char c ) { 8 char* q = malloc(sizeof(char)); /***/ 9 *q = c; 10 10 return q; 11 11 } 12 12 13 char* new_char( char c) {14 char* q = malloc(sizeof(char)); /***/15 *q = c;13 short* new_short( short s ) { 14 short* q = malloc(sizeof(short)); /***/ 15 *q = s; 16 16 return q; 17 17 } … … 23 23 } 24 24 25 void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } /***/26 25 void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/ 26 void* copy_short( const void* p ) { return new_short( *(const short*)p ); } /***/ 27 27 void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/ 28 void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } /***/ 29 void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } /***/ 30 31 int cmp_bool( const void* a, const void* b ) { /***/ 32 return *(const _Bool*)a == *(const _Bool*)b ? 0 : *(const _Bool*)a < *(const _Bool*)b ? -1 : 1; 33 } 28 void* copy_pair_short_char( const void* p ) { return copy_pair( p, copy_short, copy_char ); } /***/ 29 void free_pair_short_char( void* p ) { free_pair( p, free, free ); } /***/ 34 30 35 31 int cmp_char( const void* a, const void* b ) { /***/ 36 32 return *(const char*)a == *(const char*)b ? 0 : *(const char*)a < *(const char*)b ? -1 : 1; 33 } 34 35 int cmp_short( const void* a, const void* b ) { /***/ 36 return *(const short*)a == *(const short*)b ? 0 : *(const short*)a < *(const short*)b ? -1 : 1; 37 37 } 38 38 … … 49 49 free(xi); ) 50 50 51 struct pair * maxp = new_pair( new_ bool(0), new_char('\0') ),52 * valp = new_pair( new_ bool(1), new_char('a') );51 struct pair * maxp = new_pair( new_short(0), new_char('\0') ), 52 * valp = new_pair( new_short(42), new_char('a') ); 53 53 struct stack sp = new_stack(), tp; 54 54 55 REPEAT_TIMED( "push_pair", N, push_stack( &sp, copy_pair_ bool_char( valp ) ); )56 TIMED( "copy_pair", copy_stack( &tp, &sp, copy_pair_ bool_char ); /***/ )57 TIMED( "clear_pair", clear_stack( &sp, free_pair_ bool_char ); /***/ )55 REPEAT_TIMED( "push_pair", N, push_stack( &sp, copy_pair_short_char( valp ) ); ) 56 TIMED( "copy_pair", copy_stack( &tp, &sp, copy_pair_short_char ); /***/ ) 57 TIMED( "clear_pair", clear_stack( &sp, free_pair_short_char ); /***/ ) 58 58 REPEAT_TIMED( "pop_pair", N, 59 59 struct pair * xp = pop_stack( &tp ); 60 if ( cmp_pair( xp, maxp, cmp_ bool, cmp_char /***/ ) > 0 ) {61 free_pair_ bool_char( maxp ); /***/60 if ( cmp_pair( xp, maxp, cmp_short, cmp_char /***/ ) > 0 ) { 61 free_pair_short_char( maxp ); /***/ 62 62 maxp = xp; 63 63 } else { 64 free_pair_ bool_char( xp ); /***/64 free_pair_short_char( xp ); /***/ 65 65 } ) 66 free_pair_ bool_char( maxp ); /***/67 free_pair_ bool_char( valp ); /***/66 free_pair_short_char( maxp ); /***/ 67 free_pair_short_char( valp ); /***/ 68 68 } -
doc/papers/general/evaluation/c-stack.c
rf1f8e55 rfb2ce27 13 13 for ( struct stack_node* next = t->head; next; next = next->next ) { 14 14 *crnt = malloc(sizeof(struct stack_node)); /***/ 15 **crnt = (struct stack_node){ copy(next->value) }; /***/15 (*crnt)->value = copy(next->value); 16 16 crnt = &(*crnt)->next; 17 17 } 18 *crnt = 0;18 *crnt = NULL; 19 19 } 20 20 -
doc/papers/general/evaluation/cfa-stack.c
rf1f8e55 rfb2ce27 31 31 32 32 forall(otype T) void push( stack(T) & s, T value ) with( s ) { 33 stack_node(T)* n ew_node= malloc();34 (*n ew_node){ value, head };35 head = n ew_node;33 stack_node(T)* n = malloc(); 34 (*n){ value, head }; 35 head = n; 36 36 } 37 37 … … 39 39 stack_node(T) * n = head; 40 40 head = n->next; 41 T v= n->value;41 T x = n->value; 42 42 ^(*n){}; 43 43 free( n ); 44 return v;44 return x; 45 45 } 46 46 … … 52 52 free(crnt); 53 53 } 54 s.head = 0;54 head = 0; 55 55 } -
doc/papers/general/evaluation/cpp-bench.cpp
rf1f8e55 rfb2ce27 13 13 REPEAT_TIMED( "pop_int", N, maxi = std::max( maxi, ti.pop() ); ) 14 14 15 pair< bool, char> maxp = { false, '\0' }, valp = { true, 'a' };16 stack<pair< bool, char>> sp, tp;15 pair<short, char> maxp = { 0, '\0' }, valp = { 42, 'a' }; 16 stack<pair<short, char>> sp, tp; 17 17 18 18 REPEAT_TIMED( "push_pair", N, sp.push( valp ); ) -
doc/papers/general/evaluation/cpp-vbench.cpp
rf1f8e55 rfb2ce27 13 13 REPEAT_TIMED( "pop_int", N, maxi = std::max( maxi, ti.pop()->as<integer>() ); /***/ ) 14 14 15 ptr<pair> maxp = make<pair>( make< boolean>(false), make<character>('\0') );16 pair valp{ make< boolean>(true), make<character>('a') };15 ptr<pair> maxp = make<pair>( make<short_integer>(0), make<character>('\0') ); 16 pair valp{ make<short_integer>(42), make<character>('a') }; 17 17 stack sp, tp; 18 18 -
doc/papers/general/evaluation/cpp-vstack.cpp
rf1f8e55 rfb2ce27 7 7 node** crnt = &head; 8 8 for ( node* next = o.head; next; next = next->next ) { 9 *crnt = new node{ *next->value }; 9 *crnt = new node{ *next->value }; /***/ 10 10 crnt = &(*crnt)->next; 11 11 } -
doc/papers/general/evaluation/object.hpp
rf1f8e55 rfb2ce27 67 67 }; 68 68 69 class boolean : public ordered, public printable {70 bool x;71 public:72 boolean() = default;73 boolean(bool x) : x(x) {}74 boolean(const boolean&) = default;75 boolean(boolean&&) = default;76 ptr<object> new_inst() const override { return make<boolean>(); }77 ptr<object> new_copy() const override { return make<boolean>(*this); }78 boolean& operator= (const boolean& that) {79 x = that.x;80 return *this;81 }82 object& operator= (const object& that) override { return *this = that.as<boolean>(); } /***/83 boolean& operator= (boolean&&) = default;84 ~boolean() override = default;85 86 int cmp(const boolean& that) const { return x == that.x ? 0 : x == false ? -1 : 1; }87 int cmp(const ordered& that) const override { return cmp( that.as<boolean>() ); } /***/88 89 void print(std::ostream& out) const override { out << (x ? "true" : "false"); }90 };91 92 69 class character : public ordered, public printable { 93 70 char x; … … 116 93 }; 117 94 95 class short_integer : public ordered, public printable { 96 short x; 97 public: 98 short_integer() = default; 99 short_integer(short x) : x(x) {} 100 short_integer(const short_integer&) = default; 101 short_integer(short_integer&&) = default; 102 ptr<object> new_inst() const override { return make<short_integer>(); } 103 ptr<object> new_copy() const override { return make<short_integer>(*this); } 104 short_integer& operator= (const short_integer& that) { 105 x = that.x; 106 return *this; 107 } 108 object& operator= (const object& that) override { return *this = that.as<short_integer>(); } /***/ 109 short_integer& operator= (short_integer&&) = default; 110 ~short_integer() override = default; 111 112 int cmp(const short_integer& that) const { return x == that.x ? 0 : x < that.x ? -1 : 1; } 113 int cmp(const ordered& that) const override { return cmp( that.as<short_integer>() ); } /***/ 114 115 void print(std::ostream& out) const override { out << x; } 116 }; 117 118 118 class integer : public ordered, public printable { 119 119 int x; … … 137 137 138 138 void print(std::ostream& out) const override { out << x; } 139 };140 141 class c_string : public printable {142 static constexpr const char* empty = "";143 const char* s;144 public:145 c_string() : s(empty) {}146 c_string(const char* s) : s(s) {}147 c_string(const c_string&) = default;148 c_string(c_string&&) = default;149 ptr<object> new_inst() const override { return make<c_string>(); }150 ptr<object> new_copy() const override { return make<c_string>(s); }151 c_string& operator= (const c_string& that) {152 s = that.s;153 return *this;154 }155 object& operator= (const object& that) override { return *this = that.as<c_string>(); } /***/156 c_string& operator= (c_string&&) = default;157 ~c_string() override = default;158 159 void print(std::ostream& out) const override { out << s; }160 139 }; 161 140 … … 188 167 return y->as<ordered>().cmp( that.y->as<ordered>() ); /***/ 189 168 } 190 int cmp(const ordered& that) const override { return cmp( that.as<pair>() ); } 169 int cmp(const ordered& that) const override { return cmp( that.as<pair>() ); } /***/ 191 170 192 171 void print(std::ostream& out) const override {
Note: See TracChangeset
for help on using the changeset viewer.