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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 require"math"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 local max = math.max
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 local maxargs = 0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 function mkcase(id,sig)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
8e22b70d3ee4 - simplified test/call_suite further
Tassilo Philipp
parents: 0
diff changeset
9 local t = { "" }
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 local name = "a"..pos
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 local ch = sig:sub(i,i)
430
8e22b70d3ee4 - simplified test/call_suite further
Tassilo Philipp
parents: 0
diff changeset
15 h[#h+1] = ch.." "..name
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 h[#h+1] = ","
430
8e22b70d3ee4 - simplified test/call_suite further
Tassilo Philipp
parents: 0
diff changeset
17 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";"
511
a0c51f34023a test/call_suite:
Tassilo Philipp
parents: 506
diff changeset
18 pos = pos + 1
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 end
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 return table.concat(h,"")..table.concat(t,"")
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 end
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24
512
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 511
diff changeset
25 -- use shared helpers to generate cases
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 511
diff changeset
26 package.path = '../common/?.lua;' .. package.path
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 511
diff changeset
27 require"mk-cases"
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 function mkall()
430
8e22b70d3ee4 - simplified test/call_suite further
Tassilo Philipp
parents: 0
diff changeset
31 local lineno = 0
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 local sigtab = { }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 for line in io.lines() do
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 local sig = trim(line)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 io.write(mkcase(lineno,sig))
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 sigtab[#sigtab+1] = sig
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 lineno = lineno + 1
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 end
512
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 511
diff changeset
39 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true))
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 511
diff changeset
40 io.write(mksigtab(sigtab, '', 'G_sigtab'))
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 io.write("int G_maxargs = "..maxargs..";\n")
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 end
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 mkall()
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45