Mercurial > pub > dyncall > dyncall
annotate test/suite_aggrs/rand-sig.lua @ 462:653b65580cb4
suite_aggr:
- added arrays (inside of structs/unions, only, as only way to pass/return them by value)
- cleanups and pregen of source
author | Tassilo Philipp |
---|---|
date | Tue, 01 Feb 2022 21:44:18 +0100 |
parents | 236015fdf7a8 |
children | bd8f5da2c74b |
rev | line source |
---|---|
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
1 require"config" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
2 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid |
461 | 4 -- inf loops; closing chars are allowe to appear alone, as they are ignored |
5 -- without any opening char (does not make a lot of sense, though) | |
6 pairs_op = { '{', '<' } --, '[' } | |
7 pairs_cl = { '}', '>' } --, ']' } | |
8 | |
462 | 9 aggr_op_pattern = '[%'..table.concat(pairs_op,'%')..']' |
10 | |
461 | 11 for i = 1, #pairs_op do |
12 if string.find(types, '%'..pairs_op[i]) and not string.find(types, '%'..pairs_cl[i]) then | |
13 types = types..pairs_cl[i] | |
14 end | |
15 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
|
16 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
17 rtypes = "v"..types |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
18 |
461 | 19 function mkaggr(n_nest, maxdepth, o, c) |
20 local s = o | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
21 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
22 repeat |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
23 local id = math.random(#types) |
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 t = types:sub(id,id) |
461 | 25 s = s..mktype(t, n_nest, maxdepth, o) |
462 | 26 |
27 -- member (which cannot be first char) as array? Disallow multidimensional arrays | |
28 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then | |
29 s = s..'['..math.random(maxarraylen)..']' | |
30 end | |
461 | 31 until t == c |
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 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
33 return s |
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 |
461 | 36 function mktype(t, n_nest, maxdepth, aggr_open) |
37 -- aggregate opener? | |
38 local aggr_i = 0 | |
39 for i = 1, #pairs_op do | |
40 if pairs_op[i] == t then | |
41 aggr_i = i | |
42 break | |
43 end | |
44 end | |
45 | |
46 -- ignore new aggregates if above depth limit | |
47 if aggr_i ~= 0 and t == pairs_op[aggr_i] then | |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
48 if n_nest < maxdepth then |
461 | 49 return mkaggr(n_nest + 1, maxdepth, pairs_op[aggr_i], pairs_cl[aggr_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
|
50 else |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
51 return '' |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
52 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
53 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
54 |
461 | 55 -- aggregate closer? |
56 for i = 1, #pairs_cl do | |
57 if pairs_cl[i] == t then | |
58 aggr_i = i | |
59 break | |
60 end | |
61 end | |
62 | |
63 -- if closing char, without any open, ignore | |
64 if aggr_i ~= 0 and (aggr_open == nil or pairs_op[aggr_i] ~= aggr_open) then | |
65 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
|
66 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
67 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
68 return t |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
69 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
70 |
461 | 71 function contains_empty_aggr(s) |
72 for i = 1, #pairs_op do | |
73 if string.match(s, '%'..pairs_op[i]..'%'..pairs_cl[i]) ~= nil then | |
74 return true | |
75 end | |
76 end | |
77 return false | |
78 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
|
79 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
80 math.randomseed(seed) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
81 local id |
438 | 82 local uniq_sigs = { } |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
83 for i = 1, ncases do |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
84 local l = '' |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
85 repeat |
461 | 86 local nargs = math.random(minargs,maxargs) |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
87 id = math.random(#rtypes) |
461 | 88 local sig = { mktype(rtypes:sub(id,id), 0, math.random(maxaggrdepth), nil) } -- random depth avoids excessive nesting |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
89 for j = 1, nargs do |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
90 id = math.random(#types) |
461 | 91 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
92 end |
438 | 93 l = table.concat(sig) |
446
54c1dc2e6ea5
suite_aggrs: added knob to enable/disable generation of empty structs (some compilers like Plan9's pcc don't allow them)
Tassilo Philipp
parents:
438
diff
changeset
|
94 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) |
461 | 95 until string.match(l, aggr_op_pattern) ~= nil and uniq_sigs[l] == nil and (emptyaggrs or not contains_empty_aggr(l)) |
438 | 96 uniq_sigs[l] = 1 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
97 io.write(l.."\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
|
98 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
99 |