annotate test/call_suite_aggrs/mk-cases.lua @ 624:d28b09fa2ff9

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