@@ -18,6 +18,11 @@ export class CaseInfo {
18
18
}
19
19
}
20
20
21
+ export const enum ErasedUnion {
22
+ Default ,
23
+ WithTag
24
+ }
25
+
21
26
export type EnumCase = [ string , number ] ;
22
27
23
28
export class MethodInfo {
@@ -32,13 +37,21 @@ export class MethodInfo {
32
37
export class TypeInfo implements IEquatable < TypeInfo > {
33
38
constructor (
34
39
public fullname : string ,
35
- public generics ?: TypeInfo [ ] ,
36
- public construct ?: Constructor ,
37
- public parent ?: TypeInfo ,
38
- public fields ?: ( ) => FieldInfo [ ] ,
39
- public cases ?: ( ) => CaseInfo [ ] ,
40
- public enumCases ?: EnumCase [ ] ) {
41
- }
40
+ private info ?: {
41
+ generics ?: TypeInfo [ ] ,
42
+ construct ?: Constructor ,
43
+ parent ?: TypeInfo ,
44
+ fields ?: ( ) => FieldInfo [ ] ,
45
+ cases ?: ( ) => CaseInfo [ ] ,
46
+ enumCases ?: EnumCase [ ] ,
47
+ }
48
+ ) { }
49
+ public get generics ( ) { return this . info ?. generics ; }
50
+ public get construct ( ) { return this . info ?. construct ; }
51
+ public get parent ( ) { return this . info ?. parent ; }
52
+ public get fields ( ) { return this . info ?. fields ; }
53
+ public get cases ( ) { return this . info ?. cases ; }
54
+ public get enumCases ( ) { return this . info ?. enumCases ; }
42
55
public toString ( ) {
43
56
return fullName ( this ) ;
44
57
}
@@ -83,59 +96,74 @@ export function class_type(
83
96
generics ?: TypeInfo [ ] ,
84
97
construct ?: Constructor ,
85
98
parent ?: TypeInfo ) : TypeInfo {
86
- return new TypeInfo ( fullname , generics , construct , parent ) ;
99
+ return new TypeInfo ( fullname , { generics, construct, parent } ) ;
87
100
}
88
101
89
102
export function record_type (
90
103
fullname : string ,
91
104
generics : TypeInfo [ ] ,
92
105
construct : Constructor ,
93
106
fields : ( ) => FieldInfo [ ] ) : TypeInfo {
94
- return new TypeInfo ( fullname , generics , construct , undefined , fields ) ;
107
+ return new TypeInfo ( fullname , { generics, construct, fields } ) ;
95
108
}
96
109
97
110
export function anonRecord_type ( ...fields : FieldInfo [ ] ) : TypeInfo {
98
- return new TypeInfo ( "" , undefined , undefined , undefined , ( ) => fields ) ;
111
+ return new TypeInfo ( "" , { fields : ( ) => fields } ) ;
99
112
}
100
113
101
114
export function union_type (
102
115
fullname : string ,
103
116
generics : TypeInfo [ ] ,
104
117
construct : Constructor ,
105
118
cases : ( ) => FieldInfo [ ] [ ] ) : TypeInfo {
106
- const t : TypeInfo = new TypeInfo ( fullname , generics , construct , undefined , undefined , ( ) => {
107
- const caseNames = construct . prototype . cases ( ) as string [ ] ;
108
- return cases ( ) . map ( ( fields , i ) => new CaseInfo ( t , i , caseNames [ i ] , fields ) )
119
+ const t : TypeInfo = new TypeInfo ( fullname , {
120
+ generics,
121
+ construct,
122
+ cases ( ) {
123
+ const caseNames = construct . prototype . cases ( ) as string [ ] ;
124
+ return cases ( ) . map ( ( fields , i ) => new CaseInfo ( t , i , caseNames [ i ] , fields ) )
125
+ }
109
126
} ) ;
110
127
return t ;
111
128
}
112
129
113
130
export function tuple_type ( ...generics : TypeInfo [ ] ) : TypeInfo {
114
- return new TypeInfo ( "System.Tuple`" + generics . length , generics ) ;
131
+ return new TypeInfo ( "System.Tuple`" + generics . length , { generics } ) ;
115
132
}
116
133
117
134
export function delegate_type ( ...generics : TypeInfo [ ] ) : TypeInfo {
118
- return new TypeInfo ( "System.Func`" + generics . length , generics ) ;
135
+ return new TypeInfo ( "System.Func`" + generics . length , { generics } ) ;
119
136
}
120
137
121
138
export function lambda_type ( argType : TypeInfo , returnType : TypeInfo ) : TypeInfo {
122
- return new TypeInfo ( "Microsoft.FSharp.Core.FSharpFunc`2" , [ argType , returnType ] ) ;
139
+ return new TypeInfo ( "Microsoft.FSharp.Core.FSharpFunc`2" , {
140
+ generics : [ argType , returnType ]
141
+ } ) ;
123
142
}
124
143
125
144
export function option_type ( generic : TypeInfo ) : TypeInfo {
126
- return new TypeInfo ( "Microsoft.FSharp.Core.FSharpOption`1" , [ generic ] ) ;
145
+ return new TypeInfo ( "Microsoft.FSharp.Core.FSharpOption`1" , {
146
+ generics : [ generic ]
147
+ } ) ;
127
148
}
128
149
129
150
export function list_type ( generic : TypeInfo ) : TypeInfo {
130
- return new TypeInfo ( "Microsoft.FSharp.Collections.FSharpList`1" , [ generic ] ) ;
151
+ return new TypeInfo ( "Microsoft.FSharp.Collections.FSharpList`1" , {
152
+ generics : [ generic ]
153
+ } ) ;
131
154
}
132
155
133
156
export function array_type ( generic : TypeInfo ) : TypeInfo {
134
- return new TypeInfo ( "[]" , [ generic ] ) ;
157
+ return new TypeInfo ( "[]" , {
158
+ generics : [ generic ]
159
+ } ) ;
135
160
}
136
161
137
162
export function enum_type ( fullname : string , underlyingType : TypeInfo , enumCases : EnumCase [ ] ) : TypeInfo {
138
- return new TypeInfo ( fullname , [ underlyingType ] , undefined , undefined , undefined , undefined , enumCases ) ;
163
+ return new TypeInfo ( fullname , {
164
+ generics : [ underlyingType ] ,
165
+ enumCases
166
+ } ) ;
139
167
}
140
168
141
169
export function measure_type ( fullname : string ) : TypeInfo {
@@ -262,7 +290,9 @@ export function isInstanceOfType(t: TypeInfo, o: any) {
262
290
* but it should be enough for type comparison purposes
263
291
*/
264
292
export function getGenericTypeDefinition ( t : TypeInfo ) {
265
- return t . generics == null ? t : new TypeInfo ( t . fullname , t . generics . map ( ( ) => obj_type ) ) ;
293
+ return t . generics == null ? t : new TypeInfo ( t . fullname , {
294
+ generics : t . generics . map ( ( ) => obj_type )
295
+ } ) ;
266
296
}
267
297
268
298
export function getEnumUnderlyingType ( t : TypeInfo ) {
@@ -452,12 +482,13 @@ export function makeTuple(values: any[], _t: TypeInfo): any {
452
482
453
483
export function makeGenericType ( t : TypeInfo , generics : TypeInfo [ ] ) : TypeInfo {
454
484
return new TypeInfo (
455
- t . fullname ,
456
- generics ,
457
- t . construct ,
458
- t . parent ,
459
- t . fields ,
460
- t . cases ) ;
485
+ t . fullname , {
486
+ generics,
487
+ construct : t . construct ,
488
+ parent : t . parent ,
489
+ fields : t . fields ,
490
+ cases : t . cases
491
+ } ) ;
461
492
}
462
493
463
494
export function createInstance ( t : TypeInfo , consArgs ?: any [ ] ) : any {
0 commit comments