Browse Source

Run formatter

AnnulusGames 11 months ago
parent
commit
24cfa9c63c

+ 1 - 1
src/Lua/CodeAnalysis/Compilation/FunctionCompilationContext.cs

@@ -64,7 +64,7 @@ public class FunctionCompilationContext : IDisposable
     // loop
     FastListCore<BreakDescription> breakQueue;
     FastListCore<GotoDescription> gotoQueue;
-    
+
     /// <summary>
     /// Maximum local stack size
     /// </summary>

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

@@ -615,8 +615,8 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
 
         // push closure instruction
         context.PushInstruction(Instruction.Closure(context.StackPosition, funcIndex), node.Position, true);
-        
-        if(context.TryGetLocalVariableInThisScope(node.Name, out var variable))
+
+        if (context.TryGetLocalVariableInThisScope(node.Name, out var variable))
         {
             // assign local variable
             context.PushInstruction(Instruction.Move(variable.RegisterIndex, (ushort)(context.StackPosition - 1)), node.Position, true);
@@ -626,7 +626,7 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
             // assign global variable
             context.PushInstruction(Instruction.SetTabUp(0, (ushort)(index + 256), (ushort)(context.StackPosition - 1)), node.Position);
         }
-        
+
         return true;
     }
 
@@ -643,7 +643,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];

+ 1 - 1
src/Lua/Internal/LuaValueArrayPool.cs

@@ -34,7 +34,7 @@ internal static class LuaValueArrayPool
         }
     }
 
