Mercurial > pub > dyncall > dyncall
annotate test/call_suite_aggrs/mk-cases.lua @ 619:c754150fe87f
- x64 win disas example fix and addition
author | Tassilo Philipp |
---|---|
date | Mon, 03 Oct 2022 13:49:19 +0200 |
parents | ed8835abe05f |
children | d28b09fa2ff9 |
rev | line source |
---|---|
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
1 require"config" |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
2 require"math" |
514 | 3 |
4 -- use shared helpers to generate cases | |
5 package.path = '../common/?.lua;' .. package.path | |
6 require"mk-cases" | |
7 | |
8 | |
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 | 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 | 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 | 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 | 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 | 37 -- array? Just append to name of member var from prev loop |
38 if ch:match('[%[%]0123456789]') ~= nil then | |
39 aggr[n_nest][#aggr[n_nest]] = aggr[n_nest][#aggr[n_nest]]..ch | |
40 else | |
519 | 41 -- register (sub)aggrs on closing char |
462 | 42 if ch == '}' or ch == '>' then |
519 | 43 -- only add unseen aggregates, key is aggr sig, val is body and name |
462 | 44 if seen_aggrs[aggr_sig[n_nest]] == nil then |
45 aggrs[#aggrs+1] = aggr_sig[n_nest] | |
519 | 46 if ch == '}' then ch = 'struct ' else ch = 'union ' end |
527 | 47 ch = ch..'A'..#aggrs |
462 | 48 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch } |
49 end | |
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 | 52 n_nest = n_nest - 1 |
53 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1] | |
54 end | |
55 | |
519 | 56 -- add member type and var name to aggr |
462 | 57 if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then |
519 | 58 aggr[n_nest][#aggr[n_nest]+1] = ch |
462 | 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 | 62 -- no nesting (= actual func args), generate case code |
63 if n_nest == 0 then | |
519 | 64 h[#h+1] = ch |
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 | 75 else |
76 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" | |
77 end | |
78 | |
79 -- is return type or func arg? | |
510 | 80 if pos == -1 then |
462 | 81 h[#h+1] = " f"..id.."(" |
82 h[#h+1] = '' | |
83 t[#t] = '' -- clear; aggr return type handled explicitly | |
84 else | |
85 h[#h+1] = ' '..name | |
86 h[#h+1] = "," | |
87 end | |
88 | |
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 | 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 | 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 | 100 end |
101 | |
102 | |
103 function mkall() | |
104 local lineno = 0 | |
105 local sigtab = { } | |
106 local cases = '' | |
107 local aggrs = { } | |
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 | 110 |
111 for line in io.lines() do | |
112 local sig = trim(line) | |
527 | 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 | 116 sigtab[#sigtab+1] = sig |
117 lineno = lineno + 1 | |
118 end | |
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 | 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 | 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 | 129 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true)) |
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 |