comparison test/callback_suite/make-signatures.lua @ 0:3e629dc19168

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:24:28 +0100
parents
children 45ac093ca822
comparison
equal deleted inserted replaced
-1:000000000000 0:3e629dc19168
1 require "config"
2 require "math"
3 require "string"
4
5 local nargtypes = string.len(argtypes)
6 local nrettypes = string.len(rettypes)
7 local argrange = maxargs - minargs
8 math.randomseed(seed)
9
10 function randomSignatures(nsigs)
11 local i
12 for i = 1, nsigs do
13 local nargs = minargs + math.random(argrange+1) - 1
14 local signature = ""
15 for j = 1, nargs do
16 local typeindex = math.random(nargtypes)
17 signature = signature .. string.sub(argtypes, typeindex, typeindex)
18 end
19 local rtypeindex = math.random(nrettypes)
20 signature = signature .. ")" .. string.sub(rettypes, rtypeindex, rtypeindex)
21 io.write(signature .. "\n")
22 end
23 end
24
25 function orderedSignature(x)
26 local signature = ""
27 local typeindex
28 while true do
29 if x < nargtypes then break end
30 typeindex = 1 + math.mod(x, nargtypes)
31 signature = signature .. string.sub(argtypes, typeindex, typeindex)
32 x = math.floor( x / nargtypes )
33 end
34 typeindex = 1 + x
35 signature = signature .. ")" .. string.sub(argtypes, typeindex, typeindex)
36 return signature
37 end
38
39 function orderedSignatures(nsigs)
40 local i
41 for i = 1, nsigs do
42 io.write( orderedSignature(offset+i*step) .. "\n" )
43 end
44 end
45
46 function designedSignatures()
47 for line in io.lines(designfile) do
48 io.write( line )
49 io.write( "\n" )
50 end
51 end
52
53 if mode == "random" then
54 randomSignatures(nsigs)
55 elseif mode == "ordered" then
56 orderedSignatures(nsigs)
57 elseif mode == "designed" then
58 designedSignatures()
59 else
60 error("'mode' must be 'random' or 'ordered'")
61 end
62
63 io.flush()
64