diff test/call_suite/mk-cases.lua @ 430:8e22b70d3ee4

- simplified test/call_suite further
author Tassilo Philipp
date Mon, 17 Jan 2022 15:46:38 +0100
parents 3e629dc19168
children da5232da6270
line wrap: on
line diff
--- a/test/call_suite/mk-cases.lua	Mon Jan 17 11:36:09 2022 +0100
+++ b/test/call_suite/mk-cases.lua	Mon Jan 17 15:46:38 2022 +0100
@@ -5,42 +5,26 @@
 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end
 function mkcase(id,sig)
   local sig = trim(sig)
-  local h = { "/* ",id,":",sig," */ ",sig:sub(1,1), " f", id,"(",""}
-  local t = { "fid=",id,";" }
+  local h = { "/* ",id,":",sig," */ ",sig:sub(1,1), " f", id,"(","" }
+  local t = { "" }
   local pos = 0
   maxargs = max(maxargs, #sig-1)
   for i = 2, #sig do 
     pos = tostring(i-1)
     local name = "a"..pos
     local ch   = sig:sub(i,i)
-    
-    h[#h+1] = ch
-    h[#h+1] = " "
-    h[#h+1] = name
+    h[#h+1] = ch.." "..name
     h[#h+1] = ","
-
-    t[#t+1] = "V_"
-    t[#t+1] = ch
-    t[#t+1] = "["
-    t[#t+1] = pos
-    t[#t+1] = "]"
-    t[#t+1] = "="
-    t[#t+1] = name
-    t[#t+1] = ";"
+    t[#t+1] = "V_"..ch.."["..pos.."]="..name..";"
   end
   h[#h] = "){"
-  t[#t+1] = "ret_"
-  t[#t+1] = sig:sub(1,1)
-  t[#t+1] = "("
-  t[#t+1] = pos
-  t[#t+1] = ")"
-  t[#t+1] = "}\n"
+  t[#t+1] = "ret_"..sig:sub(1,1).."("..pos..")}\n"
   return table.concat(h,"")..table.concat(t,"")
 end
 
 function mkfuntab(n)
   local s = { "funptr G_funtab[] = {\n"}
-  for i = 1, n do
+  for i = 0, n-1 do
     s[#s+1] = "\t(funptr)&f"..i..",\n"
   end
   s[#s+1] = "};\n"
@@ -50,16 +34,14 @@
 function mksigtab(sigs)
   local s = { "char const * G_sigtab[] = {\n"}
   for k,v in pairs(sigs) do
-    s[#s+1] = '\t"'
-    s[#s+1] = v
-    s[#s+1] = '",\n'
+    s[#s+1] = '\t"'..v..'",\n'
   end
   s[#s+1] = "};\n"
   return table.concat(s,"")
 end
 
 function mkall()
-  local lineno = 1
+  local lineno = 0
   local sigtab = { }
   for line in io.lines() do
     local sig = trim(line)
@@ -67,11 +49,10 @@
     sigtab[#sigtab+1] = sig
     lineno = lineno + 1
   end
-  io.write(mkfuntab(lineno-1))
+  io.write(mkfuntab(lineno))
   io.write(mksigtab(sigtab))
   io.write("int G_maxargs = "..maxargs..";\n")
 end
 
 mkall()
--- print(mkcase(1,"vififififi"))