parsav  Diff

Differences From Artifact [89921fa130]:

To Artifact [c8b5d8bfdc]:


    32     32   	return str
    33     33   end
    34     34   
    35     35   
    36     36   do local strptr = (lib.mem.ptr(int8))
    37     37   	local strref = (lib.mem.ref(int8))
    38     38   	local byteptr = (lib.mem.ptr(uint8))
    39         -	strptr.metamethods.__cast = function(from,to,e)
    40         -		if from == &int8 then
    41         -			return `strptr {ptr = e, ct = m.sz(e)}
    42         -		elseif to == &int8 then
    43         -			return e.ptr
    44         -		end
    45         -	end
    46         -
    47         -	terra strptr:cmp(other: strptr)
    48         -		if self.ptr == nil and other.ptr == nil then return true end
    49         -		if self.ptr == nil or other.ptr == nil then return false end
    50         -
    51         -		var sz = lib.math.biggest(self.ct, other.ct)
    52         -		for i = 0, sz do
    53         -			if self.ptr[i] == 0 and other.ptr[i] == 0 then return true end
    54         -			if self.ptr[i] ~= other.ptr[i] then return false end
    55         -		end
    56         -		return true
    57         -	end
    58         -	terra strref:cmp(other: strref)
    59         -		if self.ptr == nil and other.ptr == nil then return true end
    60         -		if self.ptr == nil or other.ptr == nil then return false end
    61         -
    62         -		var sz = lib.math.biggest(self.ct, other.ct)
    63         -		for i = 0, sz do
    64         -			if self.ptr[i] == 0 and other.ptr[i] == 0 then return true end
    65         -			if self.ptr[i] ~= other.ptr[i] then return false end
    66         -		end
    67         -		return true
    68         -	end
    69         -	terra strptr:ffw()
    70         -		var newp = m.ffw(self.ptr,self.ct)
    71         -		var newct = self.ct - (newp - self.ptr)
    72         -		return strptr { ptr = newp, ct = newct }
    73         -	end
    74         -	strptr.methods.cmpl = macro(function(self,other)
    75         -		return `self:cmp(strptr { ptr = [other:asvalue()], ct = [#(other:asvalue())] })
    76         -	end)
    77         -	strref.methods.cmpl = macro(function(self,other)
    78         -		return `self:cmp(strref { ptr = [other:asvalue()], ct = [#(other:asvalue())] })
    79         -	end)
           39  +	local function install_funcs(ty)
           40  +		ty.metamethods.__cast = function(from,to,e)
           41  +			local v = e:asvalue()
           42  +			if type(v) == 'string' then
           43  +				print('hard-coding pstr',v,#v)
           44  +				return `ty {ptr = v, ct = [#v]}
           45  +			elseif from == &int8 then
           46  +				return `ty {ptr = e, ct = m.sz(e)}
           47  +			elseif to == &int8 then
           48  +				return e.ptr
           49  +			end
           50  +		end
           51  +		terra ty:cmp(other: ty)
           52  +			if self.ptr == nil and other.ptr == nil then return true end
           53  +			if self.ptr == nil or other.ptr == nil then return false end
           54  +
           55  +			var sz = lib.math.biggest(self.ct, other.ct)
           56  +			for i = 0, sz do
           57  +				if self.ptr[i] == 0 and other.ptr[i] == 0 then return true end
           58  +				if self.ptr[i] ~= other.ptr[i] then return false end
           59  +			end
           60  +			return true
           61  +		end
           62  +		terra ty:ffw()
           63  +			var newp = m.ffw(self.ptr,self.ct)
           64  +			var newct = self.ct - (newp - self.ptr)
           65  +			return ty { ptr = newp, ct = newct }
           66  +		end
           67  +	end
           68  +	install_funcs(strptr)
           69  +	install_funcs(strref)
           70  +
           71  +	--strptr.methods.cmpl = macro(function(self,other)
           72  +	--	return `self:cmp(strptr { ptr = [other:asvalue()], ct = [#(other:asvalue())] })
           73  +	--end)
           74  +	--strref.methods.cmpl = macro(function(self,other)
           75  +	--	return `self:cmp(strref { ptr = [other:asvalue()], ct = [#(other:asvalue())] })
           76  +	--end)
    80     77   
    81     78   	terra byteptr:cmp(other: byteptr)
    82     79   		var sz = lib.math.biggest(self.ct, other.ct)
    83     80   		for i = 0, sz do
    84     81   			if self.ptr[i] == 0 and other.ptr[i] == 0 then return true end
    85     82   			if self.ptr[i] ~= other.ptr[i] then return false end
    86     83   		end