From cbdf5139feb8439842afdc7fbb7843dba4d984db Mon Sep 17 00:00:00 2001 From: MESYETI Date: Wed, 1 May 2024 20:40:47 +0100 Subject: [PATCH] make it possible to inherit Array --- source/backends/linux86.d | 21 +++++++++++---------- source/backends/rm86.d | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/source/backends/linux86.d b/source/backends/linux86.d index 46a4f7a..a7b305a 100644 --- a/source/backends/linux86.d +++ b/source/backends/linux86.d @@ -72,6 +72,7 @@ class BackendLinux86 : CompilerBackend { Array[] arrays; this() { + // built in integer types types["u8"] = Type(1); types["i8"] = Type(1); types["u16"] = Type(2); @@ -84,21 +85,21 @@ class BackendLinux86 : CompilerBackend { types["size"] = Type(8); types["usize"] = Type(8); types["cell"] = Type(8); - types["Array"] = Type(24); - foreach (name, ref type ; types) { - NewConst(format("%s.sizeof", name), cast(long) type.size); - } - - // struct Array - // usize length - // usize memberSize - // addr elements - // end + // built in structs + types["Array"] = Type(24, true, [ + StructEntry("usize" in types, "length"), + StructEntry("usize" in types, "memberSize"), + StructEntry("addr" in types, "elements") + ]); NewConst("Array.length", 0); NewConst("Array.memberSize", 8); NewConst("Array.elements", 16); NewConst("Array.sizeof", 8 * 3); + + foreach (name, ref type ; types) { + NewConst(format("%s.sizeof", name), cast(long) type.size); + } } override void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) { diff --git a/source/backends/rm86.d b/source/backends/rm86.d index 5dcf600..55fd057 100644 --- a/source/backends/rm86.d +++ b/source/backends/rm86.d @@ -80,21 +80,21 @@ class BackendRM86 : CompilerBackend { types["size"] = Type(2); types["usize"] = Type(2); types["cell"] = Type(2); - types["Array"] = Type(6); - foreach (name, ref type ; types) { - NewConst(format("%s.sizeof", name), cast(long) type.size); - } - - // struct Array - // usize length - // usize memberSize - // addr elements - // end + // built in structs + types["Array"] = Type(24, true, [ + StructEntry("usize" in types, "length"), + StructEntry("usize" in types, "memberSize"), + StructEntry("addr" in types, "elements") + ]); NewConst("Array.length", 0); NewConst("Array.memberSize", 2); NewConst("Array.elements", 4); NewConst("Array.sizeof", 2 * 3); + + foreach (name, ref type ; types) { + NewConst(format("%s.sizeof", name), cast(long) type.size); + } } override void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) {