Changeset a381b46 for doc/generic_types/evaluation
- Timestamp:
- Apr 15, 2017, 7:09:59 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:
- c57d1935
- Parents:
- 308880c
- Location:
- doc/generic_types/evaluation
- Files:
-
- 1 added
- 1 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/evaluation/Makefile
r308880c ra381b46 67 67 @/usr/bin/time -f 'max_memory:\t%M kilobytes' ./c-bench 68 68 @printf 'source_size:\t%8d lines\n' `cat $(CFILES) | wc -l` 69 @printf 'redundant_type_annotations:%8d count\n' `cat $(CFILES) | fgrep '/***/' -c`69 @printf 'redundant_type_annotations:%8d lines\n' `cat $(CFILES) | fgrep '/***/' -c` 70 70 @printf 'binary_size:\t%8d bytes\n' `stat -c %s c-bench` 71 71 … … 75 75 @/usr/bin/time -f 'max_memory:\t %M kilobytes' ./cfa-bench 76 76 @printf 'source_size:\t%8d lines\n' `cat $(CFAFILES) | wc -l` 77 @printf 'redundant_type_annotations:%8d count\n' `cat $(CFAFILES) | fgrep '/***/' -c`77 @printf 'redundant_type_annotations:%8d lines\n' `cat $(CFAFILES) | fgrep '/***/' -c` 78 78 @printf 'binary_size:\t%8d bytes\n' `stat -c %s cfa-bench` 79 79 … … 83 83 @/usr/bin/time -f 'max_memory:\t %M kilobytes' ./cpp-bench 84 84 @printf 'source_size:\t%8d lines\n' `cat $(CPPFILES) | wc -l` 85 @printf 'redundant_type_annotations:%8d count\n' `cat $(CPPFILES) | fgrep '/***/' -c`85 @printf 'redundant_type_annotations:%8d lines\n' `cat $(CPPFILES) | fgrep '/***/' -c` 86 86 @printf 'binary_size:\t%8d bytes\n' `stat -c %s cpp-bench` 87 87 88 88 run-cppv: cpp-vbench 89 89 @echo 90 @echo '## C++ virtual##'90 @echo '## C++obj ##' 91 91 @/usr/bin/time -f 'max_memory:\t%M kilobytes' ./cpp-vbench 92 92 @printf 'source_size:\t%8d lines\n' `cat $(CPPVFILES) | wc -l` 93 @printf 'redundant_type_annotations:%8d count\n' `cat $(CPPVFILES) | fgrep '/***/' -c`93 @printf 'redundant_type_annotations:%8d lines\n' `cat $(CPPVFILES) | fgrep '/***/' -c` 94 94 @printf 'binary_size:\t%8d bytes\n' `stat -c %s cpp-vbench` 95 95 -
doc/generic_types/evaluation/bench.h
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <stdio.h> 4 3 #include <time.h> 5 4 6 #ifndef N 5 long ms_between(clock_t start, clock_t end) { return (end - start) / (CLOCKS_PER_SEC / 1000); } 6 7 7 #define N 40000000 8 #endif9 10 long ms_between(clock_t start, clock_t end) {11 return (end - start) / (CLOCKS_PER_SEC / 1000);12 }13 14 8 #define TIMED(name, code) { \ 15 9 volatile clock_t _start, _end; \ … … 19 13 printf("%s:\t%8ld ms\n", name, ms_between(_start, _end)); \ 20 14 } 21 22 15 #define REPEAT_N_TIMED(name, n, code) TIMED( name, for (int _i = 0; _i < n; ++_i) { code } ) 23 24 16 #define REPEAT_TIMED(name, code) REPEAT_N_TIMED(name, N, code) -
doc/generic_types/evaluation/bench.hpp
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <iomanip> 4 3 #include <iostream> 5 4 #include <time.h> 6 5 7 #ifndef N 6 long ms_between(clock_t start, clock_t end) { return (end - start) / (CLOCKS_PER_SEC / 1000); } 7 8 8 static const int N = 40000000; 9 #endif10 11 long ms_between(clock_t start, clock_t end) {12 return (end - start) / (CLOCKS_PER_SEC / 1000);13 }14 15 9 #define TIMED(name, code) { \ 16 10 volatile clock_t _start, _end; \ … … 18 12 code \ 19 13 _end = clock(); \ 20 std::cout << name << ":\t" << std::setw(8) << ms_between(_start, _end) << std::setw(0) << " ms" << std::endl; \ 14 std::cout << name << ":\t" << std::setw(8) << ms_between(_start, _end) \ 15 << std::setw(0) << " ms" << std::endl; \ 21 16 } 22 23 17 #define REPEAT_N_TIMED(name, n, code) TIMED( name, for (int _i = 0; _i < n; ++_i) { code } ) 24 25 18 #define REPEAT_TIMED(name, code) REPEAT_N_TIMED(name, N, code) -
doc/generic_types/evaluation/c-bench.c
r308880c ra381b46 25 25 26 26 void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } /***/ 27 28 27 void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/ 29 30 28 void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/ 31 32 29 void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } /***/ 33 34 30 void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } /***/ 35 31 36 int cmp_bool( const void* a, const void* b ) { 37 return *(const _Bool*)a == *(const _Bool*)b ? 0 : *(const _Bool*)a < *(const _Bool*)b ? -1 : 1; /***/32 int cmp_bool( const void* a, const void* b ) { /***/ 33 return *(const _Bool*)a == *(const _Bool*)b ? 0 : *(const _Bool*)a < *(const _Bool*)b ? -1 : 1; 38 34 } 39 35 … … 44 40 int main(int argc, char** argv) { 45 41 FILE* out = fopen("c-out.txt", "w"); 46 srand(20171025);47 48 struct stack s = new_stack();49 REPEAT_TIMED( "push_int",50 push_stack(&s, new_int( rand() ));51 )52 53 struct stack t;54 TIMED( "copy_int",55 copy_stack(&t, &s, copy_int); /***/56 )57 58 TIMED( "clear_int",59 clear_stack(&s, free); /***/60 )61 62 42 int max = 0; 43 struct stack s = new_stack(), t; 44 REPEAT_TIMED( "push_int", push_stack(&s, new_int( _i )); ) 45 TIMED( "copy_int", copy_stack(&t, &s, copy_int); /***/ ) 46 TIMED( "clear_int", clear_stack(&s, free); /***/ ) 63 47 REPEAT_TIMED( "pop_int", 64 48 int* x = pop_stack(&t); /***/ 65 49 if ( *x > max ) { max = *x; } 66 free(x); 67 ) 68 print( out, "d", max, "\n" ); /***/ 69 70 REPEAT_N_TIMED( "print_int", N/2, 71 print( out, "dsds", rand(), ":", rand(), "\n" ); /***/ 72 ) 73 74 struct stack s2 = new_stack(); 75 REPEAT_TIMED( "push_bool_char", 76 push_stack(&s2, new_pair( new_bool( rand() & 0x1 ), new_char( rand() & 0x7F ) )); 77 ) 78 79 struct stack t2; 80 TIMED( "copy_bool_char", 81 copy_stack(&t2, &s2, copy_pair_bool_char); /***/ 82 ) 83 84 TIMED( "clear_bool_char", 85 clear_stack(&s2, free_pair_bool_char); /***/ 86 ) 50 free(x); ) 51 REPEAT_N_TIMED( "print_int", N/2, print( out, "dsds", _i, ":", _i, "\n" ); /***/ ) 87 52 88 53 struct pair* max2 = new_pair( new_bool(0), new_char('\0') ); 54 struct stack s2 = new_stack(), t2; 55 56 REPEAT_TIMED( "push_bool_char", 57 push_stack(&s2, new_pair( new_bool( _i & 0x1 ), new_char( _i & 0x7F ) )); ) 58 TIMED( "copy_bool_char", copy_stack(&t2, &s2, copy_pair_bool_char); /***/ ) 59 TIMED( "clear_bool_char", clear_stack(&s2, free_pair_bool_char); /***/ ) 89 60 REPEAT_TIMED( "pop_bool_char", 90 61 struct pair* x = pop_stack(&t2); /***/ … … 94 65 } else { 95 66 free_pair_bool_char( x ); /***/ 96 } 97 ) 98 print( out, "pbc", *max2, "\n" ); /***/ 99 free_pair_bool_char( max2 ); /***/ 100 67 } ) 101 68 REPEAT_N_TIMED( "print_pair", N/2, 102 69 struct pair p1 = ((struct pair){ new_bool(rand() & 0x1), new_char(rand() & 0x7F) }); /***/ … … 104 71 print( out, "pbcspbcs", p1, ":", p2, "\n" ); /***/ 105 72 free(p1.first); free(p1.second); /***/ 106 free(p2.first); free(p2.second); /***/ 107 ) 108 73 free(p2.first); free(p2.second); /***/ ) 74 free_pair_bool_char( max2 ); /***/ 109 75 fclose(out); 110 76 } -
doc/generic_types/evaluation/c-print.h
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <stdio.h> 4 3 5 4 void print_string(FILE* out, const char* x); 6 7 5 void print_bool(FILE* out, _Bool x); 8 9 6 void print_char(FILE* out, char x); 10 11 7 void print_int(FILE* out, int x); 12 8 -
doc/generic_types/evaluation/c-stack.c
r308880c ra381b46 7 7 }; 8 8 9 struct stack new_stack() { 10 return (struct stack){ NULL }; /***/ 11 } 9 struct stack new_stack() { return (struct stack){ NULL }; /***/ } 12 10 13 11 void copy_stack(struct stack* s, const struct stack* t, void* (*copy)(const void*)) { … … 34 32 } 35 33 36 _Bool stack_empty(const struct stack* s) { 37 return s->head == NULL; 38 } 34 _Bool stack_empty(const struct stack* s) { return s->head == NULL; } 39 35 40 36 void push_stack(struct stack* s, void* value) { -
doc/generic_types/evaluation/c-stack.h
r308880c ra381b46 2 2 3 3 struct stack_node; 4 5 4 struct stack { 6 5 struct stack_node* head; … … 8 7 9 8 struct stack new_stack(); 10 11 9 void copy_stack(struct stack* dst, const struct stack* src, void* (*copy)(const void*)); 12 13 10 void clear_stack(struct stack* s, void (*free_el)(void*)); 14 11 15 12 _Bool stack_empty(const struct stack* s); 16 17 13 void push_stack(struct stack* s, void* value); 18 19 14 void* pop_stack(struct stack* s); -
doc/generic_types/evaluation/cfa-bench.c
r308880c ra381b46 10 10 int max = 0; 11 11 stack(int) s, t; 12 12 13 REPEAT_TIMED( "push_int", push( &s, _i ); ) 13 14 TIMED( "copy_int", t = s; ) 14 15 TIMED( "clear_int", clear( &s ); ) 15 REPEAT_TIMED( "pop_int", max = max( max, pop( &t ) ); ) 16 REPEAT_TIMED( "pop_int", 17 int x = pop(&t); 18 if ( x > max ) { max = x; } ) 16 19 REPEAT_TIMED( "print_int", print( out, _i, ":", _i, "\n" ); ) 17 20 18 21 stack(pair(_Bool, char)) s1, t1; 19 22 pair(_Bool, char) max = { (_Bool)0, '\0' }; 23 20 24 REPEAT_TIMED( "push_pair", push( &s1, (pair(_Bool, char)){ _i & 1, _i &0x7F } ); ) 21 25 TIMED( "copy_pair", t1 = s1; ) 22 26 TIMED( "clear_pair", clear( &s1 ); ) 23 REPEAT_TIMED( "pop_pair", max = max( max, pop( &t1 ) ); ) 27 REPEAT_TIMED( "pop_pair", 28 pair(_Bool, char) x = pop(&t1); 29 if ( x > max ) { max = x; } ) 24 30 REPEAT_TIMED( "print_pair", 25 print( out, (pair(_Bool, char)){ _i & 1, _i &0x7F }, ":", (pair(_Bool, char)){ _i & 1, _i &0x7F }, "\n" ); ) 31 print( out, (pair(_Bool, char)){ _i & 1, _i &0x7F }, ":", 32 (pair(_Bool, char)){ _i & 1, _i &0x7F }, "\n" ); ) 26 33 fclose(out); 27 34 } -
doc/generic_types/evaluation/cfa-print.h
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <stdio.h> 4 3 #include "pair" … … 8 7 9 8 void print(FILE* out, const char* x); 10 11 9 void print(FILE* out, _Bool x); 12 13 10 void print(FILE* out, char x); 14 15 11 void print(FILE* out, int x); 16 12 -
doc/generic_types/evaluation/cfa-stack.c
r308880c ra381b46 7 7 }; 8 8 9 forall(otype T) void ?{}(stack(T)* s) { 10 (&s->head){ 0 }; 11 } 12 13 forall(otype T) void copy(stack(T)* s, stack(T)* t) { 14 stack_node(T)** crnt = &s->head; 15 stack_node(T)* next = t->head; 16 while ( next ) { 17 *crnt = ((stack_node(T)*)malloc()){ next->value }; /***/ 18 stack_node(T)* acrnt = *crnt; 19 crnt = &acrnt->next; 20 next = next->next; 21 } 22 *crnt = 0; 23 } 9 forall(otype T) void ?{}(stack(T)* s) { (&s->head){ 0 }; } 24 10 25 11 forall(otype T) void ?{}(stack(T)* s, stack(T) t) { … … 42 28 } 43 29 44 forall(otype T) void ^?{}(stack(T)* s) { 45 clear(s); 46 } 30 forall(otype T) void ^?{}(stack(T)* s) { clear(s); } 47 31 48 forall(otype T) _Bool empty(const stack(T)* s) { 49 return s->head == 0; 50 } 32 forall(otype T) _Bool empty(const stack(T)* s) { return s->head == 0; } 51 33 52 34 forall(otype T) void push(stack(T)* s, T value) { -
doc/generic_types/evaluation/cfa-stack.h
r308880c ra381b46 2 2 3 3 forall(otype T) struct stack_node; 4 5 4 forall(otype T) struct stack { 6 5 stack_node(T)* head; … … 8 7 9 8 forall(otype T) void ?{}(stack(T)* s); 10 11 9 forall(otype T) void ?{}(stack(T)* s, stack(T) t); 12 13 10 forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t); 14 15 11 forall(otype T) void ^?{}(stack(T)* s); 16 12 17 13 forall(otype T) _Bool empty(const stack(T)* s); 18 19 14 forall(otype T) void push(stack(T)* s, T value); 20 21 15 forall(otype T) T pop(stack(T)* s); 22 23 16 forall(otype T) void clear(stack(T)* s); -
doc/generic_types/evaluation/cpp-bench.cpp
r308880c ra381b46 8 8 int main(int argc, char** argv) { 9 9 std::ofstream out{"cpp-out.txt"}; 10 int max = 0; 10 11 stack<int> s, t; 11 int max = 0;12 REPEAT_TIMED( "push_int", s.push( _i); )12 13 REPEAT_TIMED( "push_int", s.push( int{_i} ); ) 13 14 TIMED( "copy_int", t = s; ) 14 15 TIMED( "clear_int", s.clear(); ) … … 17 18 REPEAT_N_TIMED( "print_int", N/2, print( out, _i, ":", _i, "\n" ); ) 18 19 20 std::pair<bool, char> max1 = { false, '\0' }; 19 21 stack<std::pair<bool, char>> s1, t1; 20 std::pair<bool, char> max1 = { false, '\0' };22 21 23 REPEAT_TIMED( "push_bool_char", s1.push( std::pair<bool, char>{ _i & 0x1, _i & 0x7F } ); ) 22 24 TIMED( "copy_bool_char", t1 = s1; ) -
doc/generic_types/evaluation/cpp-print.hpp
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <iomanip> 4 3 #include <iostream> 5 4 #include <utility> 6 5 7 template<typename T> 8 void print(std::ostream& out, const T& x) { out << x; } 6 template<typename T> void print(std::ostream& out, const T& x) { out << x; } 9 7 10 template<> 11 void print<bool>(std::ostream& out, const bool& x) { out << (x ? "true" : "false"); } 8 template<> void print<bool>(std::ostream& out, const bool& x) { out << (x ? "true" : "false"); } 12 9 13 template<> 14 void print<char>(std::ostream& out, const char& x ) { 10 template<> void print<char>(std::ostream& out, const char& x ) { 15 11 if ( 0x20 <= x && x <= 0x7E ) { out << "'" << x << "'"; } 16 12 else { out << "'\\" << std::hex << (unsigned int)x << std::setbase(0) << "'"; } 17 13 } 18 14 19 template<typename R, typename S> 15 template<typename R, typename S> 20 16 std::ostream& operator<< (std::ostream& out, const std::pair<R, S>& x) { 21 17 out << "["; … … 26 22 } 27 23 28 template<typename T, typename... Args> 24 template<typename T, typename... Args> 29 25 void print(std::ostream& out, const T& arg, const Args&... rest) { 30 26 out << arg; -
doc/generic_types/evaluation/cpp-stack.hpp
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <utility> 4 3 … … 11 10 node( T&& v, node* n ) : value(std::move(v)), next(n) {} 12 11 }; 13 14 12 node* head; 15 13 … … 24 22 *crnt = nullptr; 25 23 } 26 27 24 public: 28 25 void clear() { … … 37 34 38 35 stack() : head(nullptr) {} 39 40 36 stack(const stack<T>& o) { copy(o); } 41 42 37 stack(stack<T>&& o) : head(o.head) { o.head = nullptr; } 43 44 38 ~stack() { clear(); } 45 39 … … 58 52 } 59 53 60 bool empty() const { 61 return head == nullptr; 62 } 54 bool empty() const { return head == nullptr; } 63 55 64 void push(T&& value) { 65 head = new node{ std::move(value), head }; /***/ 66 } 56 void push(T&& value) { head = new node{ std::move(value), head }; /***/ } 67 57 68 58 T pop() { -
doc/generic_types/evaluation/cpp-vbench.cpp
r308880c ra381b46 8 8 int main(int argc, char** argv) { 9 9 std::ofstream out{"cpp-vout.txt"}; 10 integer max{ 0 }; 10 11 stack s, t; 11 integer max{ 0 };12 12 13 REPEAT_TIMED( "push_int", s.push( make<integer>( _i ) ); ) 13 14 TIMED( "copy_int", t = s; ) … … 18 19 print( out, integer{_i}, c_string{":"}, integer{_i}, c_string{"\n"} ); ) 19 20 21 ptr<pair> max1 = make<pair>( make<boolean>(false), make<character>('\0') ); 20 22 stack s1, t1; 21 ptr<pair> max1 = make<pair>( make<boolean>(false), make<character>('\0') );23 22 24 REPEAT_TIMED( "push_bool_char", 23 25 s1.push( make<pair>( make<boolean>(_i & 1), make<character>(_i & 0x7F) ) ); ) -
doc/generic_types/evaluation/cpp-vprint.hpp
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <ostream> 4 3 #include "object.hpp" … … 6 5 void print(std::ostream& out, const printable& x) { x.print(out); } 7 6 8 template<typename... Args> 9 void print(std::ostream& out, const printable& x, const Args&... rest) { 7 template<typename... Args> void print(std::ostream& out, const printable& x, const Args&... rest) { 10 8 x.print(out); 11 9 print(out, rest...); -
doc/generic_types/evaluation/cpp-vstack.cpp
r308880c ra381b46 1 1 #include "cpp-vstack.hpp" 2 3 2 #include <utility> 4 3 5 4 stack::node::node( const object& v ) : value( v.new_copy() ), next( nullptr ) {} 6 7 5 stack::node::node( ptr<object>&& v, node* n ) : value( std::move(v) ), next( n ) {} 8 6 … … 18 16 } 19 17 20 void stack::clear() {21 node* next = head;22 while ( next ) {23 node* crnt = next;24 next = crnt->next;25 delete crnt;26 }27 head = nullptr;28 }29 30 18 stack::stack() : head(nullptr) {} 31 32 19 stack::stack(const stack& o) { copy(o); } 33 34 20 stack::stack(stack&& o) : head(o.head) { o.head = nullptr; } 35 36 21 stack::~stack() { clear(); } 37 22 … … 50 35 } 51 36 37 void stack::clear() { 38 node* next = head; 39 while ( next ) { 40 node* crnt = next; 41 next = crnt->next; 42 delete crnt; 43 } 44 head = nullptr; 45 } 46 47 52 48 bool stack::empty() const { return head == nullptr; } 53 49 -
doc/generic_types/evaluation/cpp-vstack.hpp
r308880c ra381b46 1 1 #pragma once 2 3 2 #include "object.hpp" 4 3 … … 9 8 10 9 node( const object& v ); 11 12 10 node( ptr<object>&& v, node* n ); 13 11 }; 14 15 12 node* head; 16 13 17 14 void copy(const stack& o); 18 19 15 public: 20 void clear();21 22 16 stack(); 23 24 17 stack(const stack& o); 25 26 18 stack(stack&& o); 27 28 19 ~stack(); 29 30 20 stack& operator= (const stack& o); 31 32 21 stack& operator= (stack&& o); 33 22 23 void clear(); 34 24 bool empty() const; 35 36 25 void push(ptr<object>&& value); 37 38 26 ptr<object> pop(); 39 27 }; -
doc/generic_types/evaluation/object.hpp
r308880c ra381b46 1 1 #pragma once 2 3 2 #include <cstddef> 4 3 #include <exception> … … 16 15 why = std::string{"bad cast of "} + f.name() + " to " + t.name(); 17 16 } 18 19 17 ~bad_cast() override = default; 20 18 … … 22 20 }; 23 21 24 template<typename T> 25 std::type_index class_of() { return { typeid(T) }; } 22 template<typename T> std::type_index class_of() { return { typeid(T) }; } 26 23 27 24 template<typename T> using ptr = std::unique_ptr<T>; 28 25 29 class object { 30 public: 26 struct object { 31 27 std::type_index get_class() const { return { this ? typeid(*this) : typeid(std::nullptr_t) }; } 32 28 33 template<typename T> 34 T& as() { 29 template<typename T> T& as() { 35 30 T* p = dynamic_cast<T*>(this); 36 31 if ( !p ) throw bad_cast{ get_class(), class_of<T>() }; … … 38 33 } 39 34 40 template<typename T> 41 const T& as() const { 35 template<typename T> const T& as() const { 42 36 const T* p = dynamic_cast<const T*>(this); 43 37 if ( !p ) throw bad_cast{ get_class(), class_of<T>() }; … … 46 40 47 41 virtual ptr<object> new_inst() const = 0; 48 49 42 virtual ptr<object> new_copy() const = 0; 50 51 43 virtual object& operator= (const object&) = 0; 52 53 44 virtual ~object() = default; 54 45 }; 55 46 56 template<typename T, typename... Args> 57 static inline ptr<T> make(Args&&... args) { return std::make_unique<T>(std::forward<Args>(args)...); } 47 template<typename T, typename... Args> static inline ptr<T> make(Args&&... args) { 48 return std::make_unique<T>(std::forward<Args>(args)...); 49 } 58 50 59 template<typename To, typename From> 51 template<typename To, typename From> 60 52 ptr<To> as_ptr( ptr<From>&& p ) { return ptr<To>{ &p.release()->template as<To>() }; } 61 53 62 class ordered : public virtual object { 63 public: 54 struct ordered : public virtual object { 64 55 virtual int cmp(const ordered&) const = 0; 65 56 66 57 bool operator< (const ordered& that) const { return cmp(that) < 0; } 67 68 58 bool operator<= ( const ordered& that ) const { return cmp(that) <= 0; } 69 70 59 bool operator== ( const ordered& that ) const { return cmp(that) == 0; } 71 72 60 bool operator!= ( const ordered& that ) const { return cmp(that) != 0; } 73 74 61 bool operator> ( const ordered& that ) const { return cmp(that) > 0; } 75 76 62 bool operator>= ( const ordered& that ) const { return cmp(that) >= 0; } 77 63 }; 78 64 79 class printable : public virtual object { 80 public: 65 struct printable : public virtual object { 81 66 virtual void print(std::ostream&) const = 0; 82 67 }; … … 84 69 class boolean : public ordered, public printable { 85 70 bool x; 86 87 71 public: 88 72 boolean() = default; 89 90 73 boolean(bool x) : x(x) {} 91 92 74 ptr<object> new_inst() const override { return make<boolean>(); } 93 94 75 ptr<object> new_copy() const override { return make<boolean>(*this); } 95 96 76 boolean& operator= (const boolean& that) { 97 77 x = that.x; 98 78 return *this; 99 79 } 100 101 80 object& operator= (const object& that) override { return *this = that.as<boolean>(); } /***/ 102 103 81 ~boolean() override = default; 104 82 105 83 int cmp(const boolean& that) const { return x == that.x ? 0 : x == false ? -1 : 1; } 106 107 84 int cmp(const ordered& that) const override { return cmp( that.as<boolean>() ); } /***/ 108 85 … … 112 89 class character : public ordered, public printable { 113 90 char x; 114 115 91 public: 116 92 character() = default; 117 118 93 character(char x) : x(x) {} 119 120 94 ptr<object> new_inst() const override { return make<character>(); } 121 122 95 ptr<object> new_copy() const override { return make<character>(*this); } 123 124 96 character& operator= (const character& that) { 125 97 x = that.x; 126 98 return *this; 127 99 } 128 129 100 object& operator= (const object& that) override { return *this = that.as<character>(); } /***/ 130 131 101 ~character() override = default; 132 102 133 103 int cmp(const character& that) const { return x == that.x ? 0 : x < that.x ? -1 : 1; } 134 135 104 int cmp(const ordered& that) const override { return cmp( that.as<character>() ); } /***/ 136 105 … … 143 112 class integer : public ordered, public printable { 144 113 int x; 145 146 114 public: 147 115 integer() = default; 148 149 116 integer(int x) : x(x) {} 150 151 117 ptr<object> new_inst() const override { return make<integer>(); } 152 153 118 ptr<object> new_copy() const override { return make<integer>(*this); } 154 155 119 integer& operator= (const integer& that) { 156 120 x = that.x; 157 121 return *this; 158 122 } 159 160 123 object& operator= (const object& that) override { return *this = that.as<integer>(); } /***/ 161 162 124 ~integer() override = default; 163 125 164 126 int cmp(const integer& that) const { return x == that.x ? 0 : x < that.x ? -1 : 1; } 165 166 127 int cmp(const ordered& that) const override { return cmp( that.as<integer>() ); } /***/ 167 128 … … 174 135 public: 175 136 c_string() : s(empty) {} 176 177 137 c_string(const char* s) : s(s) {} 178 179 138 ptr<object> new_inst() const override { return make<c_string>(); } 180 181 139 ptr<object> new_copy() const override { return make<c_string>(s); } 182 183 140 c_string& operator= (const c_string& that) { 184 141 s = that.s; 185 142 return *this; 186 143 } 187 188 144 object& operator= (const object& that) override { return *this = that.as<c_string>(); } /***/ 189 190 145 ~c_string() override = default; 191 146 … … 196 151 ptr<object> x; 197 152 ptr<object> y; 198 199 153 public: 200 154 pair() = default; 201 202 155 pair(ptr<object>&& x, ptr<object>&& y) : x(std::move(x)), y(std::move(y)) {} 203 204 156 ptr<object> new_inst() const override { return make<pair>(); } 205 206 ptr<object> new_copy() const override { 207 return make<pair>(x->new_copy(), y->new_copy()); 208 } 209 157 ptr<object> new_copy() const override { return make<pair>(x->new_copy(), y->new_copy()); } 210 158 pair& operator= (const pair& that) { 211 159 x = that.x->new_copy(); … … 213 161 return *this; 214 162 } 215 216 163 object& operator= (const object& that) override { return *this = that.as<pair>(); } /***/ 217 218 164 ~pair() override = default; 219 165 … … 223 169 return y->as<ordered>().cmp( that.y->as<ordered>() ); /***/ 224 170 } 225 226 171 int cmp(const ordered& that) const override { return cmp( that.as<pair>() ); } 227 172 -
doc/generic_types/evaluation/timing.gp
r308880c ra381b46 1 1 # set terminal pdfcairo linewidth 3 size 6,3 2 # set terminal postscript eps linewidth 3 size 6,32 # set output "timing.pdf" 3 3 set terminal pslatex size 6.25,2.25 color solid 4 4 set output "timing.tex" … … 20 20 set linetype 4 lc rgb 'green' 21 21 22 set ylabel "milli -seconds"22 set ylabel "milliseconds" 23 23 set yrange [0:*] ; 24 24 25 set datafile separator ","26 plot for [COL=2:5] 'evaluation/timing. csv' using COL:xticlabels(1) title columnheader25 # set datafile separator "," 26 plot for [COL=2:5] 'evaluation/timing.dat' using COL:xticlabels(1) title columnheader
Note:
See TracChangeset
for help on using the changeset viewer.