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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
3
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
4 -- use shared helpers to generate cases
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
5 package.path = '../common/?.lua;' .. package.path
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
6 require"mk-cases"
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
7
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
16 -- aggregate types start with special (closing) char
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
17 c = ({ ['}'] = 'struct ', ['>'] = 'union ' })[t:sub(1,1)]
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
18 if c ~= nil then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
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
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
54 -- array? Just append to name of member var from prev loop
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
55 if ch:match('[%[%]0123456789]') ~= nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
56 aggr[n_nest][#aggr[n_nest]] = aggr[n_nest][#aggr[n_nest]]..ch
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
57 else
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
58
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
59 if ch == '}' or ch == '>' then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
60 -- register yet unseen aggregates, key is sig, val is body and name
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
61 if seen_aggrs[aggr_sig[n_nest]] == nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
62 aggrs[#aggrs+1] = aggr_sig[n_nest]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
63 ch = ch..#aggrs
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
64 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch }
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
65 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
68 n_nest = n_nest - 1
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
69 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
70 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
71
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
72 if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
73 aggr[n_nest][#aggr[n_nest]+1] = canon_type(ch)
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
77 -- no nesting (= actual func args), generate case code
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
78 if n_nest == 0 then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
90 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
91 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";"
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
92 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
93
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
94 -- is return type or func arg?
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
95 if pos == -1 then
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
96 h[#h+1] = " f"..id.."("
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
97 h[#h+1] = ''
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
98 t[#t] = '' -- clear; aggr return type handled explicitly
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
99 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
100 h[#h+1] = ' '..name
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
101 h[#h+1] = ","
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
102 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
103
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
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
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
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
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
118 function split_array_decl(s)
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
119 local name = s
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
120 local n = nil -- not an array
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
121 local array_i = s:find('%[')
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
122 if array_i ~= nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
123 name = name:sub(1, array_i-1)
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
124 n = tonumber(s:sub(array_i):match('[0123456789]+'))
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
125 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
126 return { name, n }
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
127 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
145 local k = aggrs[a]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
146 local v = seen_aggrs[k]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
147 local at = canon_type(v[2]) -- aggregate type
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
164 io.write(at..' { ')
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
165 for i = 1, #am, 2 do
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
176 'void f_cp'..at:sub(8)..'('..at..' *x, const '..at..' *y) { ',
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
200 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
211 for i = 1, #am, 2 do
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
212 local m = split_array_decl(am[i+1])
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
213 if m[2] == nil then -- need array suffixes?
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
214 m[2] = 1
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
215 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
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
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 510
diff changeset
233 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true))
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 510
diff changeset
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
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
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