125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
var [val]
[exp]
in val end
return q
end);
proc = {
fork = terralib.externfunction('fork', {} -> int);
daemonize = terralib.externfunction('daemon', {int,int} -> {});
exit = terralib.externfunction('exit', int -> {});
getenv = terralib.externfunction('getenv', rawstring -> rawstring);
exec = terralib.externfunction('execv', {rawstring,&rawstring} -> int);
execp = terralib.externfunction('execvp', {rawstring,&rawstring} -> int);
};
io = {
send = terralib.externfunction('write', {int, rawstring, intptr} -> ptrdiff);
recv = terralib.externfunction('read', {int, rawstring, intptr} -> ptrdiff);
close = terralib.externfunction('close', {int} -> int);
say = macro(function(msg) return `lib.io.send(2, msg, [#(msg:asvalue())]) end);
fmt = terralib.externfunction('printf',
terralib.types.funcpointer({rawstring},{int},true));
};
str = { sz = terralib.externfunction('strlen', rawstring -> intptr) };
copy = function(tbl)
local new = {}
for k,v in pairs(tbl) do new[k] = v end
setmetatable(new, getmetatable(tbl))
return new
................................................................................
then lib.io.say([' - ' .. v .. ': true\n'])
else lib.io.say([' - ' .. v .. ': false\n'])
end
end
end
return q
end)
set.metamethods.__add = macro(function(self,other)
local new = symbol(set)
local q = quote var [new] new:clear() end
for i = 0, bytes - 1 do
q = quote [q]
new._store[i] = self._store[i] or other._store[i]
end
................................................................................
local q = quote var [new] new:clear() end
for i = 0, bytes - 1 do
q = quote [q]
new._store[i] = self._store[i] and other._store[i]
end
end
return quote [q] in new end
end)
set.metamethods.__not = macro(function(self)
local new = symbol(set)
local q = quote var [new] new:clear() end
for i = 0, bytes - 1 do
q = quote [q]
new._store[i] = not self._store[i]
................................................................................
lib.md = lib.loadlib('mbedtls','mbedtls/md.h')
lib.b64 = lib.loadlib('mbedtls','mbedtls/base64.h')
lib.net = lib.loadlib('mongoose','mongoose.h')
lib.pq = lib.loadlib('libpq','libpq-fe.h')
lib.load {
'mem', 'math', 'str', 'file', 'crypt', 'ipc';
'http', 'html', 'session', 'tpl', 'store';
'smackdown'; -- md-alike parser
}
local be = {}
for _, b in pairs(config.backends) do
be[#be+1] = terralib.loadfile('backend/' .. b .. '.t')()
................................................................................
lib.load {
'srv';
'render:nav';
'render:nym';
'render:login';
'render:profile';
'render:compose';
'render:tweet';
'render:userpage';
'render:timeline';
'render:docpage';
'render:conf:profile';
'render:conf';
'route';
}
do
local p = string.format('parsav: %s\nbuilt on %s\n', config.build.str, config.build.when)
terra version() lib.io.send(1, p, [#p]) end
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
|
>
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
...
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
...
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
var [val]
[exp]
in val end
return q
end);
proc = {
fork = terralib.externfunction('fork', {} -> int);
exit = terralib.externfunction('exit', int -> {});
getenv = terralib.externfunction('getenv', rawstring -> rawstring);
exec = terralib.externfunction('execv', {rawstring,&rawstring} -> int);
execp = terralib.externfunction('execvp', {rawstring,&rawstring} -> int);
};
io = {
send = terralib.externfunction('write', {int, rawstring, intptr} -> ptrdiff);
recv = terralib.externfunction('read', {int, rawstring, intptr} -> ptrdiff);
close = terralib.externfunction('close', {int} -> int);
say = macro(function(msg) return `lib.io.send(2, msg, [#(msg:asvalue())]) end);
fmt = terralib.externfunction('printf',
terralib.types.funcpointer({rawstring},{int},true));
ttyp = terralib.externfunction('isatty', int -> int);
};
str = { sz = terralib.externfunction('strlen', rawstring -> intptr) };
copy = function(tbl)
local new = {}
for k,v in pairs(tbl) do new[k] = v end
setmetatable(new, getmetatable(tbl))
return new
................................................................................
then lib.io.say([' - ' .. v .. ': true\n'])
else lib.io.say([' - ' .. v .. ': false\n'])
end
end
end
return q
end)
terra set:setbit(i: intptr, val: bool)
if val then
self._store[i/8] = self._store[i/8] or (1 << (i % 8))
else
self._store[i/8] = self._store[i/8] and not (1 << (i % 8))
end
end
set.bits = {}
set.idvmap = {}
for i,v in ipairs(tbl) do
set.idvmap[v] = i
set.bits[v] = quote var b: set b:clear() b:setbit(i, true) in b end
end
set.metamethods.__add = macro(function(self,other)
local new = symbol(set)
local q = quote var [new] new:clear() end
for i = 0, bytes - 1 do
q = quote [q]
new._store[i] = self._store[i] or other._store[i]
end
................................................................................
local q = quote var [new] new:clear() end
for i = 0, bytes - 1 do
q = quote [q]
new._store[i] = self._store[i] and other._store[i]
end
end
return quote [q] in new end
end)
set.metamethods.__eq = macro(function(self,other)
local rt = symbol(bool)
local fb if #tbl % 8 == 0 then fb = bytes - 1 else fb = bytes - 2 end
local q = quote rt = true end
for i = 0, fb do
q = quote
if self._store[i] ~= other._store[i] then rt = false else [q] end
end
end
-- we need to mask out any extraneous bits the values might have, as we
-- don't want the kind of noise introduced by :fill() to affect comparison
if #tbl % 8 ~= 0 then
local last = #tbl-1
local msk = (2 ^ (#tbl % 8)) - 1
q = quote
if (self._store [last] and [uint8](msk)) ~=
(other._store[last] and [uint8](msk)) then rt = false else [q] end
end
end
return quote var [rt]; [q] in rt end
end)
set.metamethods.__not = macro(function(self)
local new = symbol(set)
local q = quote var [new] new:clear() end
for i = 0, bytes - 1 do
q = quote [q]
new._store[i] = not self._store[i]
................................................................................
lib.md = lib.loadlib('mbedtls','mbedtls/md.h')
lib.b64 = lib.loadlib('mbedtls','mbedtls/base64.h')
lib.net = lib.loadlib('mongoose','mongoose.h')
lib.pq = lib.loadlib('libpq','libpq-fe.h')
lib.load {
'mem', 'math', 'str', 'file', 'crypt', 'ipc';
'http', 'html', 'session', 'tpl', 'store', 'acl';
'smackdown'; -- md-alike parser
}
local be = {}
for _, b in pairs(config.backends) do
be[#be+1] = terralib.loadfile('backend/' .. b .. '.t')()
................................................................................
lib.load {
'srv';
'render:nav';
'render:nym';
'render:login';
'render:profile';
'render:compose';
'render:tweet';
'render:tweet-page';
'render:user-page';
'render:timeline';
'render:docpage';
'render:conf:profile';
'render:conf:sec';
'render:conf';
'route';
}
do
local p = string.format('parsav: %s\nbuilt on %s\n', config.build.str, config.build.when)
terra version() lib.io.send(1, p, [#p]) end
|