52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
local rec = terralib.types.newstruct(string.format('template<%s>',tplspec.id or ''))
local symself = symbol(&rec)
do local kfac = {}
for afterseg,key in pairs(fields) do
if not kfac[key] then
rec.entries[#rec.entries + 1] = {
field = key;
type = rawstring;
}
end
kfac[key] = (kfac[key] or 0) + 1
end
for key, fac in pairs(kfac) do
tallyup[#tallyup + 1] = quote
[runningtally] = [runningtally] + lib.str.sz([symself].[key])*fac
end
end
end
local copiers = {}
local senders = {}
local appenders = {}
................................................................................
local accumulator = symbol(&lib.str.acc)
local destcon = symbol(&lib.net.mg_connection)
for idx, seg in ipairs(segs) do
copiers[#copiers+1] = quote [cpypos] = lib.mem.cpy([cpypos], [&opaque]([seg]), [#seg]) end
senders[#senders+1] = quote lib.net.mg_send([destcon], [seg], [#seg]) end
appenders[#appenders+1] = quote [accumulator]:push([seg], [#seg]) end
if fields[idx] then
copiers[#copiers+1] = quote
[cpypos] = lib.mem.cpy([cpypos],
[&opaque](symself.[fields[idx]]),
lib.str.sz(symself.[fields[idx]]))
end
senders[#senders+1] = quote
lib.net.mg_send([destcon],
symself.[fields[idx]],
lib.str.sz(symself.[fields[idx]]))
end
end
end
local tid = tplspec.id or '<anonymous>'
rec.methods.tostr = terra([symself])
lib.dbg(['compiling template ' .. tid])
|
|
|
>
>
>
|
<
<
|
<
|
>
>
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
local rec = terralib.types.newstruct(string.format('template<%s>',tplspec.id or ''))
local symself = symbol(&rec)
do local kfac = {}
for afterseg,key in pairs(fields) do
if not kfac[key] then
rec.entries[#rec.entries + 1] = {
field = key;
type = lib.mem.ptr(int8);
}
end
kfac[key] = (kfac[key] or 0) + 1
end
for key, fac in pairs(kfac) do
tallyup[#tallyup + 1] = quote
[runningtally] = [runningtally] + ([symself].[key].ct)*fac
end
end
end
local copiers = {}
local senders = {}
local appenders = {}
................................................................................
local accumulator = symbol(&lib.str.acc)
local destcon = symbol(&lib.net.mg_connection)
for idx, seg in ipairs(segs) do
copiers[#copiers+1] = quote [cpypos] = lib.mem.cpy([cpypos], [&opaque]([seg]), [#seg]) end
senders[#senders+1] = quote lib.net.mg_send([destcon], [seg], [#seg]) end
appenders[#appenders+1] = quote [accumulator]:push([seg], [#seg]) end
if fields[idx] then
--local fsz = `lib.str.sz(symself.[fields[idx]])
local fval = `symself.[fields[idx]].ptr
local fsz = `symself.[fields[idx]].ct
copiers[#copiers+1] = quote
[cpypos] = lib.mem.cpy([cpypos], [&opaque]([fval]), [fsz])
end
senders[#senders+1] = quote
lib.net.mg_send([destcon], [fval], [fsz])
end
appenders[#appenders+1] = quote
[accumulator]:push([fval], [fsz])
end
end
end
local tid = tplspec.id or '<anonymous>'
rec.methods.tostr = terra([symself])
lib.dbg(['compiling template ' .. tid])
|