Browse Source

Fix: compiler

AnnulusGames 1 year ago
parent
commit
61fddc61b5

+ 5 - 4
src/Lua/CodeAnalysis/Compilation/LuaCompiler.cs

@@ -637,6 +637,8 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
             {
             {
                 RegisterIndex = 0,
                 RegisterIndex = 0,
             });
             });
+
+            funcContext.Scope.StackPosition++;
         }
         }
 
 
         // add arguments
         // add arguments
@@ -647,9 +649,9 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
             {
             {
                 RegisterIndex = (byte)(i + (hasSelfParameter ? 1 : 0)),
                 RegisterIndex = (byte)(i + (hasSelfParameter ? 1 : 0)),
             });
             });
-        }
 
 
-        funcContext.Scope.StackPosition = (byte)parameters.Length;
+            funcContext.Scope.StackPosition++;
+        }
 
 
         foreach (var statement in statements)
         foreach (var statement in statements)
         {
         {
@@ -1078,9 +1080,8 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
         for (int i = 0; i < expressions.Length; i++)
         for (int i = 0; i < expressions.Length; i++)
         {
         {
             var expression = expressions[i];
             var expression = expressions[i];
-            var remaining = expressions.Length - i + 1;
             var isLast = i == expressions.Length - 1;
             var isLast = i == expressions.Length - 1;
-            var resultCount = isLast ? (minimumCount == -1 ? -1 : remaining) : 1;
+            var resultCount = isLast ? (minimumCount == -1 ? -1 : minimumCount - i) : 1;
 
 
             if (expression is CallFunctionExpressionNode call)
             if (expression is CallFunctionExpressionNode call)
             {
             {

+ 1 - 1
tests/Lua.Tests/tests-lua/vararg.lua

@@ -74,7 +74,7 @@ print("+")
 
 
 function oneless (a, ...) return ... end
 function oneless (a, ...) return ... end
 
 
-function f (n, a, ...)
+function f(n, a, ...)
   local b
   local b
   assert(arg == nil)
   assert(arg == nil)
   if n == 0 then
   if n == 0 then