Skip to content

Commit

Permalink
fix constructors/destructors + 0.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Dec 6, 2024
1 parent c07534a commit b693627
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 55 deletions.
2 changes: 1 addition & 1 deletion source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import callisto.backends.rm86;
import callisto.backends.arm64;
import callisto.backends.x86_64;

const static string appVersion = "Beta 0.12.1";
const static string appVersion = "Beta 0.12.2";

const static string usage = "
Callisto Compiler
Expand Down
18 changes: 9 additions & 9 deletions source/backends/arm64.d
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class BackendARM64 : CompilerBackend {

// call constructors
foreach (global ; globals) {
if (global.type.hasInit) {
if (global.type.hasInit && !global.type.ptr) {
LoadAddress("x9", format("__global_%s", global.name.Sanitise()));
output ~= "str x9, [x19], #8\n";
output ~= format("bl __type_init_%s\n", global.type.name.Sanitise());
Expand Down Expand Up @@ -291,7 +291,7 @@ class BackendARM64 : CompilerBackend {
override void End() {
// call destructors
foreach (global ; globals) {
if (global.type.hasDeinit) {
if (global.type.hasDeinit && !global.type.ptr) {
LoadAddress("x9", format("__global_%s", global.name.Sanitise()));
output ~= "str x9, [x19], #8\n";
output ~= format("bl __type_deinit_%s\n", global.type.name.Sanitise());
Expand Down Expand Up @@ -705,7 +705,7 @@ class BackendARM64 : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("add x9, x20, #%d\n", var.offset);
output ~= "str x9, [x19], #8\n";
output ~= format("bl __type_deinit_%s\n", var.type.name.Sanitise());
Expand Down Expand Up @@ -746,7 +746,7 @@ class BackendARM64 : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("add x9, x20, #%d\n", var.offset);
output ~= "str x9, [x19], #8\n";
Expand Down Expand Up @@ -775,7 +775,7 @@ class BackendARM64 : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("add x9, x20, #%d\n", var.offset);
output ~= "str x9, [x19], #8\n";
Expand Down Expand Up @@ -813,7 +813,7 @@ class BackendARM64 : CompilerBackend {
output ~= format("__while_%d_next:\n", blockNum);
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("add x9, x20, #%d\n", var.offset);
output ~= "str x9, [x19], #8\n";
Expand Down Expand Up @@ -993,7 +993,7 @@ class BackendARM64 : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("add x9, x20, #%d\n", var.offset);
output ~= "str x9, [x19], #8\n";
output ~= format("bl __type_deinit_%s\n", var.type.name.Sanitise());
Expand Down Expand Up @@ -1166,7 +1166,7 @@ class BackendARM64 : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("add x9, x20, #%d\n", var.offset);
output ~= "str x9, [x19], #8\n";
output ~= format("bl __type_deinit_%s\n", var.type.name.Sanitise());
Expand Down Expand Up @@ -1334,7 +1334,7 @@ class BackendARM64 : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("add x9, x20, #%d\n", var.offset);
output ~= "str x9, [x19], #8\n";
Expand Down
20 changes: 10 additions & 10 deletions source/backends/lua.d
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class BackendLua : CompilerBackend {
override void End() {
// call destructors
foreach (name, global ; globals) {
if (!global.type.hasDeinit) continue;
if (!global.type.hasDeinit && global.type.ptr) continue;
auto globalExtra = cast(GlobalExtra*) global.extra;

output ~= format("mem[dsp] = %d\n", globalExtra.addr);
Expand Down Expand Up @@ -389,7 +389,7 @@ class BackendLua : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("mem[dsp] = vsp + %d\n", var.offset);
output ~= "dsp = dsp + 1\n";
output ~= format("type_deinit_%s()\n", var.type.name.Sanitise());
Expand Down Expand Up @@ -428,7 +428,7 @@ class BackendLua : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("mem[dsp] = vsp + %d\n", var.offset);
output ~= "dsp = dsp + 1\n";
Expand Down Expand Up @@ -457,7 +457,7 @@ class BackendLua : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("mem[dsp] = vsp + %d\n", var.offset);
output ~= "dsp = dsp + 1\n";
Expand Down Expand Up @@ -495,7 +495,7 @@ class BackendLua : CompilerBackend {
output ~= format("::while_%d_next::\n", blockNum);
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("mem[dsp] = vsp + %d\n", var.offset);
output ~= "dsp = dsp + 1\n";
Expand Down Expand Up @@ -551,7 +551,7 @@ class BackendLua : CompilerBackend {
output ~= "mem[vsp] = 0\n";
}

if (var.type.hasInit) { // call constructor
if (var.type.hasInit && !var.type.ptr) { // call constructor
output ~= "mem[dsp] = vsp\n";
output ~= "dsp = dsp + 1\n";
output ~= format("type_init_%s()\n", var.type.name.Sanitise());
Expand All @@ -576,7 +576,7 @@ class BackendLua : CompilerBackend {

globalStack += global.Size();

if (global.type.hasInit) { // call constructor
if (global.type.hasInit && !global.type.ptr) { // call constructor
output ~= format("mem[dsp] = %d\n", extra.addr);
output ~= "dsp = dsp + 1\n";
output ~= format("type_init_%s()\n", global.type.name.Sanitise());
Expand Down Expand Up @@ -700,7 +700,7 @@ class BackendLua : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("mem[dsp] = vsp + %d\n", var.offset);
output ~= "dsp = dsp + 1\n";
output ~= format("type_deinit_%s()\n", var.type.name.Sanitise());
Expand Down Expand Up @@ -831,7 +831,7 @@ class BackendLua : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("mem[dsp] = vsp + %d\n", var.offset);
output ~= "dsp = dsp + 1\n";
output ~= format("type_deinit_%s()\n", var.type.name.Sanitise());
Expand Down Expand Up @@ -981,7 +981,7 @@ class BackendLua : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("mem[dsp] = vsp + %d\n", var.offset);
output ~= "dsp = dsp + 1\n";
Expand Down
18 changes: 9 additions & 9 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class BackendRM86 : CompilerBackend {
// call globals
// what?
foreach (global ; globals) {
if (global.type.hasInit) {
if (global.type.hasInit && !global.type.ptr) {
output ~= format(
"mov word [si], word __global_%s\n", global.name.Sanitise()
);
Expand Down Expand Up @@ -162,7 +162,7 @@ class BackendRM86 : CompilerBackend {

override void End() {
foreach (global ; globals) {
if (global.type.hasDeinit) {
if (global.type.hasDeinit && !global.type.ptr) {
output ~= format("mov word [si], word __global_%s\n", Sanitise(global.name));
output ~= "add si, 2\n";
output ~= format("call __type_deinit_%s\n", Sanitise(global.type.name));
Expand Down Expand Up @@ -492,7 +492,7 @@ class BackendRM86 : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("lea ax, [sp + %d\n]", var.offset);
output ~= "mov [si], ax\n";
output ~= "add si, 2\n";
Expand Down Expand Up @@ -538,7 +538,7 @@ class BackendRM86 : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("lea ax, [sp + %d\n]", var.offset);
output ~= "mov [si], ax\n";
Expand Down Expand Up @@ -568,7 +568,7 @@ class BackendRM86 : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("lea ax, [sp + %d\n]", var.offset);
output ~= "mov [si], ax\n";
Expand Down Expand Up @@ -607,7 +607,7 @@ class BackendRM86 : CompilerBackend {
output ~= format("__while_%d_next:\n", blockNum);
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("lea ax, [sp + %d\n]", var.offset);
output ~= "mov [si], ax\n";
Expand Down Expand Up @@ -666,7 +666,7 @@ class BackendRM86 : CompilerBackend {
output ~= format("sub sp, %d\n", var.Size());
}

if (var.type.hasInit) { // call constructor
if (var.type.hasInit && !var.type.ptr) { // call constructor
output ~= "mov [si], sp\n";
output ~= "add si, 2\n";
output ~= format("call __type_init_%s\n", Sanitise(var.type.name));
Expand Down Expand Up @@ -793,7 +793,7 @@ class BackendRM86 : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format("lea ax, [sp + %d\n]", var.offset);
output ~= "mov [si], ax\n";
output ~= "add si, 2\n";
Expand Down Expand Up @@ -1118,7 +1118,7 @@ class BackendRM86 : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format("lea ax, [sp + %d\n]", var.offset);
output ~= "mov [si], ax\n";
Expand Down
20 changes: 10 additions & 10 deletions source/backends/uxn.d
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BackendUXN : CompilerBackend {
output ~= "@calmain\n";

foreach (global ; globals) {
if (global.type.hasInit) {
if (global.type.hasInit && !global.type.ptr) {
output ~= format(";global_%s\n", global.name.Sanitise());
output ~= format("type_init_%s\n", global.type.name.Sanitise());
}
Expand Down Expand Up @@ -135,7 +135,7 @@ class BackendUXN : CompilerBackend {
override void End() {
// call destructors
foreach (global ; globals) {
if (global.type.hasDeinit) {
if (global.type.hasDeinit && !global.type.ptr) {
output ~= format(";global_%s\n", global.name.Sanitise());
output ~= format("type_deinit_%s\n", global.type.name.Sanitise());
}
Expand Down Expand Up @@ -449,7 +449,7 @@ class BackendUXN : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format(".vsp LDZ2 #.2x ADD2", var.offset);
output ~= format("type_deinit_%s\n", Sanitise(var.type.name));
}
Expand Down Expand Up @@ -496,7 +496,7 @@ class BackendUXN : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format(".vsp LDZ2 #.2x ADD2", var.offset);
output ~= format("type_deinit_%s\n", Sanitise(var.type.name));
Expand Down Expand Up @@ -526,7 +526,7 @@ class BackendUXN : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format(".vsp LDZ2 #.2x ADD2", var.offset);
output ~= format("type_deinit_%s\n", Sanitise(var.type.name));
Expand Down Expand Up @@ -565,7 +565,7 @@ class BackendUXN : CompilerBackend {
output ~= format("@while_%d_next\n", blockNum);
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format(".vsp LDZ2 #.2x ADD2", var.offset);
output ~= format("type_deinit_%s\n", Sanitise(var.type.name));
Expand Down Expand Up @@ -624,7 +624,7 @@ class BackendUXN : CompilerBackend {
output ~= format("#0000 .vsp LDZ2 STA2\n");
}

if (var.type.hasInit) {
if (var.type.hasInit && !var.type.ptr) {
output ~= format(".vsp LDZ2 type_init_%s\n", Sanitise(var.type.name));
}
}
Expand Down Expand Up @@ -744,7 +744,7 @@ class BackendUXN : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format(".vsp LDZ2 #.2x ADD2", var.offset);
output ~= format("type_deinit_%s\n", Sanitise(var.type.name));
}
Expand Down Expand Up @@ -869,7 +869,7 @@ class BackendUXN : CompilerBackend {
foreach (ref var ; variables) {
scopeSize += var.Size();

if (var.type.hasDeinit) {
if (var.type.hasDeinit && !var.type.ptr) {
output ~= format(".vsp LDZ2 #.2x ADD2", var.offset);
output ~= format("type_deinit_%s\n", Sanitise(var.type.name));
}
Expand Down Expand Up @@ -1041,7 +1041,7 @@ class BackendUXN : CompilerBackend {
// remove scope
foreach (ref var ; variables) {
if (oldVars.canFind(var)) continue;
if (!var.type.hasDeinit) continue;
if (!var.type.hasDeinit || var.type.ptr) continue;

output ~= format(".vsp LDZ2 #.2x ADD2", var.offset);
output ~= format("type_deinit_%s\n", Sanitise(var.type.name));
Expand Down
Loading

0 comments on commit b693627

Please sign in to comment.