Differences From
Artifact [579976ae23]:
1 1 -- vim: ft=terra
2 2
3 3 local util = dofile('common.lua')
4 4 local buildopts, buildargs = util.parseargs{...}
5 5 config = dofile('config.lua')
6 6
7 7 lib = {
8 - init = {};
8 + init = {}, util = util;
9 9 load = function(lst)
10 10 for _, l in pairs(lst) do
11 11 local path = {}
12 12 for m in l:gmatch('([^:]+)') do path[#path+1]=m end
13 13 local tgt = lib
14 14 for i=1,#path-1 do
15 15 if tgt[path[i]] == nil then tgt[path[i]] = {} end
................................................................................
45 45 local str = tostring(v:asvalue())
46 46 code[#code+1] = `lib.io.send(2, str, [#str])
47 47 else
48 48 code[#code+1] = quote var n = v in
49 49 lib.io.send(2, n, lib.str.sz(n)) end
50 50 end
51 51 end
52 - if nl then code[#code+1] = `lib.io.send(fd, '\n', 1) end
52 + if nl == true then code[#code+1] = `lib.io.send(fd, '\n', 1)
53 + elseif nl then code[#code+1] = `lib.io.send(fd, nl, [#nl]) end
53 54 return code
54 55 end;
55 56 emitv = function(nl,fd,...)
56 57 local vec = {}
57 58 local defs = {}
58 59 for i,v in ipairs{...} do
59 60 local str, ct
................................................................................
73 74 else--if v.tree:is 'constant' then
74 75 str = tostring(v:asvalue())
75 76 end
76 77 ct = ct or #str
77 78 end
78 79 vec[#vec + 1] = `[lib.uio.iovec]{iov_base = [&opaque](str), iov_len = ct}
79 80 end
80 - if nl then vec[#vec + 1] = `[lib.uio.iovec]{iov_base = [&opaque]('\n'), iov_len = 1} end
81 + if nl == true then vec[#vec + 1] = `[lib.uio.iovec]{iov_base = [&opaque]('\n'), iov_len = 1}
82 + elseif nl then vec[#vec + 1] = `[lib.uio.iovec]{iov_base = [&opaque](nl), iov_len = [#nl]} end
81 83 return quote
82 84 [defs]
83 85 var strs = array( [vec] )
84 86 in lib.uio.writev(fd, strs, [#vec]) end
85 87 end;
86 88 trn = macro(function(cond, i, e)
87 89 return quote
................................................................................
174 176 var dfs = arrayof(int8, 0x30 + diff/10, 0x30 + diff%10, 0x20, 0)
175 177 [ lib.emit(false, 2, ' \27[36m+', `&dfs[0]) ]
176 178 end
177 179 end
178 180
179 181 local defrep = function(level,n,code)
180 182 return macro(function(...)
181 - local q = lib.emit(true, 2, noise_header(code,n), ...)
183 + local fn = (...).filename
184 + local ln = tostring((...).linenumber)
185 + local dbgtag = string.format('\27[35m ยท \27[34m%s:\27[1m%s\27[m\n', fn,ln)
186 + local q = lib.emit(level < 3 and true or dbgtag, 2, noise_header(code,n), ...)
182 187 return quote if noise >= level then timehdr(); [q] end end
183 188 end);
184 189 end
185 190 lib.dbg = defrep(3,'debug', '32')
186 191 lib.report = defrep(2,'info', '35')
187 192 lib.warn = defrep(1,'warn', '33')
188 193 lib.bail = macro(function(...)
................................................................................
260 265 local q = quote var [new] new:clear() end
261 266 for i = 0, bytes - 1 do
262 267 q = quote [q]
263 268 new._store[i] = self._store[i] or other._store[i]
264 269 end
265 270 end
266 271 return quote [q] in new end
272 + end)
273 + set.metamethods.__and = macro(function(self,other)
274 + local new = symbol(set)
275 + local q = quote var [new] new:clear() end
276 + for i = 0, bytes - 1 do
277 + q = quote [q]
278 + new._store[i] = self._store[i] and other._store[i]
279 + end
280 + end
281 + return quote [q] in new end
282 + end)
283 + set.metamethods.__not = macro(function(self)
284 + local new = symbol(set)
285 + local q = quote var [new] new:clear() end
286 + for i = 0, bytes - 1 do
287 + q = quote [q]
288 + new._store[i] = not self._store[i]
289 + end
290 + end
291 + return quote [q] in new end
292 + end)
293 + set.metamethods.__sub = macro(function(self,other)
294 + local new = symbol(set)
295 + local q = quote var [new] new:clear() end
296 + for i = 0, bytes - 1 do
297 + q = quote [q]
298 + new._store[i] = self._store[i] and (not other._store[i])
299 + end
300 + end
301 + return quote [q] in new end
267 302 end)
268 303 bit.metamethods.__cast = function(from,to,e)
269 304 local q = quote var s = e
270 305 in (s._set._store[s._v/8] and (1 << s._v % 8)) end
271 306 if to == bit then error('casting to bit is not meaningful')
272 307 elseif to == bool then return `([q] ~= 0)
273 308 elseif to:isintegral() then return q
................................................................................
310 345
311 346 lib.cmdparse = terralib.loadfile('cmdparse.t')()
312 347
313 348 do local collate = function(path,f, ...)
314 349 return loadfile(path..'/'..f..'.lua')(path, ...)
315 350 end
316 351 data = {
352 + doc = collate('doc','load');
317 353 view = collate('view','load');
318 354 static = {};
319 355 stmap = global(lib.mem.ref(int8)[#config.embeds]); -- array of pointers to static content
320 356 } end
321 357 for i,e in ipairs(config.embeds) do local v = e[1]
322 358 local fh = io.open('static/' .. v,'r')
323 359 if fh == nil then error('static file ' .. v .. ' missing') end
................................................................................
337 373 'render:nav';
338 374 'render:login';
339 375 'render:profile';
340 376 'render:userpage';
341 377 'render:compose';
342 378 'render:tweet';
343 379 'render:timeline';
380 + 'render:docpage';
344 381 'route';
345 382 }
346 383
347 384 do
348 385 local p = string.format('parsav: %s\nbuilt on %s\n', config.build.str, config.build.when)
349 386 terra version() lib.io.send(1, p, [#p]) end
350 387 end