forked from OpenDreamProject/OpenDream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DreamReference.cs
48 lines (37 loc) · 1.69 KB
/
DreamReference.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
using DMRefType = DMCompiler.Bytecode.DMReference.Type;
namespace OpenDreamRuntime;
public struct DreamReference {
public static readonly DreamReference Src = new(DMRefType.Src, 0);
public static readonly DreamReference Self = new(DMRefType.Self, 0);
public static readonly DreamReference Usr = new(DMRefType.Usr, 0);
public static readonly DreamReference Args = new(DMRefType.Args, 0);
public static readonly DreamReference SuperProc = new(DMRefType.SuperProc, 0);
public static readonly DreamReference ListIndex = new(DMRefType.ListIndex, 0);
private long _innerValue;
public DMRefType Type => (DMRefType)(_innerValue >> 32);
public int Value => (int)_innerValue;
public DreamReference(DMRefType type, int value) {
_innerValue = ((long)type << 32) | (uint)value;
}
public static DreamReference CreateArgument(int index) {
return new DreamReference(DMRefType.Argument, index);
}
public static DreamReference CreateLocal(int index) {
return new DreamReference(DMRefType.Local, index);
}
public static DreamReference CreateGlobal(int index) {
return new DreamReference(DMRefType.Global, index);
}
public static DreamReference CreateGlobalProc(int index) {
return new DreamReference(DMRefType.GlobalProc, index);
}
public static DreamReference CreateField(int nameId) {
return new DreamReference(DMRefType.Field, nameId);
}
public static DreamReference CreateSrcField(int nameId) {
return new DreamReference(DMRefType.SrcField, nameId);
}
public static DreamReference CreateSrcProc(int nameId) {
return new DreamReference(DMRefType.SrcProc, nameId);
}
}