parsav  Diff

Differences From Artifact [dc97a3f269]:

To Artifact [022b1bf037]:


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