Skip to content

Commit

Permalink
fix CompileAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Feb 7, 2025
1 parent e56616b commit 60b8fe4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 19 deletions.
19 changes: 15 additions & 4 deletions source/backends/lua.d
Original file line number Diff line number Diff line change
Expand Up @@ -785,14 +785,25 @@ class BackendLua : CompilerBackend {
auto var = GetGlobal(name);
auto extra = cast(GlobalExtra*) var.extra;

output ~= format("mem[dsp] = %d\n", extra.addr + offset);
output ~= "dsp = dsp + 1\n";
if (var.type.ptr) {
output ~= format("mem[dsp] = mem[%d] + %d\n", extra.addr, offset);
}
else {
output ~= format("mem[dsp] = %d\n", extra.addr + offset);
}
}
else if (VariableExists(name)) {
auto var = GetVariable(name);

output ~= format("mem[dsp] = vsp + %d\n", var.offset + offset);
output ~= "dsp = dsp + 1";
if (var.type.ptr) {
writeln("HELLO!!!", var.offset, offset);
output ~= format(
"mem[dsp] = mem[vsp + %d] + %d\n", var.offset, offset
);
}
else {
output ~= format("mem[dsp] = vsp + %d\n", var.offset + offset);
}
}
else {
Error(node.error, "Variable '%s' does not exist", name);
Expand Down
27 changes: 21 additions & 6 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -889,19 +889,34 @@ class BackendRM86 : CompilerBackend {
if (GlobalExists(name)) {
auto var = GetGlobal(name);

output ~= format(
"lea ax, [__global_%s + %d]\n", name.Sanitise(), offset
);
if (var.type.ptr) {
output ~= format("mov bx, [__global_%s]\n", name.Sanitise());
output ~= format("lea ax, [bx + %d]\n", offset);
}
else {
output ~= format(
"lea ax, [__global_%s + %d]\n", name.Sanitise(), offset
);
}

output ~= "mov [si], ax\n";
output ~= "add si, 2\n";
}
else if (VariableExists(name)) {
auto var = GetVariable(name);

output ~= "mov ax, si\n";
if (var.offset > 0) {
output ~= format("add ax, %d\n", var.offset + offset);
if (var.type.ptr) {
output ~= "mov di, sp\n";
output ~= format("mov bx, [di + %d]\n", var.offset);
output ~= format("lea ax, [bx + %d]\n", offset);
}
else {
output ~= "mov ax, sp\n";
if (var.offset > 0) {
output ~= format("add ax, %d\n", var.offset + offset);
}
}

output ~= "mov [si], ax\n";
output ~= "add si, 2\n";
}
Expand Down
20 changes: 18 additions & 2 deletions source/backends/uxn.d
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,27 @@ class BackendUXN : CompilerBackend {

if (GlobalExists(name)) {
auto var = GetGlobal(name);
output ~= format(";global_%s #%.4x ADD2\n", name.Sanitise(), offset);

if (var.type.ptr) {
output ~= format(
";global_%s LDA2 #%.4x ADD2\n", name.Sanitise(), offset
);
}
else {
output ~= format(";global_%s #%.4x ADD2\n", name.Sanitise(), offset);
}
}
else if (VariableExists(name)) {
auto var = GetVariable(name);
output ~= format(".vsp LDZ2 #%.4x ADD2\n", var.offset + offset);

if (var.type.ptr) {
output ~= format(
".vsp LDZ2 #%.4x ADD2 LDA2 #%.4x ADD2\n", var.offset, offset
);
}
else {
output ~= format(".vsp LDZ2 #%.4x ADD2\n", var.offset + offset);
}
}
else {
Error(node.error, "Variable '%s' does not exist", name);
Expand Down
32 changes: 26 additions & 6 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -1203,19 +1203,39 @@ class BackendX86_64 : CompilerBackend {
if (GlobalExists(name)) {
auto var = GetGlobal(name);

output ~= format(
"lea rax, qword [__global_%s + %d]\n", name.Sanitise(), offset
);
if (var.type.ptr) {
output ~= format("mov rax, [__global_%s]\n", name.Sanitise());

if (offset > 0) {
output ~= format("lea rax, [rax + %d]\n", offset);
}
}
else {
output ~= format(
"lea rax, qword [__global_%s + %d]\n", name.Sanitise(), offset
);
}

output ~= "mov [r15], rax\n";
output ~= "add r15, 8\n";
}
else if (VariableExists(name)) {
auto var = GetVariable(name);

output ~= "mov rdi, rsp\n";
if (var.offset > 0) {
output ~= format("add rdi, %d\n", var.offset + offset);
if (var.type.ptr) {
output ~= format("mov rdi, [rsp + %d]\n", var.offset);

if (offset > 0) {
output ~= format("lea rdi, [rdi + %d]\n", offset);
}
}
else {
output ~= "mov rdi, rsp\n";
if (var.offset > 0) {
output ~= format("add rdi, %d\n", var.offset + offset);
}
}

output ~= "mov [r15], rdi\n";
output ~= "add r15, 8\n";
}
Expand Down
2 changes: 1 addition & 1 deletion std

0 comments on commit 60b8fe4

Please sign in to comment.