parsav  Diff

Differences From Artifact [265a0fa659]:

To Artifact [1e93ad8eb5]:


112
113
114
115
116
117
118




119




120
121
122
123
124
125
126
127
128
...
159
160
161
162
163
164
165

166
167
168
169
170
171
172

local terra biggest(a: intptr, b: intptr)
	if a > b then return a else return b end
end

terra m.acc:init(run: intptr)
	--lib.dbg('initializing string accumulator')




	self.buf = [rawstring](lib.mem.heapa_raw(run))




	self.run = run
	self.space = run
	self.sz = 0
	return self
end;

terra m.acc:free()
	--lib.dbg('freeing string accumulator')
	if self.buf ~= nil and self.space > 0 then
................................................................................

terra m.acc:push(str: rawstring, len: intptr)
	--var llen = len
	if str == nil then return self end
	--if str[len - 1] == 0xA then llen = llen - 1 end -- don't display newlines in debug output
	-- lib.dbg('pushing "',{str,llen},'" onto accumulator')
	if self.buf == nil then self:init(self.run) end

	if len == 0 then len = m.sz(str) end
	if len >= self.space - self.sz then
		self.space = self.space + biggest(self.run,len + 1)
		self.buf = [rawstring](lib.mem.heapr_raw(self.buf, self.space))
	end
	lib.mem.cpy(self.buf + self.sz, str, len)
	self.sz = self.sz + len







>
>
>
>
|
>
>
>
>
|
|







 







>







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

local terra biggest(a: intptr, b: intptr)
	if a > b then return a else return b end
end

terra m.acc:init(run: intptr)
	--lib.dbg('initializing string accumulator')
	if run == 0 then
		lib.warn('attempted to allocate zero-length string accumulator')
		self.buf = nil
	else
		self.buf = [rawstring](lib.mem.heapa_raw(run))
		if self.buf == nil then
			lib.warn('string buffer allocation failed, very little memory availble')
		end
	end
	self.run = lib.trn(self.buf == nil, 0, run)
	self.space = self.run
	self.sz = 0
	return self
end;

terra m.acc:free()
	--lib.dbg('freeing string accumulator')
	if self.buf ~= nil and self.space > 0 then
................................................................................

terra m.acc:push(str: rawstring, len: intptr)
	--var llen = len
	if str == nil then return self end
	--if str[len - 1] == 0xA then llen = llen - 1 end -- don't display newlines in debug output
	-- lib.dbg('pushing "',{str,llen},'" onto accumulator')
	if self.buf == nil then self:init(self.run) end
	if self.buf == nil then lib.warn('attempted to push string onto unallocated accumulator') return self end
	if len == 0 then len = m.sz(str) end
	if len >= self.space - self.sz then
		self.space = self.space + biggest(self.run,len + 1)
		self.buf = [rawstring](lib.mem.heapr_raw(self.buf, self.space))
	end
	lib.mem.cpy(self.buf + self.sz, str, len)
	self.sz = self.sz + len