Mercurial > pub > dyncall > dyncall
annotate test/call_suite_aggrs/mk-cases.lua @ 522:f7fec6699e21
- test code generator code: var abstraction
author | Tassilo Philipp |
---|---|
date | Wed, 13 Apr 2022 10:19:49 +0200 |
parents | a2de1d0a73f3 |
children | 93628a1eaed4 |
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," */ " } |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
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 |
462 | 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 -- aggregate nest level change? |
461 | 30 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
|
31 n_nest = n_nest + 1 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
32 aggr[n_nest] = { } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
33 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
|
34 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
35 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
36 aggr_sig[n_nest] = aggr_sig[n_nest]..ch |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
37 |
462 | 38 -- array? Just append to name of member var from prev loop |
39 if ch:match('[%[%]0123456789]') ~= nil then | |
40 aggr[n_nest][#aggr[n_nest]] = aggr[n_nest][#aggr[n_nest]]..ch | |
41 else | |
519 | 42 -- register (sub)aggrs on closing char |
462 | 43 if ch == '}' or ch == '>' then |
519 | 44 -- only add unseen aggregates, key is aggr sig, val is body and name |
462 | 45 if seen_aggrs[aggr_sig[n_nest]] == nil then |
46 aggrs[#aggrs+1] = aggr_sig[n_nest] | |
519 | 47 if ch == '}' then ch = 'struct ' else ch = 'union ' end |
48 ch = ch..'A'..#aggrs | |
462 | 49 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch } |
50 end | |
51 ch = seen_aggrs[aggr_sig[n_nest]][2] | |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
52 |
462 | 53 n_nest = n_nest - 1 |
54 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1] | |
55 end | |
56 | |
519 | 57 -- add member type and var name to aggr |
462 | 58 if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then |
519 | 59 aggr[n_nest][#aggr[n_nest]+1] = ch |
462 | 60 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
|
61 end |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
62 |
462 | 63 -- no nesting (= actual func args), generate case code |
64 if n_nest == 0 then | |
519 | 65 h[#h+1] = ch |
66 -- aggregate types have more than one char | |
462 | 67 if #h[#h] > 1 then |
482
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
68 if aggrcpsimple then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
69 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
|
70 else |
519 | 71 t[#t+1] = 'f_cp'..h[#h]: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
|
72 end |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
73 if aggrmutabletest then |
0f3b6898078d
suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents:
462
diff
changeset
|
74 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
|
75 end |
462 | 76 else |
77 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" | |
78 end | |
79 | |
80 -- is return type or func arg? | |
510 | 81 if pos == -1 then |
462 | 82 h[#h+1] = " f"..id.."(" |
83 h[#h+1] = '' | |
84 t[#t] = '' -- clear; aggr return type handled explicitly | |
85 else | |
86 h[#h+1] = ' '..name | |
87 h[#h+1] = "," | |
88 end | |
89 | |
90 pos = pos + 1 | |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
91 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
|
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 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
94 h[#h] = "){" |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
95 if #h[6] == 1 then |
510 | 96 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
|
97 else |
510 | 98 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
|
99 end |
521
a2de1d0a73f3
- more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents:
519
diff
changeset
|
100 return table.concat(h,"")..table.concat(t,""), pos |
519 | 101 end |
102 | |
103 | |
104 function mkall() | |
105 local lineno = 0 | |
106 local sigtab = { } | |
107 local cases = '' | |
108 local aggrs = { } | |
109 local seen_aggrs = { } | |
521
a2de1d0a73f3
- more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents:
519
diff
changeset
|
110 local max_numargs = 0 |
519 | 111 |
112 for line in io.lines() do | |
113 local sig = trim(line) | |
521
a2de1d0a73f3
- more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents:
519
diff
changeset
|
114 local c, n = mkcase(lineno, sig, aggrs, seen_aggrs) |
a2de1d0a73f3
- more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents:
519
diff
changeset
|
115 cases = cases..c |
a2de1d0a73f3
- more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents:
519
diff
changeset
|
116 max_numargs = math.max(max_numargs, n) |
519 | 117 sigtab[#sigtab+1] = sig |
118 lineno = lineno + 1 | |
119 end | |
120 | |
522
f7fec6699e21
- test code generator code: var abstraction
Tassilo Philipp
parents:
521
diff
changeset
|
121 local agg_defs, agg_sizes, agg_sigs, agg_names = mkaggrdefs(aggrs, seen_aggrs, aggrpacking, aggrpackingseed, aggrcpsimple) |
519 | 122 |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
123 -- make table.concat work |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
124 if #agg_names > 0 then |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
125 table.insert(agg_names, 1, '') |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
126 end |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
127 |
519 | 128 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
|
129 io.write(cases) |
512 | 130 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true)) |
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
138 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
139 mkall() |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
140 |