Skip to content

Commit

Permalink
make it possible to inherit Array
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed May 1, 2024
1 parent 2aab653 commit cbdf513
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 11 additions & 10 deletions source/backends/linux86.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit cbdf513

Please sign in to comment.