Changeset e84382b for doc/papers/general/evaluation
- Timestamp:
- Mar 9, 2018, 1:34:04 PM (8 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:
- 860f19f
- Parents:
- b51e5fdb (diff), 3d8f2f8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- doc/papers/general/evaluation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/c-stack.c
rb51e5fdb re84382b 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 9 void clear_stack( struct stack * s, void (*free_el)( void * ) ) { 10 for ( struct stack_node * next = s->head; next; ) { 11 struct stack_node * crnt = next; 12 next = crnt->next; 13 free_el( crnt->value ); 14 free( crnt ); 15 } 16 s->head = NULL; 17 } 8 18 9 19 struct stack new_stack() { return (struct stack){ NULL }; /***/ } 10 20 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);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 } 18 28 *crnt = NULL; 19 29 } 20 21 struct stack* assign_stack(struct stack* s, const struct stack* t, 22 void* (*copy_el)(const void*), void (*free_el)(void*)) { 30 struct stack * assign_stack( struct stack * s, const struct stack * t, 31 void * (*copy_el)( const void * ), void (*free_el)( void * ) ) { 23 32 if ( s->head == t->head ) return s; 24 33 clear_stack( s, free_el ); /***/ … … 27 36 } 28 37 29 void clear_stack(struct stack* s, void (*free_el)(void*)) { 30 for ( struct stack_node* next = s->head; next; ) { 31 struct stack_node* crnt = next; 32 next = crnt->next; 33 free_el(crnt->value); 34 free(crnt); 35 } 36 s->head = NULL; 37 } 38 _Bool stack_empty( const struct stack * s ) { return s->head == NULL; } 38 39 39 _Bool stack_empty(const struct stack* s) { return s->head == NULL; } 40 41 void push_stack(struct stack* s, void* value) { 42 struct stack_node* n = malloc(sizeof(struct stack_node)); /***/ 40 void push_stack( struct stack * s, void * value ) { 41 struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/ 43 42 *n = (struct stack_node){ value, s->head }; /***/ 44 43 s->head = n; 45 44 } 46 45 47 void * pop_stack(struct stack* s) {48 struct stack_node * n = s->head;46 void * pop_stack( struct stack * s ) { 47 struct stack_node * n = s->head; 49 48 s->head = n->next; 50 void * x= n->value;51 free( n);52 return x;49 void * v = n->value; 50 free( n ); 51 return v; 53 52 } -
doc/papers/general/evaluation/cfa-stack.c
rb51e5fdb re84382b 6 6 stack_node(T) * next; 7 7 }; 8 9 forall( otype T ) void clear( stack(T) & s ) with( s ) { 10 for ( stack_node(T) * next = head; next; ) { 11 stack_node(T) * crnt = next; 12 next = crnt->next; 13 ^(*crnt){}; 14 free(crnt); 15 } 16 head = 0; 17 } 8 18 9 19 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; } … … 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
rb51e5fdb re84382b 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 *crnt = new node{ next->value }; /***/17 crnt = &(*crnt)->next;18 }19 *crnt = nullptr;20 }21 public:22 16 void clear() { 23 for ( node* next = head; next; ) {24 node * crnt = next;17 for ( node * next = head; next; ) { 18 node * crnt = next; 25 19 next = crnt->next; 26 20 delete crnt; … … 29 23 } 30 24 31 stack() : head(nullptr) {} 32 stack(const stack<T>& o) { copy(o); } 25 void copy( const stack<T> & o ) { 26 node ** crnt = &head; 27 for ( node * next = o.head; next; next = next->next ) { 28 *crnt = new node{ next->value }; /***/ 29 crnt = &(*crnt)->next; 30 } 31 *crnt = nullptr; 32 } 33 33 34 ~stack() { clear(); } 34 35 35 stack & operator= (const stack<T>& o) {36 stack & operator= ( const stack<T> & o ) { 36 37 if ( this == &o ) return *this; 37 38 clear(); 38 copy( o);39 copy( o ); 39 40 return *this; 40 41 } … … 42 43 bool empty() const { return head == nullptr; } 43 44 44 void push( const T& value) { head = new node{ value, head }; /***/ }45 void push( const T & value ) { head = new node{ value, head }; /***/ } 45 46 46 47 T pop() { 47 node * n = head;48 node * n = head; 48 49 head = n->next; 49 T x = std::move(n->value);50 T v = std::move( n->value ); 50 51 delete n; 51 return x;52 return v; 52 53 } 53 54 }; -
doc/papers/general/evaluation/cpp-vstack.cpp
rb51e5fdb re84382b 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::clear() { 7 for ( node * next = head; next; ) { 8 node * crnt = next; 9 next = crnt->next; 10 delete crnt; 11 } 12 head = nullptr; 13 } 14 15 void stack::copy( const stack & o ) { 16 node ** crnt = &head; 17 for ( node * next = o.head; next; next = next->next ) { 9 18 *crnt = new node{ *next->value }; /***/ 10 19 crnt = &(*crnt)->next; … … 13 22 } 14 23 15 stack::stack() : head(nullptr) {} 16 stack::stack(const stack& o) { copy(o); } 24 stack::stack() : head( nullptr ) {} 25 stack::stack( const stack & o ) { copy( o ); } 26 stack::stack( stack && o ) : head( o.head ) { o.head = nullptr; } 17 27 stack::~stack() { clear(); } 18 28 19 stack & stack::operator= (const stack& o) {29 stack & stack::operator=( const stack & o ) { 20 30 if ( this == &o ) return *this; 21 31 clear(); 22 copy( o);32 copy( o ); 23 33 return *this; 24 34 } 25 35 26 void stack::clear() { 27 for ( node* next = head; next; ) { 28 node* crnt = next; 29 next = crnt->next; 30 delete crnt; 31 } 32 head = nullptr; 36 stack & stack::operator=( stack && o ) { 37 if ( this == &o ) return *this; 38 head = o.head; 39 o.head = nullptr; 40 return *this; 33 41 } 34 35 42 36 43 bool stack::empty() const { return head == nullptr; } 37 44 38 void stack::push( const object& value) { head = new node{ value, head }; /***/ }45 void stack::push( const object & value ) { head = new node{ value, head }; /***/ } 39 46 40 47 ptr<object> stack::pop() { 41 node * n = head;48 node * n = head; 42 49 head = n->next; 43 ptr<object> x = std::move(n->value);50 ptr<object> v = std::move( n->value ); 44 51 delete n; 45 return x;52 return v; 46 53 } -
doc/papers/general/evaluation/cpp-vstack.hpp
rb51e5fdb re84382b 2 2 #include "object.hpp" 3 3 4 classstack {4 struct stack { 5 5 struct node { 6 6 ptr<object> value; 7 node* next; 8 9 node( const object& v, node* n = nullptr ); 7 node * next; 8 node( const object & v, node * n = nullptr ); 10 9 }; 11 node* head; 12 13 void copy(const stack& o); 14 public: 15 stack(); 16 stack(const stack& o); 17 ~stack(); 18 stack& operator= (const stack& o); 10 node * head; 19 11 20 12 void clear(); 13 void copy( const stack & o ); 14 15 stack(); 16 stack( const stack & o ); 17 stack( stack && o ); 18 ~stack(); 19 stack & operator=( const stack& o ); 20 stack & operator=( stack && o ); 21 21 bool empty() const; 22 void push( const object& value);22 void push( const object & value ); 23 23 ptr<object> pop(); 24 24 };
Note:
See TracChangeset
for help on using the changeset viewer.