Skip to content

Commit b1aaf3e

Browse files
committed
lua
1 parent d9b35ec commit b1aaf3e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

source/backends/lua.d

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,42 @@ class BackendLua : CompilerBackend {
326326
words[node.name] = Word(WordType.Callisto, false);
327327

328328
output ~= format("function func__%s()\n", node.name.Sanitise());
329+
330+
// allocate parameters
331+
size_t paramSize;
332+
foreach (ref type ; node.paramTypes) {
333+
if (!TypeExists(type)) {
334+
Error(node.error, "Type '%s' doesn't exist", type);
335+
}
336+
337+
paramSize += GetType(type).size;
338+
}
339+
if (paramSize > 0) {
340+
output ~= format("vsp = vsp - %d\n", paramSize);
341+
foreach (ref var ; variables) {
342+
var.offset += paramSize;
343+
}
344+
345+
size_t offset;
346+
foreach (i, ref type ; node.paramTypes) {
347+
auto param = node.params[i];
348+
Variable var;
349+
350+
var.name = param;
351+
var.type = GetType(type);
352+
var.offset = cast(uint) offset;
353+
offset += var.Size();
354+
variables ~= var;
355+
}
356+
357+
// copy data to parameters
358+
output ~= format("
359+
for i = 1, %d do
360+
mem[vsp + (i - 1)] = mem[(dsp - %d) + (i - 1)]
361+
end
362+
", paramSize, paramSize);
363+
}
364+
329365
foreach (ref inode ; node.nodes) {
330366
compiler.CompileNode(inode);
331367
}

0 commit comments

Comments
 (0)