Rename allocator.init to store.string

This commit is contained in:
Rerumu 2022-06-19 05:38:47 -04:00
parent 2f7d7b564c
commit 508ea07aca
4 changed files with 16 additions and 13 deletions

View File

@ -593,6 +593,12 @@ do
by_offset(memory.data, addr).f64 = value
end
function store.string(memory, addr, data, len)
local start = by_offset(memory.data, addr)
ffi.copy(start, data, len or #data)
end
local WASM_PAGE_SIZE = 65536
local function finalizer(memory)
@ -617,10 +623,6 @@ do
return ffi.gc(memory, finalizer)
end
function allocator.init(memory, addr, data)
ffi.copy(by_offset(memory.data, addr), data, #data)
end
function allocator.grow(memory, num)
if num == 0 then
return memory.min

View File

@ -214,7 +214,7 @@ fn write_data_list(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Re
write!(w, "\"")?;
write!(w, "rt.allocator.init(target, offset, data)")?;
write!(w, "rt.store.string(target, offset, data)")?;
write!(w, "end ")?;
}

View File

@ -504,6 +504,8 @@ do
store_byte(memory.data, addr, value)
end
local store_i8 = store.i32_n8
function store.i32_n16(memory, addr, value)
store_byte(memory.data, addr, value)
store_byte(memory.data, addr + 1, bit_rshift(value, 8))
@ -533,14 +535,9 @@ do
store_i32(memory, addr + 4, data_2)
end
function allocator.new(min, max)
return { min = min, max = max, data = {} }
end
function store.string(memory, offset, data, len)
len = len or #data
local store_i8 = store.i32_n8
function allocator.init(memory, offset, data)
local len = #data
local rem = len % 4
for i = 1, len - rem, 4 do
@ -556,6 +553,10 @@ do
end
end
function allocator.new(min, max)
return { min = min, max = max, data = {} }
end
function allocator.grow(memory, num)
local old = memory.min
local new = old + num

View File

@ -213,7 +213,7 @@ fn write_data_list(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) -> Re
write!(w, "\"")?;
write!(w, "rt.allocator.init(target, offset, data)")?;
write!(w, "rt.store.string(target, offset, data)")?;
write!(w, "end ")?;
}