- Timestamp:
- Jan 19, 2021, 8:44:29 PM (2 years ago)
- Branches:
- arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- dafbde8
- Parents:
- 2f47ea4
- Location:
- tests
- Files:
-
- 81 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/avltree/avl-private.cfa
r2f47ea4 rfd54fef 11 11 // an AVL tree's height is easy to compute 12 12 // just follow path with the larger balance 13 forall( otype K | Comparable(K), otypeV)13 forall(K | Comparable(K), V) 14 14 int height(tree(K, V) * t){ 15 15 int helper(tree(K, V) * t, int ht){ … … 27 27 } 28 28 29 forall( otype K | Comparable(K), otypeV)29 forall(K | Comparable(K), V) 30 30 int calcBalance(tree(K, V) * t){ 31 31 int l = height(t->left); … … 36 36 37 37 // re-establish the link between parent and child 38 forall( otype K | Comparable(K), otypeV)38 forall(K | Comparable(K), V) 39 39 void relinkToParent(tree(K, V) * t){ 40 40 tree(K, V) * parent = t->parent; // FIX ME!! … … 49 49 50 50 // rotate left from t 51 forall( otype K | Comparable(K), otypeV)51 forall(K | Comparable(K), V) 52 52 tree(K, V) * rotateLeft(tree(K, V) * t){ 53 53 tree(K, V) * newRoot = t->right; … … 68 68 69 69 // rotate right from t 70 forall( otype K | Comparable(K), otypeV)70 forall(K | Comparable(K), V) 71 71 tree(K, V) * rotateRight(tree(K, V) * t){ 72 72 tree(K, V) * newRoot = t->left; … … 87 87 88 88 // balances a node that has balance factor -2 or 2 89 forall( otype K | Comparable(K), otypeV)89 forall(K | Comparable(K), V) 90 90 tree(K, V) * fix(tree(K, V) * t){ 91 91 // ensure that t's balance factor is one of … … 113 113 114 114 // attempt to fix the tree, if necessary 115 forall( otype K | Comparable(K), otypeV)115 forall(K | Comparable(K), V) 116 116 tree(K, V) * tryFix(tree(K, V) * t){ 117 117 int b = calcBalance(t); … … 126 126 127 127 // sets parent field of c to be p 128 forall( otype K | Comparable(K), otypeV)128 forall(K | Comparable(K), V) 129 129 void setParent(tree(K, V) * c, tree(K, V) * p){ 130 130 if (! empty(c)){ -
tests/avltree/avl-private.h
r2f47ea4 rfd54fef 5 5 6 6 // attempt to fix the tree, if necessary 7 forall( otype K | Comparable(K), otypeV)7 forall(K | Comparable(K), V) 8 8 tree(K, V) * tryFix(tree(K, V) * t); 9 9 10 10 // sets parent field of c to be p 11 forall( otype K | Comparable(K), otypeV)11 forall(K | Comparable(K), V) 12 12 void setParent(tree(K, V) * c, tree(K, V) * p); 13 13 14 forall( otype K | Comparable(K), otypeV)14 forall(K | Comparable(K), V) 15 15 int height(tree(K, V) * t); -
tests/avltree/avl.h
r2f47ea4 rfd54fef 9 9 // #include <lib.h> 10 10 11 trait Comparable( otypeT) {11 trait Comparable(T) { 12 12 int ?<?(T, T); 13 13 }; 14 14 15 forall( otypeT | Comparable(T))15 forall(T | Comparable(T)) 16 16 int ?==?(T t1, T t2); 17 17 18 forall( otypeT | Comparable(T))18 forall(T | Comparable(T)) 19 19 int ?>?(T t1, T t2); 20 20 … … 41 41 42 42 // temporary: need forward decl to get around typedef problem 43 forall( otype K | Comparable(K), otypeV)43 forall(K | Comparable(K), V) 44 44 struct tree; 45 45 46 forall( otype K | Comparable(K), otypeV)46 forall(K | Comparable(K), V) 47 47 struct tree { 48 48 K key; … … 54 54 }; 55 55 56 forall( otype K | Comparable(K), otypeV)56 forall(K | Comparable(K), V) 57 57 void ?{}(tree(K, V) &t, K key, V value); 58 58 59 forall( otype K | Comparable(K), otypeV)59 forall(K | Comparable(K), V) 60 60 void ^?{}(tree(K, V) & t); 61 61 62 forall( otype K | Comparable(K), otypeV)62 forall(K | Comparable(K), V) 63 63 tree(K, V) * create(K key, V value); 64 64 65 forall( otype K | Comparable(K), otypeV)65 forall(K | Comparable(K), V) 66 66 V * find(tree(K, V) * t, K key); 67 67 68 forall( otype K | Comparable(K), otypeV)68 forall(K | Comparable(K), V) 69 69 int empty(tree(K, V) * t); 70 70 71 71 // returns the root of the tree 72 forall( otype K | Comparable(K), otypeV)72 forall(K | Comparable(K), V) 73 73 int insert(tree(K, V) ** t, K key, V value); 74 74 75 forall( otype K | Comparable(K), otypeV)75 forall(K | Comparable(K), V) 76 76 int remove(tree(K, V) ** t, K key); 77 77 78 forall( otype K | Comparable(K), otypeV)78 forall(K | Comparable(K), V) 79 79 void copy(tree(K, V) * src, tree(K, V) ** ret); 80 80 81 forall( otype K | Comparable(K), otypeV)81 forall(K | Comparable(K), V) 82 82 void for_each(tree(K, V) * t, void (*func)(V)); 83 83 -
tests/avltree/avl0.cfa
r2f47ea4 rfd54fef 1 1 #include "avl.h" 2 2 3 forall( otypeT | Comparable(T))3 forall(T | Comparable(T)) 4 4 int ?==?(T t1, T t2) { 5 5 return !(t1 < t2) && !(t2 < t1); 6 6 } 7 7 8 forall( otypeT | Comparable(T))8 forall(T | Comparable(T)) 9 9 int ?>?(T t1, T t2) { 10 10 return t2 < t1; -
tests/avltree/avl1.cfa
r2f47ea4 rfd54fef 3 3 #include <stdlib.hfa> 4 4 5 forall( otype K | Comparable(K), otypeV)5 forall(K | Comparable(K), V) 6 6 void ?{}(tree(K, V) &t, K key, V value){ 7 7 (t.key) { key }; … … 13 13 } 14 14 15 forall( otype K| Comparable(K), otypeV)15 forall(K| Comparable(K), V) 16 16 void ^?{}(tree(K, V) & t){ 17 17 delete(t.left); … … 21 21 } 22 22 23 forall( otype K | Comparable(K), otypeV)23 forall(K | Comparable(K), V) 24 24 tree(K, V) * create(K key, V value) { 25 25 // infinite loop trying to resolve ... t = malloc(); -
tests/avltree/avl2.cfa
r2f47ea4 rfd54fef 2 2 #include "avl-private.h" 3 3 4 forall( otype K | Comparable(K), otypeV)4 forall(K | Comparable(K), V) 5 5 V * find(tree(K, V) * t, K key){ 6 6 if (empty(t)){ … … 18 18 } 19 19 20 forall( otype K | Comparable(K), otypeV)20 forall(K | Comparable(K), V) 21 21 int empty(tree(K, V) * t){ 22 22 return t == NULL; … … 24 24 25 25 // returns the root of the tree 26 forall( otype K | Comparable(K), otypeV)26 forall(K | Comparable(K), V) 27 27 int insert(tree(K, V) ** t, K key, V value) { 28 28 // handles a non-empty tree -
tests/avltree/avl3.cfa
r2f47ea4 rfd54fef 4 4 5 5 // swaps the data within two tree nodes 6 forall( otype K | Comparable(K), otypeV)6 forall(K | Comparable(K), V) 7 7 void node_swap(tree(K, V) * t, tree(K, V) * t2){ 8 8 swap( t->key, t2->key); … … 11 11 12 12 // go left as deep as possible from within the right subtree 13 forall( otype K | Comparable(K), otypeV)13 forall(K | Comparable(K), V) 14 14 tree(K, V) * find_successor(tree(K, V) * t){ 15 15 tree(K, V) * find_successor_helper(tree(K, V) * t){ … … 25 25 26 26 // cleanup - don't want to deep delete, so set children to NULL first. 27 forall( otype K | Comparable(K), otypeV)27 forall(K | Comparable(K), V) 28 28 void deleteSingleNode(tree(K, V) * t) { 29 29 t->left = NULL; … … 33 33 34 34 // does the actual remove operation once we've found the node in question 35 forall( otype K | Comparable(K), otypeV)35 forall(K | Comparable(K), V) 36 36 tree(K, V) * remove_node(tree(K, V) * t){ 37 37 // is the node a leaf? … … 85 85 86 86 // finds the node that needs to be removed 87 forall( otype K | Comparable(K), otypeV)87 forall(K | Comparable(K), V) 88 88 tree(K, V) * remove_helper(tree(K, V) * t, K key, int * worked){ 89 89 if (empty(t)){ … … 106 106 } 107 107 108 forall( otype K | Comparable(K), otypeV)108 forall(K | Comparable(K), V) 109 109 int remove(tree(K, V) ** t, K key){ 110 110 int worked = 0; -
tests/avltree/avl4.cfa
r2f47ea4 rfd54fef 4 4 // Perform a shallow copy of src, return the 5 5 // new tree in ret 6 forall( otype K | Comparable(K), otypeV)6 forall(K | Comparable(K), V) 7 7 int copy(tree(K, V) * src, tree(K, V) ** ret){ 8 8 tree(K, V) * helper(tree(K, V) * t, int * worked){ … … 35 35 36 36 // Apply func to every value element in t, using an in order traversal 37 forall( otype K | Comparable(K), otypeV)37 forall(K | Comparable(K), V) 38 38 void for_each(tree(K, V) * t, int (*func)(V)) { 39 39 if (t == NULL) { -
tests/bugs/10.cfa
r2f47ea4 rfd54fef 2 2 // https://cforall.uwaterloo.ca/trac/ticket/10 3 3 4 forall( otypeT)4 forall(T) 5 5 struct result { 6 6 union { -
tests/bugs/104.cfa
r2f47ea4 rfd54fef 4 4 [ float, float ] modf_( float x ); 5 5 6 forall( otypeT | { [T, T] modf_(T); })6 forall(T | { [T, T] modf_(T); }) 7 7 void modf(T); 8 8 -
tests/bugs/194.cfa
r2f47ea4 rfd54fef 2 2 // https://cforall.uwaterloo.ca/trac/ticket/194 3 3 4 forall( dtype T| sized(T) ) T * foo( void ) {4 forall( T & | sized(T) ) T * foo( void ) { 5 5 printf( "foo1\n" ); 6 6 return (T *)0; 7 7 } 8 forall( dtype T| sized(T) ) T & foo( void ) {8 forall( T & | sized(T) ) T & foo( void ) { 9 9 printf( "foo2\n" ); 10 10 return (T &)*(T *)0; -
tests/bugs/196.cfa
r2f47ea4 rfd54fef 2 2 // https://cforall.uwaterloo.ca/trac/ticket/196 3 3 4 forall( dtype T)4 forall(T &) 5 5 struct link; 6 6 7 forall( dtype T)7 forall(T &) 8 8 struct link { 9 9 link(T) * next; … … 12 12 // ----- 13 13 14 forall( dtype T)14 forall(T &) 15 15 struct foo; 16 16 17 forall( dtype U)17 forall(U &) 18 18 struct bar { 19 19 foo(U) * data; 20 20 }; 21 21 22 forall( dtype T)22 forall(T &) 23 23 struct foo {}; 24 24 -
tests/bugs/203-2.cfa
r2f47ea4 rfd54fef 1 1 // Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203 2 2 3 forall( dtype A)3 forall(A &) 4 4 struct empty { 5 5 // Nothing. 6 6 }; 7 7 8 forall( dtype C)8 forall(C &) 9 9 struct wrap_e { 10 10 empty(C) field; -
tests/bugs/203-7.cfa
r2f47ea4 rfd54fef 1 1 // Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203 2 2 3 forall( dtype A)3 forall(A &) 4 4 struct empty { 5 5 // Nothing. 6 6 }; 7 7 8 forall( dtype C)8 forall(C &) 9 9 struct wrap_e { 10 10 empty(C) field; -
tests/bugs/203-9.cfa
r2f47ea4 rfd54fef 1 1 // Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203 2 2 3 forall( dtype A)3 forall(A &) 4 4 struct empty { 5 5 // Nothing. 6 6 }; 7 7 8 forall( dtype C)8 forall(C &) 9 9 struct wrap_e { 10 10 empty(C) field; -
tests/bugs/7.cfa
r2f47ea4 rfd54fef 8 8 9 9 // (Bug 1 unresolved as of this test.) 10 forall( otypeT)10 forall(T) 11 11 struct stack_node; 12 12 13 forall( otypeT)13 forall(T) 14 14 struct stack_node { 15 15 stack_node(T) * next; … … 17 17 }; 18 18 19 forall( otypeT)19 forall(T) 20 20 struct stack { 21 21 stack_node(T) * head; 22 22 }; 23 23 24 trait stack_errors( otypeT) {24 trait stack_errors(T) { 25 25 T emptyStackHandler (stack(T) * this); 26 26 }; 27 27 28 forall( otypeT | stack_errors(T))28 forall(T | stack_errors(T)) 29 29 T pop (stack(T) * this) { 30 30 return (T){}; -
tests/castError.cfa
r2f47ea4 rfd54fef 14 14 // 15 15 16 forall( otypeT) struct S { T p; };16 forall(T) struct S { T p; }; 17 17 int f; 18 18 S(int) sint; -
tests/concurrent/examples/boundedBufferEXT.cfa
r2f47ea4 rfd54fef 24 24 enum { BufferSize = 50 }; 25 25 26 forall( otypeT ) {26 forall( T ) { 27 27 monitor Buffer { 28 28 int front, back, count; -
tests/concurrent/examples/boundedBufferINT.cfa
r2f47ea4 rfd54fef 24 24 enum { BufferSize = 50 }; 25 25 26 forall( otypeT ) {26 forall( T ) { 27 27 monitor Buffer { 28 28 condition full, empty; -
tests/concurrent/examples/quickSort.generic.cfa
r2f47ea4 rfd54fef 21 21 #include <string.h> // strcmp 22 22 23 forall( otypeT | { int ?<?( T, T ); } ) {23 forall( T | { int ?<?( T, T ); } ) { 24 24 thread Quicksort { 25 25 T * values; // communication variables -
tests/concurrent/multi-monitor.cfa
r2f47ea4 rfd54fef 38 38 } 39 39 40 forall( dtype T| sized(T) | { void ^?{}(T & mutex); })40 forall(T & | sized(T) | { void ^?{}(T & mutex); }) 41 41 void delete_mutex(T * x) { 42 42 ^(*x){}; -
tests/errors/completeType.cfa
r2f47ea4 rfd54fef 1 1 void foo(int *) {} 2 2 void bar(void *) {} 3 forall( otypeT) void baz(T *);4 forall( dtype T) void qux(T *);5 forall( dtype T| sized(T)) void quux(T *);3 forall(T) void baz(T *); 4 forall(T &) void qux(T *); 5 forall(T & | sized(T)) void quux(T *); 6 6 7 7 struct A; // incomplete … … 39 39 40 40 41 forall( otypeT)41 forall(T) 42 42 void baz(T * x) { 43 43 // okay … … 49 49 } 50 50 51 forall( dtype T)51 forall(T &) 52 52 void qux(T * y) { 53 53 // okay … … 61 61 } 62 62 63 forall( dtype T| sized(T))63 forall(T & | sized(T)) 64 64 void quux(T * z) { 65 65 // okay -
tests/exceptions/defaults.cfa
r2f47ea4 rfd54fef 55 55 56 56 void unhandled_test(void) { 57 forall( dtype T, dtype V| is_exception(T, V))57 forall(T &, V & | is_exception(T, V)) 58 58 void defaultTerminationHandler(T &) { 59 59 throw (unhandled_exception){}; -
tests/exceptions/polymorphic.cfa
r2f47ea4 rfd54fef 3 3 #include <exception.hfa> 4 4 5 FORALL_TRIVIAL_EXCEPTION(proxy, ( otypeT), (T));6 FORALL_TRIVIAL_INSTANCE(proxy, ( otypeU), (U))5 FORALL_TRIVIAL_EXCEPTION(proxy, (T), (T)); 6 FORALL_TRIVIAL_INSTANCE(proxy, (U), (U)) 7 7 8 8 const char * msg(proxy(int) * this) { return "proxy(int)"; } … … 33 33 } 34 34 35 FORALL_DATA_EXCEPTION(cell, ( otypeT), (T))(35 FORALL_DATA_EXCEPTION(cell, (T), (T))( 36 36 T data; 37 37 ); 38 38 39 FORALL_DATA_INSTANCE(cell, ( otypeT), (T))39 FORALL_DATA_INSTANCE(cell, (T), (T)) 40 40 41 41 const char * msg(cell(int) * this) { return "cell(int)"; } -
tests/exceptions/virtual-poly.cfa
r2f47ea4 rfd54fef 16 16 }; 17 17 18 forall( otypeT)18 forall(T) 19 19 struct mono_child_vtable { 20 20 mono_base_vtable const * const parent; 21 21 }; 22 22 23 forall( otypeT)23 forall(T) 24 24 struct mono_child { 25 25 mono_child_vtable(T) const * virtual_table; … … 37 37 } 38 38 39 forall( otypeU)39 forall(U) 40 40 struct poly_base_vtable { 41 41 poly_base_vtable(U) const * const parent; 42 42 }; 43 43 44 forall( otypeU)44 forall(U) 45 45 struct poly_base { 46 46 poly_base_vtable(U) const * virtual_table; 47 47 }; 48 48 49 forall( otypeV)49 forall(V) 50 50 struct poly_child_vtable { 51 51 poly_base_vtable(V) const * const parent; 52 52 }; 53 53 54 forall( otypeV)54 forall(V) 55 55 struct poly_child { 56 56 poly_child_vtable(V) const * virtual_table; -
tests/forall.cfa
r2f47ea4 rfd54fef 15 15 16 16 void g1() { 17 forall( otypeT ) T f( T ) {};17 forall( T ) T f( T ) {}; 18 18 void f( int ) {}; 19 19 void h( void (*p)(void) ) {}; … … 32 32 33 33 void g2() { 34 forall( otypeT ) void f( T, T ) {}35 forall( otype T, otypeU ) void f( T, U ) {}34 forall( T ) void f( T, T ) {} 35 forall( T, U ) void f( T, U ) {} 36 36 37 37 int x; … … 45 45 } 46 46 47 typedef forall ( otypeT ) int (* f)( int );48 49 forall( otypeT )47 typedef forall ( T ) int (* f)( int ); 48 49 forall( T ) 50 50 void swap( T left, T right ) { 51 51 T temp = left; … … 54 54 } 55 55 56 trait sumable( otypeT ) {56 trait sumable( T ) { 57 57 void ?{}( T &, zero_t ); // 0 literal constructor 58 58 T ?+?( T, T ); // assortment of additions … … 62 62 }; // sumable 63 63 64 forall( otypeT | sumable( T ) ) // use trait64 forall( T | sumable( T ) ) // use trait 65 65 T sum( size_t size, T a[] ) { 66 66 T total = 0; // initialize by 0 constructor … … 70 70 } // sum 71 71 72 forall( otypeT | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )72 forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } ) 73 73 T twice( T t ) { 74 74 return t + t; 75 75 } 76 76 77 forall( otypeT | { int ?<?(T, T); } )77 forall( T | { int ?<?(T, T); } ) 78 78 T min( T t1, T t2 ) { 79 79 return t1 < t2 ? t1 : t2; … … 91 91 92 92 // Multiple forall 93 forall( otype T ) forall( otypeS ) struct { int i; };94 forall( otype T ) struct { int i; } forall( otypeS );95 struct { int i; } forall( otype T ) forall( otypeS );96 forall( otype W ) struct { int i; } forall( otype T ) forall( otypeS );93 forall( T ) forall( S ) struct { int i; }; 94 forall( T ) struct { int i; } forall( S ); 95 struct { int i; } forall( T ) forall( S ); 96 forall( W ) struct { int i; } forall( T ) forall( S ); 97 97 98 98 // Distribution 99 99 struct P { int i; }; 100 forall( otypeT ) struct Q { T i; };101 forall( otypeT ) struct { int i; };100 forall( T ) struct Q { T i; }; 101 forall( T ) struct { int i; }; 102 102 struct KK { int i; }; 103 103 inline static { 104 104 void RT1() {} 105 105 } 106 forall( otypeT ) {106 forall( T ) { 107 107 T RT2( T ) { 108 108 typedef int TD1; 109 109 struct S1 { T t; }; 110 110 } 111 forall( otypeX ) {111 forall( X ) { 112 112 typedef int TD2; 113 113 struct S2 {}; … … 117 117 } 118 118 extern "C" { 119 forall( otypeW ) {119 forall( W ) { 120 120 W RT3( W ) {} 121 121 struct S3 {}; … … 123 123 } 124 124 void RT4() { 125 forall( otypeW ) struct S4 {};125 forall( W ) struct S4 {}; 126 126 typedef int TD3; 127 127 } … … 147 147 148 148 static inline { 149 forall( otypeT ) {149 forall( T ) { 150 150 int RT6( T p ); 151 151 } 152 forall( otype T, otypeU ) {152 forall( T, U ) { 153 153 int RT7( T, U ); 154 154 } 155 155 } 156 static forall( otypeT ) {156 static forall( T ) { 157 157 int RT8( T ); 158 158 } 159 forall( otypeT ) inline static {159 forall( T ) inline static { 160 160 int RT9( T ) { T t; return 3; } 161 161 } 162 162 163 forall( otypeT | { T ?+?( T, T ); } ) {164 forall( otypeS | { T ?+?( T, S ); } ) {165 forall( otypeW ) T bar( T t, S s ) { return t + s; }166 forall( otypeW | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }163 forall( T | { T ?+?( T, T ); } ) { 164 forall( S | { T ?+?( T, S ); } ) { 165 forall( W ) T bar( T t, S s ) { return t + s; } 166 forall( W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; } 167 167 struct W { T t; } (int,int) ww; 168 168 struct P pp; … … 170 170 } 171 171 172 forall( otype T | { T ?+?( T, T ); } ) forall( otypeS | { T ?+?( T, S ); } )172 forall( T | { T ?+?( T, T ); } ) forall( S | { T ?+?( T, S ); } ) 173 173 struct XW { T t; }; 174 174 XW(int,int) xww; 175 175 176 forall( otypeT ) struct S { T t; } (int) x, y, z;177 forall( otypeT ) struct { T t; } (int) a, b, c;178 179 forall( otype T ) static forall( otypeS ) {180 forall( otypeX ) struct U {176 forall( T ) struct S { T t; } (int) x, y, z; 177 forall( T ) struct { T t; } (int) a, b, c; 178 179 forall( T ) static forall( S ) { 180 forall( X ) struct U { 181 181 T x; 182 182 }; 183 183 } 184 184 185 forall( otypeT ) {185 forall( T ) { 186 186 extern "C" { 187 187 struct SS { T t; }; -
tests/function-operator.cfa
r2f47ea4 rfd54fef 22 22 23 23 // STL-like Algorithms 24 trait Assignable( dtype T, dtype U) { T ?=?(T &, U); };25 trait Copyable( dtype T) { void ?{}(T &, T); };26 trait Destructable( dtype T) { void ^?{}(T &); };24 trait Assignable(T &, U &) { T ?=?(T &, U); }; 25 trait Copyable(T &) { void ?{}(T &, T); }; 26 trait Destructable(T &) { void ^?{}(T &); }; 27 27 28 trait Iterator( dtype iter | sized(iter) | Copyable(iter) | Destructable(iter), otypeT) {28 trait Iterator(iter & | sized(iter) | Copyable(iter) | Destructable(iter), T) { 29 29 T & *?(iter); 30 30 iter ++?(iter &); … … 32 32 }; 33 33 34 forall( otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output| Iterator(Output, Tout) | Assignable(Tout, Tin))34 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout) | Assignable(Tout, Tin)) 35 35 Output copy(Input first, Input last, Output result) { 36 36 while (first != last) { … … 42 42 43 43 // test ?()(T *, ...) -- ?() with function call-by-pointer 44 forall( otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout), otype FuncRet, dtype Func| { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet))44 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout), FuncRet, Func & | { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet)) 45 45 Output transform (Input first, Input last, Output result, Func * op) { 46 46 while (first != last) { … … 52 52 53 53 // test ?()(T, ...) -- ?() with function call-by-value 54 forall( dtype Iter, otype T | Iterator(Iter, T), otypePred | { int ?()(Pred, T); })54 forall(Iter &, T | Iterator(Iter, T), Pred | { int ?()(Pred, T); }) 55 55 Iter find_if (Iter first, Iter last, Pred pred) { 56 56 while (first != last) { … … 62 62 63 63 // test ?()(T, ...) -- ?() with function call-by-reference 64 forall( otype Generator, otype GenRet | { GenRet ?()(Generator &); }, dtype Iter, otypeT | Iterator(Iter, T) | Assignable(T, GenRet))64 forall(Generator, GenRet | { GenRet ?()(Generator &); }, Iter &, T | Iterator(Iter, T) | Assignable(T, GenRet)) 65 65 void generate(Iter first, Iter last, Generator & gen) { 66 66 int i = 0; … … 108 108 } 109 109 110 forall( otypeT | { int ?==?(T, T); })110 forall(T | { int ?==?(T, T); }) 111 111 struct Equals { 112 112 T val; 113 113 }; 114 114 115 forall( otypeT | { int ?==?(T, T); })115 forall(T | { int ?==?(T, T); }) 116 116 int ?()(Equals(T) eq, T x) { 117 117 return eq.val == x; 118 118 } 119 119 120 forall( otypeT | { T ?*?(T, T); })120 forall(T | { T ?*?(T, T); }) 121 121 struct Multiply { 122 122 T val; 123 123 }; 124 124 125 forall( otypeT | { T ?*?(T, T); })125 forall(T | { T ?*?(T, T); }) 126 126 T ?()(Multiply(T) * mult, T x) { 127 127 return mult->val * x; … … 130 130 // TODO: generalize to ttype return; doesn't work yet 131 131 // like std::function 132 forall( otype Return, ttype Args)132 forall(Return, Args...) 133 133 struct function { 134 134 Return (*f)(Args); -
tests/genericUnion.cfa
r2f47ea4 rfd54fef 16 16 #include <limits.hfa> 17 17 18 forall( otypeT)18 forall(T) 19 19 union ByteView { 20 20 T val; … … 22 22 }; 23 23 24 forall( otypeT)24 forall(T) 25 25 void print(ByteView(T) x) { 26 26 for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T) … … 29 29 } 30 30 31 forall( otypeT)31 forall(T) 32 32 void f(ByteView(T) x, T val) { 33 33 print(x); -
tests/global-monomorph.cfa
r2f47ea4 rfd54fef 1 1 // Create monomorphic instances of polymorphic types at global scope. 2 2 3 forall( dtype T)3 forall(T &) 4 4 void poly0(T &) {} 5 5 6 forall( dtype T| sized(T))6 forall(T & | sized(T)) 7 7 void poly1(T &) {} 8 8 9 forall( otypeT)9 forall(T) 10 10 void poly2(T &) {} 11 11 -
tests/identity.cfa
r2f47ea4 rfd54fef 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT )18 forall( T ) 19 19 T identity( T t ) { 20 20 return t; -
tests/init1.cfa
r2f47ea4 rfd54fef 120 120 } 121 121 122 forall ( dtype T, dtype S)122 forall (T &, S &) 123 123 T & anycvt( S & s ) { 124 124 return s; // mismatched referenced type 125 125 } 126 126 127 forall ( dtype T, dtype S)127 forall (T &, S &) 128 128 T * anycvt( S * s ) { 129 129 return s; // mismatched referenced type -
tests/nested-types.cfa
r2f47ea4 rfd54fef 16 16 typedef int N; 17 17 struct A { 18 forall( otypeT)18 forall(T) 19 19 struct N { 20 20 T x; -
tests/poly-d-cycle.cfa
r2f47ea4 rfd54fef 1 1 // Check that a cycle of polymorphic dtype structures can be instancated. 2 2 3 forall( dtype T)3 forall(T &) 4 4 struct func_table; 5 5 6 forall( dtype U)6 forall(U &) 7 7 struct object { 8 8 func_table(U) * virtual_table; 9 9 }; 10 10 11 forall( dtype T)11 forall(T &) 12 12 struct func_table { 13 13 void (*object_func)(object(T) *); -
tests/poly-o-cycle.cfa
r2f47ea4 rfd54fef 1 1 // Check that a cycle of polymorphic otype structures can be instancated. 2 2 3 forall( otypeT)3 forall(T) 4 4 struct func_table; 5 5 6 forall( otypeU)6 forall(U) 7 7 struct object { 8 8 func_table(U) * virtual_table; 9 9 }; 10 10 11 forall( otypeT)11 forall(T) 12 12 struct func_table { 13 13 void (*object_func)(object(T) *); -
tests/poly-selection.cfa
r2f47ea4 rfd54fef 16 16 17 17 void testSpecializationFromGenericOverBareTyvar() { 18 forall( dtype T)18 forall( T & ) 19 19 void friend( T & ) { 20 20 printf("friending generically\n"); 21 21 } 22 22 23 forall( dtype T)23 forall(T &) 24 24 struct thing { 25 25 int x; 26 26 }; 27 27 28 forall( dtype T)28 forall( T & ) 29 29 void friend( thing(T) & ) { 30 30 printf("friending specifically\n"); … … 37 37 void testSpecializationFromGenericAccessibleWithExtraTyvars() { 38 38 39 forall( dtype T, dtype U)39 forall( T &, U & ) 40 40 struct map {}; 41 41 42 forall( dtype T)42 forall( T & ) 43 43 void f( T & ) { 44 44 printf("f-generic\n"); 45 45 } 46 46 47 forall( dtype T)47 forall( T & ) 48 48 void f( map(T, T) & ) { 49 49 printf("f-specific\n"); -
tests/polymorphism.cfa
r2f47ea4 rfd54fef 18 18 #include <fstream.hfa> 19 19 20 forall( otypeT)20 forall(T) 21 21 T f(T x, T y) { 22 22 x = y; … … 24 24 } 25 25 26 forall( otypeT) T ident(T x) {26 forall(T) T ident(T x) { 27 27 return x; 28 28 } 29 29 30 forall( otype T, otypeU )30 forall( T, U ) 31 31 size_t struct_size( T i, U j ) { 32 32 struct S { T i; U j; }; … … 34 34 } 35 35 36 forall( otype T, otypeU )36 forall( T, U ) 37 37 size_t union_size( T i, U j ) { 38 38 union B { T i; U j; }; … … 41 41 42 42 // perform some simple operations on aggregates of T and U 43 forall( otype T | { void print(T); int ?==?(T, T); }, otypeU | { void print(U); U ?=?(U&, zero_t); } )43 forall( T | { void print(T); int ?==?(T, T); }, U | { void print(U); U ?=?(U&, zero_t); } ) 44 44 U foo(T i, U j) { 45 45 struct S { T i; U j; }; -
tests/raii/ctor-autogen.cfa
r2f47ea4 rfd54fef 33 33 34 34 // dtype-static generic type is otype 35 forall( dtype T)35 forall(T &) 36 36 struct DtypeStaticStruct { 37 37 T * data; … … 39 39 }; 40 40 41 forall( dtype T)41 forall(T &) 42 42 union DtypeStaticUnion { 43 43 T * data; … … 46 46 47 47 // dynamic generic type is otype 48 forall( otypeT)48 forall(T) 49 49 struct DynamicStruct { 50 50 T x; 51 51 }; 52 52 53 forall( otypeT)53 forall(T) 54 54 union DynamicUnion { 55 55 T x; … … 80 80 81 81 82 forall( otypeT)82 forall(T) 83 83 T identity(T x) { return x; } 84 84 -
tests/simpleGenericTriple.cfa
r2f47ea4 rfd54fef 14 14 // 15 15 16 forall( otypeT)16 forall(T) 17 17 struct T3 { 18 18 T f0, f1, f2; 19 19 }; 20 20 21 forall( otypeT | { T ?+?(T, T); })21 forall(T | { T ?+?(T, T); }) 22 22 T3(T) ?+?(T3(T) x, T3(T) y) { 23 23 T3(T) z = { x.f0+y.f0, x.f1+y.f1, x.f2+y.f2 }; -
tests/sum.cfa
r2f47ea4 rfd54fef 18 18 #include <stdlib.hfa> 19 19 20 trait sumable( otypeT ) {20 trait sumable( T ) { 21 21 void ?{}( T &, zero_t ); // 0 literal constructor 22 22 T ?+?( T, T ); // assortment of additions … … 26 26 }; // sumable 27 27 28 forall( otypeT | sumable( T ) ) // use trait28 forall( T | sumable( T ) ) // use trait 29 29 T sum( size_t size, T a[] ) { 30 30 T total = 0; // initialize by 0 constructor … … 107 107 | sum( size, (S *)a ) | ", check" | (S)s; 108 108 109 forall( otypeImpl | sumable( Impl ) )109 forall( Impl | sumable( Impl ) ) 110 110 struct GS { 111 111 Impl * x, * y; … … 194 194 sum( size, (S *)a ).[i, j], s.[i, j] ); 195 195 196 forall( otypeImpl | sumable( Impl ) )196 forall( Impl | sumable( Impl ) ) 197 197 struct GS { 198 198 Impl * x, * y; -
tests/tuple/tuplePolymorphism.cfa
r2f47ea4 rfd54fef 29 29 // ensure that f is a viable candidate for g, even though its parameter structure does not exactly match 30 30 [A] f([A, B] x, B y) { printf("%g %c %g %lld %c %lld %lld %c %lld\n", x.0.[x,y,z], x.1.[x,y,z], y.[x,y,z]); return x.0; } 31 forall( otype T, otypeU | { T f(T, U, U); })31 forall(T, U | { T f(T, U, U); }) 32 32 void g(T x, U y) { f(x, y, y); } 33 33 34 34 // add two triples 35 forall( otypeT | { T ?+?(T, T); })35 forall(T | { T ?+?(T, T); }) 36 36 [T, T, T] ?+?([T, T, T] x, [T, T, T] y) { 37 37 return [x.0+y.0, x.1+y.1, x.2+y.2]; … … 64 64 } 65 65 66 forall( otypeT)66 forall(T) 67 67 [T, T] foo([T, T] y) { 68 68 [T, T] x; -
tests/tuple/tupleVariadic.cfa
r2f47ea4 rfd54fef 19 19 printf("called func(void)\n"); 20 20 } 21 forall( otype T, ttype Params| { void process(T); void func(Params); })21 forall(T, Params... | { void process(T); void func(Params); }) 22 22 void func(T arg1, Params p) { 23 23 process(arg1); … … 92 92 } 93 93 94 forall( otypeT)94 forall(T) 95 95 T * copy(T x) { 96 96 // test calling new inside a polymorphic function … … 98 98 } 99 99 100 forall( ttype T| { void foo(T); }) void bar(T x) {}100 forall(T... | { void foo(T); }) void bar(T x) {} 101 101 void foo(int) {} 102 102 -
tests/zombies/ArrayN.c
r2f47ea4 rfd54fef 6 6 // } 7 7 8 forall( otypeindex_t)8 forall(index_t) 9 9 index_t offset_to_index(unsigned offset, index_t size) { 10 10 return [offset / size.0, offset % size.1]; -
tests/zombies/Members.c
r2f47ea4 rfd54fef 2 2 int ?=?( int*, int ); 3 3 float ?=?( float*, float ); 4 forall( dtype DT) DT * ?=?( DT**, DT* );5 forall( otypeT) lvalue T *?( T* );4 forall( DT & ) DT * ?=?( DT**, DT* ); 5 forall(T) lvalue T *?( T* ); 6 6 char *__builtin_memcpy(); 7 7 -
tests/zombies/Rank2.c
r2f47ea4 rfd54fef 1 1 int ?=?( int &, int ); 2 forall( dtype DT) DT * ?=?( DT *&, DT * );2 forall(DT &) DT * ?=?( DT *&, DT * ); 3 3 4 4 void a() { 5 forall( otypeT ) void f( T );6 void g( forall( otypeU ) void p( U ) );5 forall( T ) void f( T ); 6 void g( forall( U ) void p( U ) ); 7 7 g( f ); 8 8 } … … 10 10 void g() { 11 11 void h( int *null ); 12 forall( otypeT ) T id( T );12 forall( T ) T id( T ); 13 13 // forall( dtype T ) T *0; 14 14 // int 0; -
tests/zombies/abstype.c
r2f47ea4 rfd54fef 21 21 } 22 22 23 forall( otypeT ) T *?( T * );23 forall( T ) T *?( T * ); 24 24 int ?++( int * ); 25 25 int ?=?( int *, int ); 26 forall( dtype DT) DT * ?=?( DT **, DT * );26 forall( DT & ) DT * ?=?( DT **, DT * ); 27 27 28 28 otype U = int *; -
tests/zombies/context.cfa
r2f47ea4 rfd54fef 1 1 // trait declaration 2 2 3 trait has_q( otypeT ) {3 trait has_q( T ) { 4 4 T q( T ); 5 5 }; 6 6 7 forall( otypez | has_q( z ) ) void f() {8 trait has_r( otype T, otypeU ) {7 forall( z | has_q( z ) ) void f() { 8 trait has_r( T, U ) { 9 9 T r( T, T (T,U) ); 10 10 }; -
tests/zombies/gc_no_raii/bug-repro/blockers/explicit_cast.c
r2f47ea4 rfd54fef 9 9 }; 10 10 11 forall( otypeT)11 forall(T) 12 12 struct gcpointer 13 13 { … … 15 15 }; 16 16 17 forall( otypeT)17 forall(T) 18 18 static inline gcpointer(T) gcmalloc() 19 19 { -
tests/zombies/gc_no_raii/bug-repro/blockers/recursive_realloc.c
r2f47ea4 rfd54fef 3 3 #include <stdlib.hfa> 4 4 5 trait allocator_c( otype T, otypeallocator_t)5 trait allocator_c(T, allocator_t) 6 6 { 7 7 void realloc(allocator_t* const, size_t); 8 8 }; 9 9 10 forall( otypeT)10 forall(T) 11 11 struct heap_allocator 12 12 { … … 15 15 }; 16 16 17 forall( otypeT)17 forall(T) 18 18 inline void realloc(heap_allocator(T) *const this, size_t size) 19 19 { -
tests/zombies/gc_no_raii/bug-repro/deref.c
r2f47ea4 rfd54fef 1 forall( otypeT)1 forall(T) 2 2 struct wrap 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 T *? (wrap(T) rhs) 9 9 { -
tests/zombies/gc_no_raii/bug-repro/field.c
r2f47ea4 rfd54fef 8 8 //------------------------------------------------------------------------------ 9 9 //Declaration 10 trait allocator_c( otype T, otypeallocator_t)10 trait allocator_c(T, allocator_t) 11 11 { 12 12 void ctor(allocator_t* const); … … 16 16 }; 17 17 18 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))18 forall(T, allocator_t | allocator_c(T, allocator_t)) 19 19 struct vector 20 20 { -
tests/zombies/gc_no_raii/bug-repro/malloc.c
r2f47ea4 rfd54fef 1 forall( otypeT)1 forall(T) 2 2 struct wrapper 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 void ctor(wrapper(T)* this) 9 9 { … … 11 11 } 12 12 13 forall( otypeT)13 forall(T) 14 14 wrapper(T) gcmalloc() 15 15 { … … 19 19 } 20 20 21 forall( otypeT)21 forall(T) 22 22 wrapper(T)* ?=? (wrapper(T)* lhs, wrapper(T)* rhs) 23 23 { -
tests/zombies/gc_no_raii/bug-repro/oddtype.c
r2f47ea4 rfd54fef 1 forall( dtype T)1 forall(T &) 2 2 struct wrap { 3 3 int i; 4 4 }; 5 5 6 forall( otypeT) void ?{}(wrap(T)* this) {}7 forall( otypeT) void ?=?(wrap(T)* this) {}8 forall( otypeT) void ^?{}(wrap(T)* this) {}6 forall(T) void ?{}(wrap(T)* this) {} 7 forall(T) void ?=?(wrap(T)* this) {} 8 forall(T) void ^?{}(wrap(T)* this) {} 9 9 10 10 struct List_t { -
tests/zombies/gc_no_raii/bug-repro/push_back.h
r2f47ea4 rfd54fef 1 1 //------------------------------------------------------------------------------ 2 2 //Declaration 3 trait allocator_c( otype T, otypeallocator_t) {3 trait allocator_c(T, allocator_t) { 4 4 void ctor(allocator_t* const); 5 5 void dtor(allocator_t* const); … … 8 8 }; 9 9 10 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))10 forall(T, allocator_t | allocator_c(T, allocator_t)) 11 11 struct vector 12 12 { … … 17 17 //------------------------------------------------------------------------------ 18 18 //Initialization 19 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))19 forall(T, allocator_t | allocator_c(T, allocator_t)) 20 20 void vector_ctor(vector(T, allocator_t) *const this); 21 21 22 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))22 forall(T, allocator_t | allocator_c(T, allocator_t)) 23 23 void dtor(vector(T, allocator_t) *const this); 24 24 25 25 //------------------------------------------------------------------------------ 26 26 //Allocator 27 forall( otypeT)27 forall(T) 28 28 struct heap_allocator 29 29 { … … 32 32 }; 33 33 34 forall( otypeT)34 forall(T) 35 35 void ctor(heap_allocator(T) *const this); 36 36 37 forall( otypeT)37 forall(T) 38 38 void dtor(heap_allocator(T) *const this); 39 39 40 forall( otypeT)40 forall(T) 41 41 void realloc(heap_allocator(T) *const this, size_t size); 42 42 43 forall( otypeT)43 forall(T) 44 44 inline T* data(heap_allocator(T) *const this) 45 45 { … … 49 49 //------------------------------------------------------------------------------ 50 50 //Capacity 51 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))51 forall(T, allocator_t | allocator_c(T, allocator_t)) 52 52 inline bool empty(vector(T, allocator_t) *const this) 53 53 { … … 55 55 } 56 56 57 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))57 forall(T, allocator_t | allocator_c(T, allocator_t)) 58 58 inline bool size(vector(T, allocator_t) *const this) 59 59 { … … 61 61 } 62 62 63 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))63 forall(T, allocator_t | allocator_c(T, allocator_t)) 64 64 inline void reserve(vector(T, allocator_t) *const this, size_t size) 65 65 { … … 69 69 //------------------------------------------------------------------------------ 70 70 //Modifiers 71 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))71 forall(T, allocator_t | allocator_c(T, allocator_t)) 72 72 void push_back(vector(T, allocator_t) *const this, T value); -
tests/zombies/gc_no_raii/bug-repro/realloc.c
r2f47ea4 rfd54fef 1 1 void* realloc(void*, unsigned long int); 2 2 3 forall( otypeT)3 forall(T) 4 4 struct wrap 5 5 { … … 7 7 }; 8 8 9 forall( otypeT)9 forall(T) 10 10 static inline void realloc(wrap(T) *const this, unsigned long int size) 11 11 { -
tests/zombies/gc_no_raii/bug-repro/return.c
r2f47ea4 rfd54fef 1 forall( otypeT)1 forall(T) 2 2 struct wrapper 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 wrapper(T) create() 9 9 { … … 12 12 } 13 13 14 forall( otypeT)14 forall(T) 15 15 wrapper(T)* ?=?(wrapper(T)* lhs, wrapper(T)* rhs) 16 16 { -
tests/zombies/gc_no_raii/bug-repro/return_template.c
r2f47ea4 rfd54fef 1 forall( otypeT)1 forall(T) 2 2 struct wrap 3 3 { … … 5 5 }; 6 6 7 forall( otypeT) void ?{}(wrap(T)* this);8 forall( otypeT) void ?{}(wrap(T)* this, wrap(T)* rhs);9 forall( otypeT) void ^?{}(wrap(T)* this);10 forall( otypeT) void ?=?(wrap(T)* this, wrap(T)* rhs);7 forall(T) void ?{}(wrap(T)* this); 8 forall(T) void ?{}(wrap(T)* this, wrap(T)* rhs); 9 forall(T) void ^?{}(wrap(T)* this); 10 forall(T) void ?=?(wrap(T)* this, wrap(T)* rhs); 11 11 12 forall( otypeT)12 forall(T) 13 13 wrap(T) test() 14 14 { -
tests/zombies/gc_no_raii/bug-repro/slow_malloc.c
r2f47ea4 rfd54fef 1 1 #include <stdlib.hfa> 2 2 3 forall( otypeT)3 forall(T) 4 4 struct heap_allocator 5 5 { -
tests/zombies/gc_no_raii/bug-repro/zero.c
r2f47ea4 rfd54fef 1 forall( otypeT)1 forall(T) 2 2 struct wrap 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 int ?==? (wrap(T) lhs, wrap(T) rhs) 9 9 { … … 14 14 struct wrap(int) 0; 15 15 /*/ 16 forall( otypeT)16 forall(T) 17 17 struct wrap(T) 0; 18 18 //*/ -
tests/zombies/gc_no_raii/src/gc.h
r2f47ea4 rfd54fef 13 13 // } 14 14 15 forall( otypeT)15 forall(T) 16 16 static inline void gcmalloc(gcpointer(T)* ptr) 17 17 { -
tests/zombies/gc_no_raii/src/gcpointers.c
r2f47ea4 rfd54fef 113 113 #endif 114 114 115 forall( otypeT) void ?{}(gcpointer(T)* this) {115 forall(T) void ?{}(gcpointer(T)* this) { 116 116 (&this->internal) {}; 117 117 } 118 118 119 forall( otypeT) void ?{}(gcpointer(T)* this, void* address) {119 forall(T) void ?{}(gcpointer(T)* this, void* address) { 120 120 (&this->internal) { address }; 121 121 } 122 122 123 forall( otypeT) void ?{}(gcpointer(T)* this, gcpointer(T) other) {123 forall(T) void ?{}(gcpointer(T)* this, gcpointer(T) other) { 124 124 (&this->internal) { other.internal }; 125 125 } 126 126 127 forall( otypeT) void ^?{}(gcpointer(T)* this) {127 forall(T) void ^?{}(gcpointer(T)* this) { 128 128 ^?{}(&this->internal); 129 129 } 130 130 131 forall( otypeT) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) {131 forall(T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) { 132 132 this->internal = rhs.internal; 133 133 return *this; … … 136 136 // forall(otype T) T *?(gcpointer(T) this); 137 137 138 forall( otypeT) T* get(gcpointer(T)* this) {138 forall(T) T* get(gcpointer(T)* this) { 139 139 return (T*)this->internal.ptr; 140 140 } 141 141 // 142 142 // //Logical operators 143 forall( otypeT) int ?!=?(gcpointer(T) this, int zero) {143 forall(T) int ?!=?(gcpointer(T) this, int zero) { 144 144 return this.internal.ptr != 0; 145 145 } -
tests/zombies/gc_no_raii/src/gcpointers.h
r2f47ea4 rfd54fef 4 4 #include <stdint.h> 5 5 6 forall( dtype T)6 forall(T &) 7 7 struct gcpointer; 8 8 … … 29 29 #endif 30 30 31 forall( dtype T)31 forall(T &) 32 32 struct gcpointer 33 33 { … … 36 36 37 37 // 38 forall( otypeT) void ?{}(gcpointer(T)* this);39 forall( otypeT) void ?{}(gcpointer(T)* this, void* address);40 forall( otypeT) void ?{}(gcpointer(T)* this, gcpointer(T) other);41 forall( otypeT) void ^?{}(gcpointer(T)* this);42 forall( otypeT) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs);38 forall(T) void ?{}(gcpointer(T)* this); 39 forall(T) void ?{}(gcpointer(T)* this, void* address); 40 forall(T) void ?{}(gcpointer(T)* this, gcpointer(T) other); 41 forall(T) void ^?{}(gcpointer(T)* this); 42 forall(T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs); 43 43 44 44 45 45 // forall(otype T) T *?(gcpointer(T) this); 46 forall( otypeT) T* get(gcpointer(T)* this);46 forall(T) T* get(gcpointer(T)* this); 47 47 48 48 //Logical operators 49 forall( otypeT) int ?!=?(gcpointer(T) this, int zero);50 forall( otypeT) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);51 forall( otypeT) int ?==?(gcpointer(T) this, gcpointer(T) rhs);49 forall(T) int ?!=?(gcpointer(T) this, int zero); 50 forall(T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs); 51 forall(T) int ?==?(gcpointer(T) this, gcpointer(T) rhs); -
tests/zombies/gc_no_raii/src/tools.h
r2f47ea4 rfd54fef 12 12 // } 13 13 14 trait has_equal( otypeT)14 trait has_equal(T) 15 15 { 16 16 signed int ?==?(T a, T b); 17 17 }; 18 18 19 trait InputIterator_t( otype T, otypeInputIterator)19 trait InputIterator_t(T, InputIterator) 20 20 { 21 21 signed int ?==?(InputIterator a, InputIterator b); … … 26 26 }; 27 27 28 forall( otype T | has_equal(T), otypeInputIterator | InputIterator_t(T, InputIterator))28 forall(T | has_equal(T), InputIterator | InputIterator_t(T, InputIterator)) 29 29 static inline InputIterator find( InputIterator first, const InputIterator* const last, T val) 30 30 { -
tests/zombies/hashtable.cfa
r2f47ea4 rfd54fef 14 14 15 15 16 trait has_hash( otypeK ) {16 trait has_hash( K ) { 17 17 size_t hash(K); 18 18 int ?==?( K, K ); 19 19 }; 20 20 21 trait hkey( otype K, dtype tN| has_hash(K) ) {21 trait hkey( K, tN & | has_hash(K) ) { 22 22 K key(tN &); 23 23 }; 24 24 25 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) ) {25 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) ) { 26 26 27 27 struct hashtable { … … 39 39 } 40 40 41 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {41 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) { 42 42 43 43 void ?{}( hashtable(K, tN, tE) & this, size_t n_buckets, dlist(tN, tE) *buckets ) { … … 57 57 } 58 58 59 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) ) {59 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) ) { 60 60 61 61 float fill_frac( hashtable(K, tN, tE) & this ) with(this) { … … 124 124 125 125 126 trait heaped( dtype T) {126 trait heaped(T &) { 127 127 T * alloc( size_t ); 128 128 void free( void * ); … … 133 133 } 134 134 135 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) | heaped( dlist(tN, tE) ) ) {135 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) | heaped( dlist(tN, tE) ) ) { 136 136 137 137 struct hashtable_dynamic { -
tests/zombies/hashtable2.cfa
r2f47ea4 rfd54fef 69 69 70 70 71 trait pretendsToMatter( dtype TTT) {71 trait pretendsToMatter( TTT & ) { 72 72 void actsmart(TTT &); 73 73 }; 74 74 75 forall( dtype TTTx)75 forall( TTTx & ) 76 76 void actsmart(TTTx &) {} 77 77 … … 86 86 // 2. shows up in -CFA output as hashtable_rbs(), which is bad C; expecting hashtable_rbs* 87 87 88 forall( otypeTt_unused | pretendsToMatter(Tt_unused) ) {88 forall( Tt_unused | pretendsToMatter(Tt_unused) ) { 89 89 90 90 // hashtable of request by source … … 104 104 } 105 105 106 forall( otypeTt_unused | pretendsToMatter(Tt_unused) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {106 forall( Tt_unused | pretendsToMatter(Tt_unused) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) { 107 107 108 108 void ?{}( hashtable_rbs(Tt_unused) & this, size_t n_buckets, dlist(request_in_ht_by_src, request) *buckets, … … 135 135 void defaultResumptionHandler( ht_auto_resize_pending & ex ); 136 136 137 forall( otypeTt_unused | pretendsToMatter(Tt_unused) ) {137 forall( Tt_unused | pretendsToMatter(Tt_unused) ) { 138 138 139 139 float fill_frac( hashtable_rbs(Tt_unused) & this ) with(this) { … … 221 221 222 222 223 trait heaped( dtype T) {223 trait heaped(T &) { 224 224 T * alloc( size_t ); 225 225 void free( void * ); … … 228 228 void __dynamic_defaultResumptionHandler(ht_fill_limit_crossed &); 229 229 230 forall( otypeTt_unused ) {230 forall( Tt_unused ) { 231 231 232 232 struct hashtable_rbs_dynamic { … … 263 263 264 264 265 forall( otypeTt_unused | heaped( dlist(request_in_ht_by_src, request) ) ) {265 forall( Tt_unused | heaped( dlist(request_in_ht_by_src, request) ) ) { 266 266 267 267 void ?{}( hashtable_rbs_dynamic(Tt_unused).resize_policy & this, size_t nbuckets_floor ) { … … 325 325 } 326 326 327 forall( otypeTt_unused ) {327 forall( Tt_unused ) { 328 328 void rehashToLarger_STEP( hashtable_rbs_dynamic(Tt_unused) & this, size_t new_n_buckets ) with (this) { 329 329 rehashToLarger( this, new_n_buckets ); -
tests/zombies/huge.c
r2f47ea4 rfd54fef 14 14 // 15 15 16 int huge( int n, forall( otypeT ) T (*f)( T ) ) {16 int huge( int n, forall( T ) T (*f)( T ) ) { 17 17 if ( n <= 0 ) 18 18 return f( 0 ); -
tests/zombies/it_out.c
r2f47ea4 rfd54fef 16 16 typedef unsigned long streamsize_type; 17 17 18 trait ostream( dtype os_type) {18 trait ostream( os_type & ) { 19 19 os_type *write( os_type *, const char *, streamsize_type ); 20 20 int fail( os_type * ); 21 21 }; 22 22 23 trait writeable( otypeT ) {24 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, T );23 trait writeable( T ) { 24 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, T ); 25 25 }; 26 26 27 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, char );28 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, int );29 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, const char * );27 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, char ); 28 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, int ); 29 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, const char * ); 30 30 31 trait istream( dtype is_type) {31 trait istream( is_type & ) { 32 32 is_type *read( is_type *, char *, streamsize_type ); 33 33 is_type *unread( is_type *, char ); … … 36 36 }; 37 37 38 trait readable( otypeT ) {39 forall( dtype is_type| istream( is_type ) ) is_type * ?<<?( is_type *, T );38 trait readable( T ) { 39 forall( is_type & | istream( is_type ) ) is_type * ?<<?( is_type *, T ); 40 40 }; 41 41 42 forall( dtype is_type| istream( is_type ) ) is_type * ?>>?( is_type *, char* );43 forall( dtype is_type| istream( is_type ) ) is_type * ?>>?( is_type *, int* );42 forall( is_type & | istream( is_type ) ) is_type * ?>>?( is_type *, char* ); 43 forall( is_type & | istream( is_type ) ) is_type * ?>>?( is_type *, int* ); 44 44 45 trait iterator( otype iterator_type, otypeelt_type ) {45 trait iterator( iterator_type, elt_type ) { 46 46 iterator_type ?++( iterator_type* ); 47 47 iterator_type ++?( iterator_type* ); … … 52 52 }; 53 53 54 forall( otypeelt_type | writeable( elt_type ),55 otypeiterator_type | iterator( iterator_type, elt_type ),56 dtype os_type| ostream( os_type ) )54 forall( elt_type | writeable( elt_type ), 55 iterator_type | iterator( iterator_type, elt_type ), 56 os_type & | ostream( os_type ) ) 57 57 void write_all( iterator_type begin, iterator_type end, os_type *os ); 58 58 59 forall( otypeelt_type | writeable( elt_type ),60 otypeiterator_type | iterator( iterator_type, elt_type ),61 dtype os_type| ostream( os_type ) )59 forall( elt_type | writeable( elt_type ), 60 iterator_type | iterator( iterator_type, elt_type ), 61 os_type & | ostream( os_type ) ) 62 62 void write_all( elt_type begin, iterator_type end, os_type *os ) { 63 63 os << begin; -
tests/zombies/new.c
r2f47ea4 rfd54fef 14 14 // 15 15 16 forall( otypeT )16 forall( T ) 17 17 void f( T *t ) { 18 18 t--; -
tests/zombies/occursError.cfa
r2f47ea4 rfd54fef 1 forall( otypeT ) void f( void (*)( T, T * ) );2 forall( otypeU ) void g( U, U * );3 forall( otypeU ) void h( U *, U );1 forall( T ) void f( void (*)( T, T * ) ); 2 forall( U ) void g( U, U * ); 3 forall( U ) void h( U *, U ); 4 4 5 5 void test() { -
tests/zombies/prolog.c
r2f47ea4 rfd54fef 25 25 void is_integer( int x ) {} 26 26 27 trait ArithmeticType( otypeT ) {27 trait ArithmeticType( T ) { 28 28 void is_arithmetic( T ); 29 29 }; 30 30 31 trait IntegralType( otypeT | ArithmeticType( T ) ) {31 trait IntegralType( T | ArithmeticType( T ) ) { 32 32 void is_integer( T ); 33 33 }; 34 34 35 forall( otypeT | IntegralType( T ) | { void printResult( T ); } )35 forall( T | IntegralType( T ) | { void printResult( T ); } ) 36 36 void hornclause( T param ) { 37 37 printResult( param ); -
tests/zombies/quad.c
r2f47ea4 rfd54fef 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT | { T ?*?( T, T ); } )18 forall( T | { T ?*?( T, T ); } ) 19 19 T square( T t ) { 20 20 return t * t; 21 21 } 22 22 23 forall( otypeU | { U square( U ); } )23 forall( U | { U square( U ); } ) 24 24 U quad( U u ) { 25 25 return square( square( u ) ); -
tests/zombies/scope.cfa
r2f47ea4 rfd54fef 20 20 y p; 21 21 22 trait has_u( otypez ) {22 trait has_u( z ) { 23 23 z u(z); 24 24 }; 25 25 26 forall( otypet | has_u( t ) )26 forall( t | has_u( t ) ) 27 27 y q( t the_t ) { 28 28 t y = u( the_t ); -
tests/zombies/simplePoly.c
r2f47ea4 rfd54fef 14 14 // 15 15 16 forall( otype T, otypeU | { T f( T, U ); } )16 forall( T, U | { T f( T, U ); } ) 17 17 T q( T t, U u ) { 18 18 return f( t, u ); -
tests/zombies/simpler.c
r2f47ea4 rfd54fef 14 14 // 15 15 16 forall( otypeT ) T id( T, T );16 forall( T ) T id( T, T ); 17 17 18 18 int main() { -
tests/zombies/specialize.c
r2f47ea4 rfd54fef 39 39 } 40 40 41 forall( otypeT ) T f( T t )41 forall( T ) T f( T t ) 42 42 { 43 43 printf( "in f; sizeof T is %d\n", sizeof( T ) ); -
tests/zombies/square.c
r2f47ea4 rfd54fef 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT | { T ?*?( T, T ); } )18 forall( T | { T ?*?( T, T ); } ) 19 19 T square( T t ) { 20 20 return t * t; -
tests/zombies/structMember.cfa
r2f47ea4 rfd54fef 66 66 S.T; 67 67 .S.T; 68 forall( otype S, otypeT ) struct W {68 forall( S, T ) struct W { 69 69 struct X {}; 70 70 }; -
tests/zombies/subrange.cfa
r2f47ea4 rfd54fef 1 1 // A small context defining the notion of an ordered otype. (The standard 2 2 // library should probably contain a context for this purpose.) 3 trait ordered( otypeT) {3 trait ordered(T) { 4 4 int ?<?(T, T), ?<=?(T, T); 5 5 }; … … 7 7 // A subrange otype resembling an Ada subotype with a base otype and a range 8 8 // constraint. 9 otype subrange( otypebase_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;9 otype subrange(base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t; 10 10 11 11 // Note that subrange() can be applied to floating-point and pointer otypes, not … … 28 28 29 29 // Convenient access to subrange bounds, for instance for iteration: 30 forall ( otypeT, T low, T high)30 forall (T, T low, T high) 31 31 T lbound( subrange(T, low, high) v) { 32 32 return low; 33 33 } 34 34 35 forall ( otypeT, T low, T high)35 forall (T, T low, T high) 36 36 T hbound( subrange(T, low, high) v) { 37 37 return high; … … 44 44 // of exception handling here. Inlining allows the compiler to eliminate 45 45 // bounds checks. 46 forall ( otypeT | ordered(T), T low, T high)46 forall (T | ordered(T), T low, T high) 47 47 inline subrange(T, low, high) ?=?(subrange(T, low, high)* target, T source) { 48 48 if (low <= source && source <= high) *((T*)target) = source; … … 54 54 // compares range bounds so that the compiler can optimize checks away when the 55 55 // ranges are known to overlap. 56 forall ( otypeT | ordered(T), T t_low, T t_high, T s_low, T s_high)56 forall (T | ordered(T), T t_low, T t_high, T s_low, T s_high) 57 57 inline subrange(T, t_low, t_high) ?=?(subrange(T, t_low, t_high)* target, 58 58 subrange(T, s_low, s_high) source) { -
tests/zombies/twice.c
r2f47ea4 rfd54fef 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT | { T ?+?( T, T ); } )18 forall( T | { T ?+?( T, T ); } ) 19 19 T twice( const T t ) { 20 20 return t + t; -
tests/zombies/typeGenerator.cfa
r2f47ea4 rfd54fef 1 context addable( otypeT ) {1 context addable( T ) { 2 2 T ?+?( T,T ); 3 3 T ?=?( T*, T); 4 4 }; 5 5 6 otype List1( otypeT | addable( T ) ) = struct { T data; List1( T ) *next; } *;6 otype List1( T | addable( T ) ) = struct { T data; List1( T ) *next; } *; 7 7 typedef List1( int ) ListOfIntegers; 8 8 //List1( int ) li; … … 11 11 [int] h( * List1( int ) p ); // new declaration syntax 12 12 13 struct( otypeT ) S2 { T i; }; // actual definition13 struct( T ) S2 { T i; }; // actual definition 14 14 struct( int ) S3 v1, *p; // expansion and instantiation 15 struct( otypeT )( int ) S24 { T i; } v2; // actual definition, expansion and instantiation16 struct( otypeT )( int ) { T i; } v2; // anonymous actual definition, expansion and instantiation15 struct( T )( int ) S24 { T i; } v2; // actual definition, expansion and instantiation 16 struct( T )( int ) { T i; } v2; // anonymous actual definition, expansion and instantiation 17 17 18 struct( otypeT | addable( T ) ) node { T data; struct( T ) node *next; };19 otype List( otypeT ) = struct( T ) node *;18 struct( T | addable( T ) ) node { T data; struct( T ) node *next; }; 19 otype List( T ) = struct( T ) node *; 20 20 List( int ) my_list; 21 21 -
tests/zombies/withStatement.cfa
r2f47ea4 rfd54fef 54 54 } 55 55 56 forall( otypeT )56 forall( T ) 57 57 struct Box { 58 58 T x; 59 59 }; 60 60 61 forall( otypeT )61 forall( T ) 62 62 void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function 63 63 x{}; … … 66 66 void print( int i ) { sout | i; } 67 67 68 forall( otypeT | { void print( T ); })68 forall( T | { void print( T ); }) 69 69 void foo( T t ) { 70 70 Box( T ) b = { t }; -
tests/zombies/wrapper/src/pointer.h
r2f47ea4 rfd54fef 8 8 // type safe malloc / free 9 9 10 forall( otypeT)10 forall(T) 11 11 T* new() 12 12 { … … 16 16 } 17 17 18 forall( otypeT)18 forall(T) 19 19 void delete(T* p) 20 20 {
Note: See TracChangeset
for help on using the changeset viewer.