-    public static void Return1024(LuaValue[] array,bool clear=false)
+    public static void Return1024(LuaValue[] array, bool clear = false)
     {
         if (array.Length != 1024)
         {

+ 8 - 8
src/Lua/Internal/LuaValueDictionary.cs

@@ -82,7 +82,7 @@ namespace Lua.Internal
         public bool ContainsValue(LuaValue value)
         {
             Entry[]? entries = _entries;
-            
+
             for (int i = 0; i < _count; i++)
             {
                 if (entries![i].next >= -1 && entries[i].value.Equals(value))
@@ -139,13 +139,13 @@ namespace Lua.Internal
 
             goto ReturnNotFound;
 
-            ConcurrentOperation:
+        ConcurrentOperation:
             ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
-            ReturnFound:
+        ReturnFound:
             ref LuaValue value = ref entry.value;
-            Return:
+        Return:
             return ref value;
-            ReturnNotFound:
+        ReturnNotFound:
             value = ref Unsafe.NullRef<LuaValue>();
             goto Return;
         }
@@ -174,8 +174,8 @@ namespace Lua.Internal
             {
                 _nilCount++;
             }
-            
-            if(_buckets == null)
+
+            if (_buckets == null)
             {
                 Initialize(0);
             }
@@ -191,7 +191,7 @@ namespace Lua.Internal
             uint collisionCount = 0;
             ref int bucket = ref GetBucket(hashCode);
             int i = bucket - 1; // Value in _buckets is 1-based
-            
+
             {
                 ref Entry entry = ref Unsafe.NullRef<Entry>();
                 while ((uint)i < (uint)entries.Length)

+ 1 - 1
src/Lua/LuaCoroutine.cs

@@ -243,7 +243,7 @@ public sealed class LuaCoroutine : LuaThread, IValueTaskSource<LuaCoroutine.Yiel
             }, this);
         }
 
-        RETRY:
+    RETRY:
         try
         {
             var result = await new ValueTask<YieldContext>(this, yield.Version);

+ 1 - 1
src/Lua/LuaFunctionExecutionContext.cs

@@ -14,7 +14,7 @@ public readonly record struct LuaFunctionExecutionContext
     public SourcePosition? SourcePosition { get; init; }
     public string? RootChunkName { get; init; }
     public string? ChunkName { get; init; }
-    public  int? CallerInstructionIndex { get; init; }
+    public int? CallerInstructionIndex { get; init; }
     public object? AdditionalContext { get; init; }
 
     public ReadOnlySpan<LuaValue> Arguments

+ 0 - 1
src/Lua/LuaFunctionExtensions.cs

@@ -4,7 +4,6 @@ namespace Lua;
 
 public static class LuaFunctionExtensions
 {
-
     public static async ValueTask<LuaValue[]> InvokeAsync(this LuaFunction function, LuaState state, LuaValue[] arguments, CancellationToken cancellationToken = default)
     {
         using var buffer = new PooledArray<LuaValue>(1024);

+ 2 - 2
src/Lua/LuaState.cs

@@ -88,7 +88,7 @@ public sealed class LuaState
 
     public Traceback GetTraceback()
     {
-        if(threadStack.Count==0)
+        if (threadStack.Count == 0)
         {
             return new()
             {
@@ -105,7 +105,7 @@ public sealed class LuaState
         }
         foreach (var thread in threadStack.AsSpan())
         {
-            if(thread.CallStack.Count==0) continue;
+            if (thread.CallStack.Count == 0) continue;
             foreach (var frame in thread.GetCallStackFrames()[1..])
             {
                 list.Add(frame);

+ 0 - 1
src/Lua/LuaThread.cs

@@ -38,7 +38,6 @@ public abstract class LuaThread
         callStack.Push(frame);
     }
 
-
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     internal void PopCallStackFrame()
     {

+ 12 - 12
src/Lua/LuaValue.cs

@@ -329,24 +329,24 @@ public readonly struct LuaValue : IEquatable<LuaValue>
         switch (Type)
         {
             case LuaValueType.Boolean:
-            {
-                var v = value != 0;
-                return Unsafe.As<bool, T>(ref v);
-            }
+                {
+                    var v = value != 0;
+                    return Unsafe.As<bool, T>(ref v);
+                }
             case LuaValueType.Number:
-            {
-                var v = value;
-                return Unsafe.As<double, T>(ref v);
-            }
+                {
+                    var v = value;
+                    return Unsafe.As<double, T>(ref v);
+                }
             case LuaValueType.String:
             case LuaValueType.Thread:
             case LuaValueType.Function:
             case LuaValueType.Table:
             case LuaValueType.UserData:
-            {
-                var v = referenceValue!;
-                return Unsafe.As<object, T>(ref v);
-            }
+                {
+                    var v = referenceValue!;
+                    return Unsafe.As<object, T>(ref v);
+                }
         }
 
         return default!;

+ 0 - 1
src/Lua/Runtime/CallStackFrame.cs

@@ -1,5 +1,4 @@
 using System.Runtime.InteropServices;
-using Lua.CodeAnalysis;
 
 namespace Lua.Runtime;
 

+ 1 - 1
src/Lua/Runtime/Instruction.cs

@@ -23,7 +23,7 @@ public struct Instruction : IEquatable<Instruction>
     public byte A
     {
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        get => (byte)((_value >> 6) ); // 8 bits
+        get => (byte)((_value >> 6)); // 8 bits
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         set => _value = (_value & 0xFFFFC03F) | (((uint)value & 0xFF) << 6);
     }

+ 18 - 24
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -54,7 +54,7 @@ public static partial class LuaVirtualMachine
         public bool PopFromBuffer(Span<LuaValue> result)
         {
             ref var callStack = ref Thread.CallStack;
-            Re:
+        Re:
             var frames = callStack.AsSpan();
             if (frames.Length == BaseCallStackCount) return false;
             ref readonly var frame = ref frames[^1];
@@ -93,15 +93,15 @@ public static partial class LuaVirtualMachine
             switch (opCode)
             {
                 case OpCode.Call:
-                {
-                    var c = callInstruction.C;
-                    if (c != 0)
                     {
-                        targetCount = c - 1;
-                    }
+                        var c = callInstruction.C;
+                        if (c != 0)
+                        {
+                            targetCount = c - 1;
+                        }
 
-                    break;
-                }
+                        break;
+                    }
                 case OpCode.TForCall:
                     target += 3;
                     targetCount = callInstruction.C;
@@ -201,10 +201,8 @@ public static partial class LuaVirtualMachine
         Compare,
     }
 
-
     [AsyncStateMachine(typeof(AsyncStateMachine))]
-    internal static ValueTask<int> ExecuteClosureAsync(LuaState luaState, Memory<LuaValue> buffer,
-        CancellationToken cancellationToken)
+    internal static ValueTask<int> ExecuteClosureAsync(LuaState luaState, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
         var thread = luaState.CurrentThread;
         ref readonly var frame = ref thread.GetCallStackFrames()[^1];
@@ -230,10 +228,10 @@ public static partial class LuaVirtualMachine
         {
             Running = 0,
 
-            //Await is the state where the task is awaited
+            // Await is the state where the task is awaited
             Await,
 
-            //End is the state where the function is done
+            // End is the state where the function is done
             End
         }
 
@@ -247,7 +245,7 @@ public static partial class LuaVirtualMachine
 #endif
         public void MoveNext()
         {
-            //If the state is end, the function is done, so set the result and return. I think this state is not reachable in this implementation
+            // If the state is end, the function is done, so set the result and return. I think this state is not reachable in this implementation
             if (state == State.End)
             {
                 Builder.SetResult(Context.ResultCount);
@@ -305,8 +303,8 @@ public static partial class LuaVirtualMachine
                     state = State.Running;
                 }
 
-                //This is a label to restart the execution when new function is called or restarted
-                Restart:
+            // This is a label to restart the execution when new function is called or restarted
+            Restart:
 
                 ref var instructionsHead = ref context.Chunk.Instructions[0];
                 var frameBase = context.FrameBase;
@@ -989,14 +987,13 @@ public static partial class LuaVirtualMachine
                     }
                 }
 
-                Await:
-                //Set the state to await and return with setting this method as the task's continuation
+            Await:
+                // Set the state to await and return with setting this method as the task's continuation
                 state = State.Await;
                 Builder.AwaitOnCompleted(ref context.Awaiter, ref this);
                 return;
 
-
-                End:
+            End:
                 state = State.End;
                 LuaValueArrayPool.Return1024(context.ResultsBuffer);
                 Builder.SetResult(context.ResultCount);
@@ -1034,7 +1031,6 @@ public static partial class LuaVirtualMachine
         }
     }
 
-
     static void SelfPostOperation(ref VirtualMachineExecutionContext context)
     {
         var stack = context.Stack;
@@ -1103,7 +1099,6 @@ public static partial class LuaVirtualMachine
             }
         }
 
-
         var thread = context.Thread;
         var (newBase, argumentCount, variableArgumentCount) = PrepareForFunctionCall(thread, func, instruction, RA);
 
@@ -1595,14 +1590,13 @@ public static partial class LuaVirtualMachine
         return true;
     }
 
-
     [MethodImpl(MethodImplOptions.NoInlining)]
     static bool ExecuteCompareOperationMetaMethod(LuaValue vb, LuaValue vc,
         ref VirtualMachineExecutionContext context, string name, string? description, out bool doRestart)
     {
         doRestart = false;
         bool reverseLe = false;
-        ReCheck:
+    ReCheck:
         if (vb.TryGetMetamethod(context.State, name, out var metamethod) ||
             vc.TryGetMetamethod(context.State, name, out metamethod))
         {