view test/suite_aggrs/rand-sig.lua @ 433:45662241d9cd

suite_aggrs now handling struct by value return types, also still missing: nesting, unions, arrays note: this doesn't compile against this same checked in revision of dyncall, but only my working copy; a future checkin will catch up
author Tassilo Philipp
date Sat, 22 Jan 2022 16:07:57 +0100
parents 167faab0c0be
children 3d2c5d156d78
line wrap: on
line source

require"config"

-- assure aggr chars are present in pairs (can be weighted, though), to avoid
-- inf loops
if string.match(types,'{') and not string.match(types,'}') then types = types..'}' end

rtypes   = "v"..types


function mkstruct(n_nest)
  local s = "{"

  repeat
    local id = math.random(#types)
    local t = types:sub(id,id)
    s = s..mktype(t, n_nest)
  until t == '}'

  return s
end

function mktype(t, n_nest)
  -- ignore new structs if above depth limit
  if t == '{' then
    if n_nest < maxaggrdepth then
      return mkstruct(n_nest + 1)
    else
      return ''
    end
  end

  -- if '}', without any open, use empty struct
  if n_nest == 0 and t == '}' then
    return "{}"
  end

  return t
end


math.randomseed(seed)
local id
for i = 1, ncases do
  id = math.random(#rtypes)
  local nargs = math.random(minargs,maxargs)
  local sig   = { mktype(rtypes:sub(id,id), 0) }
  for j = 1, nargs do
    id = math.random(#types)
    sig[#sig+1] = mktype(types:sub(id,id), 0)
  end
  io.write(table.concat(sig))
  io.write("\n")
end