mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-16 17:35:02 +01:00
fix struct literals
This commit is contained in:
parent
b0b92dae0f
commit
1551847d8c
2 changed files with 11 additions and 5 deletions
10
src/lower.ts
10
src/lower.ts
|
|
@ -970,7 +970,11 @@ function lowerExpr(
|
||||||
// TODO: scratch locals...
|
// TODO: scratch locals...
|
||||||
const ptrLocal = fcx.wasmType.params.length + fcx.wasm.locals.length;
|
const ptrLocal = fcx.wasmType.params.length + fcx.wasm.locals.length;
|
||||||
fcx.wasm.locals.push("i32");
|
fcx.wasm.locals.push("i32");
|
||||||
instrs.push({ kind: "local.set", imm: ptrLocal });
|
instrs.push({ kind: "local.tee", imm: ptrLocal });
|
||||||
|
|
||||||
|
// Store the refcount
|
||||||
|
instrs.push({ kind: "i32.const", imm: 0n });
|
||||||
|
instrs.push({ kind: "i32.store", imm: { align: 4 } });
|
||||||
|
|
||||||
// Now, set all fields.
|
// Now, set all fields.
|
||||||
expr.fields.forEach((field, i) => {
|
expr.fields.forEach((field, i) => {
|
||||||
|
|
@ -1169,13 +1173,15 @@ function sizeOfValtype(type: wasm.ValType): number {
|
||||||
export function layoutOfStruct(ty: TyStruct): StructLayout {
|
export function layoutOfStruct(ty: TyStruct): StructLayout {
|
||||||
const fieldWasmTys = ty.fields.map(([, field]) => wasmTypeForBody(field));
|
const fieldWasmTys = ty.fields.map(([, field]) => wasmTypeForBody(field));
|
||||||
|
|
||||||
|
// TODO: Use the max alignment instead.
|
||||||
const align = fieldWasmTys.some((field) =>
|
const align = fieldWasmTys.some((field) =>
|
||||||
field.some((type) => type === "i64")
|
field.some((type) => type === "i64")
|
||||||
)
|
)
|
||||||
? 8
|
? 8
|
||||||
: 4;
|
: 4;
|
||||||
|
|
||||||
let offset = 0;
|
// i32 refcount is at offset 0.
|
||||||
|
let offset = 4;
|
||||||
|
|
||||||
const fields: StructFieldLayout[] = fieldWasmTys.map((field, i) => {
|
const fields: StructFieldLayout[] = fieldWasmTys.map((field, i) => {
|
||||||
const value: StructFieldLayout = {
|
const value: StructFieldLayout = {
|
||||||
|
|
|
||||||
4
std.nil
4
std.nil
|
|
@ -98,12 +98,12 @@ mod rt (
|
||||||
// 16 pages, very arbitrary.
|
// 16 pages, very arbitrary.
|
||||||
let result = __memory_grow(16_I32);
|
let result = __memory_grow(16_I32);
|
||||||
// If allocation failed we get -1. We don't have negative numbers yet, lol.
|
// If allocation failed we get -1. We don't have negative numbers yet, lol.
|
||||||
if result > 100000000_I32 then (
|
if result > 4294967295_I32 then (
|
||||||
std.abort("failed to grow memory");
|
std.abort("failed to grow memory");
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
0_I32
|
actualObjPtr
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue