Changeset ac4dad2 for doc/papers/general
- Timestamp:
- Apr 28, 2018, 9:20:28 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, with_gc
- Children:
- 6926a6d
- Parents:
- aa5fdac
- Location:
- doc/papers/general/evaluation
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/c-bench.c
raa5fdac rac4dad2 5 5 #include "c-stack.h" 6 6 7 char * new_char( char c ) {8 char* q = malloc( sizeof(char)); /***/7 char * new_char( char c ) { 8 char* q = malloc( sizeof(char) ); /***/ 9 9 *q = c; 10 10 return q; 11 11 } 12 12 13 short * new_short( short s ) {14 short* q = malloc( sizeof(short)); /***/13 short * new_short( short s ) { 14 short* q = malloc( sizeof(short) ); /***/ 15 15 *q = s; 16 16 return q; … … 18 18 19 19 int* new_int( int i ) { 20 int* q = malloc( sizeof(int)); /***/20 int* q = malloc( sizeof(int) ); /***/ 21 21 *q = i; 22 22 return q; 23 23 } 24 24 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 void * copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/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 ); } /***/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 void * copy_int( const void * p ) { return new_int( *(const int*)p ); } /***/ 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 ); } /***/ 30 30 31 31 int cmp_char( const void* a, const void* b ) { /***/ … … 37 37 } 38 38 39 int main(int argc, char ** argv) {39 int main(int argc, char * argv[] ) { 40 40 int maxi = 0, vali = 42; 41 41 struct stack si = new_stack(), ti; -
doc/papers/general/evaluation/c-pair.c
raa5fdac rac4dad2 2 2 #include "c-pair.h" 3 3 4 struct pair* new_pair(void* first, void* second) {5 struct pair* p = malloc(sizeof(struct pair)); /***/6 *p = ( structpair){ first, second }; /***/4 pair * new_pair( void * first, void * second ) { 5 pair * p = malloc( sizeof(pair) ); /***/ 6 *p = (pair){ first, second }; /***/ 7 7 return p; 8 8 } 9 9 10 struct pair* copy_pair(const struct pair* src,11 void * (*copy_first)(const void*), void* (*copy_second)(const void*)) {10 pair * copy_pair( const pair * src, 11 void * (* copy_first)(const void* ), void * (* copy_second)(const void *)) { 12 12 return new_pair( copy_first(src->first), copy_second(src->second) ); 13 13 } 14 14 15 void free_pair( struct pair* p, void (*free_first)(void*), void (*free_second)(void*)) {16 free_first( p->first);17 free_second( p->second);18 free( p);15 void free_pair( pair * p, void (* free_first)(void *), void (* free_second)(void *)) { 16 free_first( p->first ); 17 free_second( p->second ); 18 free( p ); 19 19 } 20 20 21 int cmp_pair( const struct pair* a, const struct pair* b,22 int (* cmp_first)(const void*, const void*), int (*cmp_second)(const void*, const void*)) {23 int c = cmp_first( a->first, b->first);24 if ( c == 0 ) c = cmp_second( a->second, b->second);21 int cmp_pair( const pair * a, const pair * b, 22 int (* cmp_first)(const void *, const void *), int (* cmp_second)(const void *, const void *)) { 23 int c = cmp_first( a->first, b->first ); 24 if ( c == 0 ) c = cmp_second( a->second, b->second ); 25 25 return c; 26 26 } -
doc/papers/general/evaluation/c-pair.h
raa5fdac rac4dad2 1 1 #pragma once 2 2 3 struct pair {4 void * first;5 void * second;6 } ;3 typedef struct pair { 4 void * first; 5 void * second; 6 } pair; 7 7 8 struct pair* new_pair(void* first, void* second);8 pair * new_pair( void * first, void * second ); 9 9 10 struct pair* copy_pair(const struct pair* src,11 void * (*copy_first)(const void*), void* (*copy_second)(const void*));10 pair * copy_pair( const pair * src, 11 void * (* copy_first)(const void *), void * (* copy_second)(const void *)); 12 12 13 void free_pair( struct pair* p, void (*free_first)(void*), void (*free_second)(void*));13 void free_pair( pair * p, void (* free_first)(void *), void (* free_second)(void *)); 14 14 15 int cmp_pair( const struct pair* a, const struct pair* b,16 int (* cmp_first)(const void*, const void*), int (*cmp_second)(const void*, const void*));15 int cmp_pair( const pair * a, const pair * b, 16 int (* cmp_first)(const void *, const void *), int (* cmp_second)(const void *, const void *)); -
doc/papers/general/evaluation/c-print.c
raa5fdac rac4dad2 4 4 #include "c-print.h" 5 5 6 void print_string( FILE* out, const char* x) { fprintf(out, "%s", x); }6 void print_string( FILE * out, const char * x ) { fprintf( out, "%s", x ); } 7 7 8 void print_bool( FILE* out, _Bool x) { fprintf(out, "%s", x ? "true" : "false"); }8 void print_bool( FILE * out, _Bool x ) { fprintf( out, "%s", x ? "true" : "false" ); } 9 9 10 void print_char( FILE* out, char x) {11 if ( 0x20 <= x && x <= 0x7E ) { fprintf( out, "'%c'", x); }12 else { fprintf( out, "'\\%x'", x); }10 void print_char( FILE * out, char x ) { 11 if ( 0x20 <= x && x <= 0x7E ) { fprintf( out, "'%c'", x ); } 12 else { fprintf( out, "'\\%x'", x ); } 13 13 } 14 14 15 void print_int( FILE* out, int x) { fprintf(out, "%d", x); }15 void print_int( FILE * out, int x ) { fprintf( out, "%d", x ); } 16 16 17 void print_fmt( FILE* out, char fmt, void* p) {17 void print_fmt( FILE * out, char fmt, void * p ) { 18 18 switch( fmt ) { 19 case 's': print_string( out, (const char*)p); break; /***/20 case 'b': print_bool( out, *(_Bool*)p); break; /***/21 case 'c': print_char( out, *(char*)p); break; /***/22 case 'd': print_int( out, *(int*)p); break; /***/19 case 's': print_string( out, (const char*)p ); break; /***/ 20 case 'b': print_bool( out, *(_Bool*)p ); break; /***/ 21 case 'c': print_char( out, *(char*)p ); break; /***/ 22 case 'd': print_int( out, *(int*)p ); break; /***/ 23 23 } 24 24 } 25 25 26 void print( FILE* out, const char* fmt, ...) {26 void print( FILE * out, const char * fmt, ... ) { 27 27 va_list args; 28 28 va_start(args, fmt); 29 for ( const char* it = fmt; *it; ++it) {29 for ( const char * it = fmt; *it; ++it ) { 30 30 switch( *it ) { 31 case 's': print_string( out, va_arg(args, const char*)); break; /***/32 case 'b': print_bool( out, va_arg(args, int)); break; /***/33 case 'c': print_char( out, va_arg(args, int)); break; /***/34 case 'd': print_int( out, va_arg(args, int)); break; /***/31 case 's': print_string( out, va_arg( args, const char * ) ); break; /***/ 32 case 'b': print_bool( out, va_arg( args, int ) ); break; /***/ 33 case 'c': print_char( out, va_arg( args, int ) ); break; /***/ 34 case 'd': print_int( out, va_arg( args, int ) ); break; /***/ 35 35 case 'p': { 36 const struct pair x = va_arg( args, const struct pair); /***/37 fprintf( out, "[");38 print_fmt( out, *++it, x.first); /***/39 fprintf( out, ", ");40 print_fmt( out, *++it, x.second); /***/41 fprintf( out, "]");36 const struct pair x = va_arg( args, const struct pair ); /***/ 37 fprintf( out, "[" ); 38 print_fmt( out, *++it, x.first ); /***/ 39 fprintf( out, ", " ); 40 print_fmt( out, *++it, x.second ); /***/ 41 fprintf( out, "]" ); 42 42 break; 43 43 } 44 44 } 45 45 } 46 va_end( args);46 va_end( args ); 47 47 } -
doc/papers/general/evaluation/c-print.h
raa5fdac rac4dad2 2 2 #include <stdio.h> 3 3 4 void print_string( FILE* out, const char* x);5 void print_bool( FILE* out, _Bool x);6 void print_char( FILE* out, char x);7 void print_int( FILE* out, int x);4 void print_string( FILE * out, const char * x ); 5 void print_bool( FILE * out, _Bool x ); 6 void print_char( FILE * out, char x ); 7 void print_int( FILE * out, int x ); 8 8 9 void print( FILE* out, const char* fmt, ...);9 void print( FILE * out, const char * fmt, ... ); -
doc/papers/general/evaluation/c-stack.c
raa5fdac rac4dad2 2 2 #include "c-stack.h" 3 3 4 struct stack_node {4 typedef struct node { 5 5 void * value; 6 struct stack_node * next;7 } ;6 struct node * next; 7 } node; 8 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 ); 9 void copy_stack( stack * s, const stack * t, void * (*copy)( const void * ) ) { 10 node ** cr = &s->head; 11 for ( node * nx = t->head; nx; nx = nx->next ) { 12 *cr = malloc( sizeof(node) ); /***/ 13 (*cr)->value = copy( nx->value ); 14 cr = &(*cr)->next; 15 } 16 *cr = NULL; 17 } 18 19 void clear_stack( stack * s, void (* free_el)( void * ) ) { 20 for ( node * nx = s->head; nx; ) { 21 node * cr = nx; 22 nx = cr->next; 23 free_el( cr->value ); 24 free( cr ); 15 25 } 16 26 s->head = NULL; 17 27 } 18 28 19 st ruct stack new_stack() { return (structstack){ NULL }; /***/ }29 stack new_stack() { return (stack){ NULL }; /***/ } 20 30 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 ); 26 crnt = &(*crnt)->next; 27 } 28 *crnt = NULL; 29 } 30 struct stack * assign_stack( struct stack * s, const struct stack * t, 31 stack * assign_stack( stack * s, const stack * t, 31 32 void * (*copy_el)( const void * ), void (*free_el)( void * ) ) { 32 33 if ( s->head == t->head ) return s; … … 36 37 } 37 38 38 _Bool stack_empty( const st ruct stack * s ) { return s->head == NULL; }39 _Bool stack_empty( const stack * s ) { return s->head == NULL; } 39 40 40 void push_stack( st ruct stack * s, void * v ) {41 struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/42 *n = ( struct stack_node){ v, s->head }; /***/41 void push_stack( stack * s, void * v ) { 42 node * n = malloc( sizeof(node) ); /***/ 43 *n = (node){ v, s->head }; /***/ 43 44 s->head = n; 44 45 } 45 46 46 void * pop_stack( st ruct stack * s ) {47 struct stack_node * n = s->head;47 void * pop_stack( stack * s ) { 48 node * n = s->head; 48 49 s->head = n->next; 49 50 void * v = n->value; -
doc/papers/general/evaluation/c-stack.h
raa5fdac rac4dad2 1 1 #pragma once 2 2 3 struct stack_node;4 struct stack {5 struct stack_node* head;6 } ;3 struct node; 4 typedef struct stack { 5 struct node * head; 6 } stack; 7 7 8 st ruct stack new_stack();9 void copy_stack(st ruct stack* dst, const struct stack* src, void* (*copy)(const void*));10 st ruct stack* assign_stack(struct stack* dst, const struct stack* src,11 void * (*copy_el)(const void*), void (*free_el)(void*));12 void clear_stack(st ruct stack* s, void (*free_el)(void*));8 stack new_stack(); 9 void copy_stack(stack * dst, const stack * src, void * (* copy)(const void *)); 10 stack * assign_stack( stack * dst, const stack * src, 11 void * (* copy_el)(const void *), void (* free_el)(void *)); 12 void clear_stack(stack * s, void (*free_el)(void *)); 13 13 14 _Bool stack_empty( const struct stack* s);15 void push_stack( struct stack* s, void* value);16 void * pop_stack(struct stack* s);14 _Bool stack_empty( const stack * s ); 15 void push_stack( stack * s, void * value ); 16 void * pop_stack( stack * s ); -
doc/papers/general/evaluation/cfa-stack.c
raa5fdac rac4dad2 2 2 #include "cfa-stack.h" 3 3 4 forall( otype T ) struct stack_node { 5 T value; 6 stack_node(T) * next; 7 }; 4 forall( otype T ) { 5 struct node { 6 T value; 7 node(T) * next; 8 }; 8 9 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); 10 void ?{}( stack(T) & s ) { (s.head){ 0 }; } 11 12 void ?{}( stack(T) & s, stack(T) t ) { 13 node(T) ** cr = &s.head; 14 for ( node(T) * nx = t.head; nx; nx = nx->next ) { 15 *cr = alloc(); 16 ((*cr)->value){ nx->value }; 17 cr = &(*cr)->next; 18 } 19 *cr = 0; 15 20 } 16 head = 0; 21 22 void ^?{}( stack(T) & s) { clear( s ); } 23 24 void clear( stack(T) & s ) with( s ) { 25 for ( node(T) * nx = head; nx; ) { 26 node(T) * cr = nx; 27 nx = cr->next; 28 ^(*cr){}; 29 free(cr); 30 } 31 head = 0; 32 } 33 34 stack(T) ?=?( stack(T) & s, stack(T) t ) { 35 if ( s.head == t.head ) return s; 36 clear( s ); 37 s{ t }; 38 return s; 39 } 40 41 _Bool empty( const stack(T) & s ) { return s.head == 0; } 42 43 void push( stack(T) & s, T value ) with( s ) { 44 node(T) * n = alloc(); 45 (*n){ value, head }; 46 head = n; 47 } 48 49 T pop( stack(T) & s ) with( s ) { 50 node(T) * n = head; 51 head = n->next; 52 T v = n->value; 53 ^(*n){}; 54 free( n ); 55 return v; 56 } 17 57 } 18 19 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }20 21 forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {22 stack_node(T) ** crnt = &s.head;23 for ( stack_node(T) * next = t.head; next; next = next->next ) {24 *crnt = alloc();25 ((*crnt)->value){ next->value };26 crnt = &(*crnt)->next;27 }28 *crnt = 0;29 }30 31 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) {32 if ( s.head == t.head ) return s;33 clear( s );34 s{ t };35 return s;36 }37 38 forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }39 40 forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }41 42 forall( otype T ) void push( stack(T) & s, T value ) with( s ) {43 stack_node(T) * n = alloc();44 (*n){ value, head };45 head = n;46 }47 48 forall( otype T ) T pop( stack(T) & s ) with( s ) {49 stack_node(T) * n = head;50 head = n->next;51 T v = n->value;52 ^(*n){};53 free( n );54 return v;55 } -
doc/papers/general/evaluation/cfa-stack.h
raa5fdac rac4dad2 1 1 #pragma once 2 2 3 forall( otype T ) struct stack_node; 4 forall( otype T ) struct stack { 5 stack_node(T) * head; 6 }; 3 forall( otype T ) { 4 struct node; 5 struct stack { 6 node(T) * head; 7 }; 7 8 8 forall( otype T )void ?{}( stack(T) & s );9 forall( otype T )void ?{}( stack(T) & s, stack(T) t );10 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t);11 forall( otype T ) void ^?{}( stack(T) & s);9 void ?{}( stack(T) & s ); 10 void ?{}( stack(T) & s, stack(T) t ); 11 void ^?{}( stack(T) & s); 12 void clear( stack(T) & s ); 12 13 13 forall( otype T ) _Bool empty( const stack(T) & s ); 14 forall( otype T ) void push( stack(T) & s, T value ); 15 forall( otype T ) T pop( stack(T) & s ); 16 forall( otype T ) void clear( stack(T) & s ); 14 stack(T) ?=?( stack(T) & s, stack(T) t ); 15 _Bool empty( const stack(T) & s ); 16 void push( stack(T) & s, T value ); 17 T pop( stack(T) & s ); 18 } -
doc/papers/general/evaluation/cpp-stack.hpp
raa5fdac rac4dad2 14 14 15 15 void clear() { 16 for ( node * n ext = head; next; ) {17 node * cr nt = next;18 n ext = crnt->next;19 delete cr nt;16 for ( node * nx = head; nx; ) { 17 node * cr = nx; 18 nx = cr->next; 19 delete cr; 20 20 } 21 21 head = nullptr; … … 23 23 24 24 void copy( const stack<T> & o ) { 25 node ** cr nt= &head;26 for ( node * n ext = o.head; next; next = next->next ) {27 *cr nt = new node{ next->value }; /***/28 cr nt = &(*crnt)->next;25 node ** cr = &head; 26 for ( node * nx = o.head; nx; nx = nx->next ) { 27 *cr = new node{ nx->value }; /***/ 28 cr = &(*cr)->next; 29 29 } 30 *cr nt= nullptr;30 *cr = nullptr; 31 31 } 32 32 -
doc/papers/general/evaluation/cpp-vstack.cpp
raa5fdac rac4dad2 5 5 6 6 void stack::clear() { 7 for ( node * n ext = head; next; ) {8 node * cr nt = next;9 n ext = crnt->next;10 delete cr nt;7 for ( node * nx = head; nx; ) { 8 node * cr = nx; 9 nx = cr->next; 10 delete cr; 11 11 } 12 12 head = nullptr; … … 14 14 15 15 void stack::copy( const stack & o ) { 16 node ** cr nt= &head;17 for ( node * n ext = o.head; next; next = next->next ) {18 *cr nt = new node{ *next->value }; /***/19 cr nt = &(*crnt)->next;16 node ** cr = &head; 17 for ( node * nx = o.head; nx; nx = nx->next ) { 18 *cr = new node{ *nx->value }; /***/ 19 cr = &(*cr)->next; 20 20 } 21 *cr nt= nullptr;21 *cr = nullptr; 22 22 } 23 23
Note: See TracChangeset
for help on using the changeset viewer.