annotate test/call_suite_aggrs/mk-cases.lua @ 527:ed8835abe05f

- cosmetics
author Tassilo Philipp
date Thu, 14 Apr 2022 10:13:10 +0200
parents 93628a1eaed4
children d28b09fa2ff9
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
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
9
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
10 -- returns: generated case str, num args; accumulates unique idx => aggr-sig in
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
11 -- aggrs (sequentially) and aggr-sig => {body,name} in seen_aggrs (depth first
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
12 -- for nested aggrs, so sub-aggrs conveniently precede parents)
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
13 function mkcase(id, sig, aggrs, seen_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
14 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
15 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
16 local h = { "/* ",id,":",sig," */ " }
526
93628a1eaed4 tests: integrate new tests into makefiles, some cleanups
Tassilo Philipp
parents: 522
diff changeset
17 local t = { }
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
18 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
19 local n_nest = 0
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
20 local aggr = { }
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
21 local aggr_sig = { }
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
22 aggr[0] = { } -- non-sequential [0] collects all non-aggr types (not used, though)
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
23 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
24 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
25 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
26 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
27
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
28 -- aggregate nest level change?
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
29 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
30 n_nest = n_nest + 1
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
31 aggr[n_nest] = { }
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
32 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
33 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
34
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
35 aggr_sig[n_nest] = aggr_sig[n_nest]..ch
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
36
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
37 -- array? Just append to name of member var from prev loop
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
38 if ch:match('[%[%]0123456789]') ~= nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
39 aggr[n_nest][#aggr[n_nest]] = aggr[n_nest][#aggr[n_nest]]..ch
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
40 else
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
41 -- register (sub)aggrs on closing char
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
42 if ch == '}' or ch == '>' then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
43 -- only add unseen aggregates, key is aggr sig, val is body and name
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
44 if seen_aggrs[aggr_sig[n_nest]] == nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
45 aggrs[#aggrs+1] = aggr_sig[n_nest]
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
46 if ch == '}' then ch = 'struct ' else ch = 'union ' end
527
ed8835abe05f - cosmetics
Tassilo Philipp
parents: 526
diff changeset
47 ch = ch..'A'..#aggrs
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
48 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch }
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
49 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
50 ch = seen_aggrs[aggr_sig[n_nest]][2]
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
51
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
52 n_nest = n_nest - 1
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
53 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
54 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
55
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
56 -- add member type and var name to aggr
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
57 if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
58 aggr[n_nest][#aggr[n_nest]+1] = ch
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
59 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
60 end
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
61
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
62 -- no nesting (= actual func args), generate case code
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
63 if n_nest == 0 then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
64 h[#h+1] = ch
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
65 -- aggregate types have more than one char
526
93628a1eaed4 tests: integrate new tests into makefiles, some cleanups
Tassilo Philipp
parents: 522
diff changeset
66 if #ch > 1 then
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
67 if aggrcpsimple then
526
93628a1eaed4 tests: integrate new tests into makefiles, some cleanups
Tassilo Philipp
parents: 522
diff changeset
68 t[#t+1] = '*('..ch..'*)V_a['..pos.."]="..name..";"
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
69 else
526
93628a1eaed4 tests: integrate new tests into makefiles, some cleanups
Tassilo Philipp
parents: 522
diff changeset
70 t[#t+1] = 'f_cp'..ch:match('A.*')..'(V_a['..pos.."],&"..name..");"
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
71 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
72 if aggrmutabletest then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
73 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
74 end
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
75 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
76 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";"
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
77 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
78
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
79 -- is return type or func arg?
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
80 if pos == -1 then
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
81 h[#h+1] = " f"..id.."("
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
82 h[#h+1] = ''
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
83 t[#t] = '' -- clear; aggr return type handled explicitly
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
84 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
85 h[#h+1] = ' '..name
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
86 h[#h+1] = ","
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 pos = pos + 1
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
90 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
91 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
92 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
93 h[#h] = "){"
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
94 if #h[6] == 1 then
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
95 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
96 else
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
97 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
98 end
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
99 return table.concat(h,"")..table.concat(t,""), pos
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
100 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
101
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
102
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
103 function mkall()
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
104 local lineno = 0
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
105 local sigtab = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
106 local cases = ''
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
107 local aggrs = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
108 local seen_aggrs = { }
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
109 local max_numargs = 0
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
110
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
111 for line in io.lines() do
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
112 local sig = trim(line)
527
ed8835abe05f - cosmetics
Tassilo Philipp
parents: 526
diff changeset
113 local c, n = mkcase(lineno, sig, aggrs, seen_aggrs)
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
114 cases = cases..c
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
115 max_numargs = math.max(max_numargs, n)
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
116 sigtab[#sigtab+1] = sig
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
117 lineno = lineno + 1
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
118 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
119
522
f7fec6699e21 - test code generator code: var abstraction
Tassilo Philipp
parents: 521
diff changeset
120 local agg_defs, agg_sizes, agg_sigs, agg_names = mkaggrdefs(aggrs, seen_aggrs, aggrpacking, aggrpackingseed, aggrcpsimple)
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
121
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
122 -- make table.concat work
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
123 if #agg_names > 0 then
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
124 table.insert(agg_names, 1, '')
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
125 end
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
126
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
127 io.write(table.concat(agg_defs,'\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
128 io.write(cases)
512
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 510
diff changeset
129 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true))
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 510
diff changeset
130 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
131 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
132 io.write('int G_agg_sizes[] = {\n\t'..table.concat(agg_sizes, ',\n\t')..'\n};\n')
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
133 io.write('funptr G_agg_touchAfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_touch'),2)..'\n};\n')
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
134 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
135 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
136 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
137
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
138 mkall()
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
139