From 02232b46ca72d255899350dfd1efab5184f9d47e Mon Sep 17 00:00:00 2001 From: Rerumu Date: Mon, 17 Jan 2022 01:59:02 -0500 Subject: [PATCH] Disambiguate allocator and memory --- wasm/runtime/luajit.lua | 10 +++++----- wasm/runtime/luau.lua | 10 +++++----- wasm/src/writer/luajit.rs | 4 ++-- wasm/src/writer/luau.rs | 4 ++-- wasm/src/writer/shared.rs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/wasm/runtime/luajit.lua b/wasm/runtime/luajit.lua index cd46774..ccf3f73 100644 --- a/wasm/runtime/luajit.lua +++ b/wasm/runtime/luajit.lua @@ -320,7 +320,7 @@ end do local load = {} local store = {} - local memory = {} + local allocator = {} ffi.cdef([[ union Any { @@ -465,7 +465,7 @@ do ffi.fill(by_offset(memory.data, old), new - old, 0) end - function memory.new(min, max) + function allocator.new(min, max) local data = ffi.C.calloc(max, WASM_PAGE_SIZE) assert(data ~= nil, "failed to allocate") @@ -475,11 +475,11 @@ do return ffi.gc(memory, finalizer) end - function memory.init(memory, addr, data) + function allocator.init(memory, addr, data) ffi.copy(by_offset(memory.data, addr), data, #data - 1) end - function memory.grow(memory, num) + function allocator.grow(memory, num) local old = memory.min local new = old + num @@ -495,7 +495,7 @@ do module.load = load module.store = store - module.memory = memory + module.allocator = allocator end return module diff --git a/wasm/runtime/luau.lua b/wasm/runtime/luau.lua index 9b8d4b6..094e63d 100644 --- a/wasm/runtime/luau.lua +++ b/wasm/runtime/luau.lua @@ -239,7 +239,7 @@ end do local load = {} local store = {} - local memory = {} + local allocator = {} local function rip_u64(x) return math.floor(x / 0x100000000), x % 0x100000000 @@ -327,11 +327,11 @@ do store.i32(memory, addr + 4, hi) end - function memory.new(min, max) + function allocator.new(min, max) return { min = min, max = max, data = {} } end - function memory.init(memory, offset, data) + function allocator.init(memory, offset, data) local store_i8 = module.store.i32_n8 local store_i32 = module.store.i32 @@ -351,7 +351,7 @@ do end end - function memory.grow(memory, num) + function allocator.grow(memory, num) local old = memory.min local new = old + num @@ -366,7 +366,7 @@ do module.load = load module.store = store - module.memory = memory + module.allocator = allocator end return module diff --git a/wasm/src/writer/luajit.rs b/wasm/src/writer/luajit.rs index 2350136..07fa115 100644 --- a/wasm/src/writer/luajit.rs +++ b/wasm/src/writer/luajit.rs @@ -148,7 +148,7 @@ impl Driver for MemorySize { impl Driver for MemoryGrow { 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)?; write!(w, ")") } @@ -645,7 +645,7 @@ impl<'a> LuaJIT<'a> { write!(w, "\"")?; - write!(w, "rt.memory.init(target, offset, data)")?; + write!(w, "rt.allocator.init(target, offset, data)")?; write!(w, "end ")?; } diff --git a/wasm/src/writer/luau.rs b/wasm/src/writer/luau.rs index cd81321..1c15a89 100644 --- a/wasm/src/writer/luau.rs +++ b/wasm/src/writer/luau.rs @@ -137,7 +137,7 @@ impl Driver for MemorySize { impl Driver for MemoryGrow { 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)?; write!(w, ")") } @@ -642,7 +642,7 @@ impl<'a> Luau<'a> { write!(w, "\"")?; - write!(w, "rt.memory.init(target, offset, data)")?; + write!(w, "rt.allocator.init(target, offset, data)")?; write!(w, "end ")?; } diff --git a/wasm/src/writer/shared.rs b/wasm/src/writer/shared.rs index 17bb7a0..fd7cc61 100644 --- a/wasm/src/writer/shared.rs +++ b/wasm/src/writer/shared.rs @@ -30,7 +30,7 @@ pub fn write_memory_init(limit: &ResizableLimits, w: Writer) -> Result<()> { let a = limit.initial(); 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<()> {