parsav  Diff

Differences From Artifact [392d24dbd5]:

To Artifact [d3351b7874]:


   240    240   		}
   241    241   	}
   242    242   	n.name = string.format("stat<%s>", ty.name)
   243    243   	n.stat_basetype = ty
   244    244   	return n
   245    245   end)
   246    246   lib.enum = function(tbl)
          247  +	if type(tbl) == 'string' then -- shorthand syntax
          248  +		local t = {}
          249  +		for w in tbl:gmatch('(%g+)') do t[#t+1] = w end
          250  +		tbl = t
          251  +	end
   247    252   	local ty = uint8
   248    253   	if #tbl >= 2^32 then ty = uint64 -- hey, can't be too safe
   249    254   	elseif #tbl >= 2^16 then ty = uint32
   250    255   	elseif #tbl >= 2^8 then ty = uint16 end
   251    256   	local o = { t = ty, members = tbl }
   252    257   	local strings = {}
   253    258   	for i, name in ipairs(tbl) do
................................................................................
   265    270   	local o = {}
   266    271   	for i, name in ipairs(tbl) do o[name] = i end
   267    272   	local struct set { _store: uint8[bytes] }
   268    273   	local struct bit { _v: intptr _set: &set}
   269    274   	terra set:clear() for i=0,bytes do self._store[i] = 0 end end
   270    275   	terra set:fill() for i=0,bytes do self._store[i] = 0xFF end end
   271    276   	set.members = tbl
          277  +	set.idvmap = o
          278  +	set.null = quote var s: set s:clear() in s end
   272    279   	set.name = string.format('set<%s>', table.concat(tbl, '|'))
   273    280   	set.metamethods.__entrymissing = macro(function(val, obj)
   274    281   		if o[val] == nil then error('value ' .. val .. ' not in set') end
   275    282   		return `bit { _v=[o[val] - 1], _set = &(obj) }
   276    283   	end)
   277    284   	terra set:sz()
   278    285   		var ct: intptr = 0
................................................................................
   306    313   	terra set:setbit(i: intptr, val: bool)
   307    314   		if val then
   308    315   			self._store[i/8] = self._store[i/8] or (1 << (i % 8))
   309    316   		else
   310    317   			self._store[i/8] = self._store[i/8] and not (1 << (i % 8))
   311    318   		end
   312    319   	end
          320  +	local qksetexp = function(self,idx,rhs)
          321  +		local ch,bit
          322  +		if terralib.isconstant(idx) then
          323  +			ch = math.floor(idx/8)
          324  +			bit = idx%8
          325  +		else
          326  +			ch = `[idx]/8
          327  +			bit = `[idx]%8
          328  +		end
          329  +
          330  +		if terralib.isconstant(rhs) then
          331  +			local b = rhs:asvalue()
          332  +			if b == true then return quote
          333  +				self._store[ch] = self._store[ch] or (1 << bit)
          334  +			end elseif b == false then return quote
          335  +				self._store[ch] = self._store[ch] and not (1 << bit)
          336  +			end end
          337  +		else
          338  +			return quote self:setbit([ch], rhs) end
          339  +		end
          340  +	end
          341  +	set.metamethods.__update = macro(qksetexp)
          342  +	set.metamethods.__setentry = macro(function(field,self,rhs)
          343  +		return `self:setbit([o[field]-1],rhs)
          344  +		--return qksetexp(self, o[field], rhs)
          345  +	end)
   313    346   	set.bits = {}
   314         -	set.idvmap = {}
   315    347   	for i,v in ipairs(tbl) do
   316         -		set.idvmap[v] = i
   317    348   		set.bits[v] = quote var b: set b:clear() b:setbit([i-1], true) in b end
   318    349   	end
   319    350   	set.metamethods.__add = macro(function(self,other)
   320    351   		local new = symbol(set)
   321    352   		local q = quote var [new] new:clear() end
   322    353   		for i = 0, bytes - 1 do
   323    354   			q = quote [q]