Browse Source

Run formatter

AnnulusGames 11 months ago
parent
commit
c4d560fd4b
2 changed files with 13 additions and 17 deletions
  1. 5 5
      src/Lua/CodeAnalysis/Compilation/LuaCompiler.cs
  2. 8 12
      src/Lua/Runtime/Closure.cs

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

@@ -274,7 +274,7 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
                                     break;
                             }
 
-                            context.PushInstruction(Instruction.SetList(tableRegisterIndex, (ushort)(isFixedItems ? context.StackTopPosition - tableRegisterIndex: 0), arrayBlock), listItem.Position);
+                            context.PushInstruction(Instruction.SetList(tableRegisterIndex, (ushort)(isFixedItems ? context.StackTopPosition - tableRegisterIndex : 0), arrayBlock), listItem.Position);
                             currentArrayChunkSize = 0;
                         }
                         else
@@ -638,7 +638,7 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
         // assign global variable
         var first = node.MemberPath[0];
         var tableIndex = GetOrLoadIdentifier(first.Name, context, first.Position, true);
-        
+
         for (int i = 1; i < node.MemberPath.Length - 1; i++)
         {
             var member = node.MemberPath[i];
@@ -753,7 +753,7 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
                 childNode.Accept(this, scopeContext);
             }
 
-            stackPositionToClose =scopeContext.HasCapturedLocalVariables ? stackPositionToClose: (byte)0;
+            stackPositionToClose = scopeContext.HasCapturedLocalVariables ? stackPositionToClose : (byte)0;
             if (hasElse)
             {
                 endJumpIndexList.Add(scopeContext.Function.Instructions.Length);
@@ -782,7 +782,7 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
                 childNode.Accept(this, scopeContext);
             }
 
-            stackPositionToClose =scopeContext.HasCapturedLocalVariables ? stackPositionToClose: (byte)0;
+            stackPositionToClose = scopeContext.HasCapturedLocalVariables ? stackPositionToClose : (byte)0;
             // skip if node doesn't have else statements
             if (hasElse)
             {
@@ -813,7 +813,7 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
         {
             context.Function.Instructions[index].SBx = context.Function.Instructions.Length - 1 - index;
         }
-        
+
         return true;
     }
 

+ 8 - 12
src/Lua/Runtime/Closure.cs

@@ -17,11 +17,11 @@ public sealed class Closure : LuaFunction
         for (int i = 0; i < proto.UpValues.Length; i++)
         {
             var description = proto.UpValues[i];
-            var upValue = GetUpValueFromDescription(state, state.CurrentThread,environment == null ? state.EnvUpValue : UpValue.Closed(environment), description);
+            var upValue = GetUpValueFromDescription(state, state.CurrentThread, environment == null ? state.EnvUpValue : UpValue.Closed(environment), description);
             upValues.Add(upValue);
         }
     }
-    
+
     public Chunk Proto => proto;
     public ReadOnlySpan<UpValue> UpValues => upValues.AsSpan();
 
@@ -37,25 +37,21 @@ public sealed class Closure : LuaFunction
         upValues[index].SetValue(value);
     }
 
-    static UpValue GetUpValueFromDescription(LuaState state, LuaThread thread,UpValue envUpValue,  UpValueInfo description)
+    static UpValue GetUpValueFromDescription(LuaState state, LuaThread thread, UpValue envUpValue, UpValueInfo description)
     {
-        
         if (description.IsInRegister)
         {
-            return state.GetOrAddUpValue(thread, thread.GetCallStackFrames()[^1].Base+ description.Index);
-            
+            return state.GetOrAddUpValue(thread, thread.GetCallStackFrames()[^1].Base + description.Index);
         }
         if (description.Index == -1) // -1 is global environment
         {
             return envUpValue;
         }
+        if (thread.GetCallStackFrames()[^1].Function is Closure parentClosure)
         {
-            if (thread.GetCallStackFrames()[^1].Function is Closure parentClosure)
-            {
-                return parentClosure.UpValues[description.Index];
-            }
-
-            throw new Exception();
+            return parentClosure.UpValues[description.Index];
         }
+
+        throw new Exception();
     }
 }