Browse Source

Refactor: Change closure check by property to `is`

Akeit0 11 months ago
parent
commit
e625bf5638
3 changed files with 8 additions and 16 deletions
  1. 0 6
      src/Lua/LuaFunction.cs
  2. 0 2
      src/Lua/Runtime/Closure.cs
  3. 8 8
      src/Lua/Runtime/LuaVirtualMachine.cs

+ 0 - 6
src/Lua/LuaFunction.cs

@@ -8,12 +8,6 @@ public class LuaFunction(string name, Func<LuaFunctionExecutionContext, Memory<L
     public string Name { get; } = name;
     public string Name { get; } = name;
     internal Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> Func { get; } = func;
     internal Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> Func { get; } = func;
 
 
-    internal bool IsClosure
-    {
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        get; private protected init;
-    } = false;
-
     public LuaFunction(Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> func) : this("anonymous", func)
     public LuaFunction(Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> func) : this("anonymous", func)
     {
     {
     }
     }

+ 0 - 2
src/Lua/Runtime/Closure.cs

@@ -20,8 +20,6 @@ public sealed class Closure : LuaFunction
             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);
             upValues.Add(upValue);
         }
         }
-
-        IsClosure = true;
     }
     }
 
 
     public Chunk Proto => proto;
     public Chunk Proto => proto;

+ 8 - 8
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -984,7 +984,7 @@ public static partial class LuaVirtualMachine
                     }
                     }
                 }
                 }
 
 
-            Await:
+                Await:
                 // Set the state to await and return with setting this method as the task's continuation
                 // Set the state to await and return with setting this method as the task's continuation
                 state = State.Await;
                 state = State.Await;
                 Builder.AwaitOnCompleted(ref context.Awaiter, ref this);
                 Builder.AwaitOnCompleted(ref context.Awaiter, ref this);
@@ -1102,7 +1102,7 @@ public static partial class LuaVirtualMachine
         var newFrame = func.CreateNewFrame(ref context, newBase, variableArgumentCount);
         var newFrame = func.CreateNewFrame(ref context, newBase, variableArgumentCount);
 
 
         thread.PushCallStackFrame(newFrame);
         thread.PushCallStackFrame(newFrame);
-        if (func.IsClosure)
+        if (func is Closure)
         {
         {
             context.Push(newFrame);
             context.Push(newFrame);
             doRestart = true;
             doRestart = true;
@@ -1274,7 +1274,7 @@ public static partial class LuaVirtualMachine
         stack.NotifyTop(newBase + 2);
         stack.NotifyTop(newBase + 2);
         var newFrame = iterator.CreateNewFrame(ref context, newBase);
         var newFrame = iterator.CreateNewFrame(ref context, newBase);
         context.Thread.PushCallStackFrame(newFrame);
         context.Thread.PushCallStackFrame(newFrame);
-        if (iterator.IsClosure)
+        if (iterator is Closure)
         {
         {
             context.Push(newFrame);
             context.Push(newFrame);
             doRestart = true;
             doRestart = true;
@@ -1384,7 +1384,7 @@ public static partial class LuaVirtualMachine
 
 
             context.Thread.PushCallStackFrame(newFrame);
             context.Thread.PushCallStackFrame(newFrame);
 
 
-            if (indexTable.IsClosure)
+            if (indexTable is Closure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;
@@ -1460,7 +1460,7 @@ public static partial class LuaVirtualMachine
 
 
             context.Thread.PushCallStackFrame(newFrame);
             context.Thread.PushCallStackFrame(newFrame);
 
 
-            if (indexTable.IsClosure)
+            if (indexTable is Closure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;
@@ -1504,7 +1504,7 @@ public static partial class LuaVirtualMachine
 
 
             context.Thread.PushCallStackFrame(newFrame);
             context.Thread.PushCallStackFrame(newFrame);
 
 
-            if (func.IsClosure)
+            if (func is Closure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;
@@ -1550,7 +1550,7 @@ public static partial class LuaVirtualMachine
 
 
             context.Thread.PushCallStackFrame(newFrame);
             context.Thread.PushCallStackFrame(newFrame);
 
 
-            if (func.IsClosure)
+            if (func is Closure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;
@@ -1607,7 +1607,7 @@ public static partial class LuaVirtualMachine
             if (reverseLe) newFrame.Flags |= CallStackFrameFlags.ReversedLe;
             if (reverseLe) newFrame.Flags |= CallStackFrameFlags.ReversedLe;
             context.Thread.PushCallStackFrame(newFrame);
             context.Thread.PushCallStackFrame(newFrame);
 
 
-            if (func.IsClosure)
+            if (func is Closure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;