forked from iskiselev/JSIL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackedArray.cs
More file actions
95 lines (83 loc) · 2.85 KB
/
Copy pathPackedArray.cs
File metadata and controls
95 lines (83 loc) · 2.85 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSIL.Meta;
namespace JSIL.Runtime {
internal class LinkedTypeAttribute : Attribute {
public readonly Type Type;
public LinkedTypeAttribute (Type type) {
Type = type;
}
}
public unsafe interface IPackedArray<T> {
T this[int index] {
[JSRuntimeDispatch]
[JSResultIsNew]
[JSIsPure]
get;
// HACK: value technically escapes, but since the packed array stores its raw values instead of its reference, we don't want it to be copied.
[JSRuntimeDispatch]
[JSEscapingArguments()]
[JSMutatedArguments()]
set;
}
/// <summary>
/// Returns a reference to an element of the packed array.
/// </summary>
[JSRuntimeDispatch]
[JSResultIsNew]
[JSIsPure]
void* GetReference (int index);
/// <summary>
/// Returns a proxy for the particular element of the packed array. You can use the proxy's members to manipulate the packed element directly.
/// </summary>
[JSRuntimeDispatch]
[JSResultIsNew]
[JSIsPure]
T GetItemProxy (int index);
/// <summary>
/// Reads an element out of the packed array, into result.
/// </summary>
[JSEscapingArguments()]
[JSMutatedArguments("result")]
[JSRuntimeDispatch]
void GetItemInto (int index, out T result);
[JSIsPure]
[JSRuntimeDispatch]
int Length { get; }
}
public static class PackedArray {
[JSReplacement("JSIL.PackedArray.New($T, $size)")]
[JSPackedArrayReturnValue]
public static T[] New<T> (int size)
where T : struct
{
return new T[size];
}
}
public static class TypedArrayExtensionMethods {
/// <summary>
/// If the specified array is backed by a typed array, returns its backing array buffer.
/// </summary>
[JSReplacement("JSIL.GetArrayBuffer($array)")]
[JSAllowPackedArrayArguments]
[JSIsPure]
public static dynamic GetArrayBuffer<T> (this T[] array)
where T : struct {
throw new NotImplementedException("Not supported when running as C#");
}
}
public static class PackedArrayExtensionMethods {
/// <summary>
/// If the specified array is a packed array, returns its backing typed array.
/// </summary>
[JSReplacement("JSIL.GetBackingTypedArray($array)")]
[JSAllowPackedArrayArguments]
[JSIsPure]
public static dynamic GetBackingTypedArray<T> (this T[] array)
where T : struct {
throw new NotImplementedException("Not supported when running as C#");
}
}
}