Skip to content

Commit

Permalink
fix usage and .sizeof not working
Browse files Browse the repository at this point in the history
  • Loading branch information
yeti0904 committed Aug 25, 2024
1 parent c599c4d commit 7c00a00
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
4 changes: 2 additions & 2 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Flags:
Backends and their operating systems:
rm86 - Real mode x86, for bare-metal, DOS
x86_64 - 64-bit x86, for bare-metal, Linux
arm64 - 64-bit ARM, for Linux
x86_64 - 64-bit x86, for bare-metal, linux, osx
arm64 - 64-bit ARM, for linux
uxn - Varvara/Uxn
lua - Lua, uses subset CallistoScript
Expand Down
13 changes: 11 additions & 2 deletions source/backends/arm64.d
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class BackendARM64 : CompilerBackend {
types ~= Type("size", 8);
types ~= Type("usize", 8);
types ~= Type("cell", 8);
types ~= Type("bool", 8);

// built in structs
types ~= Type("Array", 24, true, [
Expand All @@ -126,8 +127,16 @@ class BackendARM64 : CompilerBackend {
NewConst("Array.elements", 16);
NewConst("Array.sizeof", 8 * 3);

foreach (name, ref type ; types) {
NewConst(format("%s.sizeof", name), cast(long) type.size);
types ~= Type("Exception", 24 + 8, true, [
StructEntry(GetType("bool"), "error"),
StructEntry(GetType("Array"), "msg")
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 8);
NewConst("Exception.sizeof", 24 + 8);

foreach (ref type ; types) {
NewConst(format("%s.sizeof", type.name), cast(long) type.size);
}
}

Expand Down
13 changes: 11 additions & 2 deletions source/backends/lua.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class BackendLua : CompilerBackend {
types ~= Type("size", 1);
types ~= Type("usize", 1);
types ~= Type("cell", 1);
types ~= Type("bool", 1);

// built in structs
types ~= Type("Array", 3, true, [
Expand All @@ -108,8 +109,16 @@ class BackendLua : CompilerBackend {
NewConst("Array.elements", 2);
NewConst("Array.sizeof", 3);

foreach (name, ref type ; types) {
NewConst(format("%s.sizeof", name), cast(long) type.size);
types ~= Type("Exception", 3 + 1, true, [
StructEntry(GetType("bool"), "error"),
StructEntry(GetType("Array"), "msg")
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 1);
NewConst("Exception.sizeof", 3 + 1);

foreach (ref type ; types) {
NewConst(format("%s.sizeof", type.name), cast(long) type.size);
}
}

Expand Down
25 changes: 17 additions & 8 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ class BackendRM86 : CompilerBackend {
this() {
defaultOS = "dos";

types ~= Type("u8", 1);
types ~= Type("i8", 1);
types ~= Type("u16", 2);
types ~= Type("i16", 2);
types ~= Type("addr", 2);
types ~= Type("size", 2);
types ~= Type("u8", 1);
types ~= Type("i8", 1);
types ~= Type("u16", 2);
types ~= Type("i16", 2);
types ~= Type("addr", 2);
types ~= Type("size", 2);
types ~= Type("usize", 2);
types ~= Type("cell", 2);
types ~= Type("cell", 2);
types ~= Type("bool", 2);

// built in structs
types ~= Type("Array", 6, true, [
Expand All @@ -104,11 +105,19 @@ class BackendRM86 : CompilerBackend {
NewConst("Array.elements", 4);
NewConst("Array.sizeof", 2 * 3);

types ~= Type("Exception", 6 + 2, true, [
StructEntry(GetType("bool"), "error"),
StructEntry(GetType("Array"), "msg")
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 2);
NewConst("Exception.sizeof", 6 + 2);

foreach (ref type ; types) {
NewConst(format("%s.sizeof", type.name), cast(long) type.size);
}

if (!opts.noDos) {
if (!opts.noDos) { // TODO: remove this
globals["__rm86_argv"] = Global(GetType("addr"), false, 0);
globals["__rm86_arglen"] = Global(GetType("cell"), false, 0);
}
Expand Down
12 changes: 10 additions & 2 deletions source/backends/uxn.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ class BackendUXN : CompilerBackend {
NewConst("Array.elements", 4);
NewConst("Array.sizeof", 2 * 3);

foreach (name, ref type ; types) {
NewConst(format("%s.sizeof", name), cast(long) type.size);
types ~= Type("Exception", 6 + 2, true, [
StructEntry(GetType("bool"), "error"),
StructEntry(GetType("Array"), "msg")
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 2);
NewConst("Exception.sizeof", 6 + 2);

foreach (ref type ; types) {
NewConst(format("%s.sizeof", type.name), cast(long) type.size);
}
}

Expand Down
13 changes: 11 additions & 2 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class BackendX86_64 : CompilerBackend {
types ~= Type("size", 8);
types ~= Type("usize", 8);
types ~= Type("cell", 8);
types ~= Type("bool", 8);

// built in structs
types ~= Type("Array", 24, true, [
Expand All @@ -128,8 +129,16 @@ class BackendX86_64 : CompilerBackend {
NewConst("Array.elements", 16);
NewConst("Array.sizeof", 8 * 3);

foreach (name, ref type ; types) {
NewConst(format("%s.sizeof", name), cast(long) type.size);
types ~= Type("Exception", 24 + 8, true, [
StructEntry(GetType("bool"), "error"),
StructEntry(GetType("Array"), "msg")
]);
NewConst("Exception.bool", 0);
NewConst("Exception.msg", 8);
NewConst("Exception.sizeof", 24 + 8);

foreach (ref type ; types) {
NewConst(format("%s.sizeof", type.name), cast(long) type.size);
}
}

Expand Down

0 comments on commit 7c00a00

Please sign in to comment.