@@ -40,7 +40,7 @@ struct TargetPointer
40
40
struct TargetNInt
41
41
{
42
42
public long Value ;
43
- // Add a full set of operators to support arithmetic as well as casting to/from TargetPointer
43
+ // Add a full set of operators to support arithmetic as well as casting to/from TargetPointer
44
44
}
45
45
46
46
struct TargetNUInt
@@ -72,109 +72,53 @@ struct FieldLayout
72
72
public FieldType Type ;
73
73
}
74
74
75
- interface IAlgorithmContract
76
- {
77
- void Init ( ) ;
78
- }
79
-
80
75
interface IContract
81
76
{
82
77
string Name { get ; }
83
78
uint Version { get ; }
84
79
}
85
- class Target
80
+
81
+ class Target
86
82
{
87
83
// Users of the data contract may adjust this number to force re-reading of all data
88
84
public int CurrentEpoch = 0 ;
89
85
90
- sbyte ReadInt8 ( TargetPointer pointer ) ;
91
- byte ReadUInt8 ( TargetPointer pointer ) ;
92
- short ReadInt16 ( TargetPointer pointer ) ;
93
- ushort ReadUInt16 ( TargetPointer pointer ) ;
94
- int ReadInt32 ( TargetPointer pointer ) ;
95
- uint ReadUInt32 ( TargetPointer pointer ) ;
96
- long ReadInt64 ( TargetPointer pointer ) ;
97
- ulong ReadUInt64 ( TargetPointer pointer ) ;
98
- TargetPointer ReadTargetPointer ( TargetPointer pointer ) ;
99
- TargetNInt ReadNInt ( TargetPointer pointer ) ;
100
- TargetNUInt ReadNUint ( TargetPointer pointer ) ;
86
+ public T Read < T > ( ulong address ) where T : unmanaged, IBinaryInteger < T > , IMinMaxValue < T > ;
87
+ TargetPointer ReadPointer ( ulong address ) ;
88
+
101
89
byte [ ] ReadByteArray ( TargetPointer pointer , ulong size ) ;
102
90
void FillByteArray ( TargetPointer pointer , byte [ ] array , ulong size ) ;
103
91
104
- bool TryReadInt8 ( TargetPointer pointer , out sbyte value ) ;
105
- bool TryReadUInt8 ( TargetPointer pointer , out byte value ) ;
106
- bool TryReadInt16 ( TargetPointer pointer , out short value ) ;
107
- bool TryReadUInt16 ( TargetPointer pointer , out ushort value ) ;
108
- bool TryReadInt32 ( TargetPointer pointer , out int value ) ;
109
- bool TryReadUInt32 ( TargetPointer pointer , out uint value ) ;
110
- bool TryReadInt64 ( TargetPointer pointer , out long value ) ;
111
- bool TryReadUInt64 ( TargetPointer pointer , out ulong value ) ;
112
- bool TryReadTargetPointer ( TargetPointer pointer , out TargetPointer value ) ;
113
- bool TryReadNInt ( TargetPointer pointer , out TargetNInt value ) ;
114
- bool TryReadNUInt ( TargetPointer pointer , out TargetNUInt value ) ;
115
- bool TryReadByteArray ( TargetPointer pointer , ulong size , out byte [ ] value ) ;
116
- bool TryFillByteArray ( TargetPointer pointer , byte [ ] array , ulong size ) ;
117
-
118
92
// If pointer is 0, then the return value will be 0
119
93
TargetPointer GetTargetPointerForField ( TargetPointer pointer , FieldLayout fieldLayout ) ;
120
94
121
- sbyte ReadGlobalInt8 ( string globalName ) ;
122
- byte ReadGlobalUInt8 ( string globalName ) ;
123
- short ReadGlobalInt16 ( string globalName ) ;
124
- ushort ReadGlobalUInt16 ( string globalName ) ;
125
- int ReadGlobalInt32 ( string globalName ) ;
126
- uint ReadGlobalUInt32 ( string globalName ) ;
127
- long ReadGlobalInt64 ( string globalName ) ;
128
- ulong ReadGlobalUInt64 ( string globalName ) ;
129
- TargetPointer ReadGlobalTargetPointer ( string globalName ) ;
130
-
131
- bool TryReadGlobalInt8 ( string globalName , out sbyte value ) ;
132
- bool TryReadGlobalUInt8 ( string globalName , out byte value ) ;
133
- bool TryReadGlobalInt16 ( string globalName , out short value ) ;
134
- bool TryReadGlobalUInt16 ( string globalName , out ushort value ) ;
135
- bool TryReadGlobalInt32 ( string globalName , out int value ) ;
136
- bool TryReadGlobalUInt32 ( string globalName , out uint value ) ;
137
- bool TryReadGlobalInt64 ( string globalName , out long value ) ;
138
- bool TryReadGlobalUInt64 ( string globalName , out ulong value ) ;
139
- bool TryReadGlobalTargetPointer ( string globalName , out TargetPointer value ) ;
140
-
141
- Contracts Contract { get ; }
142
-
143
- partial class Contracts
144
- {
145
- FieldLayout GetFieldLayout ( string typeName , string fieldName ) ;
146
- bool TryGetFieldLayout ( string typeName , string fieldName , out FieldLayout layout ) ;
147
- int GetTypeSize ( string typeName ) ;
148
- bool TryGetTypeSize ( string typeName , out int size ) ;
95
+ T ReadGlobal < T > ( string globalName ) where T : unmanaged, IBinaryInteger < T > , IMinMaxValue < T > ;
96
+ TargetPointer ReadGlobalPointer ( string globalName ) ;
149
97
150
- object GetContract ( string contractName ) ;
151
- bool TryGetContract ( string contractName , out object contract ) ;
98
+ Contracts . Registry Contracts { get ; }
99
+ }
152
100
101
+ // Types defined by contracts live here
102
+ namespace Contracts
103
+ {
104
+ class Registry
105
+ {
153
106
// Every contract that is defined has a field here. As an example this document defines a MethodTableContract
154
107
// If the contract is not supported by the runtime in use, then the implementation of the contract will be the base type which
155
108
// is defined to throw if it is ever used.
156
109
157
110
// List of contracts will be inserted here by source generator
158
111
MethodTableContract MethodTableContract ;
159
112
}
160
- }
161
-
162
- // Types defined by contracts live here
163
- namespace ContractDefinitions
164
- {
165
- class CompositeContract
166
- {
167
- List < Tuple < string , uint > > Subcontracts ;
168
- }
169
113
170
114
class DataStructureContract
171
115
{
172
116
string MethodTableName { get ; }
173
117
List < Tuple < string , FieldLayout > > FieldData ;
174
118
}
175
119
176
- // Insert Algorithmic Contract definitions here
177
- class MethodTableContract
120
+ // Insert contract definitions here
121
+ interface MethodTableContract : IContract
178
122
{
179
123
public virtual int DynamicTypeID ( TargetPointer methodTablePointer ) { throw new NotImplementedException ( ) ; }
180
124
public virtual int BaseSize ( TargetPointer methodTablePointer ) { throw new NotImplementedException ( ) ; }
@@ -207,7 +151,7 @@ public class FeatureFlags_2
207
151
}
208
152
209
153
[ DataContractAlgorithm ( 1 ) ]
210
- class MethodTableContract_1 : ContractDefinitions . MethodTableContract , IAlgorithmContract
154
+ readonly struct MethodTableContract_1 : Contracts . MethodTableContract
211
155
{
212
156
DataContracts . Target Target ;
213
157
readonly uint ContractVersion ;
@@ -219,7 +163,7 @@ class MethodTableContract_1 : ContractDefinitions.MethodTableContract, IAlgorith
219
163
220
164
// This is used for version 2 and 3 of the contract, where the dynamic type id is no longer present, and baseSize has a new limitation in that it can only be a value up to 0x1FFFFFFF in v3
221
165
[ DataContractAlgorithm ( 2 , 3 ) ]
222
- class MethodTableContract_2 : ContractDefinitions . MethodTableContract , IAlgorithmContract
166
+ readonly struct MethodTableContract_2 : Contracts . MethodTableContract
223
167
{
224
168
DataContracts . Target Target ;
225
169
readonly uint ContractVersion ;
0 commit comments