Changeset 81e8ab0 for doc/papers/general/evaluation
- Timestamp:
- Mar 9, 2018, 9:30:47 AM (7 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:
- 8b001bd
- Parents:
- 29db723
- Location:
- doc/papers/general/evaluation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/c-stack.c
r29db723 r81e8ab0 3 3 4 4 struct stack_node { 5 void * value;6 struct stack_node * next;5 void * value; 6 struct stack_node * next; 7 7 }; 8 8 9 9 struct stack new_stack() { return (struct stack){ NULL }; /***/ } 10 10 11 void copy_stack(struct stack* s, const struct stack* t, void* (*copy)(const void*)) { 12 struct stack_node** crnt = &s->head; 13 for ( struct stack_node* next = t->head; next; next = next->next ) { 14 *crnt = malloc(sizeof(struct stack_node)); /***/ 15 (*crnt)->value = copy(next->value); 11 void clear_stack( struct stack * s, void (*free_el)( void * ) ) { 12 for ( struct stack_node * next = s->head; next; ) { 13 struct stack_node * crnt = next; 14 next = crnt->next; 15 free_el( crnt->value ); 16 free( crnt ); 17 } 18 s->head = NULL; 19 } 20 21 void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) { 22 struct stack_node ** crnt = &s->head; 23 for ( struct stack_node * next = t->head; next; next = next->next ) { 24 *crnt = malloc( sizeof(struct stack_node) ); /***/ 25 (*crnt)->value = copy( next->value ); 16 26 crnt = &(*crnt)->next; 17 27 } … … 19 29 } 20 30 21 void clear_stack(struct stack* s, void (*free_el)(void*)) { 22 for ( struct stack_node* next = s->head; next; ) { 23 struct stack_node* crnt = next; 24 next = crnt->next; 25 free_el(crnt->value); 26 free(crnt); 27 } 28 s->head = NULL; 29 } 31 _Bool stack_empty( const struct stack * s ) { return s->head == NULL; } 30 32 31 _Bool stack_empty(const struct stack* s) { return s->head == NULL; } 32 33 void push_stack(struct stack* s, void* value) { 34 struct stack_node* n = malloc(sizeof(struct stack_node)); /***/ 33 void push_stack( struct stack * s, void * value ) { 34 struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/ 35 35 *n = (struct stack_node){ value, s->head }; /***/ 36 36 s->head = n; 37 37 } 38 38 39 void * pop_stack(struct stack* s) {40 struct stack_node * n = s->head;39 void * pop_stack( struct stack * s ) { 40 struct stack_node * n = s->head; 41 41 s->head = n->next; 42 void * x= n->value;43 free( n);44 return x;42 void * v = n->value; 43 free( n ); 44 return v; 45 45 } -
doc/papers/general/evaluation/cfa-stack.c
r29db723 r81e8ab0 17 17 } 18 18 *crnt = 0; 19 } 20 21 forall( otype T ) void clear( stack(T) & s ) with( s ) { 22 for ( stack_node(T) * next = head; next; ) { 23 stack_node(T) * crnt = next; 24 next = crnt->next; 25 ^(*crnt){}; 26 free(crnt); 27 } 28 head = 0; 19 29 } 20 30 … … 44 54 return v; 45 55 } 46 47 forall( otype T ) void clear( stack(T) & s ) with( s ) {48 for ( stack_node(T) * next = head; next; ) {49 stack_node(T) * crnt = next;50 next = crnt->next;51 ^(*crnt){};52 free(crnt);53 }54 head = 0;55 } -
doc/papers/general/evaluation/cpp-stack.hpp
r29db723 r81e8ab0 2 2 #include <utility> 3 3 4 template<typename T> classstack {4 template<typename T> struct stack { 5 5 struct node { 6 6 T value; 7 node* next; 7 node * next; 8 node( const T & v, node * n = nullptr ) : value( v ), next( n ) {} 9 }; 10 node * head; 8 11 9 node( const T& v, node* n = nullptr ) : value(v), next(n) {}10 };11 node* head;12 stack() : head( nullptr ) {} 13 stack( const stack<T> & o) { copy( o ); } 14 stack( stack<T> && o ) : head( o.head ) { o.head = nullptr; } 12 15 13 void copy( const stack<T>& o) {14 node ** crnt = &head;15 for ( node * next = o.head; next; next = next->next ) {16 void copy( const stack<T> & o ) { 17 node ** crnt = &head; 18 for ( node * next = o.head; next; next = next->next ) { 16 19 *crnt = new node{ next->value }; /***/ 17 20 crnt = &(*crnt)->next; … … 19 22 *crnt = nullptr; 20 23 } 21 public: 24 22 25 void clear() { 23 for ( node* next = head; next; ) {24 node * crnt = next;26 for ( node * next = head; next; ) { 27 node * crnt = next; 25 28 next = crnt->next; 26 29 delete crnt; … … 29 32 } 30 33 31 stack() : head(nullptr) {}32 stack(const stack<T>& o) { copy(o); }33 stack(stack<T>&& o) : head(o.head) { o.head = nullptr; }34 34 ~stack() { clear(); } 35 35 36 stack & operator= (const stack<T>& o) {36 stack & operator= ( const stack<T> & o ) { 37 37 if ( this == &o ) return *this; 38 38 clear(); 39 copy( o);39 copy( o ); 40 40 return *this; 41 41 } 42 42 43 stack & operator= (stack<T>&& o) {43 stack & operator= ( stack<T> && o ) { 44 44 if ( this == &o ) return *this; 45 45 head = o.head; … … 50 50 bool empty() const { return head == nullptr; } 51 51 52 void push( const T& value) { head = new node{ value, head }; /***/ }52 void push( const T & value ) { head = new node{ value, head }; /***/ } 53 53 54 54 T pop() { 55 node * n = head;55 node * n = head; 56 56 head = n->next; 57 T x = std::move(n->value);57 T v = std::move( n->value ); 58 58 delete n; 59 return x;59 return v; 60 60 } 61 61 }; -
doc/papers/general/evaluation/cpp-vstack.cpp
r29db723 r81e8ab0 2 2 #include <utility> 3 3 4 stack::node::node( const object & v, node* n ) : value( v.new_copy() ), next( n ) {}4 stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {} 5 5 6 void stack::copy( const stack& o) {7 node ** crnt = &head;8 for ( node * next = o.head; next; next = next->next ) {6 void stack::copy( const stack & o ) { 7 node ** crnt = &head; 8 for ( node * next = o.head; next; next = next->next ) { 9 9 *crnt = new node{ *next->value }; /***/ 10 10 crnt = &(*crnt)->next; … … 13 13 } 14 14 15 stack::stack() : head(nullptr) {} 16 stack::stack(const stack& o) { copy(o); } 17 stack::stack(stack&& o) : head(o.head) { o.head = nullptr; } 15 void stack::clear() { 16 for ( node * next = head; next; ) { 17 node * crnt = next; 18 next = crnt->next; 19 delete crnt; 20 } 21 head = nullptr; 22 } 23 24 stack::stack() : head( nullptr ) {} 25 stack::stack( const stack & o ) { copy( o ); } 26 stack::stack( stack && o ) : head( o.head ) { o.head = nullptr; } 18 27 stack::~stack() { clear(); } 19 28 20 stack & stack::operator= (const stack& o) {29 stack & stack::operator=( const stack & o ) { 21 30 if ( this == &o ) return *this; 22 31 clear(); 23 copy( o);32 copy( o ); 24 33 return *this; 25 34 } 26 35 27 stack & stack::operator= (stack&& o) {36 stack & stack::operator=( stack && o ) { 28 37 if ( this == &o ) return *this; 29 38 head = o.head; … … 32 41 } 33 42 34 void stack::clear() {35 for ( node* next = head; next; ) {36 node* crnt = next;37 next = crnt->next;38 delete crnt;39 }40 head = nullptr;41 }42 43 43 44 44 bool stack::empty() const { return head == nullptr; } 45 45 46 void stack::push( const object& value) { head = new node{ value, head }; /***/ }46 void stack::push( const object & value ) { head = new node{ value, head }; /***/ } 47 47 48 48 ptr<object> stack::pop() { 49 node * n = head;49 node * n = head; 50 50 head = n->next; 51 ptr<object> x = std::move(n->value);51 ptr<object> v = std::move( n->value ); 52 52 delete n; 53 return x;53 return v; 54 54 } -
doc/papers/general/evaluation/cpp-vstack.hpp
r29db723 r81e8ab0 2 2 #include "object.hpp" 3 3 4 classstack {4 struct stack { 5 5 struct node { 6 6 ptr<object> value; 7 node* next; 7 node * next; 8 node( const object & v, node * n = nullptr ); 9 }; 10 node * head; 8 11 9 node( const object& v, node* n = nullptr ); 10 }; 11 node* head; 12 void copy( const stack & o ); 12 13 13 void copy(const stack& o);14 public:15 14 stack(); 16 stack( const stack& o);17 stack( stack&& o);15 stack( const stack & o ); 16 stack( stack && o ); 18 17 ~stack(); 19 stack& operator= (const stack& o);20 stack& operator= (stack&& o);18 stack& operator=( const stack& o ); 19 stack& operator=( stack && o ); 21 20 22 21 void clear(); 23 22 bool empty() const; 24 void push( const object& value);23 void push( const object & value ); 25 24 ptr<object> pop(); 26 25 };
Note: See TracChangeset
for help on using the changeset viewer.