Mercurial > pub > dyncall > dyncall
annotate test/call_suite_aggrs/mk-cases.lua @ 514:01f928eb9584
- more test code generator code sharing
author | Tassilo Philipp |
---|---|
date | Sun, 10 Apr 2022 16:18:28 +0200 |
parents | 4d0541bf9b38 |
children | 99819b874bac |
rev | line source |
---|---|
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
1 require"config" |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
2 require"math" |
514 | 3 |
4 -- use shared helpers to generate cases | |
5 package.path = '../common/?.lua;' .. package.path | |
6 require"mk-cases" | |
7 | |
8 | |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
9 local max_numargs = 0 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
10 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
11 local aggrs = { } |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
12 local seen_aggrs = { } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
13 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
14 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
15 function canon_type(t) |
461 | 16 -- aggregate types start with special (closing) char |
17 c = ({ ['}'] = 'struct ', ['>'] = 'union ' })[t:sub(1,1)] | |
18 if c ~= nil then | |
19 return c..'A'..t:sub(2) | |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
20 end |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
21 return t |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
22 end |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
23 |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
24 function put_sig_rtype_first(sig) |
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
25 return sig:sub(sig:find(')')+1,-1)..sig:sub(1,sig:find(')')-1) |
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
26 end |
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
27 |
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
28 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
29 function mkcase(id,sig) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
30 local sig = trim(sig) |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
31 local fsig = put_sig_rtype_first(sig) |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
32 local h = { "/* ",id,":",sig," */ " } |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
33 local t = { "" } |
510 | 34 local pos = -1 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
35 local n_nest = 0 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
36 local aggr = { } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
37 local aggr_sig = { } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
38 aggr[0] = { } -- non-sequential [0] collects all non-aggr types |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
39 aggr_sig[0] = '' |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
40 for i = 1, #fsig do |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
41 local name = "a"..pos |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
485
diff
changeset
|
42 local ch = fsig:sub(i,i) |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
43 |
462 | 44 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
45 -- aggregate nest level change? |
461 | 46 if ch == '{' or ch == '<' then |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
47 n_nest = n_nest + 1 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
48 aggr[n_nest] = { } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
49 aggr_sig[n_nest] = '' |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
50 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
51 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
52 aggr_sig[n_nest] = aggr_sig[n_nest]..ch |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
53 |
462 | 54 -- array? Just append to name of member var from prev loop |
55 if ch:match('[%[%]0123456789]') ~= nil then | |
56 aggr[n_nest][#aggr[n_nest]] = aggr[n_nest][#aggr[n_nest]]..ch | |
57 else | |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
58 |
462 | 59 if ch == '}' or ch == '>' then |
60 -- register yet unseen aggregates, key is sig, val is body and name | |
61 if seen_aggrs[aggr_sig[n_nest]] == nil then | |
62 aggrs[#aggrs+1] = aggr_sig[n_nest] | |
63 ch = ch..#aggrs | |
64 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch } | |
65 end | |
66 ch = seen_aggrs[aggr_sig[n_nest]][2] | |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
67 |
462 | 68 n_nest = n_nest - 1 |
69 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1] | |
70 end | |
71 | |
72 if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then | |
73 aggr[n_nest][#aggr[n_nest]+1] = canon_type(ch) | |
74 aggr[n_nest][#aggr[n_nest]+1] = 'm'..(#aggr[n_nest] >> 1) | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
75 end |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
76 |
462 | 77 -- no nesting (= actual func args), generate case code |
78 if n_nest == 0 then | |
79 h[#h+1] = canon_type(ch) | |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
80 -- aggregate types have more than one |
462 | 81 if #h[#h] > 1 then |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
82 if aggrcpsimple then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
83 t[#t+1] = '*('..h[#h]..'*)V_a['..pos.."]="..name..";" |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
84 else |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
85 t[#t+1] = 'f_cp'..h[#h]:sub(8)..'(V_a['..pos.."],&"..name..");" |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
86 end |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
87 if aggrmutabletest then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
88 t[#t] = t[#t]..'memset(&'..name..',0,sizeof('..name..'));' |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
89 end |
462 | 90 else |
91 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" | |
92 end | |
93 | |
94 -- is return type or func arg? | |
510 | 95 if pos == -1 then |
462 | 96 h[#h+1] = " f"..id.."(" |
97 h[#h+1] = '' | |
98 t[#t] = '' -- clear; aggr return type handled explicitly | |
99 else | |
100 h[#h+1] = ' '..name | |
101 h[#h+1] = "," | |
102 end | |
103 | |
104 pos = pos + 1 | |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
105 end |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
106 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
107 end |
510 | 108 max_numargs = math.max(max_numargs, pos) |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
109 h[#h] = "){" |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
110 if #h[6] == 1 then |
510 | 111 t[#t+1] = "ret_"..h[6].."("..pos..")}\n" |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
112 else |
510 | 113 t[#t+1] = "ret_a("..pos..","..h[6]..")}\n" |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
114 end |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
115 return table.concat(h,"")..table.concat(t,"") |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
116 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
117 |
462 | 118 function split_array_decl(s) |
119 local name = s | |
120 local n = nil -- not an array | |
121 local array_i = s:find('%[') | |
122 if array_i ~= nil then | |
123 name = name:sub(1, array_i-1) | |
124 n = tonumber(s:sub(array_i):match('[0123456789]+')) | |
125 end | |
126 return { name, n } | |
127 end | |
128 | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
129 function mkall() |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
130 local lineno = 0 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
131 local sigtab = { } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
132 local cases = '' |
501
62c3746390da
- call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents:
500
diff
changeset
|
133 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
134 for line in io.lines() do |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
135 local sig = trim(line) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
136 cases = cases..mkcase(lineno,sig) |
501
62c3746390da
- call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents:
500
diff
changeset
|
137 sigtab[#sigtab+1] = sig |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
138 lineno = lineno + 1 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
139 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
140 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
141 agg_sizes = {} |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
142 agg_sigs = {} |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
143 agg_names = {} |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
144 for a = 1, #aggrs do |
462 | 145 local k = aggrs[a] |
146 local v = seen_aggrs[k] | |
147 local at = canon_type(v[2]) -- aggregate type | |
148 local am = v[1] -- aggregate members | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
149 |
462 | 150 agg_sizes[#agg_sizes + 1] = 'sizeof('..at..')' |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
151 agg_sigs [#agg_sigs + 1] = k |
462 | 152 agg_names[#agg_names + 1] = at:sub(8) |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
153 |
461 | 154 -- aggregate def |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
155 io.write('/* '..k..' */\n') |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
156 if aggrpacking ~= 0 then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
157 local pack = aggrpacking |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
158 if pack < 0 then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
159 pack = math.floor(math.pow(2,math.floor(math.log(math.random(math.abs(pack)),2)))) |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
160 end |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
161 io.write('#pragma pack(push,'..pack..')\n') |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
162 end |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
163 |
462 | 164 io.write(at..' { ') |
165 for i = 1, #am, 2 do | |
166 io.write(am[i]..' '..am[i+1]..'; ') | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
167 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
168 io.write("};\n") |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
169 |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
170 if aggrpacking ~= 0 then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
171 io.write('#pragma pack(pop)\n') |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
172 end |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
173 |
461 | 174 -- aggregate cp and cmp funcs |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
175 s = { |
462 | 176 'void f_cp'..at:sub(8)..'('..at..' *x, const '..at..' *y) { ', |
177 'int f_cmp'..at:sub(8)..'(const '..at..' *x, const '..at..' *y) { return ' | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
178 } |
441
e59e381b4fca
- suite_aggrs: silenced warning, generated real case list
Tassilo Philipp
parents:
438
diff
changeset
|
179 o = { '=', '==', 'f_cp', 'f_cmp', '; ', ' && ', '', '1' } |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
180 for t = 1, 2 do |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
181 if t ~= 1 or aggrcpsimple == false then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
182 io.write(s[t]) |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
183 local b = {} |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
184 for i = 1, #am, 2 do |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
185 local m = split_array_decl(am[i+1]) |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
186 local fmt = '' |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
187 if m[2] ~= nil then -- need array suffixes? |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
188 fmt = '[%d]' |
462 | 189 else |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
190 m[2] = 1 |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
191 end |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
192 |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
193 for j = 1, m[2] do |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
194 name = m[1]..string.format(fmt, j-1) |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
195 if string.match(am[i], ' ') then -- aggregate canonical types contain at least one space |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
196 b[#b+1] = o[t+2]..am[i]:sub(8)..'(&x->'..name..', &y->'..name..')' |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
197 else |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
198 b[#b+1] = 'x->'..name..' '..o[t]..' y->'..name |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
199 end |
462 | 200 end |
201 end | |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
202 if #b == 0 then -- to handle empty aggregates |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
203 b[1] = o[t+6] |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
204 end |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
205 io.write(table.concat(b,o[t+4]).."; };\n") |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
206 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
207 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
208 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
209 -- convenient dcnewstruct helper funcs |
500
7426cfbe92d5
- call_suite_aggrs; removal of old isPod logic
Tassilo Philipp
parents:
496
diff
changeset
|
210 io.write('DCaggr* f_touchdcst'..at:sub(8)..'() {\n\tstatic DCaggr* at = NULL;\n\tif(!at) {\n\t\tat = dcNewAggr('..(#am>>1)..', sizeof('..at..'));\n\t\t') |
462 | 211 for i = 1, #am, 2 do |
212 local m = split_array_decl(am[i+1]) | |
213 if m[2] == nil then -- need array suffixes? | |
214 m[2] = 1 | |
215 end | |
216 if string.match(am[i], ' ') then -- aggregate canonical types contain at least one space | |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
217 --io.write('dcAggrField(at, DC_SIGCHAR_AGGREGATE, offsetof('..at..', '..m[1]..'), '..m[2]..', f_touchdcst'..am[i]:sub(8)..'());\n\t\t') |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
218 io.write("AFa("..at..','..m[1]..','..m[2]..','..am[i]:sub(8)..')\n\t\t') |
462 | 219 else |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
220 --io.write("dcAggrField(at, '"..am[i].."', offsetof("..at..', '..m[1]..'), '..m[2]..');\n\t\t') |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
221 io.write("AF('"..am[i].."',"..at..','..m[1]..','..m[2]..')\n\t\t') |
462 | 222 end |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
223 end |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
224 io.write("dcCloseAggr(at);\n\t}\n\treturn at;\n};\n") |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
225 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
226 |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
227 -- make table.concat work |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
228 if #agg_names > 0 then |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
229 table.insert(agg_names, 1, '') |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
230 end |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
231 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
232 io.write(cases) |
512 | 233 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true)) |
234 io.write(mksigtab(sigtab, '', 'G_sigtab')) | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
235 io.write('const char* G_agg_sigs[] = {\n\t"'..table.concat(agg_sigs, '",\n\t"')..'"\n};\n') |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
236 io.write('int G_agg_sizes[] = {\n\t'..table.concat(agg_sizes, ',\n\t')..'\n};\n') |
438 | 237 io.write('funptr G_agg_touchdcstfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_touchdcst'),2)..'\n};\n') |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
238 io.write('funptr G_agg_cmpfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_cmp'),2)..'\n};\n') |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
239 io.write("int G_maxargs = "..max_numargs..";\n") |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
240 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
241 |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
242 math.randomseed(seed) |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
243 mkall() |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
244 |