parsav  Diff

Differences From Artifact [ee5af81e76]:

To Artifact [0c9ba1d780]:


    28     28   	      (@str == @' ' or @str == @'\t' or @str == @'\n') do
    29     29   		str = str + 1
    30     30   		maxlen = maxlen - 1
    31     31   	end
    32     32   	return str
    33     33   end
    34     34   
    35         -
    36     35   do local strptr = (lib.mem.ptr(int8))
    37     36   	local strref = (lib.mem.ref(int8))
    38     37   	local byteptr = (lib.mem.ptr(uint8))
    39     38   	local function install_funcs(ty)
    40     39   		ty.metamethods.__cast = function(from,to,e)
    41     40   			local v = e:asvalue()
    42     41   			if type(v) == 'string' then
    43     42   				return `ty {ptr = v, ct = [#v]}
    44     43   			elseif from == &int8 then
    45     44   				return `ty {ptr = e, ct = m.sz(e)}
    46     45   			elseif to == &int8 then
    47     46   				return e.ptr
    48     47   			end
           48  +		end
           49  +		terra ty:pdup(p: &lib.mem.pool): strptr
           50  +			if not @self then return strptr.null() end
           51  +			if self.ct == 0 then self.ct = m.sz(self.ptr) end
           52  +			var newstr = p:alloc(int8, self.ct)
           53  +			lib.mem.cpy(newstr.ptr, self.ptr, self.ct)
           54  +			return newstr
    49     55   		end
    50     56   		terra ty:cmp(other: ty)
    51     57   			if self.ptr == nil and other.ptr == nil then return true end
    52     58   			if self.ptr == nil or other.ptr == nil then return false end
    53     59   
    54     60   			var sz = lib.math.biggest(self.ct, other.ct)
    55     61   			for i = 0, sz do