Remove memory intrinsics

This commit is contained in:
nora 2024-05-13 20:15:11 +02:00
parent 9270f52e6b
commit 1e97275cf2
5 changed files with 15 additions and 19 deletions

View file

@ -491,8 +491,6 @@ export const BUILTINS = [
"__i64_store",
"__i32_load",
"__i64_load",
"__memory_size",
"__memory_grow",
"__i32_extend_to_i64_u",
"___transmute",
"___asm",

View file

@ -851,17 +851,6 @@ function lowerExpr(
instrs.push({ kind: "i64.store", imm: {} });
break exprKind;
}
case "__memory_size": {
assertArgs(0);
instrs.push({ kind: "memory.size" });
break exprKind;
}
case "__memory_grow": {
assertArgs(1);
lowerExpr(fcx, instrs, expr.args[0]);
instrs.push({ kind: "memory.grow" });
break exprKind;
}
case "__i32_extend_to_i64_u": {
assertArgs(1);
lowerExpr(fcx, instrs, expr.args[0]);

View file

@ -68,10 +68,6 @@ export function typeOfBuiltinValue(
return mkTyFn([TYS.I32], TYS.I32);
case "__i64_load":
return mkTyFn([TYS.I32], TYS.INT);
case "__memory_size":
return mkTyFn([], TYS.I32);
case "__memory_grow":
return mkTyFn([TYS.I32], TYS.I32);
case "__i32_extend_to_i64_u":
return mkTyFn([TYS.I32], TYS.INT);
default: {

View file

@ -15,9 +15,9 @@ function allocate(size: I32, align: I32): I32 = (
let alignedPtr = std.alignUp(HEAD_PTR, align);
let newHeadPtr = alignedPtr + size;
if newHeadPtr > __memory_size() then (
if newHeadPtr > std.rt.memorySize() then (
// 16 pages, very arbitrary.
let result = __memory_grow(16_I32);
let result = std.rt.memoryGrow(16_I32);
// If allocation failed we get -1. We don't have negative numbers yet, lol.
if result > 4294967295_I32 then (
std.abort("failed to grow memory");

View file

@ -9,3 +9,16 @@ function memcpy(_dst: I32, _src: I32, _n: I32) =
"local.get 0",
"memory.copy",
);
function memoryGrow(_size: I32): I32 =
___asm(
__locals(),
"local.get 0",
"memory.grow",
);
function memorySize(): I32 =
___asm(
__locals(),
"memory.size",
);