Disambiguate allocator and memory
This commit is contained in:
parent
5fb7899c7e
commit
02232b46ca
@ -320,7 +320,7 @@ end
|
|||||||
do
|
do
|
||||||
local load = {}
|
local load = {}
|
||||||
local store = {}
|
local store = {}
|
||||||
local memory = {}
|
local allocator = {}
|
||||||
|
|
||||||
ffi.cdef([[
|
ffi.cdef([[
|
||||||
union Any {
|
union Any {
|
||||||
@ -465,7 +465,7 @@ do
|
|||||||
ffi.fill(by_offset(memory.data, old), new - old, 0)
|
ffi.fill(by_offset(memory.data, old), new - old, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function memory.new(min, max)
|
function allocator.new(min, max)
|
||||||
local data = ffi.C.calloc(max, WASM_PAGE_SIZE)
|
local data = ffi.C.calloc(max, WASM_PAGE_SIZE)
|
||||||
|
|
||||||
assert(data ~= nil, "failed to allocate")
|
assert(data ~= nil, "failed to allocate")
|
||||||
@ -475,11 +475,11 @@ do
|
|||||||
return ffi.gc(memory, finalizer)
|
return ffi.gc(memory, finalizer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function memory.init(memory, addr, data)
|
function allocator.init(memory, addr, data)
|
||||||
ffi.copy(by_offset(memory.data, addr), data, #data - 1)
|
ffi.copy(by_offset(memory.data, addr), data, #data - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function memory.grow(memory, num)
|
function allocator.grow(memory, num)
|
||||||
local old = memory.min
|
local old = memory.min
|
||||||
local new = old + num
|
local new = old + num
|
||||||
|
|
||||||
@ -495,7 +495,7 @@ do
|
|||||||
|
|
||||||
module.load = load
|
module.load = load
|
||||||
module.store = store
|
module.store = store
|
||||||
module.memory = memory
|
module.allocator = allocator
|
||||||
end
|
end
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
@ -239,7 +239,7 @@ end
|
|||||||
do
|
do
|
||||||
local load = {}
|
local load = {}
|
||||||
local store = {}
|
local store = {}
|
||||||
local memory = {}
|
local allocator = {}
|
||||||
|
|
||||||
local function rip_u64(x)
|
local function rip_u64(x)
|
||||||
return math.floor(x / 0x100000000), x % 0x100000000
|
return math.floor(x / 0x100000000), x % 0x100000000
|
||||||
@ -327,11 +327,11 @@ do
|
|||||||
store.i32(memory, addr + 4, hi)
|
store.i32(memory, addr + 4, hi)
|
||||||
end
|
end
|
||||||
|
|
||||||
function memory.new(min, max)
|
function allocator.new(min, max)
|
||||||
return { min = min, max = max, data = {} }
|
return { min = min, max = max, data = {} }
|
||||||
end
|
end
|
||||||
|
|
||||||
function memory.init(memory, offset, data)
|
function allocator.init(memory, offset, data)
|
||||||
local store_i8 = module.store.i32_n8
|
local store_i8 = module.store.i32_n8
|
||||||
local store_i32 = module.store.i32
|
local store_i32 = module.store.i32
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function memory.grow(memory, num)
|
function allocator.grow(memory, num)
|
||||||
local old = memory.min
|
local old = memory.min
|
||||||
local new = old + num
|
local new = old + num
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ do
|
|||||||
|
|
||||||
module.load = load
|
module.load = load
|
||||||
module.store = store
|
module.store = store
|
||||||
module.memory = memory
|
module.allocator = allocator
|
||||||
end
|
end
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
@ -148,7 +148,7 @@ impl Driver for MemorySize {
|
|||||||
|
|
||||||
impl Driver for MemoryGrow {
|
impl Driver for MemoryGrow {
|
||||||
fn visit(&self, v: &mut Visitor, w: Writer) -> Result<()> {
|
fn visit(&self, v: &mut Visitor, w: Writer) -> Result<()> {
|
||||||
write!(w, "rt.memory.grow(memory_at_{}, ", self.memory)?;
|
write!(w, "rt.allocator.grow(memory_at_{}, ", self.memory)?;
|
||||||
self.value.visit(v, w)?;
|
self.value.visit(v, w)?;
|
||||||
write!(w, ")")
|
write!(w, ")")
|
||||||
}
|
}
|
||||||
@ -645,7 +645,7 @@ impl<'a> LuaJIT<'a> {
|
|||||||
|
|
||||||
write!(w, "\"")?;
|
write!(w, "\"")?;
|
||||||
|
|
||||||
write!(w, "rt.memory.init(target, offset, data)")?;
|
write!(w, "rt.allocator.init(target, offset, data)")?;
|
||||||
|
|
||||||
write!(w, "end ")?;
|
write!(w, "end ")?;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ impl Driver for MemorySize {
|
|||||||
|
|
||||||
impl Driver for MemoryGrow {
|
impl Driver for MemoryGrow {
|
||||||
fn visit(&self, v: &mut Visitor, w: Writer) -> Result<()> {
|
fn visit(&self, v: &mut Visitor, w: Writer) -> Result<()> {
|
||||||
write!(w, "rt.memory.grow(memory_at_{}, ", self.memory)?;
|
write!(w, "rt.allocator.grow(memory_at_{}, ", self.memory)?;
|
||||||
self.value.visit(v, w)?;
|
self.value.visit(v, w)?;
|
||||||
write!(w, ")")
|
write!(w, ")")
|
||||||
}
|
}
|
||||||
@ -642,7 +642,7 @@ impl<'a> Luau<'a> {
|
|||||||
|
|
||||||
write!(w, "\"")?;
|
write!(w, "\"")?;
|
||||||
|
|
||||||
write!(w, "rt.memory.init(target, offset, data)")?;
|
write!(w, "rt.allocator.init(target, offset, data)")?;
|
||||||
|
|
||||||
write!(w, "end ")?;
|
write!(w, "end ")?;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ pub fn write_memory_init(limit: &ResizableLimits, w: Writer) -> Result<()> {
|
|||||||
let a = limit.initial();
|
let a = limit.initial();
|
||||||
let b = new_limit_max(limit);
|
let b = new_limit_max(limit);
|
||||||
|
|
||||||
write!(w, "rt.memory.new({}, {})", a, b)
|
write!(w, "rt.allocator.new({}, {})", a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_func_name(wasm: &Module, index: u32, offset: u32, w: Writer) -> Result<()> {
|
pub fn write_func_name(wasm: &Module, index: u32, offset: u32, w: Writer) -> Result<()> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user