comparison test/suite_aggrs/mk-cases.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
comparison
equal deleted inserted replaced
432:167faab0c0be 433:45662241d9cd
7 7
8 8
9 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end 9 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end
10 function mkcase(id,sig) 10 function mkcase(id,sig)
11 local sig = trim(sig) 11 local sig = trim(sig)
12 -- @@@ return value hard-guessed by first char, doesn't hold anymore 12 local h = { "/* ",id,":",sig," */ " }
13 local h = { "/* ",id,":",sig," */ ",sig:sub(1,1), " f", id,"(","" }
14 local t = { "" } 13 local t = { "" }
15 local pos = 1 14 local pos = 0
16 local n_nest = 0 15 local n_nest = 0
17 local aggr 16 local aggr
18 local aggr_sig = '' 17 local aggr_sig = ''
19 for i = 2, #sig do 18 for i = 1, #sig do
20 local name = "a"..pos 19 local name = "a"..pos
21 local ch = sig:sub(i,i) 20 local ch = sig:sub(i,i)
22 21
23 aggr_sig = aggr_sig..ch 22 aggr_sig = aggr_sig..ch
24 23
49 end 48 end
50 49
51 if n_nest == 0 then 50 if n_nest == 0 then
52 -- struct types (more than one char) need copying via a func 51 -- struct types (more than one char) need copying via a func
53 if #ch > 1 then 52 if #ch > 1 then
54 h[#h+1] = 'struct '..ch.." "..name 53 h[#h+1] = 'struct '..ch
55 t[#t+1] = 'f_cp'..ch..'(V_a['..pos.."],&"..name..");" 54 t[#t+1] = 'f_cp'..ch..'(V_a['..pos.."],&"..name..");"
56 else 55 else
57 h[#h+1] = ch.." "..name 56 h[#h+1] = ch
58 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" 57 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";"
59 end 58 end
60 h[#h+1] = "," 59
60 -- is return type or func arg?
61 if pos == 0 then
62 h[#h+1] = " f"..id.."("
63 h[#h+1] = ''
64 t[#t] = '' -- clear; aggr return type handled explicitly
65 else
66 h[#h+1] = ' '..name
67 h[#h+1] = ","
68 end
61 69
62 pos = pos + 1 70 pos = pos + 1
63 end 71 end
64 end 72 end
65 maxargs = max(maxargs, pos-1) 73 maxargs = max(maxargs, pos-1)
66 h[#h] = "){" 74 h[#h] = "){"
67 t[#t+1] = "ret_"..sig:sub(1,1).."("..(pos-1)..")}\n" 75 if #h[6] == 1 then
76 t[#t+1] = "ret_"..h[6].."("..(pos-1)..")}\n"
77 else
78 t[#t+1] = "ret_a("..(pos-1)..","..h[6]..")}\n"
79 end
68 return table.concat(h,"")..table.concat(t,"") 80 return table.concat(h,"")..table.concat(t,"")
69 end 81 end
70 82
71 function mkfuntab(n) 83 function mkfuntab(n)
72 local s = { "funptr G_funtab[] = {\n"} 84 local s = { "funptr G_funtab[] = {\n"}
139 io.write("dcStructField(st, '"..v[1][i].."', offsetof("..st..', '..v[1][i+1]..'), 1); ') 151 io.write("dcStructField(st, '"..v[1][i].."', offsetof("..st..', '..v[1][i+1]..'), 1); ')
140 end 152 end
141 io.write(" dcCloseStruct(st); return st; };\n") 153 io.write(" dcCloseStruct(st); return st; };\n")
142 end 154 end
143 155
156 -- make table.concat work
157 if #agg_names > 0 then
158 table.insert(agg_names, 1, '')
159 end
160
144 io.write(cases) 161 io.write(cases)
145 io.write(mkfuntab(lineno)) 162 io.write(mkfuntab(lineno))
146 io.write(mksigtab(sigtab)) 163 io.write(mksigtab(sigtab))
147 io.write('const char* G_agg_sigs[] = {\n\t"'..table.concat(agg_sigs, '",\n\t"')..'"\n};\n') 164 io.write('const char* G_agg_sigs[] = {\n\t"'..table.concat(agg_sigs, '",\n\t"')..'"\n};\n')
148 io.write('int G_agg_sizes[] = {\n\t'..table.concat(agg_sizes, ',\n\t')..'\n};\n') 165 io.write('int G_agg_sizes[] = {\n\t'..table.concat(agg_sizes, ',\n\t')..'\n};\n')
149 io.write('funptr G_agg_newdcstfuncs[] = {\n\t(funptr)&f_newdcst'..table.concat(agg_names, ',\n\t(funptr)&f_newdcst')..'\n};\n') 166 io.write('funptr G_agg_newdcstfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_newdcst'),2)..'\n};\n')
150 io.write('funptr G_agg_cmpfuncs[] = {\n\t(funptr)&f_cmp'..table.concat(agg_names, ',\n\t(funptr)&f_cmp')..'\n};\n') 167 io.write('funptr G_agg_cmpfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_cmp'),2)..'\n};\n')
151 io.write("int G_maxargs = "..maxargs..";\n") 168 io.write("int G_maxargs = "..maxargs..";\n")
152 end 169 end
153 170
154 mkall() 171 mkall()
155 172