Mercurial > pub > dyncall > dyncall
annotate test/call_suite/mk-cases.lua @ 512:4d0541bf9b38
- sharing some test case gen code
author | Tassilo Philipp |
---|---|
date | Sun, 10 Apr 2022 15:51:00 +0200 |
parents | a0c51f34023a |
children | 01f928eb9584 |
rev | line source |
---|---|
0 | 1 require"math" |
2 local max = math.max | |
3 local maxargs = 0 | |
4 | |
5 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end | |
6 function mkcase(id,sig) | |
7 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:
430
diff
changeset
|
8 local h = { "/* ",id,":",sig," */ ",sig:sub(-1), " f", id,"(","" } |
430 | 9 local t = { "" } |
0 | 10 local pos = 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:
430
diff
changeset
|
11 maxargs = max(maxargs, #sig-2) |
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
430
diff
changeset
|
12 for i = 1, #sig-2 do |
0 | 13 local name = "a"..pos |
14 local ch = sig:sub(i,i) | |
430 | 15 h[#h+1] = ch.." "..name |
0 | 16 h[#h+1] = "," |
430 | 17 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" |
511 | 18 pos = pos + 1 |
0 | 19 end |
20 h[#h] = "){" | |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
430
diff
changeset
|
21 t[#t+1] = "ret_"..sig:sub(-1).."("..pos..")}\n" |
0 | 22 return table.concat(h,"")..table.concat(t,"") |
23 end | |
24 | |
512 | 25 -- use shared helpers to generate cases |
26 package.path = '../common/?.lua;' .. package.path | |
27 require"mk-cases" | |
0 | 28 |
29 | |
30 function mkall() | |
430 | 31 local lineno = 0 |
0 | 32 local sigtab = { } |
33 for line in io.lines() do | |
34 local sig = trim(line) | |
35 io.write(mkcase(lineno,sig)) | |
36 sigtab[#sigtab+1] = sig | |
37 lineno = lineno + 1 | |
38 end | |
512 | 39 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true)) |
40 io.write(mksigtab(sigtab, '', 'G_sigtab')) | |
0 | 41 io.write("int G_maxargs = "..maxargs..";\n") |
42 end | |
43 | |
44 mkall() | |
45 |