Skip to content

Commit 514514d

Browse files
committed
Optimization
1 parent bec6058 commit 514514d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

VM/VirtualMachine.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ namespace VM
88
{
99
internal unsafe class VirtualMachine
1010
{
11-
public dynamic[] Stack = new dynamic[0];
11+
public object[] Stack = new object[0];
1212
public IntPtr MemoryPointer { get; set; }
1313
public int ImageSize { get; set; }
1414
public int CodeSectionOffset { get; set; }
1515
public int TextSectionOffset { get; set; }
1616
public int CSharpTypesSectionOffset { get; set; }
1717
public int ClearSectionOffset { get; set; }
18-
public dynamic[] GlobalVariables = new dynamic[512];
18+
public object[] GlobalVariables = new object[512];
1919

2020
public VirtualMachine(byte[] b)
2121
{
@@ -30,26 +30,26 @@ public VirtualMachine(byte[] b)
3030
MemoryPointer = IntPtr.Add(MemoryPointer, 24);
3131
}
3232

33-
private dynamic Pop()
33+
private object Pop()
3434
{
3535
if (Stack.Length > 0)
3636
{
37-
dynamic rez = Stack[Stack.Length - 1];
37+
object rez = Stack[Stack.Length - 1];
3838
Array.Resize(ref Stack, Stack.Length - 1);
3939
return rez;
4040
}
4141
return null;
4242
}
4343

44-
public void Push(dynamic val)
44+
public void Push(object val)
4545
{
4646
Array.Resize(ref Stack, Stack.Length + 1);
4747
Stack[Stack.Length - 1] = val;
4848
}
4949

5050
public void Run(int Offset)
5151
{
52-
dynamic[] LocalVariables = new dynamic[512];
52+
object[] LocalVariables = new object[512];
5353
while (true)
5454
{
5555
byte curByte = Marshal.ReadByte(IntPtr.Add(MemoryPointer, CodeSectionOffset + Offset++));
@@ -93,7 +93,7 @@ public void Run(int Offset)
9393
}
9494
case 0x70: //Newarr
9595
{
96-
int length = Pop();
96+
int length = (int)Pop();
9797
byte[] temp = new byte[Marshal.ReadInt32(MemoryPointer, CodeSectionOffset + Offset + 4)];
9898
Marshal.Copy(
9999
IntPtr.Add(MemoryPointer,
@@ -106,17 +106,17 @@ public void Run(int Offset)
106106
}
107107
case 0x71: //Setarr
108108
{
109-
dynamic value = Pop();
110-
dynamic index = Pop();
111-
dynamic arr = Pop();
109+
object value = Pop();
110+
int index = (int)Pop();
111+
object[] arr = (object[])Pop();
112112
arr[index] = value;
113113
Push(arr);
114114
break;
115115
}
116116
case 0x72: //Getarr
117117
{
118-
dynamic index = Pop();
119-
dynamic arr = Pop();
118+
int index = (int)Pop();
119+
object[] arr = (object[])Pop();
120120
Push(arr[index]);
121121
break;
122122
}
@@ -159,7 +159,7 @@ public void Run(int Offset)
159159
string voidname = Encoding.UTF8.GetString(temp);
160160
int argcount = Marshal.ReadInt32(MemoryPointer, CodeSectionOffset + Offset + 16);
161161
Type[] types = new Type[argcount];
162-
dynamic[] arguments = new dynamic[argcount];
162+
object[] arguments = new object[argcount];
163163
for (int i = argcount - 1; i > -1; i--)
164164
{
165165
temp = new byte[Marshal.ReadInt32(MemoryPointer, CodeSectionOffset + Offset + 20 + i * 8)];
@@ -185,7 +185,7 @@ public void Run(int Offset)
185185
}
186186
case 0x42: //CallVirt C# Method
187187
{
188-
dynamic obj = Pop();
188+
object obj = Pop();
189189
Type type = obj.GetType();
190190
byte[] temp = new byte[Marshal.ReadInt32(MemoryPointer, CodeSectionOffset + Offset + 4)];
191191
Marshal.Copy(
@@ -194,7 +194,7 @@ public void Run(int Offset)
194194
string voidname = Encoding.UTF8.GetString(temp);
195195
int argcount = Marshal.ReadInt32(MemoryPointer, CodeSectionOffset + Offset + 8);
196196
Type[] types = new Type[argcount];
197-
dynamic[] arguments = new dynamic[argcount];
197+
object[] arguments = new object[argcount];
198198
for (int i = argcount - 1; i > -1; i--)
199199
{
200200
temp = new byte[Marshal.ReadInt32(MemoryPointer, CodeSectionOffset + Offset + 12 + i * 8)];

0 commit comments

Comments
 (0)