Skip to content

Commit d9b35ec

Browse files
committed
uxn
1 parent 0f8c21f commit d9b35ec

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

source/backends/uxn.d

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,41 @@ class BackendUXN : CompilerBackend {
351351

352352
output ~= format("@%s\n", symbol);
353353

354+
// allocate parameters
355+
size_t paramSize;
356+
foreach (ref type ; node.paramTypes) {
357+
if (!TypeExists(type)) {
358+
Error(node.error, "Type '%s' doesn't exist", type);
359+
}
360+
361+
paramSize += GetType(type).size;
362+
}
363+
if (paramSize > 0) {
364+
output ~= format(".vsp LDZ2 #%.4x SUB2 .vsp STZ2\n", paramSize);
365+
foreach (ref var ; variables) {
366+
var.offset += paramSize;
367+
}
368+
369+
size_t offset;
370+
foreach (i, ref type ; node.paramTypes) {
371+
auto param = node.params[i];
372+
Variable var;
373+
374+
var.name = param;
375+
var.type = GetType(type);
376+
var.offset = cast(uint) offset;
377+
offset += var.Size();
378+
variables ~= var;
379+
}
380+
381+
// copy all parameters
382+
foreach_reverse (ref param ; node.params) {
383+
auto setNode = new SetNode(node.error);
384+
setNode.var = param;
385+
CompileSet(setNode);
386+
}
387+
}
388+
354389
foreach (ref inode ; node.nodes) {
355390
compiler.CompileNode(inode);
356391
}

0 commit comments

Comments
 (0)