-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackItem.cs
100 lines (81 loc) · 2.41 KB
/
StackItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Quras.VM.Types;
using System;
using System.Linq;
using System.Numerics;
using System.Text;
using Array = Quras.VM.Types.Array;
using Boolean = Quras.VM.Types.Boolean;
namespace Quras.VM
{
public abstract class StackItem : IEquatable<StackItem>
{
public virtual bool IsArray => false;
public virtual bool IsStruct => false;
public abstract bool Equals(StackItem other);
public static StackItem FromInterface(IInteropInterface value)
{
return new InteropInterface(value);
}
public virtual StackItem[] GetArray()
{
throw new NotSupportedException();
}
public virtual BigInteger GetBigInteger()
{
return new BigInteger(GetByteArray());
}
public virtual bool GetBoolean()
{
return GetByteArray().Any(p => p != 0);
}
public virtual byte GetByte()
{
return Byte.Parse(new BigInteger(GetByteArray()).ToString());
}
public abstract byte[] GetByteArray();
public virtual T GetInterface<T>() where T : class, IInteropInterface
{
throw new NotSupportedException();
}
public virtual string GetString()
{
return Encoding.UTF8.GetString(GetByteArray());
}
public static implicit operator StackItem(int value)
{
return (BigInteger)value;
}
public static implicit operator StackItem(uint value)
{
return (BigInteger)value;
}
public static implicit operator StackItem(long value)
{
return (BigInteger)value;
}
public static implicit operator StackItem(ulong value)
{
return (BigInteger)value;
}
public static implicit operator StackItem(BigInteger value)
{
return new Integer(value);
}
public static implicit operator StackItem(bool value)
{
return new Boolean(value);
}
public static implicit operator StackItem(byte[] value)
{
return new ByteArray(value);
}
public static implicit operator StackItem(StackItem[] value)
{
return new Array(value);
}
public static implicit operator StackItem(byte value)
{
return new BigInteger(value);
}
}
}