@@ -18,6 +18,11 @@ export class CaseInfo {
1818 }
1919}
2020
21+ export const enum ErasedUnion {
22+ Default ,
23+ WithTag
24+ }
25+
2126export type EnumCase = [ string , number ] ;
2227
2328export class MethodInfo {
@@ -32,13 +37,21 @@ export class MethodInfo {
3237export class TypeInfo implements IEquatable < TypeInfo > {
3338 constructor (
3439 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 ; }
4255 public toString ( ) {
4356 return fullName ( this ) ;
4457 }
@@ -83,59 +96,74 @@ export function class_type(
8396 generics ?: TypeInfo [ ] ,
8497 construct ?: Constructor ,
8598 parent ?: TypeInfo ) : TypeInfo {
86- return new TypeInfo ( fullname , generics , construct , parent ) ;
99+ return new TypeInfo ( fullname , { generics, construct, parent } ) ;
87100}
88101
89102export function record_type (
90103 fullname : string ,
91104 generics : TypeInfo [ ] ,
92105 construct : Constructor ,
93106 fields : ( ) => FieldInfo [ ] ) : TypeInfo {
94- return new TypeInfo ( fullname , generics , construct , undefined , fields ) ;
107+ return new TypeInfo ( fullname , { generics, construct, fields } ) ;
95108}
96109
97110export function anonRecord_type ( ...fields : FieldInfo [ ] ) : TypeInfo {
98- return new TypeInfo ( "" , undefined , undefined , undefined , ( ) => fields ) ;
111+ return new TypeInfo ( "" , { fields : ( ) => fields } ) ;
99112}
100113
101114export function union_type (
102115 fullname : string ,
103116 generics : TypeInfo [ ] ,
104117 construct : Constructor ,
105118 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+ }
109126 } ) ;
110127 return t ;
111128}
112129
113130export function tuple_type ( ...generics : TypeInfo [ ] ) : TypeInfo {
114- return new TypeInfo ( "System.Tuple`" + generics . length , generics ) ;
131+ return new TypeInfo ( "System.Tuple`" + generics . length , { generics } ) ;
115132}
116133
117134export function delegate_type ( ...generics : TypeInfo [ ] ) : TypeInfo {
118- return new TypeInfo ( "System.Func`" + generics . length , generics ) ;
135+ return new TypeInfo ( "System.Func`" + generics . length , { generics } ) ;
119136}
120137
121138export 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+ } ) ;
123142}
124143
125144export 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+ } ) ;
127148}
128149
129150export 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+ } ) ;
131154}
132155
133156export function array_type ( generic : TypeInfo ) : TypeInfo {
134- return new TypeInfo ( "[]" , [ generic ] ) ;
157+ return new TypeInfo ( "[]" , {
158+ generics : [ generic ]
159+ } ) ;
135160}
136161
137162export 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+ } ) ;
139167}
140168
141169export function measure_type ( fullname : string ) : TypeInfo {
@@ -262,7 +290,9 @@ export function isInstanceOfType(t: TypeInfo, o: any) {
262290 * but it should be enough for type comparison purposes
263291 */
264292export 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+ } ) ;
266296}
267297
268298export function getEnumUnderlyingType ( t : TypeInfo ) {
@@ -452,12 +482,13 @@ export function makeTuple(values: any[], _t: TypeInfo): any {
452482
453483export function makeGenericType ( t : TypeInfo , generics : TypeInfo [ ] ) : TypeInfo {
454484 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+ } ) ;
461492}
462493
463494export function createInstance ( t : TypeInfo , consArgs ?: any [ ] ) : any {
0 commit comments