Skip to content

Commit

Permalink
fix broken Array and Exception (thanks soxfox)
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Dec 8, 2024
1 parent b693627 commit fd8559d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
14 changes: 5 additions & 9 deletions source/backends/arm64.d
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ class BackendARM64 : CompilerBackend {

// built in structs
types ~= Type("Array", 24, true, [
StructEntry(UsedType(GetType("usize"), false), "length"),
StructEntry(UsedType(GetType("usize"), false), "memberSize"),
StructEntry(UsedType(GetType("addr"), false), "elements")
StructEntry(UsedType(GetType("usize"), false), "length", false, 8, 0),
StructEntry(UsedType(GetType("usize"), false), "memberSize", false, 8, 8),
StructEntry(UsedType(GetType("addr"), false), "elements", false, 8, 16)
]);
NewConst("Array.length", 0);
NewConst("Array.memberSize", 8);
NewConst("Array.elements", 16);
NewConst("Array.sizeOf", 8 * 3);

types ~= Type("Exception", 24 + 8, true, [
StructEntry(UsedType(GetType("bool"), false), "error"),
StructEntry(UsedType(GetType("Array"), false), "msg")
StructEntry(UsedType(GetType("bool"), false), "error", false, 8, 0),
StructEntry(UsedType(GetType("Array"), false), "msg", false, 8 * 3, 8)
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 8);
Expand Down Expand Up @@ -398,10 +398,6 @@ class BackendARM64 : CompilerBackend {
size = var.type.Size();
}

if (var.type.isStruct && !member) {
Error(node.error, "Can't push value of struct");
}

string base;
if (deref) {
output ~= format("ldr x9, [x20, #%d]\n", var.offset);
Expand Down
10 changes: 5 additions & 5 deletions source/backends/lua.d
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ class BackendLua : CompilerBackend {

// built in structs
types ~= Type("Array", 3, true, [
StructEntry(UsedType(GetType("usize"), false), "length"),
StructEntry(UsedType(GetType("usize"), false), "memberSize"),
StructEntry(UsedType(GetType("addr"), false), "elements")
StructEntry(UsedType(GetType("usize"), false), "length", false, 1, 0),
StructEntry(UsedType(GetType("usize"), false), "memberSize", false, 1, 1),
StructEntry(UsedType(GetType("addr"), false), "elements", false, 1, 2)
]);
NewConst("Array.length", 0);
NewConst("Array.memberSize", 1);
NewConst("Array.elements", 2);
NewConst("Array.sizeOf", 3);

types ~= Type("Exception", 3 + 1, true, [
StructEntry(UsedType(GetType("bool"), false), "error"),
StructEntry(UsedType(GetType("Array"), false), "msg")
StructEntry(UsedType(GetType("bool"), false), "error", false, 1, 0),
StructEntry(UsedType(GetType("Array"), false), "msg", false, 3, 1)
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 1);
Expand Down
10 changes: 5 additions & 5 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ class BackendRM86 : CompilerBackend {

// built in structs
types ~= Type("Array", 6, true, [
StructEntry(UsedType(GetType("usize"), false), "length"),
StructEntry(UsedType(GetType("usize"), false), "memberSize"),
StructEntry(UsedType(GetType("addr"), false), "elements")
StructEntry(UsedType(GetType("usize"), false), "length", false, 2, 0),
StructEntry(UsedType(GetType("usize"), false), "memberSize", false, 2, 2),
StructEntry(UsedType(GetType("addr"), false), "elements", false, 2, 4)
]);
NewConst("Array.length", 0);
NewConst("Array.memberSize", 2);
NewConst("Array.elements", 4);
NewConst("Array.sizeOf", 2 * 3);

types ~= Type("Exception", 6 + 2, true, [
StructEntry(UsedType(GetType("bool"), false), "error"),
StructEntry(UsedType(GetType("Array"), false), "msg")
StructEntry(UsedType(GetType("bool"), false), "error", false, 2, 0),
StructEntry(UsedType(GetType("Array"), false), "msg", false, 6, 2)
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 2);
Expand Down
10 changes: 5 additions & 5 deletions source/backends/uxn.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ class BackendUXN : CompilerBackend {

// built in structs
types ~= Type("Array", 6, true, [
StructEntry(UsedType(GetType("usize"), false), "length"),
StructEntry(UsedType(GetType("usize"), false), "memberSize"),
StructEntry(UsedType(GetType("addr"), false), "elements")
StructEntry(UsedType(GetType("usize"), false), "length", false, 2, 0),
StructEntry(UsedType(GetType("usize"), false), "memberSize", false, 2, 2),
StructEntry(UsedType(GetType("addr"), false), "elements", false, 2, 4)
]);
NewConst("Array.length", 0);
NewConst("Array.memberSize", 2);
NewConst("Array.elements", 4);
NewConst("Array.sizeOf", 2 * 3);

types ~= Type("Exception", 6 + 2, true, [
StructEntry(UsedType(GetType("bool"), false), "error"),
StructEntry(UsedType(GetType("Array"), false), "msg")
StructEntry(UsedType(GetType("bool"), false), "error", false, 2, 0),
StructEntry(UsedType(GetType("Array"), false), "msg", false, 6, 0)
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 2);
Expand Down
10 changes: 5 additions & 5 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ class BackendX86_64 : CompilerBackend {

// built in structs
types ~= Type("Array", 24, true, [
StructEntry(UsedType(GetType("usize"), false), "length"),
StructEntry(UsedType(GetType("usize"), false), "memberSize"),
StructEntry(UsedType(GetType("addr"), false), "elements")
StructEntry(UsedType(GetType("usize"), false), "length", false, 8, 0),
StructEntry(UsedType(GetType("usize"), false), "memberSize", false, 8, 8),
StructEntry(UsedType(GetType("addr"), false), "elements", false, 8, 16)
]);
NewConst("Array.length", 0);
NewConst("Array.memberSize", 8);
NewConst("Array.elements", 16);
NewConst("Array.sizeOf", 8 * 3);

types ~= Type("Exception", 24 + 8, true, [
StructEntry(UsedType(GetType("bool"), false), "error"),
StructEntry(UsedType(GetType("Array"), false), "msg")
StructEntry(UsedType(GetType("bool"), false), "error", false, 8, 0),
StructEntry(UsedType(GetType("Array"), false), "msg", false, 24, 8)
]);
NewConst("Exception.error", 0);
NewConst("Exception.msg", 8);
Expand Down
2 changes: 1 addition & 1 deletion source/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class CompilerBackend {
}

offset += structure[index].offset;
size_t size = structure[index].type.size;
size_t size = structure[index].type.Size();

return StructVariable(size, offset);
}
Expand Down

0 comments on commit fd8559d

Please sign in to comment.