diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-26 22:24:19 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-26 22:24:19 +0000 |
| commit | d40cdf49825e4fc449a5e172f4e14088bb467606 (patch) | |
| tree | a57b5a2cbfe8ff1f3c9b47520c0e63c81f33b4d7 /src/main/java | |
| parent | b752cc73d1d9c0dafb3fd4f564ee64dc1a467abd (diff) | |
Use correct types for heap alloc call
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java index a3c2e944..890217e8 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java @@ -162,16 +162,25 @@ public class PatioToWasm { return switch (patioInstruction) { case PatioAllocHeap patioAllocHeap -> { context = context - .addInstruction(new WasmI32Const(sizeOf( - patioAllocHeap.layout(), - platformTarget - ))) - .addInstruction(new WasmI32Const(offsetOf( - patioAllocHeap.layout(), - patioAllocHeap.gcChildrenOffset(), - platformTarget - ))) - .addInstruction(new WasmI32Const(patioAllocHeap.gcChildrenCount())) + .addInstruction(wasmConst( + platformTarget.sizeT(), + sizeOf( + patioAllocHeap.layout(), + platformTarget + ) + )) + .addInstruction(wasmConst( + platformTarget.sizeT(), + offsetOf( + patioAllocHeap.layout(), + patioAllocHeap.gcChildrenOffset(), + platformTarget + ) + )) + .addInstruction(wasmConst( + platformTarget.sizeT(), + patioAllocHeap.gcChildrenCount() + )) .addInstruction(new WasmCall(new WasmFuncName(ALLOC_NAME))) .addInstruction(new WasmLocalSet(context.wasmLocalIndex(patioAllocHeap.target()))); @@ -711,6 +720,17 @@ public class PatioToWasm { : List.of(patioTypeToWasmValueType(type, platformTarget)); } + private static WasmInstruction wasmConst(WasmValueType wasmValueType, int value) { + // TODO: find a better way of doing this. Turn the number types into an enum? + if (wasmValueType == WasmValueType.I32) { + return new WasmI32Const(value); + } else if (wasmValueType == WasmValueType.I64) { + return new WasmI64Const(value); + } else { + throw new IllegalArgumentException("Cannot create int const for " + wasmValueType); + } + } + private static class Context { public static Context forFunction( WasmTarget platformTarget, |
