comparison test/call_suite_aggrs/main.c @ 501:62c3746390da

- call_suite_aggrs: simplified and made output more consistent with dyncall sig style
author Tassilo Philipp
date Fri, 08 Apr 2022 17:32:48 +0200
parents 29d09d10ecd9
children ed7d1f5e7973
comparison
equal deleted inserted replaced
500:7426cfbe92d5 501:62c3746390da
35 static int find_agg_idx(int* len, const char* sig) 35 static int find_agg_idx(int* len, const char* sig)
36 { 36 {
37 int i; 37 int i;
38 for(i=0; i<G_naggs; ++i) { 38 for(i=0; i<G_naggs; ++i) {
39 const char* agg_sig = G_agg_sigs[i]; 39 const char* agg_sig = G_agg_sigs[i];
40 *len = strlen(agg_sig); 40 int l = strlen(agg_sig);
41 if(strncmp(agg_sig, sig, *len) == 0) 41 if(len)
42 *len = l;
43 if(strncmp(agg_sig, sig, l) == 0)
42 return i; 44 return i;
43 } 45 }
44 return -1; 46 return -1;
45 } 47 }
46 48
47 static int invoke(char const* signature, void* t) 49 static int invoke(char const* signature, void* t)
48 { 50 {
49 DCCallVM * p = (DCCallVM*) G_callvm; 51 DCCallVM * p = (DCCallVM*) G_callvm;
50 char const * sig = signature; 52 const char * sig = signature;
51 char const * sig_args; 53 const char * rtype;
52 char rtype;
53 DCaggr * rtype_a = NULL; 54 DCaggr * rtype_a = NULL;
54 int rtype_size = 0; 55 int rtype_size = 0;
55 funptr rtype_a_cmp = NULL; 56 funptr rtype_a_cmp = NULL;
56 char atype; 57 char atype;
57 int pos = 0; 58 int pos = 0;
59 60
60 clear_V(); 61 clear_V();
61 62
62 dcReset(p); 63 dcReset(p);
63 64
64 if(*sig == '{' || *sig == '<') { 65 /* locate return type in sig; if no ')' separator, test failed */
65 int len; 66 rtype = strchr(sig, ')');
66 int i = find_agg_idx(&len, sig); 67 if(!rtype) {
68 printf("cannot locate rtype in sig '%s' ;", signature);
69 return 0;
70 }
71
72 ++rtype;
73 if(*rtype == '{' || *rtype == '<') {
74 int i = find_agg_idx(NULL, rtype);
67 if(i == -1) { 75 if(i == -1) {
68 printf("unknown rtype sig at '%s' ;", sig); 76 printf("unknown rtype sig at '%s' ;", rtype);
69 return 0; 77 return 0;
70 } 78 }
71 rtype = *sig;
72 sig += len;
73 79
74 rtype_size = G_agg_sizes[i]; 80 rtype_size = G_agg_sizes[i];
75 rtype_a_cmp = G_agg_cmpfuncs[i]; 81 rtype_a_cmp = G_agg_cmpfuncs[i];
76 rtype_a = ((DCaggr*(*)())G_agg_touchdcstfuncs[i])(); 82 rtype_a = ((DCaggr*(*)())G_agg_touchdcstfuncs[i])();
77 dcBeginCallAggr(p, rtype_a); 83 dcBeginCallAggr(p, rtype_a);
78 } 84 }
79 else 85
80 rtype = *sig++; 86
81 87 while ( (atype = *sig) != ')') {
82 sig_args = sig;
83
84 while ( (atype = *sig) != '\0') {
85 pos++; 88 pos++;
86 switch(atype) { 89 switch(atype) {
87 case 'c': dcArgChar (p,K_c[pos]); break; 90 case 'c': dcArgChar (p,K_c[pos]); break;
88 case 's': dcArgShort (p,K_s[pos]); break; 91 case 's': dcArgShort (p,K_s[pos]); break;
89 case 'i': dcArgInt (p,K_i[pos]); break; 92 case 'i': dcArgInt (p,K_i[pos]); break;
116 default: printf("unknown atype '%c' (1) ;", atype); return 0; 119 default: printf("unknown atype '%c' (1) ;", atype); return 0;
117 } 120 }
118 ++sig; 121 ++sig;
119 } 122 }
120 123
121 switch(rtype) 124 switch(*rtype)
122 { 125 {
123 case 'v': dcCallVoid(p,t); s=1; break; /*TODO:check that no return-arg was touched.*/ 126 case 'v': dcCallVoid(p,t); s=1; break; /*TODO:check that no return-arg was touched.*/
124 case 'c': s = ( dcCallChar (p,t) == K_c[pos]); break; 127 case 'c': s = ( dcCallChar (p,t) == K_c[pos]); break;
125 case 's': s = ( dcCallShort (p,t) == K_s[pos]); break; 128 case 's': s = ( dcCallShort (p,t) == K_s[pos]); break;
126 case 'i': s = ( dcCallInt (p,t) == K_i[pos]); break; 129 case 'i': s = ( dcCallInt (p,t) == K_i[pos]); break;
148 printf("writing rval overflowed into adjacent memory;"); 151 printf("writing rval overflowed into adjacent memory;");
149 return 0; 152 return 0;
150 } 153 }
151 break; 154 break;
152 } 155 }
153 default: printf("unknown rtype '%c'", rtype); return 0; 156 default: printf("unknown rtype '%s'", rtype); return 0;
154 } 157 }
155 158
156 if (!s) { printf("rval wrong;"); return 0; } 159 if (!s) { printf("rval wrong;"); return 0; }
157 160
158 /* test V_* array against values passed to func: */ 161 /* test V_* array against values passed to func: */
159 sig = sig_args; 162 sig = signature;
160 pos = 1; 163 pos = 1;
161 while ( (atype = *sig) != '\0') { 164 while ( (atype = *sig) != ')') {
162 switch(atype) { 165 switch(atype) {
163 case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_c[pos], K_c[pos]); break; 166 case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_c[pos], K_c[pos]); break;
164 case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_s[pos], K_s[pos]); break; 167 case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_s[pos], K_s[pos]); break;
165 case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_i[pos], K_i[pos]); break; 168 case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_i[pos], K_i[pos]); break;
166 case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'%c':%d: %ld != %ld ; ", atype, pos, V_j[pos], K_j[pos]); break; 169 case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'%c':%d: %ld != %ld ; ", atype, pos, V_j[pos], K_j[pos]); break;