File: make-signatures.lua

package info (click to toggle)
nqp 2014.07-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,596 kB
  • ctags: 7,993
  • sloc: ansic: 22,689; java: 20,240; cpp: 4,956; asm: 3,976; perl: 950; python: 267; sh: 245; makefile: 14
file content (64 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require "config"
require "math"
require "string"

local nargtypes = string.len(argtypes)
local nrettypes = string.len(rettypes)
local argrange  = maxargs - minargs
math.randomseed(seed)

function randomSignatures(nsigs)
  local i 
  for i = 1, nsigs do
    local nargs = minargs + math.random(argrange+1) - 1 
    local signature = ""
    for j = 1, nargs do
      local typeindex = math.random(nargtypes)
      signature = signature .. string.sub(argtypes, typeindex, typeindex)
    end
    local rtypeindex = math.random(nrettypes)
    signature = signature .. ")" .. string.sub(rettypes, rtypeindex, rtypeindex)
    io.write(signature .. "\n")
  end
end

function orderedSignature(x)
  local signature = ""
  local typeindex
  while true do
    if x < nargtypes then break end
    typeindex = 1 + math.mod(x, nargtypes)
    signature = signature .. string.sub(argtypes, typeindex, typeindex)
    x = math.floor( x / nargtypes )
  end
  typeindex = 1 + x
  signature = signature .. ")" .. string.sub(argtypes, typeindex, typeindex)
  return signature
end

function orderedSignatures(nsigs)
  local i 
  for i = 1, nsigs do
    io.write( orderedSignature(offset+i*step) .. "\n" )
  end
end

function designedSignatures()
 for line in io.lines(designfile) do
   io.write( line )
   io.write( "\n" )
 end
end

if mode == "random" then
  randomSignatures(nsigs)
elseif mode == "ordered" then
  orderedSignatures(nsigs)
elseif mode == "designed" then
  designedSignatures()
else
  error("'mode' must be 'random' or 'ordered'")
end

io.flush()