annotate test/call_suite_aggrs/mk-cases.lua @ 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 7426cfbe92d5
children ed7d1f5e7973
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"
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
3 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
4
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
5 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
6 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
7
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
8
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
9 function canon_type(t)
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
10 -- aggregate types start with special (closing) char
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
11 c = ({ ['}'] = 'struct ', ['>'] = 'union ' })[t:sub(1,1)]
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
12 if c ~= nil then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
13 return c..'A'..t:sub(2)
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
14 end
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
15 return t
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
16 end
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
17
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
18 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
19 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
20 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
21
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
22
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
23 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
24 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
25 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
26 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
27 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
28 local t = { "" }
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
29 local pos = 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
30 local n_nest = 0
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
31 local aggr = { }
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
32 local aggr_sig = { }
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
33 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
34 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
35 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
36 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
37 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
38
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
39
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
40 -- aggregate nest level change?
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
41 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
42 n_nest = n_nest + 1
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
43 aggr[n_nest] = { }
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
44 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
45 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
46
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
47 aggr_sig[n_nest] = aggr_sig[n_nest]..ch
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
48
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
49 -- array? Just append to name of member var from prev loop
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
50 if ch:match('[%[%]0123456789]') ~= nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
51 aggr[n_nest][#aggr[n_nest]] = aggr[n_nest][#aggr[n_nest]]..ch
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
52 else
434
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 if ch == '}' or ch == '>' then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
55 -- register yet unseen aggregates, key is sig, val is body and name
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
56 if seen_aggrs[aggr_sig[n_nest]] == nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
57 aggrs[#aggrs+1] = aggr_sig[n_nest]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
58 ch = ch..#aggrs
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
59 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch }
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
60 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
61 ch = seen_aggrs[aggr_sig[n_nest]][2]
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
62
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
63 n_nest = n_nest - 1
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
64 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
65 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
66
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
67 if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
68 aggr[n_nest][#aggr[n_nest]+1] = canon_type(ch)
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
69 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
70 end
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
71
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
72 -- no nesting (= actual func args), generate case code
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
73 if n_nest == 0 then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
74 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
75 -- aggregate types have more than one
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
76 if #h[#h] > 1 then
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
77 if aggrcpsimple then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
78 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
79 else
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
80 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
81 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
82 if aggrmutabletest then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
83 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
84 end
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
85 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
86 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";"
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
87 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
88
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
89 -- is return type or func arg?
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
90 if pos == 0 then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
91 h[#h+1] = " f"..id.."("
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
92 h[#h+1] = ''
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
93 t[#t] = '' -- clear; aggr return type handled explicitly
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
94 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
95 h[#h+1] = ' '..name
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
96 h[#h+1] = ","
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
97 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
98
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
99 pos = pos + 1
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
100 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
101 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
102 end
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
103 max_numargs = math.max(max_numargs, 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
104 h[#h] = "){"
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
105 if #h[6] == 1 then
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
106 t[#t+1] = "ret_"..h[6].."("..(pos-1)..")}\n"
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
107 else
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
108 t[#t+1] = "ret_a("..(pos-1)..","..h[6]..")}\n"
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
109 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
110 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
111 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
112
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
113 function mkfuntab(n)
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
114 local s = { "funptr G_funtab[] = {\n"}
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
115 for i = 0, n-1 do
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
116 s[#s+1] = "\t(funptr)&f"..i..",\n"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
117 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
118 s[#s+1] = "};\n"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
119 return table.concat(s,"")
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
120 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
121
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
122 function mksigtab(sigs)
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
123 local s = { "char const * G_sigtab[] = {\n"}
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
124 for k,v in pairs(sigs) do
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
125 s[#s+1] = '\t"'..v..'",\n'
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
126 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
127 s[#s+1] = "};\n"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
128 return table.concat(s,"")
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
129 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
130
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
131 function split_array_decl(s)
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
132 local name = s
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
133 local n = nil -- not an array
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
134 local array_i = s:find('%[')
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
135 if array_i ~= nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
136 name = name:sub(1, array_i-1)
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
137 n = tonumber(s:sub(array_i):match('[0123456789]+'))
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
138 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
139 return { name, n }
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
140 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
141
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
142 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
143 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
144 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
145 local cases = ''
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 500
diff changeset
146
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
147 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
148 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
149 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
150 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
151 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
152 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
153
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
154 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
155 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
156 agg_names = {}
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
157 for a = 1, #aggrs do
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
158 local k = aggrs[a]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
159 local v = seen_aggrs[k]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
160 local at = canon_type(v[2]) -- aggregate type
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
161 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
162
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
163 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
164 agg_sigs [#agg_sigs + 1] = k
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
165 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
166
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
167 -- 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
168 io.write('/* '..k..' */\n')
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
169 if aggrpacking ~= 0 then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
170 local pack = aggrpacking
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
171 if pack < 0 then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
172 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
173 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
174 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
175 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
176
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
177 io.write(at..' { ')
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
178 for i = 1, #am, 2 do
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
179 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
180 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
181 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
182
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
183 if aggrpacking ~= 0 then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
184 io.write('#pragma pack(pop)\n')
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
185 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
186
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
187 -- 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
188 s = {
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
189 'void f_cp'..at:sub(8)..'('..at..' *x, const '..at..' *y) { ',
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
190 '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
191 }
441
e59e381b4fca - suite_aggrs: silenced warning, generated real case list
Tassilo Philipp
parents: 438
diff changeset
192 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
193 for t = 1, 2 do
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
194 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
195 io.write(s[t])
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
196 local b = {}
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
197 for i = 1, #am, 2 do
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
198 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
199 local fmt = ''
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
200 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
201 fmt = '[%d]'
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
202 else
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
203 m[2] = 1
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
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
206 for j = 1, m[2] do
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
207 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
208 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
209 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
210 else
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
211 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
212 end
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
213 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
214 end
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
215 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
216 b[1] = o[t+6]
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
217 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
218 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
219 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
220 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
221
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
222 -- convenient dcnewstruct helper funcs
500
7426cfbe92d5 - call_suite_aggrs; removal of old isPod logic
Tassilo Philipp
parents: 496
diff changeset
223 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
224 for i = 1, #am, 2 do
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
225 local m = split_array_decl(am[i+1])
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
226 if m[2] == nil then -- need array suffixes?
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
227 m[2] = 1
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
228 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
229 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
230 --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
231 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
232 else
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
233 --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
234 io.write("AF('"..am[i].."',"..at..','..m[1]..','..m[2]..')\n\t\t')
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
235 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
236 end
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
237 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
238 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
239
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
240 -- make table.concat work
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
241 if #agg_names > 0 then
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
242 table.insert(agg_names, 1, '')
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
243 end
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
244
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
245 io.write(cases)
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
246 io.write(mkfuntab(lineno))
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
247 io.write(mksigtab(sigtab))
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
248 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
249 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
250 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
251 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
252 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
253 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
254
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
255 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
256 mkall()
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
257