comparison test/call_suite/main.c @ 504:f263eb7a206e

- call_suite: made output more consistent with dyncall sig style
author Tassilo Philipp
date Fri, 08 Apr 2022 20:33:14 +0200
parents e3bf15207d93
children ed7d1f5e7973
comparison
equal deleted inserted replaced
503:e6d8ae2a116c 504:f263eb7a206e
34 34
35 35
36 static int invoke(char const* signature, void* t) 36 static int invoke(char const* signature, void* t)
37 { 37 {
38 DCCallVM * p = (DCCallVM*) G_callvm; 38 DCCallVM * p = (DCCallVM*) G_callvm;
39 char const * sig = signature; 39 const char * sig = signature;
40 char rtype; 40 const char * rtype;
41 char atype; 41 char atype;
42 int pos = 0; 42 int pos = 0;
43 int s = 0; 43 int s = 0;
44 44
45 clear_V(); 45 clear_V();
46 46
47 rtype = *sig++;
48 dcReset(p); 47 dcReset(p);
49 48
50 while ( (atype = *sig++) != '\0') { 49 /* locate return type in sig; if no ')' separator, test failed */
50 rtype = strchr(sig, ')');
51 if(!rtype) {
52 printf("cannot locate rtype in sig '%s' ;", signature);
53 return 0;
54 }
55
56 ++rtype;
57
58 while ( (atype = *sig++) != ')') {
51 pos++; 59 pos++;
52 switch(atype) { 60 switch(atype) {
53 case 'c': dcArgChar (p,K_c[pos]); break; 61 case 'c': dcArgChar (p,K_c[pos]); break;
54 case 's': dcArgShort (p,K_s[pos]); break; 62 case 's': dcArgShort (p,K_s[pos]); break;
55 case 'i': dcArgInt (p,K_i[pos]); break; 63 case 'i': dcArgInt (p,K_i[pos]); break;
65 case 'd': dcArgDouble (p,K_d[pos]); break; 73 case 'd': dcArgDouble (p,K_d[pos]); break;
66 default: printf("unknown atype '%c' (1) ;", atype); return 0; 74 default: printf("unknown atype '%c' (1) ;", atype); return 0;
67 } 75 }
68 } 76 }
69 77
70 switch(rtype) 78 switch(*rtype)
71 { 79 {
72 case 'v': dcCallVoid (p,t); s=1; break; /*TODO:check that no return-arg was touched.*/ 80 case 'v': dcCallVoid (p,t); s=1; break; /*TODO:check that no return-arg was touched.*/
73 case 'c': s = ( dcCallChar (p,t) == K_c[pos]); break; 81 case 'c': s = ( dcCallChar (p,t) == K_c[pos]); break;
74 case 's': s = ( dcCallShort (p,t) == K_s[pos]); break; 82 case 's': s = ( dcCallShort (p,t) == K_s[pos]); break;
75 case 'i': s = ( dcCallInt (p,t) == K_i[pos]); break; 83 case 'i': s = ( dcCallInt (p,t) == K_i[pos]); break;
81 case 'J': s = ((unsigned long) dcCallLong (p,t) == K_J[pos]); break; 89 case 'J': s = ((unsigned long) dcCallLong (p,t) == K_J[pos]); break;
82 case 'L': s = ((unsigned long long)dcCallLongLong(p,t) == K_L[pos]); break; 90 case 'L': s = ((unsigned long long)dcCallLongLong(p,t) == K_L[pos]); break;
83 case 'p': s = ( dcCallPointer (p,t) == K_p[pos]); break; 91 case 'p': s = ( dcCallPointer (p,t) == K_p[pos]); break;
84 case 'f': s = ( dcCallFloat (p,t) == K_f[pos]); break; 92 case 'f': s = ( dcCallFloat (p,t) == K_f[pos]); break;
85 case 'd': s = ( dcCallDouble (p,t) == K_d[pos]); break; 93 case 'd': s = ( dcCallDouble (p,t) == K_d[pos]); break;
86 default: printf("unknown rtype '%c'", rtype); return 0; 94 default: printf("unknown rtype '%s'", rtype); return 0;
87 } 95 }
88 96
89 if (!s) { printf("rval wrong;"); return 0; } 97 if (!s) { printf("rval wrong;"); return 0; }
98
90 /* test: */ 99 /* test: */
91 sig = signature+1; 100 sig = signature;
92 pos = 1; 101 pos = 1;
93 while ( (atype = *sig++) != '\0') { 102 while ( (atype = *sig++) != ')') {
94 switch(atype) { 103 switch(atype) {
95 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; 104 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;
96 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; 105 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;
97 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; 106 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;
98 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; 107 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;