89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
end
local copiers = {}
local senders = {}
local appenders = {}
local symtxt = symbol(lib.mem.ptr(int8))
local cpypos = symbol(&opaque)
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] and fields[idx].mode then
local f = fields[idx]
local fp = `symself.[f.key]
copiers[#copiers+1] = quote
if fp.ct > 0 then
var san = lib.html.sanitize(fp, [f.mode == ':'])
[cpypos] = lib.mem.cpy([cpypos], [&opaque](san.ptr), san.ct)
--san:free()
end
end
senders[#senders+1] = quote
if fp.ct > 0 then
var san = lib.html.sanitize(fp, [f.mode == ':'])
lib.net.mg_send([destcon], san.ptr, san.ct)
--san:free()
end
end
appenders[#appenders+1] = quote
if fp.ct > 0 then
var san = lib.html.sanitize(fp, [f.mode == ':'])
[accumulator]:ppush(san)
--san:free()
end
end
elseif fields[idx] then
local f = fields[idx]
local fp = `symself.[f.key]
................................................................................
appenders[#appenders+1] = quote
if fp.ct > 0 then [accumulator]:ppush(fp) end
end
end
end
local tid = tplspec.id or '<anonymous>'
rec.methods.tostr = terra([symself])
lib.dbg(['compiling template ' .. tid])
[tallyup]
var [symtxt] = lib.mem.heapa(int8, [runningtally])
var [cpypos] = [&opaque](symtxt.ptr)
[copiers]
@[&int8](cpypos) = 0
symtxt.ct = [&int8](cpypos) - symtxt.ptr
return symtxt
end
rec.methods.append = terra([symself], [accumulator])
lib.dbg(['appending template ' .. tid])
[tallyup]
accumulator:cue([runningtally])
[appenders]
return accumulator
end
rec.methods.head = terra([symself], [destcon], code: uint16, hd: lib.mem.ptr(lib.http.header))
lib.dbg(['transmitting template headers ' .. tid])
[tallyup]
lib.net.mg_printf([destcon], 'HTTP/1.1 %s', lib.http.codestr(code))
for i = 0, hd.ct do
lib.net.mg_printf([destcon], '%s: %s\r\n', hd.ptr[i].key, hd.ptr[i].value)
end
lib.net.mg_printf([destcon],'Content-Length: %llu\r\n\r\n', [runningtally] + 1)
end
rec.methods.send = terra([symself], [destcon], code: uint16, hd: lib.mem.ptr(lib.http.header))
lib.dbg(['transmitting template ' .. tid])
symself:head(destcon,code,hd)
[senders]
lib.net.mg_send([destcon],'\r\n',2)
end
rec.methods.sz = terra([symself])
lib.dbg(['tallying template ' .. tid])
[tallyup]
return [runningtally] + 1
end
return rec
end
return m
|
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
end
local copiers = {}
local senders = {}
local appenders = {}
local symtxt = symbol(lib.mem.ptr(int8))
local cpypos = symbol(&opaque)
local pool = symbol(&lib.mem.pool)
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] and fields[idx].mode then
local f = fields[idx]
local fp = `symself.[f.key]
copiers[#copiers+1] = quote
if fp.ct > 0 then
var san = lib.html.sanitize(pool, fp, [f.mode == ':'])
[cpypos] = lib.mem.cpy([cpypos], [&opaque](san.ptr), san.ct)
--san:free()
end
end
senders[#senders+1] = quote
if fp.ct > 0 then
var san = lib.html.sanitize(pool, fp, [f.mode == ':'])
lib.net.mg_send([destcon], san.ptr, san.ct)
--san:free()
end
end
appenders[#appenders+1] = quote
if fp.ct > 0 then
var san = lib.html.sanitize(pool, fp, [f.mode == ':'])
[accumulator]:ppush(san)
--san:free()
end
end
elseif fields[idx] then
local f = fields[idx]
local fp = `symself.[f.key]
................................................................................
appenders[#appenders+1] = quote
if fp.ct > 0 then [accumulator]:ppush(fp) end
end
end
end
local tid = tplspec.id or '<anonymous>'
rec.methods.poolstr = terra([symself],[pool])
lib.dbg(['pooling template ' .. tid])
[tallyup]
var [symtxt] = pool:alloc(int8, [runningtally])
var [cpypos] = [&opaque](symtxt.ptr)
[copiers]
@[&int8](cpypos) = 0
symtxt.ct = [&int8](cpypos) - symtxt.ptr
return symtxt
end
rec.methods.tostr = terra([symself])
lib.dbg(['compiling template ' .. tid])
[tallyup]
var [symtxt] = lib.mem.heapa(int8, [runningtally])
var [cpypos] = [&opaque](symtxt.ptr)
var p: lib.mem.pool p:init(128)
var [pool] = &p
[copiers]
@[&int8](cpypos) = 0
symtxt.ct = [&int8](cpypos) - symtxt.ptr
pool:free()
return symtxt
end
rec.methods.append = terra([symself], [accumulator])
var [pool]
var p: lib.mem.pool
if [accumulator].pool == nil then
p:init(128)
pool = &p
else pool = [accumulator].pool end
lib.dbg(['appending template ' .. tid])
[tallyup]
accumulator:cue([runningtally])
[appenders]
if [accumulator].pool == nil then p:free() end
return accumulator
end
rec.methods.head = terra([symself], [destcon], code: uint16, hd: lib.mem.ptr(lib.http.header))
var p: lib.mem.pool p:init(128) -- FIXME
var [pool] = &p
lib.dbg(['transmitting template headers ' .. tid])
[tallyup]
lib.net.mg_printf([destcon], 'HTTP/1.1 %s', lib.http.codestr(code))
for i = 0, hd.ct do
lib.net.mg_printf([destcon], '%s: %s\r\n', hd.ptr[i].key, hd.ptr[i].value)
end
lib.net.mg_printf([destcon],'Content-Length: %llu\r\n\r\n', [runningtally] + 1)
p:free()
end
rec.methods.send = terra([symself], [destcon], code: uint16, hd: lib.mem.ptr(lib.http.header))
var p: lib.mem.pool p:init(128) -- FIXME
var [pool] = &p
lib.dbg(['transmitting template ' .. tid])
symself:head(destcon,code,hd)
[senders]
lib.net.mg_send([destcon],'\r\n',2)
p:free()
end
rec.methods.sz = terra([symself])
lib.dbg(['tallying template ' .. tid])
[tallyup]
return [runningtally] + 1
end
return rec
end
return m
|